TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::IWindowBackend Class Referenceabstract

Makes and manages the OS windows and delivers their input; GUIApplication::SetWindowBackend sets one, SDLWindowBackend is the default. More...

#include <gui_core/windows/gui_window_backend.h>

Inheritance diagram for tachyon::IWindowBackend:

Public Member Functions

 IWindowBackend ()
virtual ~IWindowBackend ()
virtual OSWindowHandle CreateWindow (std::string_view title, int2 size, WindowFlags windowFlags, OSWindowHandle parentOSHandle)=0
 Creates a window whose client area is size pixels, placed by the OS.
virtual OSWindowHandle CreateWindow (std::string_view title, IntRect rect, WindowFlags windowFlags, OSWindowHandle parentOSHandle)=0
 Creates a window whose client area is rect (screen pixels); otherwise as the size overload.
virtual bool DestroyWindow (OSWindowHandle)=0
 Queues the window for destruction: the next PollEvents passes its context to cleanup, then destroys it.
virtual void AttachInputHandlerToWindow (OSWindowHandle window, IPlatformInputHandler *inputHandler)=0
 Where the window's input goes (see IPlatformInputHandler); not owned, nullptr for none.
virtual void AttachContextToWindow (OSWindowHandle window, IWindowContext *context)=0
 Stores the window's context (not owned), for GetWindowContext, for the ID passed with the window's input, and for PollEvents' cleanup.
virtual void DetachWindowContext (OSWindowHandle)=0
 Clears the context pointer stored in the OS window, so PollEvents' cleanup callback gets nullptr instead of double-freeing a context the caller destroys.
virtual bool IsWindow (OSWindowHandle)=0
 True while the handle is a live window of this backend; false once it was destroyed (by code or the user) and for nullptr.
virtual IWindowContext * GetWindowContext (OSWindowHandle)=0
 The context attached with AttachContextToWindow, or nullptr.
virtual void BringToFront (OSWindowHandle)=0
 Raises the window above the others and asks the OS for the input focus.
virtual OSWindowHandle GetWindowUnderMouse ()=0
 The backend's window under the mouse, or nullptr.
virtual OSWindowHandle GetActiveWindow ()=0
 The window with the keyboard focus, or nullptr when none of the backend's windows has it.
virtual uint32_t GetFocusChangeCount () const =0
 Goes up whenever keyboard focus moves between windows, or to or from another application; open popups are checked against it.
virtual void PollEvents (std::function< void(OSWindowHandle, IWindowContext *)> cleanup)=0
 Handles the OS's pending events, delivering input to the attached handlers.
virtual int2 GetScreenMousePos ()=0
 The mouse position in screen pixels (SDL: as of the last PollEvents).
virtual MouseButtons GetMouseButtons ()=0
 The mouse buttons held down, wherever the mouse is (SDL: as of the last PollEvents).
virtual float GetDoubleClickMilliseconds ()
 The OS's double-click time in milliseconds, or 0 where the platform has none.
virtual bool PrefersReducedMotion ()
 Whether the OS asks for less motion (animations turned off); false where the platform has no such setting.
virtual std::optional< color4b > ReadScreenPixel (int2)
 The color of a screen pixel, anywhere on the desktop (an eyedropper); nothing where the platform can't read the screen.
virtual bool TakeCloseRequest (OSWindowHandle)
 Whether the OS asked to close a WindowFlags::ConfirmClose window since last asked.
virtual void SetCursor (MouseCursor cursor)=0
 Shows the system cursor for that shape; MouseCursor::None hides the cursor.
virtual void SetTextInputArea (OSWindowHandle window, IntRect rect)=0
 Where text is being typed in the window (window coordinates), so the IME places its candidate list next to it.
virtual float GetWindowDisplayScale (OSWindowHandle window)=0
 The UI scale the OS asks for in this window: pixel density times the monitor's content scale (1.5 on a 150% display).
virtual IntRect GetWindowPixelRect (OSWindowHandle window)=0
 The window's render target: OS position (for OS compositing) and size in physical pixels.
virtual void SwapBuffers (OSWindowHandle)=0
 Presents for a graphics API that swaps through the window (OpenGL).
virtual IntRect GetWindowRect (OSWindowHandle)=0
 Client area in pixels; {0,0,0,0} while minimized.
virtual int2 GetWindowPos (OSWindowHandle)=0
 The client area's top-left in screen pixels.
virtual int2 GetWindowSize (OSWindowHandle)=0
 The client area's size in pixels; {0,0} while minimized.
virtual void * GetNativeHandle (OSWindowHandle)=0
 The OS's own window handle, passed to GraphicsContext::CreateWindowContext (HWND on Windows, NSWindow on macOS, an X11 window or Wayland surface on Linux); nullptr without one.
virtual bool SetWindowRect (OSWindowHandle, const IntRect &clientRect)=0
 Moves and resizes the window so its client area is clientRect (screen pixels); the backend accounts for the frame.
virtual void SetWindowVisible (OSWindowHandle, bool visible)=0
 Shows or hides the window; hiding doesn't destroy it.
virtual bool SetWindowCloaked (OSWindowHandle, bool)
 Cloaks a shown window: it takes frames but stays invisible, so it can be drawn before it appears.
virtual uint32_t ShowFade (OSWindowHandle, IWindowContext *, IntRect, float)
 A layered stand-in for window showing what context drew last, at screenRect (screen pixels) and opacity (0 to 1), so the window itself can be hidden or cloaked while it fades in or out.
virtual void MoveFade (uint32_t, IntRect, float)
 Moves a stand-in and sets its opacity.
virtual void EndFade (uint32_t)
 Removes a stand-in.
virtual std::vector< MonitorInfo > GetMonitors () const =0
 Every monitor, the primary first.
virtual int GetMonitorAt (int2 pos) const =0
 Index into GetMonitors of the monitor holding the screen point pos; 0 (the primary) when no monitor holds it, -1 without monitors.
virtual int GetMonitorFromWindow (OSWindowHandle handle) const =0
 Index into GetMonitors of the window's monitor; -1 for an unknown window.
virtual uint32_t GetTicks () const =0
 A millisecond clock (SDL: since SDL started).
virtual void SetWindowMode (OSWindowHandle, WindowMode)
 Sets the window's state: minimized, maximized, restored or fullscreen.
virtual WindowMode GetWindowMode (OSWindowHandle) const
 The window's state as the OS has it now; WindowMode::Normal by default.
virtual std::string GetPreferredLanguage () const
 The user's preferred language as a BCP 47 tag ("ja", "en-US"), or empty when the platform doesn't say.
virtual int32_t GetCursorSize () const
 The OS mouse cursor's size in pixels (its accessibility size at the display's scale), or 0 when the platform doesn't say.
virtual void SetGraphicsContext (GraphicsContext *graphicsContext)
 The graphics context the windows are made for and painted with (during an OS live resize).
void SetWindowMovedCallback (std::function< void()> cb)
 Sets cb, called as soon as any window moves or resizes, even inside the OS modal move / resize loop (before the next frame), so it must be safe outside the frame.
void SetHitTestCallback (std::function< WindowHitArea(OSWindowHandle, int2 screenPos)> cb)
 Classifies points (screen pixels) of CustomTitleBar windows for the OS.
WindowHitArea HitTestWindow (OSWindowHandle window, int2 screenPos) const
 What a point (screen pixels) of the window is, from the hit-test callback; WindowHitArea::Client without one.

Protected Attributes

std::function< void()> m_onWindowMoved
 Set by SetWindowMovedCallback; a backend calls it when a window moves or resizes.
std::function< WindowHitArea(OSWindowHandle, int2)> m_hitTest
 Set by SetHitTestCallback; a backend asks it through HitTestWindow.
GraphicsContext * m_graphicsContext = nullptr
 Set by SetGraphicsContext; not owned.

Detailed Description

Makes and manages the OS windows and delivers their input; GUIApplication::SetWindowBackend sets one, SDLWindowBackend is the default.

Positions and sizes are physical pixels. NullWindowBackend is the minimal implementation.

Constructor & Destructor Documentation

◆ IWindowBackend()

tachyon::IWindowBackend::IWindowBackend ( )
inline

◆ ~IWindowBackend()

virtual tachyon::IWindowBackend::~IWindowBackend ( )
inlinevirtual

Member Function Documentation

◆ CreateWindow() [1/2]

virtual OSWindowHandle tachyon::IWindowBackend::CreateWindow ( std::string_view title,
int2 size,
WindowFlags windowFlags,
OSWindowHandle parentOSHandle )
pure virtual

Creates a window whose client area is size pixels, placed by the OS.

parentOSHandle is the owner window, or nullptr for a top-level one. Returns nullptr on failure.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ CreateWindow() [2/2]

virtual OSWindowHandle tachyon::IWindowBackend::CreateWindow ( std::string_view title,
IntRect rect,
WindowFlags windowFlags,
OSWindowHandle parentOSHandle )
pure virtual

Creates a window whose client area is rect (screen pixels); otherwise as the size overload.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ DestroyWindow()

virtual bool tachyon::IWindowBackend::DestroyWindow ( OSWindowHandle )
pure virtual

Queues the window for destruction: the next PollEvents passes its context to cleanup, then destroys it.

False for a handle that isn't one of the backend's windows.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ AttachInputHandlerToWindow()

virtual void tachyon::IWindowBackend::AttachInputHandlerToWindow ( OSWindowHandle window,
IPlatformInputHandler * inputHandler )
pure virtual

Where the window's input goes (see IPlatformInputHandler); not owned, nullptr for none.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ AttachContextToWindow()

virtual void tachyon::IWindowBackend::AttachContextToWindow ( OSWindowHandle window,
IWindowContext * context )
pure virtual

Stores the window's context (not owned), for GetWindowContext, for the ID passed with the window's input, and for PollEvents' cleanup.

nullptr clears it.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ DetachWindowContext()

virtual void tachyon::IWindowBackend::DetachWindowContext ( OSWindowHandle )
pure virtual

Clears the context pointer stored in the OS window, so PollEvents' cleanup callback gets nullptr instead of double-freeing a context the caller destroys.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ IsWindow()

virtual bool tachyon::IWindowBackend::IsWindow ( OSWindowHandle )
pure virtual

True while the handle is a live window of this backend; false once it was destroyed (by code or the user) and for nullptr.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowContext()

virtual IWindowContext * tachyon::IWindowBackend::GetWindowContext ( OSWindowHandle )
pure virtual

The context attached with AttachContextToWindow, or nullptr.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ BringToFront()

virtual void tachyon::IWindowBackend::BringToFront ( OSWindowHandle )
pure virtual

Raises the window above the others and asks the OS for the input focus.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowUnderMouse()

virtual OSWindowHandle tachyon::IWindowBackend::GetWindowUnderMouse ( )
pure virtual

The backend's window under the mouse, or nullptr.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetActiveWindow()

virtual OSWindowHandle tachyon::IWindowBackend::GetActiveWindow ( )
pure virtual

The window with the keyboard focus, or nullptr when none of the backend's windows has it.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetFocusChangeCount()

virtual uint32_t tachyon::IWindowBackend::GetFocusChangeCount ( ) const
pure virtual

Goes up whenever keyboard focus moves between windows, or to or from another application; open popups are checked against it.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ PollEvents()

virtual void tachyon::IWindowBackend::PollEvents ( std::function< void(OSWindowHandle, IWindowContext *)> cleanup)
pure virtual

Handles the OS's pending events, delivering input to the attached handlers.

Then the windows destroyed since the last call (DestroyWindow, or closed by the OS) go: cleanup gets each handle and its context while the window still exists. Runs in UpdateFrame, and again in RecordFrame.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetScreenMousePos()

virtual int2 tachyon::IWindowBackend::GetScreenMousePos ( )
pure virtual

The mouse position in screen pixels (SDL: as of the last PollEvents).

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetMouseButtons()

virtual MouseButtons tachyon::IWindowBackend::GetMouseButtons ( )
pure virtual

The mouse buttons held down, wherever the mouse is (SDL: as of the last PollEvents).

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetDoubleClickMilliseconds()

virtual float tachyon::IWindowBackend::GetDoubleClickMilliseconds ( )
inlinevirtual

The OS's double-click time in milliseconds, or 0 where the platform has none.

Reimplemented in tachyon::SDLWindowBackend.

◆ PrefersReducedMotion()

virtual bool tachyon::IWindowBackend::PrefersReducedMotion ( )
inlinevirtual

Whether the OS asks for less motion (animations turned off); false where the platform has no such setting.

Reimplemented in tachyon::SDLWindowBackend.

◆ ReadScreenPixel()

virtual std::optional< color4b > tachyon::IWindowBackend::ReadScreenPixel ( int2 )
inlinevirtual

The color of a screen pixel, anywhere on the desktop (an eyedropper); nothing where the platform can't read the screen.

Reimplemented in tachyon::ImageWindowBackend, and tachyon::SDLWindowBackend.

◆ TakeCloseRequest()

virtual bool tachyon::IWindowBackend::TakeCloseRequest ( OSWindowHandle )
inlinevirtual

Whether the OS asked to close a WindowFlags::ConfirmClose window since last asked.

Reimplemented in tachyon::ImageWindowBackend, and tachyon::SDLWindowBackend.

◆ SetCursor()

virtual void tachyon::IWindowBackend::SetCursor ( MouseCursor cursor)
pure virtual

Shows the system cursor for that shape; MouseCursor::None hides the cursor.

The library sets it once per frame.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ SetTextInputArea()

virtual void tachyon::IWindowBackend::SetTextInputArea ( OSWindowHandle window,
IntRect rect )
pure virtual

Where text is being typed in the window (window coordinates), so the IME places its candidate list next to it.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowDisplayScale()

virtual float tachyon::IWindowBackend::GetWindowDisplayScale ( OSWindowHandle window)
pure virtual

The UI scale the OS asks for in this window: pixel density times the monitor's content scale (1.5 on a 150% display).

0 when unknown.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowPixelRect()

virtual IntRect tachyon::IWindowBackend::GetWindowPixelRect ( OSWindowHandle window)
pure virtual

The window's render target: OS position (for OS compositing) and size in physical pixels.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ SwapBuffers()

virtual void tachyon::IWindowBackend::SwapBuffers ( OSWindowHandle )
pure virtual

Presents for a graphics API that swaps through the window (OpenGL).

The library doesn't call it: a Vulkan window context presents itself.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowRect()

virtual IntRect tachyon::IWindowBackend::GetWindowRect ( OSWindowHandle )
pure virtual

Client area in pixels; {0,0,0,0} while minimized.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowPos()

virtual int2 tachyon::IWindowBackend::GetWindowPos ( OSWindowHandle )
pure virtual

The client area's top-left in screen pixels.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowSize()

virtual int2 tachyon::IWindowBackend::GetWindowSize ( OSWindowHandle )
pure virtual

The client area's size in pixels; {0,0} while minimized.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetNativeHandle()

virtual void * tachyon::IWindowBackend::GetNativeHandle ( OSWindowHandle )
pure virtual

The OS's own window handle, passed to GraphicsContext::CreateWindowContext (HWND on Windows, NSWindow on macOS, an X11 window or Wayland surface on Linux); nullptr without one.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ SetWindowRect()

virtual bool tachyon::IWindowBackend::SetWindowRect ( OSWindowHandle ,
const IntRect & clientRect )
pure virtual

Moves and resizes the window so its client area is clientRect (screen pixels); the backend accounts for the frame.

True on success.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ SetWindowVisible()

virtual void tachyon::IWindowBackend::SetWindowVisible ( OSWindowHandle ,
bool visible )
pure virtual

Shows or hides the window; hiding doesn't destroy it.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ SetWindowCloaked()

virtual bool tachyon::IWindowBackend::SetWindowCloaked ( OSWindowHandle ,
bool  )
inlinevirtual

Cloaks a shown window: it takes frames but stays invisible, so it can be drawn before it appears.

False when the backend can't (then the window is hidden until drawn instead).

Reimplemented in tachyon::SDLWindowBackend.

◆ ShowFade()

virtual uint32_t tachyon::IWindowBackend::ShowFade ( OSWindowHandle ,
IWindowContext * ,
IntRect ,
float  )
inlinevirtual

A layered stand-in for window showing what context drew last, at screenRect (screen pixels) and opacity (0 to 1), so the window itself can be hidden or cloaked while it fades in or out.

Returns the stand-in, or 0 where there are none: then the window shows and hides at once.

Reimplemented in tachyon::SDLWindowBackend.

◆ MoveFade()

virtual void tachyon::IWindowBackend::MoveFade ( uint32_t ,
IntRect ,
float  )
inlinevirtual

Moves a stand-in and sets its opacity.

Reimplemented in tachyon::SDLWindowBackend.

◆ EndFade()

virtual void tachyon::IWindowBackend::EndFade ( uint32_t )
inlinevirtual

Removes a stand-in.

Reimplemented in tachyon::SDLWindowBackend.

◆ GetMonitors()

virtual std::vector< MonitorInfo > tachyon::IWindowBackend::GetMonitors ( ) const
pure virtual

Every monitor, the primary first.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetMonitorAt()

virtual int tachyon::IWindowBackend::GetMonitorAt ( int2 pos) const
pure virtual

Index into GetMonitors of the monitor holding the screen point pos; 0 (the primary) when no monitor holds it, -1 without monitors.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetMonitorFromWindow()

virtual int tachyon::IWindowBackend::GetMonitorFromWindow ( OSWindowHandle handle) const
pure virtual

Index into GetMonitors of the window's monitor; -1 for an unknown window.

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ GetTicks()

virtual uint32_t tachyon::IWindowBackend::GetTicks ( ) const
pure virtual

A millisecond clock (SDL: since SDL started).

Implemented in tachyon::ImageWindowBackend, tachyon::NullWindowBackend, and tachyon::SDLWindowBackend.

◆ SetWindowMode()

virtual void tachyon::IWindowBackend::SetWindowMode ( OSWindowHandle ,
WindowMode  )
inlinevirtual

Sets the window's state: minimized, maximized, restored or fullscreen.

The default does nothing.

Reimplemented in tachyon::ImageWindowBackend, and tachyon::SDLWindowBackend.

◆ GetWindowMode()

virtual WindowMode tachyon::IWindowBackend::GetWindowMode ( OSWindowHandle ) const
inlinevirtual

The window's state as the OS has it now; WindowMode::Normal by default.

Reimplemented in tachyon::ImageWindowBackend, and tachyon::SDLWindowBackend.

◆ GetPreferredLanguage()

virtual std::string tachyon::IWindowBackend::GetPreferredLanguage ( ) const
inlinevirtual

The user's preferred language as a BCP 47 tag ("ja", "en-US"), or empty when the platform doesn't say.

Reimplemented in tachyon::ImageWindowBackend, and tachyon::SDLWindowBackend.

◆ GetCursorSize()

virtual int32_t tachyon::IWindowBackend::GetCursorSize ( ) const
inlinevirtual

The OS mouse cursor's size in pixels (its accessibility size at the display's scale), or 0 when the platform doesn't say.

Reimplemented in tachyon::ImageWindowBackend, and tachyon::SDLWindowBackend.

◆ SetGraphicsContext()

virtual void tachyon::IWindowBackend::SetGraphicsContext ( GraphicsContext * graphicsContext)
inlinevirtual

The graphics context the windows are made for and painted with (during an OS live resize).

GUIApplication::Initialize sets it before initializing the context.

Reimplemented in tachyon::ImageWindowBackend, and tachyon::SDLWindowBackend.

◆ SetWindowMovedCallback()

void tachyon::IWindowBackend::SetWindowMovedCallback ( std::function< void()> cb)
inline

Sets cb, called as soon as any window moves or resizes, even inside the OS modal move / resize loop (before the next frame), so it must be safe outside the frame.

◆ SetHitTestCallback()

void tachyon::IWindowBackend::SetHitTestCallback ( std::function< WindowHitArea(OSWindowHandle, int2 screenPos)> cb)
inline

Classifies points (screen pixels) of CustomTitleBar windows for the OS.

Called from inside PollEvents and the OS's modal move/resize loop.

◆ HitTestWindow()

WindowHitArea tachyon::IWindowBackend::HitTestWindow ( OSWindowHandle window,
int2 screenPos ) const
inline

What a point (screen pixels) of the window is, from the hit-test callback; WindowHitArea::Client without one.

For backends, from their OS hit testing.

Member Data Documentation

◆ m_onWindowMoved

std::function<void()> tachyon::IWindowBackend::m_onWindowMoved
protected

Set by SetWindowMovedCallback; a backend calls it when a window moves or resizes.

◆ m_hitTest

std::function<WindowHitArea(OSWindowHandle, int2)> tachyon::IWindowBackend::m_hitTest
protected

Set by SetHitTestCallback; a backend asks it through HitTestWindow.

◆ m_graphicsContext

GraphicsContext* tachyon::IWindowBackend::m_graphicsContext = nullptr
protected

Set by SetGraphicsContext; not owned.


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