|
TachyonUI 0.1.0
High-performance UI for building tools.
|
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. | |
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.
|
protecteddefault |
|
virtualdefault |
|
explicit |
For tests without real windows: no style / gradient managers, no context init.
| tachyon::OSWindowManager::OSWindowManager | ( | GraphicsContext * | graphicsContext, |
| IWindowBackend * | backendWindowManager, | ||
| IPlatformInputHandler * | inputHandler, | ||
| StyleManager & | styleManager, | ||
| GradientManager & | gradientManager ) |
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.
|
inline |
Reduced motion: popups show and hide at once.
| bool tachyon::OSWindowManager::BeginFrame | ( | ) |
Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse report) when unbalanced.
| bool tachyon::OSWindowManager::EndFrame | ( | ) |
Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse report) when unbalanced.
| 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.
|
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.
|
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.
|
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).
Places the IME candidate window at screenRect (e.g.
the text caret) in window id; only tells the OS when it changes.
| bool tachyon::OSWindowManager::Update | ( | ) |
Polls the OS events and destroys closed windows' contexts; call outside BeginFrame / EndFrame.
| void tachyon::OSWindowManager::DestroyAllWindowContexts | ( | ) |
Destroys every window's IWindowContext.
Call on shutdown, before tearing down the graphics device and the window backend.
|
inline |
Whether the OS asked to close this (ConfirmClose) window since last asked.
|
inline |
|
inline |
|
inline |
| 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.
|
inline |
|
inline |
| IntRect tachyon::OSWindowManager::GetMonitorArea | ( | int | monitorIndex | ) |
| IntRect tachyon::OSWindowManager::CenterInMonitor | ( | int | monitorIndex, |
| int | width, | ||
| int | height ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Moves and resizes a window so its client area is clientRect (screen pixels).
True on success. Call between BeginFrame and EndFrame.
|
inline |
|
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.
|
inline |
Closes a window from code; unlike RequestUserClose, declaring it again reopens it.
|
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.
|
inline |
True when the user closed the window and it isn't reopened yet.
|
inline |
|
inline |
|
inline |
The OS UI scale where the window is (see IWindowBackend::GetWindowDisplayScale); 1 when unknown.
| 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.
| 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.
|
inline |
The window's context; nullptr when the window doesn't exist.
|
inline |
|
inline |
Invalid for a handle this manager doesn't own.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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.
| 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.
|
inline |
| 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.
| 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.
|
inline |
Calls func for each live window's context with its render-target rect (OS position, size in physical pixels).
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Popups fade unless motion is reduced; tooltips fade without sliding.
|
protected |
How far a fading popup is shown now, 0 to 1 (linear in time).
|
protected |
Where a popup shown (0 to 1) of the way in is: short of its rect, towards its anchor.
|
protected |
Starts the stand-in of a cloaked popup that has been drawn; false when there can't be one.
|
protected |
Removes a popup's stand-in.
|
protected |
Moves the stand-ins, and ends the fades that are done.
|
protected |
First top-level window still open; null when there is none.
|
protected |
|
protected |
|
protected |
|
protected |
Application-owned; handed to each new window context for RenderFrame, so the graphics context itself has no style/gradient dependency.
|
protected |
Application-owned; handed to each new window context for RenderFrame, so the graphics context itself has no style/gradient dependency.
|
protected |
|
staticconstexpr |
a menu or popup fading in
|
staticconstexpr |
a tooltip fading in
|
staticconstexpr |
either fading out
|
staticconstexpr |
CSS px a popup slides in from its anchor.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Windows the user closed (not code), which declaring doesn't reopen.
|
protected |