97 unsigned bw,
unsigned bh,
98 unsigned sx,
unsigned sy);
123 unsigned borderH(
void)
const noexcept {
return(borderh_); }
126 unsigned borderW(
void)
const noexcept {
return(borderw_); }
129 unsigned firstH(
void)
const noexcept {
return(borderh_); }
132 unsigned firstW(
void)
const noexcept {
return(borderw_); }
135 unsigned lastH(
void)
const noexcept {
return(lasth_); }
138 unsigned lastW(
void)
const noexcept {
return(lastw_); }
141 unsigned totH(
void)
const noexcept {
return(toth_); }
144 unsigned totW(
void)
const noexcept {
return(totw_); }
147 unsigned winH(
void)
const noexcept {
return(windowh_); }
150 unsigned winW(
void)
const noexcept {
return(windoww_); }
153 unsigned scaleX(
void)
const noexcept {
return(scalex_); }
156 unsigned scaleY(
void)
const noexcept {
return(scaley_); }
166 unsigned scalex_,scaley_;
167 unsigned borderw_,borderh_;
168 unsigned lastw_,lasth_;
169 unsigned totw_,toth_;
170 unsigned windoww_,windowh_;
198 ZXEco & operator=(
ZXEco && disptomove) =
delete;
213 void activate(
const std::string & title,
219 uint8_t * bitmap =
nullptr, uint8_t * attrmap =
nullptr);
248 std::chrono::time_point<std::chrono::steady_clock>
startTime(
void)
noexcept
282 unsigned period = 20,
400 {
return(refreshwhichevents_); }
587 Keyboard
keyboard(std::string * lastprstr =
nullptr);
609 bool waitForKey(Keyboard & kb,
unsigned millis = 20,
bool zxandpc =
false);
630 void waitForNoKey(
unsigned millis = 20,
bool zxandpc =
false);
647 std::string * lastprstr =
nullptr,
648 unsigned millis = 20);
675 double volume(
void)
const noexcept {
return(soundvol_); }
678 void play(
const Beep &b,
bool async =
false);
706 static const unsigned COLBORDERINK_;
710 static uint8_t zxColToPal(BrightColor bc)
noexcept
712 {
return(bc.linear()); }
714 static uint8_t pixelToPalCol(uint8_t pixelval,
715 const AttrColors & cs)
noexcept
716 {
return(zxColToPal({pixelval ? cs.ink().basic() :
718 static_cast<bool>(cs.bright())})); }
722 static void bothPixelPalCols(
const AttrColors & cs,
724 uint8_t & palcolink)
noexcept
726 palcolink = zxColToPal({cs.ink().basic(),
727 static_cast<bool>(cs.bright())});
728 palcolpap = zxColToPal({cs.paper().basic(),
729 static_cast<bool>(cs.bright())});
735 RawGeometry dispinfo_;
736 std::string mywindowtitle_;
744 std::atomic<bool> isrefreshing_;
745 std::atomic<bool> decolour_mode_;
747 std::atomic<bool> isincode_;
752 std::chrono::time_point<std::chrono::steady_clock> t0_;
753 std::mutex winmux_,runcodemux_,keymux_,pointmux_,soundmux_;
755 ZXEco(
void)
noexcept;
757 bool activated(
void)
const noexcept {
return(mywindow_ !=
nullptr); }
758 void deactivate(
void)
noexcept;
759 void checkActivated(
void)
const
761 RUNTIMEEXCEP(
"No screen since the ecosystem is inactive"); }
763 template <
class RECT>
766 dispinfo_.borderW()),
767 static_cast<unsigned>(r.corner.y +
768 dispinfo_.borderH()),
769 static_cast<unsigned>(r.area.width),
770 static_cast<unsigned>(r.area.height)});}
774 bool decolourGridForCursor(
const CharCursor & c)
const;
775 void printAtWindow(uint8_t c,
unsigned x0,
unsigned y0,
776 unsigned inkpalcol = COLBORDERINK_);
777 void printDecolourGuides(
void);
779 bool swapPixels(
bool pass);
781 void zxmapFromKMap(Membrane & m)
const noexcept;
785 {
return( (
static_cast<int>(a) &
static_cast<int>(b)) != 0 ); }
#define RUNTIMEEXCEP(txt)
Raise a runtime exception with the given std::string TXT + additional info.
@ W_CLOSED
The close window event.
KeyID
IDs for the most common keys in a keyboard.
Interface with the functionality that a desktop must provide.
A map of the keyboard, as seen by the desktop.
A palettized window on the desktop.
List of events that occurred in the window, in chronological order.
Events that the window can receive from its desktop environment.
A rectangle on a palettized window.
Class that computes some statistics of a series of values of a given type.
constexpr PixelDist SCREENH
Height in pixels of the original zx screen.
constexpr PixelDist SCREENW
Width in pixels of the original zx screen.
Rect< BorderDistT, BorderDistT > BorderRect
Shortcut for this kind of rectangle.
uint16_t PixelDist
A distance measured in screen pixels.
Rect< CharDistT, CharDistT > CharRect
Shortcut for this kind of rectangle.
Rect< PixelDistT, PixelDistT > PixRect
Shortcut for this kind of rectangle.
Cursor< CharCoordT, CharCoordT > CharCursor
Shortcut for this kind of cursor.
void resetRefreshStats(void)
Reset the statistics of refresh.
RefreshMode
Modes of refreshing while executing user code.
@ NEVER
Don't refresh anything automatically.
@ PERIODIC
Refresh periodical & automatically.
void play(const Beep &b, bool async=false)
Play a beep.
std::string to_string(void) const
Return a textual representation of the object.
const PalettizedWindow::Event::IDSet & refreshWhichEvents(void) const noexcept
< Return a reference to the current set of events that are being recorded
unsigned lastH(void) const noexcept
Return the unscaled y-coord of the bottom-right pixel of drawable.
unsigned firstH(void) const noexcept
Return the unscaled y-coord of the top-left pixel of the drawable.
void forceCapsLock(bool state=true)
Forces a new state for the caps lock by simulating pressing CAPS+2.
bool desktopKeyPressed(DesktopInterface::KeyID k)
Update the internal image of PC keyboard and return TRUE if K pressed.
void windowRefresh(const PixRect &rect=PixRect{})
Command the desktop window to show on the desktop its current content.
double volume(void) const noexcept
Get the current volume of sound.
RefreshMode refreshMode(void) const noexcept
Return the current refresh mode (not thread-safe).
unsigned borderW(void) const noexcept
Return the unscaled width of the left border zone in pixels.
std::function< void(ZXEco &)> UserCode
Prototype for user routines that can be executed while refreshing.
Membrane membrane(void)
Get a copy of the internal membrane after updating PC keyboard.
void close(void)
Deactivate the zx ecosystem.
RefreshType refreshType(void) const noexcept
Return the current refresh type (not thread-safe).
Screen & screen(void) const
If the ecosystem has been activated, return a reference to the screen.
void deactivateDecolourMode(void)
Deactivate the decolour mode and all attrs return to their colours.
unsigned winH(void) const noexcept
Scaled height in pixels of the desktop window of border + drawable.
unsigned lastW(void) const noexcept
Return the unscaled w-coord of the bottom-right pixel of drawable.
Screen::InputCallbacks flatInputCallbacks(void)
Construct and return the callbacks needed for input in the flat model.
RawGeometry(void)=default
Default constructor: invalid data.
unsigned totH(void) const noexcept
Return the unscaled height in pixels of border + drawable.
void windowUpdate(const PixRect &rect=PixRect{})
Commit the given region of the ZX Screen to the desktop window.
unsigned firstW(void) const noexcept
Return the unscaled x-coord of the top-left pixel of the drawable.
void waitForNoKey(unsigned millis=20, bool zxandpc=false)
Wait for no key pressed, sampling the keyboard every MILLIS.
bool decolourModeActive(void) const noexcept
Return TRUE if the decolour mode is currently active.
RawGeometry(const DoubleArea &sizes, unsigned bw, unsigned bh, unsigned sx, unsigned sy)
Constructor from the information provided at ZXEco activation.
const BorderRect & topBorder(void) const noexcept
Return a reference to the unscaled top border rectangle.
void activate(const std::string &title, PixelDist borderwidth, PixelDist borderheight, unsigned scalex=1, unsigned scaley=1, const PixArea &size={SCREENW, SCREENH}, const Screen::ExpandToken &exptok=Screen::kInvExpandToken, uint8_t *bitmap=nullptr, uint8_t *attrmap=nullptr)
Activate the zx ecosystem, opening its window.
bool refreshingScreen(void) const noexcept
Return whether there is a refresh in course or not, right now.
bool inkAndPaperSwappedByFlash(void) const noexcept
Return whether a swapping of paper and ink colors is happening.
unsigned winW(void) const noexcept
Scaled width in pixels of the desktop window of border + drawable.
unsigned totW(void) const noexcept
Return the unscaled width in pixels of border + drawable.
PalettizedWindow & desktopWindow(void)
Return the desktop window used by the managed display methods.
void refreshCode(const UserCode &codetorun, RefreshMode rm=RefreshMode::PERIODIC, RefreshType rt=RefreshType::BOTH, unsigned period=20, const PalettizedWindow::Event::IDSet &whichevents={{PalettizedWindow::Event::ID::W_CLOSED}}, const UserCode &periodiccode=kNullUserCode)
Execute user code once with some refresh mode, type and parameters.
void refresh(RefreshType rt=RefreshType::BOTH, const PalettizedWindow::Event::IDSet &whichevents={true})
Do a refresh of the screen, the window events, or both, manually.
unsigned borderH(void) const noexcept
Return the unscaled height of the top border zone in pixels.
void clearEvents(void) noexcept
Dismiss all still recorded events in the ZXEco window from the desktop.
DesktopInterface & myDesktopInterface(void) noexcept
Return the associated DesktopInterface.
RefreshType
Types of refreshes that can be done while executing user code.
@ BOTH
Refreshes both things.
@ EVENTS
Only refreshes events received.
@ SCREEN
Only refreshes screen on display.
static const UserCode kNullUserCode
A user code that does nothing.
const LongTimeStat & refreshStats(void)
Consult the statistics of refresh.
static ZXEco & theZXEco(DesktopInterface *desktop=nullptr)
Return the singleton ZXEco object for the application.
const BorderRect & rightBorder(void) const noexcept
Return a reference to the unscaled right border rectangle.
void windowBorderRefresh(const BorderRect &rect=BorderRect{})
Command the desktop window to show on the desktop the border content.
bool pointingStatus(PointingStatus &ps) noexcept
Get the status of the mouse within the drawable zone of the ZX window.
const BorderRect & bottomBorder(void) const noexcept
Return a reference to the unscaled bottom border rectangle.
bool isInRefreshingCode(void) const noexcept
Return TRUE if the caller is in the context of a previous refresh().
const std::string & windowTitle(void) const
Return a reference to the title of the last activation.
Keyboard waitForKeyChange(const Keyboard &oldkb, std::string *lastprstr=nullptr, unsigned millis=20)
Wait for a change in the ZX keyboard that makes it different from OLDKB.
SimpleStats< double, SSOvPol_IgnoreMoreData< double > > LongTimeStat
Simple statistics about durations, gathered for a long time.
const DoubleArea & basics(void) const noexcept
Return a reference to the drawable area within the window.
unsigned scaleX(void) const noexcept
Scale factor in X.
unsigned scaleY(void) const noexcept
Scale factor in Y.
bool valid(void)
Whether the zx ecosystem is valid or not.
void activateDecolourMode(const CharRect &rect={})
Activate the decolour mode, where all attrs are turned into a gray grid.
Keyboard waitOneKey(unsigned ms=20)
Wait for only one ZX key or combination of keys to be pressed.
Keyboard keyboard(std::string *lastprstr=nullptr)
Update internal membrane and PC/ZX keyboards, returning the latter.
void windowBorderUpdate(const BorderRect &rect=BorderRect{})
Commit the given region of the border to the desktop window.
bool extractEvent(PalettizedWindow::Event &ev, const PalettizedWindow::Event::IDSet &which={true}, const PalettizedWindow::Event::IDSet &equalstoskip={false}) noexcept
Extract into EV the oldest event in the system, or return FALSE if none.
const RawGeometry & rawGeometry(void) const
Return a const reference to the raw geometry of the window.
const BorderRect & leftBorder(void) const noexcept
Return a reference to the unscaled left border rectangle.
std::chrono::time_point< std::chrono::steady_clock > startTime(void) noexcept
Return the start-up time of the zx ecosystem.
void setVolume(double v)
Change sound volume (from 0.0 to 1.0) for future sounds.
bool waitForKey(Keyboard &kb, unsigned millis=20, bool zxandpc=false)
Wait for any key to be pressed, sampling the keyboard every MILLIS.
Class that provides access to the entire ecosystem: graphics, keyboard, etc.
Raw geometrical information about the window geometry of ZXEco objects.
An area with both char and pixel resolutions, possibly synchronized.
std::function< std::string(uint8_t c)> ExpandToken
User's routine that must expand a given token code into the token text.
static const ExpandToken kInvExpandToken
Expand token routine that always generates CHRINVALID as expansion.
The class that provides the main support for managing the ZX screen.
The main namespace of the library, that spans across all the zx modules.
constexpr bool operator&(ZXEco::RefreshType a, ZXEco::RefreshType b)
Definition needed for completing the RefreshType functionality.