30#ifndef DESKTOPINTERFACESDL2
31#define DESKTOPINTERFACESDL2
37#define SDL_MAIN_HANDLED
90 const std::string & filepath);
99 unsigned dimw,
unsigned dimh,
100 unsigned scalex,
unsigned scaley);
195 static std::unique_ptr<DesktopSDL2> pgi;
197 static void audio_callback(
void *userdata, Uint8 *buffer,
int length);
200 SDL_AudioSpec soundspecs_;
204 volatile std::atomic<bool> playing_;
269 ListOfEvents * evs =
nullptr);
284 bool & leftbutton,
bool & rightbutton);
312 static std::thread::id mainthreadid_;
315 SDL_Renderer *renderer_;
316 SDL_Surface *surfpal_;
317 SDL_Surface *surfaux_;
318 SDL_Texture *texture_;
323 PalWinSDL2(
const std::string & title,
unsigned dimw,
unsigned dimh,
324 unsigned scalex,
unsigned scaley);
326 void destroy(
void)
noexcept;
A 2D matrix of certain type that has contiguous storage.
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).
static constexpr unsigned NUMCOLSPAL
No. of colors in palette.
uint8_t PaletteIndex
Index of a color in the palette.
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.
To refer to pixels in the drawable area of the window.
Cursor to refer to pixels that includes checking code.
Main parameters of the sound player.
A rectangle on a palettized window.
void pausePlaying(void)
Pause the current playing, if any, and play just silence.
CursorCheck getCursorCheck(unsigned x=0, unsigned y=0)
Get a checking cursor that points to that pixel.
void serveEvents(const PalettizedWindow::Event::IDSet &whichevents={true}, ListOfEvents *evs=nullptr)
Serve pending events.
std::string copyFromClipboard(void) const
Return a copy of the text existing in the clipboard, if any.
void disableTextEvents(void)
Disable K_TEXT events from now on to the active window in the desktop.
DesktopSDL2 & operator=(DesktopSDL2 &&)=delete
Assignment-moves forbidden.
static DesktopSDL2 & theDesktop(const SoundPlayerParms &spps)
Get the singleton desktop interface with SPPS (created in the 1st call)
void fillRect(const Rectangle &r, PaletteIndex c)
Fill a rectangle in the window with the given color, efficiently.
void writePNGImageFile(const RGBImage &img, const std::string &filepath)
Write an RGBImage into a PNG image in the given file.
void copyToClipboard(const std::string &txt) const
Copy TXT, if not empty, to the clipboard.
void refresh(const Rectangle &rect=Rectangle{})
Render the internal displayable data onto the desktop window.
PalWinSDL2 & operator=(const PalWinSDL2 &)=delete
Assignments forb.
PalWinSDL2(const PalWinSDL2 &)=delete
Copies forbidden.
PalWinSDL2(PalWinSDL2 &&)=delete
Moves forbidden.
void setPaletteColors(const PaletteLevel *colors, PaletteIndex first, PaletteIndex count)
Change color(s) in the palette of the window.
bool soundPlaying(void) const noexcept
Return TRUE if the last commanded sound is still playing.
bool textEventsEnabled(void) const
Enable K_TEXT events from now on to the active window in the desktop.
void getDesktopResolution(unsigned &w, unsigned &h)
Fill W and H with the current desktop resolution in pixels.
RGBImage readPNGImageFile(const std::string &filepath)
Read a PNG image from file and return it as an RGBImage.
PaletteIndex getPixel(const Cursor &cursor)
Return the value of the pixel at CURSOR in the window, if all is valid.
virtual ~PalWinSDL2(void)
Destructor: close the window.
virtual ~DesktopSDL2(void)
Destructor: finish both libraries.
DesktopSDL2(const DesktopSDL2 &)=delete
Copies forbidden.
void resumePlaying(void)
Resume a previously paused playing.
bool getPointingInWindow(unsigned &x, unsigned &y, bool &leftbutton, bool &rightbutton)
Get the status of the mouse within the entire window.
void enableTextEvents(void)
Enable K_TEXT events from now on to the active window in the desktop.
double lastSoundDuration(void) const noexcept
Get the current sound duration.
void playSound(double secs, const SoundMonoProducer &waveprod, bool async)
Start playing the sound produced by WAVEPROD for the next SECS seconds.
bool playingPaused(void)
Return whether there is a paused playing or not.
PalWinSDL2 & operator=(PalWinSDL2 &&)=delete
Assignment-moves forb.
const SoundMonoProducer & lastSoundProducer(void) const
Get the current sound producer or raise an exception if none.
bool keyPressed(DesktopInterface::KeyID k)
Check whether the key K is pressed now when the focus is on the window.
void setPixel(const Cursor &cursor, PaletteIndex b)
Set pixel at CURSOR to B, if all is valid.
void updateKeypressMap(DesktopInterface::KeypressMap &map)
Update MAP with key press information when the focus is on the window.
DesktopSDL2 & operator=(const DesktopSDL2 &)=delete
Assignments forbidden.
PalettizedWindow * createWindow(const std::string &title, unsigned dimw, unsigned dimh, unsigned scalex, unsigned scaley)
Factory method: return a new palettized window of type PalWinSDL2.
DesktopSDL2(DesktopSDL2 &&)=delete
Moves forbidden.
void nextSoundPlayingTime(double &t) noexcept
Update T with the next time where the sound callback will be called.
Cursor getCursor(unsigned x=0, unsigned y=0) noexcept
Get a non-checking cursor that points to that pixel.
The desktop interface main class, based on SDL2 and SDL2-image.
A palettized window managed by SDL2.