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

Keeps the OS windows (through an IWindowBackend) and their window contexts for the GUI's window elements, keyed by ID. More...

#include <gui_core/windows/gui_os_window_manager.h>

Public Member Functions

virtual ~OSWindowManager ()=default
 OSWindowManager (GraphicsContext *graphicsContext, IWindowBackend *backend)
 For tests without real windows: no style / gradient managers, no context init.
 OSWindowManager (GraphicsContext *graphicsContext, IWindowBackend *backendWindowManager, IPlatformInputHandler *inputHandler, StyleManager &styleManager, GradientManager &gradientManager)
void SetPopupSlide (ID id, int2 away)
 The way popup id opens, away from its anchor (one step on one axis, e.g.
void SetReducedMotion (bool reduced)
 Reduced motion: popups show and hide at once.
void ReleaseUndeclaredWindows (const std::function< bool(ID)> &declared)
 Releases the windows the app no longer declares (declared(id) is false): popups are hidden for a fast reopen, the others closed, reopenable.
bool HasAlivePopupWindows () const
 True while a popup menu window is alive.
bool HasAliveSecondaryWindows () const
 True while a secondary top-level window (popup or utility window) is alive.
void HidePopupWindow (ID id)
 Hides a popup / menu window, kept (WindowState::Hidden) for a fast reopen.
void SetTextInputArea (ID id, IntRect screenRect)
 Places the IME candidate window at screenRect (e.g.
bool Update ()
 Polls the OS events and destroys closed windows' contexts; call outside BeginFrame / EndFrame.
void DestroyAllWindowContexts ()
 Destroys every window's IWindowContext.
std::optional< color4b > ReadScreenPixel (int2 screenPos)
bool TakeCloseRequest (ID id)
 Whether the OS asked to close this (ConfirmClose) window since last asked.
int2 GetScreenMousePos ()
MouseButtons GetMouseButtons ()
bool IsNotAlive (ID id) const
AddWindowResult GetOrCreateWindow (ID id, std::string_view title, IntRect rect, OnGuiFunc onGui, WindowFlags windowFlags=WindowFlags::DefaultFlags|WindowFlags::CloseWithParent, ID parentID=ID::Invalid(), int monitorIndex=-1)
 Creates the OS window for id on first call (SuccessCreate), returns the existing one after (SuccessRecycle).
void RefreshMonitors ()
size_t GetMonitorCount () const
IntRect GetMonitorArea (int monitorIndex)
IntRect CenterInMonitor (int monitorIndex, int width, int height)
const std::vector< MonitorInfo > & Monitors () const
const MonitorInfo & GetMonitor (int index) const
int GetMonitorIndexAt (int2 pos) const
int GetPrimaryMonitorIndex () const
const MonitorInfo & GetPrimaryMonitor () const
bool SetWindowRect (ID id, const IntRect &clientRect)
 Moves and resizes a window so its client area is clientRect (screen pixels).
RequestCloseResult RequestClose (ID id)
RequestCloseResult RequestUserClose (ID id)
 Closes a window on the user's behalf (e.g.
RequestCloseResult RequestCloseAllowReopen (ID id)
 Closes a window from code; unlike RequestUserClose, declaring it again reopens it.
void AllowReopenWindow (ID id)
 Lets a window the user closed be reopened by declaring it.
bool WasUserClosed (ID id) const
 True when the user closed the window and it isn't reopened yet.
WindowState GetWindowState (ID id) const
bool HasBeenRegistered (ID id) const
float GetWindowDisplayScale (ID id) const
 The OS UI scale where the window is (see IWindowBackend::GetWindowDisplayScale); 1 when unknown.
float MainDisplayScale () const
 The display scale of the main window (the first top-level window still open), or of the primary monitor before there is one.
float MainRefreshRate () const
 Refresh rate in Hz of the monitor showing the main window, or of the primary monitor before there is one; 0 when unknown.
IWindowContext * GetWindowContext (ID id) const
 The window's context; nullptr when the window doesn't exist.
OSWindowHandle GetWindowHandle (ID id) const
ID GetWindowID (OSWindowHandle handle) const
 Invalid for a handle this manager doesn't own.
void SetWindowMode (ID id, WindowMode mode)
WindowMode GetWindowMode (ID id) const
IntRect GetWindowRect (ID id) const
int2 GetWindowSize (ID id) const
int2 GetWindowPosition (ID id) const
void BringToFront (ID id)
ID GetWindowUnderMouse () const
ID GetActiveWindow () const
size_t WindowCount () const
const std::vector< Window > & AllWindows () const
bool HasAliveMainWindow () const
 Any alive non-popup, non-tooltip window.
ID GetTopModalWindow () const
 Returns the ID of the top-most modal window (last created, still alive), or ID::Invalid() if there are no alive modal windows.
bool WasWindowUserClosed (ID id) const
void ForEachAliveWindowContext (const std::function< void(IWindowContext *, IntRect)> &func)
 Calls func for each live window's context with its render-target rect (OS position, size in physical pixels).

Static Public Attributes

static constexpr uint32_t kPopupInMs = 120
 a menu or popup fading in
static constexpr uint32_t kTooltipInMs = 100
 a tooltip fading in
static constexpr uint32_t kPopupOutMs = 80
 either fading out
static constexpr int kPopupSlide = 4
 CSS px a popup slides in from its anchor.

Protected Member Functions

 OSWindowManager ()=default
Window * FindWindow (ID id)
Window * FindWindow (OSWindowHandle handle)
int32_t IndexOf (ID id) const
int32_t IndexOf (OSWindowHandle handle) const
bool IsNotAlive (int32_t index) const
int GetMonitorIndexForWindow (ID id) const
RequestCloseResult RequestClose (int32_t index)
RequestCloseResult RequestClose (int32_t index, std::vector< ID > &detach_children)
void RemoveWindowFromSiblingList (int32_t window_index)
float QueryDisplayScale (OSWindowHandle handle) const
void RaisePopup (const Window &window)
bool MayFade (const Window &window) const
 Popups fade unless motion is reduced; tooltips fade without sliding.
float FadeProgress (const Window &window, uint32_t nowMs) const
 How far a fading popup is shown now, 0 to 1 (linear in time).
IntRect FadeRect (const Window &window, float shown) const
 Where a popup shown (0 to 1) of the way in is: short of its rect, towards its anchor.
bool BeginFadeIn (Window &window, uint32_t nowMs)
 Starts the stand-in of a cloaked popup that has been drawn; false when there can't be one.
void EndFadeOf (Window &window)
 Removes a popup's stand-in.
void AnimateFades ()
 Moves the stand-ins, and ends the fades that are done.
const Window * MainWindow () const
 First top-level window still open; null when there is none.
void LinkToParent (int32_t window_index, ID parentID)
void ClearParentIDInChildren (int32_t window_index)
void RemoveWindow (int32_t window_index)

Protected Attributes

IPlatformInputHandler * inputHandler = nullptr
GraphicsContext * graphicsContext = nullptr
IWindowBackend * windowBackendManager = nullptr
std::vector< Window > windows
std::unordered_map< ID, int32_t > IDToWindowIndex
std::unordered_map< OSWindowHandle, int32_t > HandleToWindowIndex
std::unordered_set< ID > userClosedWindows
 Windows the user closed (not code), which declaring doesn't reopen.
bool m_reducedMotion = false
StyleManager * styleManager = nullptr
 Application-owned; handed to each new window context for RenderFrame, so the graphics context itself has no style/gradient dependency.
GradientManager * gradientManager = nullptr
 Application-owned; handed to each new window context for RenderFrame, so the graphics context itself has no style/gradient dependency.
bool BeginFrame ()
 Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse report) when unbalanced.
bool EndFrame ()
 Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse report) when unbalanced.
void DestroyWindowContexts ()
 For a lost GPU device: the contexts go before the device, and come back on the new one for the same OS windows.
bool RecreateWindowContexts ()
 For a lost GPU device: the contexts go before the device, and come back on the new one for the same OS windows.

Detailed Description

Keeps the OS windows (through an IWindowBackend) and their window contexts for the GUI's window elements, keyed by ID.

Rects are in screen pixels.

Constructor & Destructor Documentation

◆ OSWindowManager() [1/3]

tachyon::OSWindowManager::OSWindowManager ( )
protecteddefault

◆ ~OSWindowManager()

virtual tachyon::OSWindowManager::~OSWindowManager ( )
virtualdefault

◆ OSWindowManager() [2/3]

tachyon::OSWindowManager::OSWindowManager ( GraphicsContext * graphicsContext,
IWindowBackend * backend )
explicit

For tests without real windows: no style / gradient managers, no context init.

◆ OSWindowManager() [3/3]

tachyon::OSWindowManager::OSWindowManager ( GraphicsContext * graphicsContext,
IWindowBackend * backendWindowManager,
IPlatformInputHandler * inputHandler,
StyleManager & styleManager,
GradientManager & gradientManager )

Member Function Documentation

◆ SetPopupSlide()

void tachyon::OSWindowManager::SetPopupSlide ( ID id,
int2 away )

The way popup id opens, away from its anchor (one step on one axis, e.g.

{ 0, 1 } below it): it slides in that way. Set each frame by whoever places it.

◆ SetReducedMotion()

void tachyon::OSWindowManager::SetReducedMotion ( bool reduced)
inline

Reduced motion: popups show and hide at once.

◆ BeginFrame()

bool tachyon::OSWindowManager::BeginFrame ( )

Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse report) when unbalanced.

◆ EndFrame()

bool tachyon::OSWindowManager::EndFrame ( )

Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse report) when unbalanced.

◆ ReleaseUndeclaredWindows()

void tachyon::OSWindowManager::ReleaseUndeclaredWindows ( const std::function< bool(ID)> & declared)

Releases the windows the app no longer declares (declared(id) is false): popups are hidden for a fast reopen, the others closed, reopenable.

Undeclared windows also lose their user-closed flag. Call each frame, before layout.

◆ HasAlivePopupWindows()

bool tachyon::OSWindowManager::HasAlivePopupWindows ( ) const
inline

True while a popup menu window is alive.

Gates synthetic mouse events: a parented popup can make the OS swallow a click on its parent.

◆ HasAliveSecondaryWindows()

bool tachyon::OSWindowManager::HasAliveSecondaryWindows ( ) const
inline

True while a secondary top-level window (popup or utility window) is alive.

Clicking another of the app's windows then can make SDL swallow the click, so the input layer repairs it with synthetic events.

◆ HidePopupWindow()

void tachyon::OSWindowManager::HidePopupWindow ( ID id)
inline

Hides a popup / menu window, kept (WindowState::Hidden) for a fast reopen.

Safe to call outside the frame (e.g. during OS modal loops).

◆ SetTextInputArea()

void tachyon::OSWindowManager::SetTextInputArea ( ID id,
IntRect screenRect )
inline

Places the IME candidate window at screenRect (e.g.

the text caret) in window id; only tells the OS when it changes.

◆ Update()

bool tachyon::OSWindowManager::Update ( )

Polls the OS events and destroys closed windows' contexts; call outside BeginFrame / EndFrame.

◆ DestroyAllWindowContexts()

void tachyon::OSWindowManager::DestroyAllWindowContexts ( )

Destroys every window's IWindowContext.

Call on shutdown, before tearing down the graphics device and the window backend.

◆ ReadScreenPixel()

std::optional< color4b > tachyon::OSWindowManager::ReadScreenPixel ( int2 screenPos)
inline

◆ TakeCloseRequest()

bool tachyon::OSWindowManager::TakeCloseRequest ( ID id)
inline

Whether the OS asked to close this (ConfirmClose) window since last asked.

◆ GetScreenMousePos()

int2 tachyon::OSWindowManager::GetScreenMousePos ( )
inline

◆ GetMouseButtons()

MouseButtons tachyon::OSWindowManager::GetMouseButtons ( )
inline

◆ IsNotAlive() [1/2]

bool tachyon::OSWindowManager::IsNotAlive ( ID id) const
inline

◆ GetOrCreateWindow()

AddWindowResult tachyon::OSWindowManager::GetOrCreateWindow ( ID id,
std::string_view title,
IntRect rect,
OnGuiFunc onGui,
WindowFlags windowFlags = WindowFlags::DefaultFlags|WindowFlags::CloseWithParent,
ID parentID = ID::Invalid(),
int monitorIndex = -1 )

Creates the OS window for id on first call (SuccessCreate), returns the existing one after (SuccessRecycle).

rect is the client rect in screen pixels. Call between BeginFrame and EndFrame. Not thread safe.

◆ RefreshMonitors()

void tachyon::OSWindowManager::RefreshMonitors ( )
inline

◆ GetMonitorCount()

size_t tachyon::OSWindowManager::GetMonitorCount ( ) const
inline

◆ GetMonitorArea()

IntRect tachyon::OSWindowManager::GetMonitorArea ( int monitorIndex)

◆ CenterInMonitor()

IntRect tachyon::OSWindowManager::CenterInMonitor ( int monitorIndex,
int width,
int height )

◆ Monitors()

const std::vector< MonitorInfo > & tachyon::OSWindowManager::Monitors ( ) const
inline

◆ GetMonitor()

const MonitorInfo & tachyon::OSWindowManager::GetMonitor ( int index) const
inline

◆ GetMonitorIndexAt()

int tachyon::OSWindowManager::GetMonitorIndexAt ( int2 pos) const
inline

◆ GetPrimaryMonitorIndex()

int tachyon::OSWindowManager::GetPrimaryMonitorIndex ( ) const
inline

◆ GetPrimaryMonitor()

const MonitorInfo & tachyon::OSWindowManager::GetPrimaryMonitor ( ) const
inline

◆ SetWindowRect()

bool tachyon::OSWindowManager::SetWindowRect ( ID id,
const IntRect & clientRect )

Moves and resizes a window so its client area is clientRect (screen pixels).

True on success. Call between BeginFrame and EndFrame.

◆ RequestClose() [1/3]

RequestCloseResult tachyon::OSWindowManager::RequestClose ( ID id)
inline

◆ RequestUserClose()

RequestCloseResult tachyon::OSWindowManager::RequestUserClose ( ID id)
inline

Closes a window on the user's behalf (e.g.

its title bar's close button): like closing it through the OS, it isn't reopened while the app keeps declaring it.

◆ RequestCloseAllowReopen()

RequestCloseResult tachyon::OSWindowManager::RequestCloseAllowReopen ( ID id)
inline

Closes a window from code; unlike RequestUserClose, declaring it again reopens it.

◆ AllowReopenWindow()

void tachyon::OSWindowManager::AllowReopenWindow ( ID id)
inline

Lets a window the user closed be reopened by declaring it.

The flag also clears when a window isn't declared for a frame (ReleaseUndeclaredWindows), so stopping and resuming the declaration reopens it.

◆ WasUserClosed()

bool tachyon::OSWindowManager::WasUserClosed ( ID id) const
inline

True when the user closed the window and it isn't reopened yet.

◆ GetWindowState()

WindowState tachyon::OSWindowManager::GetWindowState ( ID id) const
inline

◆ HasBeenRegistered()

bool tachyon::OSWindowManager::HasBeenRegistered ( ID id) const
inline

◆ GetWindowDisplayScale()

float tachyon::OSWindowManager::GetWindowDisplayScale ( ID id) const
inline

The OS UI scale where the window is (see IWindowBackend::GetWindowDisplayScale); 1 when unknown.

◆ MainDisplayScale()

float tachyon::OSWindowManager::MainDisplayScale ( ) const

The display scale of the main window (the first top-level window still open), or of the primary monitor before there is one.

◆ MainRefreshRate()

float tachyon::OSWindowManager::MainRefreshRate ( ) const

Refresh rate in Hz of the monitor showing the main window, or of the primary monitor before there is one; 0 when unknown.

◆ GetWindowContext()

IWindowContext * tachyon::OSWindowManager::GetWindowContext ( ID id) const
inline

The window's context; nullptr when the window doesn't exist.

◆ GetWindowHandle()

OSWindowHandle tachyon::OSWindowManager::GetWindowHandle ( ID id) const
inline

◆ GetWindowID()

ID tachyon::OSWindowManager::GetWindowID ( OSWindowHandle handle) const
inline

Invalid for a handle this manager doesn't own.

◆ SetWindowMode()

void tachyon::OSWindowManager::SetWindowMode ( ID id,
WindowMode mode )
inline

◆ GetWindowMode()

WindowMode tachyon::OSWindowManager::GetWindowMode ( ID id) const
inline

◆ GetWindowRect()

IntRect tachyon::OSWindowManager::GetWindowRect ( ID id) const
inline

◆ GetWindowSize()

int2 tachyon::OSWindowManager::GetWindowSize ( ID id) const
inline

◆ GetWindowPosition()

int2 tachyon::OSWindowManager::GetWindowPosition ( ID id) const
inline

◆ BringToFront()

void tachyon::OSWindowManager::BringToFront ( ID id)
inline

◆ GetWindowUnderMouse()

ID tachyon::OSWindowManager::GetWindowUnderMouse ( ) const
inline

◆ GetActiveWindow()

ID tachyon::OSWindowManager::GetActiveWindow ( ) const
inline

◆ WindowCount()

size_t tachyon::OSWindowManager::WindowCount ( ) const
inline

◆ AllWindows()

const std::vector< Window > & tachyon::OSWindowManager::AllWindows ( ) const
inline

◆ HasAliveMainWindow()

bool tachyon::OSWindowManager::HasAliveMainWindow ( ) const
inline

Any alive non-popup, non-tooltip window.

The run loop exits without one, so cached popups and tooltips don't keep the application open.

◆ GetTopModalWindow()

ID tachyon::OSWindowManager::GetTopModalWindow ( ) const

Returns the ID of the top-most modal window (last created, still alive), or ID::Invalid() if there are no alive modal windows.

◆ WasWindowUserClosed()

bool tachyon::OSWindowManager::WasWindowUserClosed ( ID id) const
inline

◆ DestroyWindowContexts()

void tachyon::OSWindowManager::DestroyWindowContexts ( )

For a lost GPU device: the contexts go before the device, and come back on the new one for the same OS windows.

Recreate is false when one couldn't be made.

◆ RecreateWindowContexts()

bool tachyon::OSWindowManager::RecreateWindowContexts ( )

For a lost GPU device: the contexts go before the device, and come back on the new one for the same OS windows.

Recreate is false when one couldn't be made.

◆ ForEachAliveWindowContext()

void tachyon::OSWindowManager::ForEachAliveWindowContext ( const std::function< void(IWindowContext *, IntRect)> & func)
inline

Calls func for each live window's context with its render-target rect (OS position, size in physical pixels).

◆ FindWindow() [1/2]

Window * tachyon::OSWindowManager::FindWindow ( ID id)
inlineprotected

◆ FindWindow() [2/2]

Window * tachyon::OSWindowManager::FindWindow ( OSWindowHandle handle)
inlineprotected

◆ IndexOf() [1/2]

int32_t tachyon::OSWindowManager::IndexOf ( ID id) const
inlineprotected

◆ IndexOf() [2/2]

int32_t tachyon::OSWindowManager::IndexOf ( OSWindowHandle handle) const
inlineprotected

◆ IsNotAlive() [2/2]

bool tachyon::OSWindowManager::IsNotAlive ( int32_t index) const
inlineprotected

◆ GetMonitorIndexForWindow()

int tachyon::OSWindowManager::GetMonitorIndexForWindow ( ID id) const
inlineprotected

◆ RequestClose() [2/3]

RequestCloseResult tachyon::OSWindowManager::RequestClose ( int32_t index)
protected

◆ RequestClose() [3/3]

RequestCloseResult tachyon::OSWindowManager::RequestClose ( int32_t index,
std::vector< ID > & detach_children )
protected

◆ RemoveWindowFromSiblingList()

void tachyon::OSWindowManager::RemoveWindowFromSiblingList ( int32_t window_index)
protected

◆ QueryDisplayScale()

float tachyon::OSWindowManager::QueryDisplayScale ( OSWindowHandle handle) const
protected

◆ RaisePopup()

void tachyon::OSWindowManager::RaisePopup ( const Window & window)
protected

◆ MayFade()

bool tachyon::OSWindowManager::MayFade ( const Window & window) const
protected

Popups fade unless motion is reduced; tooltips fade without sliding.

◆ FadeProgress()

float tachyon::OSWindowManager::FadeProgress ( const Window & window,
uint32_t nowMs ) const
protected

How far a fading popup is shown now, 0 to 1 (linear in time).

◆ FadeRect()

IntRect tachyon::OSWindowManager::FadeRect ( const Window & window,
float shown ) const
protected

Where a popup shown (0 to 1) of the way in is: short of its rect, towards its anchor.

◆ BeginFadeIn()

bool tachyon::OSWindowManager::BeginFadeIn ( Window & window,
uint32_t nowMs )
protected

Starts the stand-in of a cloaked popup that has been drawn; false when there can't be one.

◆ EndFadeOf()

void tachyon::OSWindowManager::EndFadeOf ( Window & window)
protected

Removes a popup's stand-in.

◆ AnimateFades()

void tachyon::OSWindowManager::AnimateFades ( )
protected

Moves the stand-ins, and ends the fades that are done.

◆ MainWindow()

const Window * tachyon::OSWindowManager::MainWindow ( ) const
protected

First top-level window still open; null when there is none.

◆ LinkToParent()

void tachyon::OSWindowManager::LinkToParent ( int32_t window_index,
ID parentID )
protected

◆ ClearParentIDInChildren()

void tachyon::OSWindowManager::ClearParentIDInChildren ( int32_t window_index)
protected

◆ RemoveWindow()

void tachyon::OSWindowManager::RemoveWindow ( int32_t window_index)
protected

Member Data Documentation

◆ styleManager

StyleManager* tachyon::OSWindowManager::styleManager = nullptr
protected

Application-owned; handed to each new window context for RenderFrame, so the graphics context itself has no style/gradient dependency.

◆ gradientManager

GradientManager* tachyon::OSWindowManager::gradientManager = nullptr
protected

Application-owned; handed to each new window context for RenderFrame, so the graphics context itself has no style/gradient dependency.

◆ inputHandler

IPlatformInputHandler* tachyon::OSWindowManager::inputHandler = nullptr
protected

◆ kPopupInMs

uint32_t tachyon::OSWindowManager::kPopupInMs = 120
staticconstexpr

a menu or popup fading in

◆ kTooltipInMs

uint32_t tachyon::OSWindowManager::kTooltipInMs = 100
staticconstexpr

a tooltip fading in

◆ kPopupOutMs

uint32_t tachyon::OSWindowManager::kPopupOutMs = 80
staticconstexpr

either fading out

◆ kPopupSlide

int tachyon::OSWindowManager::kPopupSlide = 4
staticconstexpr

CSS px a popup slides in from its anchor.

◆ graphicsContext

GraphicsContext* tachyon::OSWindowManager::graphicsContext = nullptr
protected

◆ windowBackendManager

IWindowBackend* tachyon::OSWindowManager::windowBackendManager = nullptr
protected

◆ windows

std::vector<Window> tachyon::OSWindowManager::windows
protected

◆ IDToWindowIndex

std::unordered_map<ID, int32_t> tachyon::OSWindowManager::IDToWindowIndex
protected

◆ HandleToWindowIndex

std::unordered_map<OSWindowHandle, int32_t> tachyon::OSWindowManager::HandleToWindowIndex
protected

◆ userClosedWindows

std::unordered_set<ID> tachyon::OSWindowManager::userClosedWindows
protected

Windows the user closed (not code), which declaring doesn't reopen.

◆ m_reducedMotion

bool tachyon::OSWindowManager::m_reducedMotion = false
protected

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