29#ifndef DESKTOPINTERFACE
30#define DESKTOPINTERFACE
72 enum KeyID { K_ESC =0, K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9,
73 K_F10, K_F11, K_F12, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8,
74 K_9, K_0, K_BACK, K_DEL,
75 K_TAB, K_BEGIN, K_END,K_PGUP,K_PGDOWN,
76 K_Q, K_W, K_E, K_R, K_T, K_Y, K_U,
77 K_I, K_O, K_P, K_ENTER, K_CAPSLOCK, K_A, K_S, K_D, K_F, K_G,
78 K_H, K_J, K_K, K_L, K_CAPSLEFT, K_Z, K_X, K_C, K_V, K_B, K_N,
79 K_M, K_COMMA, K_PERIOD, K_CAPSRIGHT, K_CTRLLEFT, K_ALTLEFT,
80 K_SPACE, K_ALTRIGHT, K_CTRLRIGHT, K_LEFT, K_DOWN, K_UP,
81 K_RIGHT, K_MINUS, K_PLUS, K_DIV, K_MULT, K_BSLASH, K_UNDERS,
82 K_SQUBRO, K_SQUBRC, K_CURBRO, K_CURBRC, K_EXCL, K_DQUOTE,
83 K_AT, K_SHARP, K_DOLLAR, K_PERC, K_AMPER, K_PARO, K_PARC,
84 K_EQUAL, K_QUEST, K_VERT, K_CIRC, K_APOST, K_LESS, K_GREAT,
111 {
return((kid >= KeyID::K_1) && (kid <= KeyID::K_0)); }
115 {
return(((kid >= KeyID::K_Q) && (kid <= KeyID::K_P)) ||
116 ((kid >= KeyID::K_A) && (kid <= KeyID::K_L)) ||
117 ((kid >= KeyID::K_Z) && (kid <= KeyID::K_M))); }
121 {
return((kid >= KeyID::K_F1) && (kid <= KeyID::K_F12)); }
125 {
return((kid == KeyID::K_TAB) ||
126 (kid == KeyID::K_BEGIN) || (kid == KeyID::K_END) ||
127 (kid == KeyID::K_PGUP) || (kid == KeyID::K_PGDOWN) ||
128 (kid == KeyID::K_LEFT) || (kid == KeyID::K_RIGHT) ||
129 (kid == KeyID::K_DOWN) || (kid == KeyID::K_UP)); }
132 typedef std::function<double (
double t, uint64_t i,
197 const std::string & filepath) = 0;
212 unsigned dimw,
unsigned dimh,
213 unsigned scalex,
unsigned scaley)=0;
223 {
return(playerparms_); }
351 unsigned wi,
unsigned he)
noexcept:
x0{x},
y0{y},
w{wi},
h{he} {}
354 bool empty(
void)
const noexcept {
return((
w == 0) || (
h == 0)); }
358 {
return(
"winrect{{" + std::to_string(
x0) +
"," +
359 std::to_string(
y0) +
"},{" +
360 std::to_string(
w) +
"," +
361 std::to_string(
h) +
"}}"); }
416 class IDSet:
public std::bitset<N_IDS>
426 {
for (
auto id : sids) set(
static_cast<size_t>(
id)); }
430 {
return(
operator[](
static_cast<size_t>(
id))); }
480 {
return(std::find_if(cbegin(),cend(),
481 [eid](
const Event & e)->
bool
482 {
return(e.
id == eid); }) != cend()); }
503 unsigned x=0,
unsigned y=0,
504 size_t bytesperpixel = 1) noexcept;
510 unsigned x(
void) const noexcept {
return(x_); }
513 unsigned y(
void)
const noexcept {
return(
y_); }
516 bool outside(
void)
const noexcept {
return(
false); }
548 unsigned x=0,
unsigned y=0,
549 size_t bytesperpixel = 1) noexcept;
611 ListOfEvents * evs =
nullptr) = 0;
658 bool & leftbutton,
bool & rightbutton) = 0;
715 unsigned scalex,
unsigned scaley);
A 2D matrix of certain type that has contiguous storage.
bool buttons[2]
0-> left, 1-> right; TRUE-> clickd
virtual void playSound(double secs, const SoundMonoProducer &waveprod, bool async)=0
Play a sound.
char utf8char[7]
Recognized UTF-8 char (0-ended).
static bool keyIsLetter(KeyID kid) noexcept
< Return TRUE if the given KEY is a letter.
virtual Cursor getCursor(unsigned x=0, unsigned y=0) noexcept=0
Get a non-checking cursor that points to that pixel.
virtual void nextSoundPlayingTime(double &t) noexcept=0
Fill T with the next time the user's callback will be called.
union PalettizedWindow::Event::@5 data
Data of the event.
KeypressMap(void)
Default constructor: a map with one entry per KeyID, all unpressed.
static bool keyIsFunction(KeyID kid) noexcept
< Return TRUE if the given KEY is a function key.
virtual void copyToClipboard(const std::string &txt) const =0
Must copy TXT, if not empty, to the clipboard.
std::function< double(double t, uint64_t i, unsigned l, unsigned pos)> SoundMonoProducer
A routine to produce a mono-channel sound wave.
uint8_t PaletteLevel
Intensity of a color component (r, g, b).
int32_t incy
Increment in Y.
std::string to_string(void) const
Convert the list to a string.
virtual double lastSoundDuration(void) const noexcept=0
Get the duration of the last sound being played.
struct PalettizedWindow::Event::@5::@10 wheel
Data for a M_WHEEL event.
const unsigned width_
Unscaled dims of the bitmap drawable.
SoundPlayerParms(void)
Default constructor with default parameters.
virtual void updateKeypressMap(DesktopInterface::KeypressMap &map)=0
Must update MAP with the current state of all keys.
virtual bool textEventsEnabled(void) const =0
Must return the current enabled state of K_TEXT events.
std::string to_string(void) const noexcept
Return a description of the cursor.
double sampling_period
In secs, between a sound value and the next.
const unsigned scx_
Scale of the bitmap when rendered.
virtual bool keyPressed(DesktopInterface::KeyID k)=0
Must inform about whether the key K is pressed or not.
virtual void serveEvents(const PalettizedWindow::Event::IDSet &whichevents={true}, ListOfEvents *evs=nullptr)=0
Serve all pending events for the window to the underlying desktop systm.
void incX(void) noexcept
Make the iterator point to the next pixel in x.
static bool keyIsNumber(KeyID kid) noexcept
< Return TRUE if the given KEY is a number.
unsigned y_
Cursor position in coordinates.
int32_t incx
Increment in X.
const SoundPlayerParms & playerParms(void) const noexcept
< Must return the current parameters of the sound player system.
virtual void writePNGImageFile(const RGBImage &img, const std::string &filepath)=0
Must write the data of IMG into the file FILEPATH in PNG format.
struct PalettizedWindow::Event::@5::@6 keyboard
Data for a K_PRESSED / K_UNPRESSED evnt.
unsigned y0
x0,y0 are the pixel at the left-top corner.
unsigned sample_size
Number of samples that are buffered.
virtual CursorCheck getCursorCheck(unsigned x=0, unsigned y=0)=0
Get a checking cursor that points to that pixel.
Rectangle(void) noexcept
Default constructor: empty rectangle.
const unsigned swidth_
Scaled dim of bitmap (dim of window).
unsigned y
Pos of the mouse after event.
virtual PalettizedWindow * createWindow(const std::string &title, unsigned dimw, unsigned dimh, unsigned scalex, unsigned scaley)=0
Factory: create a new window that supports palettized pixels.
void incY(void) noexcept
Make the iterator point to the pixel right below the current one.
virtual PaletteIndex getPixel(const Cursor &cursor)=0
Return the value of the pixel at CURSOR in the window, if all is valid.
char which
'L' (left) or 'R' (right)
bool contains(ID id) const noexcept
< Convenience check of existence of ID in the set.
virtual void enableTextEvents(void)=0
Must enable K_TEXT events from now on to the active window in desktop.
virtual void disableTextEvents(void)=0
Must disable K_TEXT events from now on to the active window in desktop.
size_t o_
Linear size of the window, in bytes.
unsigned w
Dimensions of the rectangle in pixels.
static const SoundMonoProducer SilenceMonoProducer
Pre-defined sound producing routine that generates silence all time.
static constexpr unsigned NUMCOLSPAL
No. of colors in palette.
unsigned width(void) const noexcept
Return the width in (non-scaled) pixels of the window.
IDSet(const std::set< ID > &sids)
struct PalettizedWindow::Event::@5::@8 motion
Data for a M_MOVED event.
const size_t size_
Size in pixels of the window.
virtual void getDesktopResolution(unsigned &w, unsigned &h)=0
Get the resolution of the display in pixels.
bool anyKeyPressed(void) const
Return TRUE if any key appears pressed in the map.
SoundPlayerParms(double sper, unsigned ss)
Specific constructor.
unsigned x(void) const noexcept
X coordinate of the cursor.
virtual const SoundMonoProducer & lastSoundProducer(void) const =0
Get the routine that is currently producing sounds.
unsigned h
Dimensions of the rectangle in pixels.
virtual RGBImage readPNGImageFile(const std::string &filepath)=0
Must read the PNG image file with path FILEPATH and return an RGBImage.
uint8_t PaletteIndex
Index of a color in the palette.
virtual void setPaletteColors(const PaletteLevel *colors, PaletteIndex first, PaletteIndex count)=0
Change the given color(s) in the window palette.
std::string to_string(void) const noexcept
Return a description of the cursor.
static const std::vector< std::string > KeyNames
Key names.
bool contains(Event::ID eid) const noexcept
< To inherit all constructors
size_t offset(void) const noexcept
Return the linear offset within the drawable area of the cursor.
const unsigned sheight_
Scaled dim of bitmap (dim of window).
size_t n_
Linear size of the window, in bytes.
static const uint8_t N_IDS
Number of event IDs
const unsigned height_
Unscaled dims of the bitmap drawable.
virtual bool playingPaused(void)=0
Return whether there is a paused playing or not.
const std::string title_
Title of the window.
bool empty(void) const noexcept
Return TRUE if the rectangle is empty.
Rectangle(unsigned x, unsigned y, unsigned wi, unsigned he) noexcept
Constructor.
IDSet(bool all=false) noexcept
< Constructor of empty (ALL == FALSE) or full (ALL == TRUE) set.
CursorCheck(const PalettizedWindow &palwin, unsigned x=0, unsigned y=0, size_t bytesperpixel=1) noexcept
Constructor for the given window and with the given values.
virtual void setPixel(const Cursor &cursor, PaletteIndex b)=0
Set pixel at CURSOR to B, if all is valid.
virtual bool soundPlaying(void) const noexcept=0
Whether there is a sound being played or not.
std::string to_string(void) const
Return a text describing the rectangle.
Cursor(const PalettizedWindow &palwin, unsigned x=0, unsigned y=0, size_t bytesperpixel=1) noexcept
Default constructor from the coords of a given pixel in PALWIN.
ID
< IDs for the events that the desktop can send to a window.
@ W_MOVED
The drag-and-drop window event.
@ M_BUTTONUNCLICKED
Mouse unclick.
@ W_CLOSED
The close window event.
@ K_UNPRESSED
Key unpressed.
@ M_BUTTONCLICKED
Mouse click.
@ W_MINIMIZED
The minimize window event.
@ W_RESTORED
The restore (from min.) window event.
@ W_EXPOSED
Window exposed & needed of a refresh.
@ K_TEXT
Key or combination recognized as text.
@ M_WHEEL
Mouse wheel change.
static bool keyIsForMotion(KeyID kid) noexcept
< Return TRUE if the key can be used for moving things on the screen.
DesktopInterface::KeyID key
Key pressed or unpress.
void check(void) const
Throw if the parameters are invalid.
virtual std::string copyFromClipboard(void) const =0
Must return a copy of the text existing in the clipboard, if any.
std::list< Event > Base
A shortcut.
unsigned y(void) const noexcept
Y coordinate of the cursor.
virtual ~KeypressMap(void)=default
Destructor.
virtual void resumePlaying(void)=0
Resume a previously paused playing.
unsigned height(void) const noexcept
Return the height in (non-scaled) pixels of the window.
struct PalettizedWindow::Event::@5::@7 textkey
Data for a K_TEXT event.
size_t pitch_
Length of one row of pixels in memory.
virtual bool getPointingInWindow(unsigned &x, unsigned &y, bool &leftbutton, bool &rightbutton)=0
Must get the mouse status on the window.
struct PalettizedWindow::Event::@5::@9 button
Data for a M_BUTTON* event.
std::string to_string(void) const
Return a text with the event info.
int32_t incvert
Increment in vertical.
virtual void refresh(const Rectangle &rect=Rectangle{})=0
Render current screen content on the desktop with proper scaling.
unsigned x0
x0,y0 are the pixel at the left-top corner.
void incY(void) noexcept
Make the iterator point to the pixel right below the current one.
KeyID
IDs for the most common keys in a keyboard.
void incX(void) noexcept
Make the iterator point to the next pixel in x.
virtual void pausePlaying(void)=0
Pause the current playing, if any, and play just silence.
bool outside(void) const noexcept
Whether the cursor is outside the drawable. FALSE for non-checking.
bool outside(void) const noexcept
Whether the cursor is outside the drawable. FALSE for non-checking.
ID id
ID of the event that occurred.
virtual void fillRect(const Rectangle &r, PaletteIndex c)=0
Fill a rectangle in the window with the given color, efficiently.
const unsigned scy_
Scale of the bitmap when rendered.
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.
To refer to pixels in the drawable area of the window.
Cursor to refer to pixels that includes checking code.
List of events that occurred in the window, in chronological order.
Main parameters of the sound player.
Events that the window can receive from its desktop environment.
A rectangle on a palettized window.