psychic-ui 0.0.0
Loading...
Searching...
No Matches
psychic_ui::SDL3SystemWindow Class Reference

#include <SDL3SystemWindow.hpp>

Inheritance diagram for psychic_ui::SDL3SystemWindow:
psychic_ui::SystemWindow

Public Member Functions

 SDL3SystemWindow (std::shared_ptr< Window > window, SDL_Window *sdlWindow, SDL_GLContext glContext)
 SDL3SystemWindow (const SDL3SystemWindow &)=delete
SDL3SystemWindow & operator= (const SDL3SystemWindow &)=delete
 SDL3SystemWindow (SDL3SystemWindow &&)=delete
SDL3SystemWindow & operator= (SDL3SystemWindow &&)=delete
SDL_Window * sdlWindow () const
bool handleEvent (const SDL_Event &event)
bool render () override
GLProc glProcAddress (const char *name) const override
void setTitle (const std::string &title) override
void setFullscreen (bool fullscreen) override
bool getMinimized () const override
void setMinimized (bool minimized) override
bool getMaximized () const override
void setMaximized (bool maximized) override
void setVisible (bool visible) override
void setCursor (Cursor cursor) override
void startDrag () override
void stopDrag () override
bool supportsDrag () const override
void setSize (int width, int height) override
void setPosition (int x, int y) override
void startTextInput () override
void stopTextInput () override
void setTextInputArea (int x, int y, int width, int height, int cursor) override
std::chrono::nanoseconds gestureTime () const override
void wake () override
ColorScheme colorScheme () const override
std::string getClipboardText () const override
void setClipboardText (const std::string &text) override
bool installHitTest ()
SDL_HitTestResult hitTest (int x, int y)
Public Member Functions inherited from psychic_ui::SystemWindow
 SystemWindow (std::shared_ptr< Window > window)
 SystemWindow (const SystemWindow &)=delete
SystemWindow & operator= (const SystemWindow &)=delete
 SystemWindow (SystemWindow &&)=delete
SystemWindow & operator= (SystemWindow &&)=delete
std::shared_ptr< Window > window () const
bool sharesContext () const
void setSharesContext (bool sharesContext)
int getX () const
int getY () const
int getWidth () const
int getHeight () const
int getFramebufferWidth () const
int getFramebufferHeight () const
float getPixelRatio () const
int getSamples () const
int getStencilBits () const

Static Public Member Functions

static Uint32 wakeEventType ()
static Mod mapMods (SDL_Keymod mods)
static Key mapKey (SDL_Keycode keycode)

Protected Member Functions

virtual SDL_TouchDeviceType touchDeviceType (SDL_TouchID touchID) const
void handleFingerEvent (const SDL_TouchFingerEvent &finger)
void handlePenButton (MouseButton button, bool down, float x, float y)
void readSize ()
Protected Member Functions inherited from psychic_ui::SystemWindow
void detach ()
void readFramebufferFormat ()

Protected Attributes

SDL_Window * _sdlWindow {nullptr}
SDL_GLContext _glContext {nullptr}
std::array< SDL_Cursor *, 6 > _cursors {}
float _dragOffsetX {0}
float _dragOffsetY {0}
bool _hitTestInstalled {false}
bool _fingerDown {false}
SDL_FingerID _finger {0}
unsigned _penButtons {0}
std::vector< std::string > _droppedFiles {}
Protected Attributes inherited from psychic_ui::SystemWindow
std::shared_ptr< Window > _window
bool _sharesContext {false}
bool _dragging {false}
int _stencilBits {8}
int _samples {0}
float _mouseX {0}
float _mouseY {0}
int _x {0}
int _y {0}
int _width {0}
int _height {0}
int _fbWidth {0}
int _fbHeight {0}
bool _focused {false}
bool _minimized {false}
bool _maximized {false}

Friends

class SDL3Application

Additional Inherited Members

Public Types inherited from psychic_ui::SystemWindow
using GLProc = void (*)()

Detailed Description

Shows a Psychic UI Window in an SDL3 window that has an OpenGL context.

SDL3Application makes one for each window it opens. A host application with its own SDL window, GL context and loop embeds Psychic UI the same way:

auto ui = std::make_shared<MyWindow>();
psychic_ui::SDL3SystemWindow adapter(ui, sdlWindow, glContext);

while (running) {
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
        adapter.handleEvent(event); // false when the event isn't for this window
    }
    adapter.render();               // makes the context current and draws
    SDL_GL_SwapWindow(sdlWindow);
}

A host that waits for events while nothing changes asks the window when to draw again (Window::untilNextFrame), as SDL3Application::run does.

For custom title bars (Window::addDragArea) and the resize borders of an undecorated window, also call adapter.installHitTest(), which replaces the window's SDL hit test.

The adapter never creates, shows, destroys or polls anything of the host's: destroy it before the SDL window and the GL context.

Constructor & Destructor Documentation

◆ SDL3SystemWindow()

psychic_ui::SDL3SystemWindow::SDL3SystemWindow ( std::shared_ptr< Window > window,
SDL_Window * sdlWindow,
SDL_GLContext glContext )
Parameters
glContextThe window's context, made current to draw; nullptr when the host makes a context current itself before render()

Member Function Documentation

◆ colorScheme()

ColorScheme psychic_ui::SDL3SystemWindow::colorScheme ( ) const
nodiscardoverridevirtual

SDL_GetSystemTheme. handleEvent passes SDL_EVENT_SYSTEM_THEME_CHANGED on to the window, whatever window the event names (it names none). Virtual so that tests can make up a system.

Reimplemented from psychic_ui::SystemWindow.

◆ gestureTime()

std::chrono::nanoseconds psychic_ui::SDL3SystemWindow::gestureTime ( ) const
nodiscardoverridevirtual

SDL's clock, which times its events

Reimplemented from psychic_ui::SystemWindow.

◆ getClipboardText()

std::string psychic_ui::SDL3SystemWindow::getClipboardText ( ) const
nodiscardoverridevirtual

The system clipboard's text, in UTF-8. Without a system clipboard (this default), a clipboard that only lives in this system window.

Reimplemented from psychic_ui::SystemWindow.

◆ getMaximized()

bool psychic_ui::SDL3SystemWindow::getMaximized ( ) const
nodiscardoverridevirtual

◆ getMinimized()

bool psychic_ui::SDL3SystemWindow::getMinimized ( ) const
nodiscardoverridevirtual

◆ glProcAddress()

SystemWindow::GLProc psychic_ui::SDL3SystemWindow::glProcAddress ( const char * name) const
overridevirtual

Address of an OpenGL function in this window's context, which Skia builds its GL interface from

Implements psychic_ui::SystemWindow.

◆ handleEvent()

bool psychic_ui::SDL3SystemWindow::handleEvent ( const SDL_Event & event)

Translates an SDL event into the window's events

Returns
Whether the event was for this window

◆ hitTest()

SDL_HitTestResult psychic_ui::SDL3SystemWindow::hitTest ( int x,
int y )

What a point of the window (window coordinates) is for: moving the window on the Window's drag areas, resizing it on the borders of an undecorated resizable window, otherwise normal input

◆ installHitTest()

bool psychic_ui::SDL3SystemWindow::installHitTest ( )

Lets SDL ask hitTest where presses go, so the window manager or compositor moves the window from its drag areas and resizes it from the borders of an undecorated window, on Wayland too

Returns
false when the platform has no hit testing; startDrag() then moves the window itself

◆ render()

bool psychic_ui::SDL3SystemWindow::render ( )
overridevirtual

Draws the window into its framebuffer, without presenting it.

Returns
false when there's nothing to draw (the window is hidden)

Implements psychic_ui::SystemWindow.

◆ setClipboardText()

void psychic_ui::SDL3SystemWindow::setClipboardText ( const std::string & text)
overridevirtual

Reimplemented from psychic_ui::SystemWindow.

◆ setCursor()

void psychic_ui::SDL3SystemWindow::setCursor ( Cursor cursor)
overridevirtual

◆ setFullscreen()

void psychic_ui::SDL3SystemWindow::setFullscreen ( bool fullscreen)
overridevirtual

◆ setMaximized()

void psychic_ui::SDL3SystemWindow::setMaximized ( bool maximized)
overridevirtual

◆ setMinimized()

void psychic_ui::SDL3SystemWindow::setMinimized ( bool minimized)
overridevirtual

◆ setPosition()

void psychic_ui::SDL3SystemWindow::setPosition ( int x,
int y )
overridevirtual

◆ setSize()

void psychic_ui::SDL3SystemWindow::setSize ( int width,
int height )
overridevirtual

◆ setTextInputArea()

void psychic_ui::SDL3SystemWindow::setTextInputArea ( int x,
int y,
int width,
int height,
int cursor )
overridevirtual

Where text is being typed (window coordinates), with the caret cursor from its left, so that an on-screen keyboard or an input method's candidates stay clear of it. Adapters without either ignore it.

Reimplemented from psychic_ui::SystemWindow.

◆ setTitle()

void psychic_ui::SDL3SystemWindow::setTitle ( const std::string & title)
overridevirtual

◆ setVisible()

void psychic_ui::SDL3SystemWindow::setVisible ( bool visible)
overridevirtual

◆ startDrag()

void psychic_ui::SDL3SystemWindow::startDrag ( )
overridevirtual

◆ startTextInput()

void psychic_ui::SDL3SystemWindow::startTextInput ( )
overridevirtual

Reimplemented from psychic_ui::SystemWindow.

◆ stopDrag()

void psychic_ui::SDL3SystemWindow::stopDrag ( )
overridevirtual

◆ stopTextInput()

void psychic_ui::SDL3SystemWindow::stopTextInput ( )
overridevirtual

Reimplemented from psychic_ui::SystemWindow.

◆ supportsDrag()

bool psychic_ui::SDL3SystemWindow::supportsDrag ( ) const
nodiscardoverridevirtual

Whether the window can be moved from inside it, by Window::isDragArea or startDrag()

Reimplemented from psychic_ui::SystemWindow.

◆ touchDeviceType()

SDL_TouchDeviceType psychic_ui::SDL3SystemWindow::touchDeviceType ( SDL_TouchID touchID) const
nodiscardprotectedvirtual

What kind of touch device sent finger events: only touch screens (direct) are followed, trackpads also move the mouse. Virtual so that tests can make up touch screens.

◆ wake()

void psychic_ui::SDL3SystemWindow::wake ( )
overridevirtual

Pushes an event of wakeEventType(), which ends an SDL_WaitEvent: a host that waits for events draws when it gets one (the adapter ignores it)

Reimplemented from psychic_ui::SystemWindow.

◆ wakeEventType()

Uint32 psychic_ui::SDL3SystemWindow::wakeEventType ( )
static

The event type wake pushes, registered with SDL on first use

Member Data Documentation

◆ _cursors

std::array<SDL_Cursor *, 6> psychic_ui::SDL3SystemWindow::_cursors {}
protected

System cursors, indexed by Cursor

◆ _dragOffsetX

float psychic_ui::SDL3SystemWindow::_dragOffsetX {0}
protected

Where the window was grabbed, relative to its position, while dragging it ourselves

◆ _droppedFiles

std::vector<std::string> psychic_ui::SDL3SystemWindow::_droppedFiles {}
protected

Files of the drop in progress, dispatched together when it completes

◆ _fingerDown

bool psychic_ui::SDL3SystemWindow::_fingerDown {false}
protected

The finger the window follows (the first one down on a touch screen), while one is down

◆ _penButtons

unsigned psychic_ui::SDL3SystemWindow::_penButtons {0}
protected

Buttons held with the pen, mouse style (the tip is the left button)


The documentation for this class was generated from the following files: