11#include <unordered_map>
12#include <unordered_set>
75 int32_t childCount = 0;
80 int32_t monitorIndex = -1;
81 float displayScale = 1.0f;
82 uint32_t sequence = 0;
83 int32_t framesHidden = 0;
89 int32_t fadeWait = -1;
90 bool fadingIn =
false;
91 float fadeFrom = 0.0f;
92 uint32_t fadeStartMs = 0;
102 std::vector<MonitorInfo> monitors;
103 uint32_t m_nextSequence = 0;
105 uint32_t m_focusChangeCount = 0;
107 int primaryMonitorIndex = 0;
109 bool insideBeginEnd =
false;
204 const IntRect local{ screenRect.x - w->rect.x, screenRect.y - w->rect.y, screenRect.w, screenRect.h };
205 if (
id == m_textInputWindow && local == m_textInputArea)
return;
206 m_textInputWindow = id;
207 m_textInputArea = local;
227 const int32_t index =
IndexOf(
id);
259 for (
size_t i = 0; i < monitors.size(); ++i)
261 if (monitors[i].isPrimary)
263 primaryMonitorIndex =
static_cast<int>(i);
271 return monitors.size();
277 const std::vector<MonitorInfo>&
Monitors()
const {
return monitors; }
281 return (index >= 0 && index <
static_cast<int>(monitors.size()))
293 if (primaryMonitorIndex < 0 ||
size_t(primaryMonitorIndex) >= monitors.size())
295 return primaryMonitorIndex;
301 if (primaryMonitorIndex < 0 ||
size_t(primaryMonitorIndex) >= monitors.size())
303 return monitors[primaryMonitorIndex];
361 return index == -1 ? 1.0f :
windows[index].displayScale;
375 const int32_t index =
IndexOf(
id);
376 return index == -1 ? nullptr :
windows[index].context;
380 const int32_t index =
IndexOf(
id);
381 return index == -1 ? nullptr :
windows[index].GetWindowHandle();
386 const int32_t index =
IndexOf(handle);
406 return index == -1 ?
int2 {} :
windows[index].rect.size;
412 return index == -1 ?
int2 {} :
windows[index].rect.position;
420 if (index == -1)
return;
428 int32_t index =
IndexOf(handle);
436 if (handle ==
nullptr)
440 int32_t index =
IndexOf(handle);
511 if (index == -1)
return nullptr;
517 int32_t index =
IndexOf(handle);
518 if (index == -1)
return nullptr;
539 return index < 0 || index >=
static_cast<int32_t
>(
windows.size()) ||
546 return (index != -1) ?
windows[index].monitorIndex : -1;
The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient,...
Definition gui_gradient_manager.h:64
A graphics backend: the device, the window contexts that render the GUI's windows,...
Definition gui_graphics_context.h:60
Makes and manages the OS windows and delivers their input; GUIApplication::SetWindowBackend sets one,...
Definition gui_window_backend.h:105
virtual IntRect GetWindowPixelRect(OSWindowHandle window)=0
The window's render target: OS position (for OS compositing) and size in physical pixels.
virtual void BringToFront(OSWindowHandle)=0
Raises the window above the others and asks the OS for the input focus.
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 h...
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 ne...
virtual OSWindowHandle GetActiveWindow()=0
The window with the keyboard focus, or nullptr when none of the backend's windows has it.
virtual OSWindowHandle GetWindowUnderMouse()=0
The backend's window under the mouse, or nullptr.
virtual void SetWindowMode(OSWindowHandle, WindowMode)
Sets the window's state: minimized, maximized, restored or fullscreen.
Definition gui_window_backend.h:233
virtual bool TakeCloseRequest(OSWindowHandle)
Whether the OS asked to close a WindowFlags::ConfirmClose window since last asked.
Definition gui_window_backend.h:167
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 void SetWindowVisible(OSWindowHandle, bool visible)=0
Shows or hides the window; hiding doesn't destroy it.
virtual std::optional< color4b > ReadScreenPixel(int2)
The color of a screen pixel, anywhere on the desktop (an eyedropper); nothing where the platform can'...
Definition gui_window_backend.h:165
virtual WindowMode GetWindowMode(OSWindowHandle) const
The window's state as the OS has it now; WindowMode::Normal by default.
Definition gui_window_backend.h:235
A window's rendering state: made by GraphicsContext::CreateWindowContext for each OS window,...
Definition gui_window_backend.h:72
The images the shaders can sample, each at an ImageIndex. Implemented by the backend.
Definition gui_image.h:44
bool IsNotAlive(int32_t index) const
Definition gui_os_window_manager.h:537
std::unordered_map< ID, int32_t > IDToWindowIndex
Definition gui_os_window_manager.h:500
Window * FindWindow(OSWindowHandle handle)
Definition gui_os_window_manager.h:515
bool HasAlivePopupWindows() const
True while a popup menu window is alive.
Definition gui_os_window_manager.h:165
MouseButtons GetMouseButtons()
Definition gui_os_window_manager.h:236
bool WasWindowUserClosed(ID id) const
Definition gui_os_window_manager.h:470
const Window * MainWindow() const
First top-level window still open; null when there is none.
static constexpr uint32_t kTooltipInMs
a tooltip fading in
Definition gui_os_window_manager.h:134
GradientManager * gradientManager
Application-owned; handed to each new window context for RenderFrame, so the graphics context itself ...
Definition gui_os_window_manager.h:118
std::unordered_set< ID > userClosedWindows
Windows the user closed (not code), which declaring doesn't reopen.
Definition gui_os_window_manager.h:504
bool HasAliveMainWindow() const
Any alive non-popup, non-tooltip window.
Definition gui_os_window_manager.h:456
const MonitorInfo & GetPrimaryMonitor() const
Definition gui_os_window_manager.h:298
size_t WindowCount() const
Definition gui_os_window_manager.h:451
ID GetActiveWindow() const
Definition gui_os_window_manager.h:433
float FadeProgress(const Window &window, uint32_t nowMs) const
How far a fading popup is shown now, 0 to 1 (linear in time).
void AllowReopenWindow(ID id)
Lets a window the user closed be reopened by declaring it.
Definition gui_os_window_manager.h:333
IntRect GetWindowRect(ID id) const
Definition gui_os_window_manager.h:397
ID GetTopModalWindow() const
Returns the ID of the top-most modal window (last created, still alive), or ID::Invalid() if there ar...
size_t GetMonitorCount() const
Definition gui_os_window_manager.h:269
virtual ~OSWindowManager()=default
const std::vector< MonitorInfo > & Monitors() const
Definition gui_os_window_manager.h:277
void SetWindowMode(ID id, WindowMode mode)
Definition gui_os_window_manager.h:390
void DestroyWindowContexts()
For a lost GPU device: the contexts go before the device, and come back on the new one for the same O...
void ClearParentIDInChildren(int32_t window_index)
bool IsNotAlive(ID id) const
Definition gui_os_window_manager.h:243
bool Update()
Polls the OS events and destroys closed windows' contexts; call outside BeginFrame / EndFrame.
int32_t IndexOf(OSWindowHandle handle) const
Definition gui_os_window_manager.h:530
bool HasBeenRegistered(ID id) const
Definition gui_os_window_manager.h:350
RequestCloseResult RequestClose(int32_t index, std::vector< ID > &detach_children)
OSWindowManager()=default
int GetMonitorIndexForWindow(ID id) const
Definition gui_os_window_manager.h:543
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...
void SetReducedMotion(bool reduced)
Reduced motion: popups show and hide at once.
Definition gui_os_window_manager.h:142
IPlatformInputHandler * inputHandler
Definition gui_os_window_manager.h:121
int GetMonitorIndexAt(int2 pos) const
Definition gui_os_window_manager.h:286
void SetPopupSlide(ID id, int2 away)
The way popup id opens, away from its anchor (one step on one axis, e.g.
void RaisePopup(const Window &window)
int GetPrimaryMonitorIndex() const
Definition gui_os_window_manager.h:291
Window * FindWindow(ID id)
Definition gui_os_window_manager.h:508
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.
void AnimateFades()
Moves the stand-ins, and ends the fades that are done.
bool BeginFrame()
Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse repo...
float QueryDisplayScale(OSWindowHandle handle) const
RequestCloseResult RequestCloseAllowReopen(ID id)
Closes a window from code; unlike RequestUserClose, declaring it again reopens it.
Definition gui_os_window_manager.h:323
ID GetWindowUnderMouse() const
Definition gui_os_window_manager.h:424
bool SetWindowRect(ID id, const IntRect &clientRect)
Moves and resizes a window so its client area is clientRect (screen pixels).
std::optional< color4b > ReadScreenPixel(int2 screenPos)
Definition gui_os_window_manager.h:219
void ForEachAliveWindowContext(const std::function< void(IWindowContext *, IntRect)> &func)
Calls func for each live window's context with its render-target rect (OS position,...
Definition gui_os_window_manager.h:484
bool TakeCloseRequest(ID id)
Whether the OS asked to close this (ConfirmClose) window since last asked.
Definition gui_os_window_manager.h:225
bool EndFrame()
Brackets the frame's window work (GetOrCreateWindow, SetWindowRect, closes); false (and a misuse repo...
std::unordered_map< OSWindowHandle, int32_t > HandleToWindowIndex
Definition gui_os_window_manager.h:501
bool MayFade(const Window &window) const
Popups fade unless motion is reduced; tooltips fade without sliding.
bool m_reducedMotion
Definition gui_os_window_manager.h:566
IWindowContext * GetWindowContext(ID id) const
The window's context; nullptr when the window doesn't exist.
Definition gui_os_window_manager.h:373
void RemoveWindowFromSiblingList(int32_t window_index)
static constexpr uint32_t kPopupInMs
a menu or popup fading in
Definition gui_os_window_manager.h:133
static constexpr int kPopupSlide
CSS px a popup slides in from its anchor.
Definition gui_os_window_manager.h:136
StyleManager * styleManager
Application-owned; handed to each new window context for RenderFrame, so the graphics context itself ...
Definition gui_os_window_manager.h:117
float MainDisplayScale() const
The display scale of the main window (the first top-level window still open), or of the primary monit...
bool HasAliveSecondaryWindows() const
True while a secondary top-level window (popup or utility window) is alive.
Definition gui_os_window_manager.h:177
OSWindowHandle GetWindowHandle(ID id) const
Definition gui_os_window_manager.h:378
static constexpr uint32_t kPopupOutMs
either fading out
Definition gui_os_window_manager.h:135
IntRect GetMonitorArea(int monitorIndex)
void HidePopupWindow(ID id)
Hides a popup / menu window, kept (WindowState::Hidden) for a fast reopen.
Definition gui_os_window_manager.h:190
void SetTextInputArea(ID id, IntRect screenRect)
Places the IME candidate window at screenRect (e.g.
Definition gui_os_window_manager.h:200
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.
WindowMode GetWindowMode(ID id) const
Definition gui_os_window_manager.h:391
IWindowBackend * windowBackendManager
Definition gui_os_window_manager.h:497
void DestroyAllWindowContexts()
Destroys every window's IWindowContext.
RequestCloseResult RequestUserClose(ID id)
Closes a window on the user's behalf (e.g.
Definition gui_os_window_manager.h:316
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 (SuccessRe...
float GetWindowDisplayScale(ID id) const
The OS UI scale where the window is (see IWindowBackend::GetWindowDisplayScale); 1 when unknown.
Definition gui_os_window_manager.h:358
int32_t IndexOf(ID id) const
Definition gui_os_window_manager.h:522
WindowState GetWindowState(ID id) const
Definition gui_os_window_manager.h:344
int2 GetWindowPosition(ID id) const
Definition gui_os_window_manager.h:409
void RemoveWindow(int32_t window_index)
RequestCloseResult RequestClose(int32_t index)
bool RecreateWindowContexts()
For a lost GPU device: the contexts go before the device, and come back on the new one for the same O...
IntRect CenterInMonitor(int monitorIndex, int width, int height)
void LinkToParent(int32_t window_index, ID parentID)
float MainRefreshRate() const
Refresh rate in Hz of the monitor showing the main window, or of the primary monitor before there is ...
GraphicsContext * graphicsContext
Definition gui_os_window_manager.h:496
OSWindowManager(GraphicsContext *graphicsContext, IWindowBackend *backend)
For tests without real windows: no style / gradient managers, no context init.
int2 GetWindowSize(ID id) const
Definition gui_os_window_manager.h:403
const MonitorInfo & GetMonitor(int index) const
Definition gui_os_window_manager.h:279
const std::vector< Window > & AllWindows() const
Definition gui_os_window_manager.h:452
void RefreshMonitors()
Definition gui_os_window_manager.h:256
void BringToFront(ID id)
Definition gui_os_window_manager.h:417
bool WasUserClosed(ID id) const
True when the user closed the window and it isn't reopened yet.
Definition gui_os_window_manager.h:339
RequestCloseResult RequestClose(ID id)
Definition gui_os_window_manager.h:312
void EndFadeOf(Window &window)
Removes a popup's stand-in.
ID GetWindowID(OSWindowHandle handle) const
Invalid for a handle this manager doesn't own.
Definition gui_os_window_manager.h:384
OSWindowManager(GraphicsContext *graphicsContext, IWindowBackend *backendWindowManager, IPlatformInputHandler *inputHandler, StyleManager &styleManager, GradientManager &gradientManager)
std::vector< Window > windows
Definition gui_os_window_manager.h:499
int2 GetScreenMousePos()
Definition gui_os_window_manager.h:231
Bakes serializable Styles into deduplicated runtime layout/visual styles; a StyleRef holds indices in...
Definition gui_style_manager.h:39
@ Success
Definition gui_element_storage.h:44
@ Hidden
Content clipped, no scrollbars.
Definition gui_style.h:236
std::function< void()> OnGuiFunc
Definition gui_base_types.h:14
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:12
RequestCloseResult
Outcome of an OSWindowManager close request; negative values are failures.
Definition gui_os_window_manager.h:41
WindowMode
A window's state (IWindowBackend::SetWindowMode). Any window can go fullscreen.
Definition gui_window_backend.h:60
WindowState
The life cycle of a managed window.
Definition gui_os_window_manager.h:51
void * OSWindowHandle
An OS window, opaque; what it points to is up to the window backend.
Definition gui_window_backend.h:37
AddWindowResult
Outcome of OSWindowManager::GetOrCreateWindow; negative values are failures.
Definition gui_os_window_manager.h:29
@ DefaultFlags
Definition gui_window_flags.h:61
@ CloseWithParent
Closes with its parent window; without it the window becomes top-level when the parent closes.
Definition gui_window_flags.h:45
@ NotFocusable
Never takes keyboard focus (e.g. tooltips).
Definition gui_window_flags.h:37
@ None
Definition gui_window_flags.h:13
@ Utility
Definition gui_window_flags.h:24
@ PopupMenu
Stays on top without blocking other windows; closes when another (non-child) window gets focus.
Definition gui_window_flags.h:31
@ UnknownError
Another failure.
Definition gui_os_window_manager.h:46
@ WindowAlreadyClosed
Window was already closed.
Definition gui_os_window_manager.h:45
@ CalledOutsideFrame
Called outside of BeginFrame/EndFrame.
Definition gui_os_window_manager.h:43
@ Normal
as placed (restored)
Definition gui_window_backend.h:61
@ NotRegistered
no window with this ID (GetWindowState for an unknown ID)
Definition gui_os_window_manager.h:52
@ Closing
close requested (this frame) or already closed
Definition gui_os_window_manager.h:54
@ Hidden
OS window hidden but context alive (for fast reopen of popups/menus).
Definition gui_os_window_manager.h:55
@ Alive
normal
Definition gui_os_window_manager.h:53
@ FailedToCreateOSWindow
OS window creation failed.
Definition gui_os_window_manager.h:34
@ InvalidID
Provided ID was invalid.
Definition gui_os_window_manager.h:35
@ IndexOutOfBounds
Internal error: window index out of bounds.
Definition gui_os_window_manager.h:33
@ SuccessCreate
New window created.
Definition gui_os_window_manager.h:30
@ SuccessRecycle
Existing window returned (a hidden one is shown again).
Definition gui_os_window_manager.h:31
@ WindowUserClosed
The user closed it; not reopened until AllowReopenWindow.
Definition gui_os_window_manager.h:36
@ CalledOutsideOfFrame
Called outside of BeginFrame/EndFrame.
Definition gui_os_window_manager.h:32
Definition gui_logging.h:24
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
Definition gui_base_types.h:407
Window, monitor and mouse coordinates are physical pixels.
Definition gui_window_backend.h:42
Integer 2D vector.
Definition gui_base_types.h:19