TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_null_window_backend.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <atomic>
6#include <chrono>
7#include <condition_variable>
8#include <mutex>
9#include <unordered_map>
10#include <unordered_set>
11
12namespace tachyon
13{
16
20 class NullWindowBackend final : public IWindowBackend
21 {
22 public:
25 explicit NullWindowBackend(IntRect monitor = { 0, 0, 1920, 1080 }, float refreshHz = 0.0f);
26
27 OSWindowHandle CreateWindow(std::string_view title, int2 size, WindowFlags windowFlags, OSWindowHandle parentOSHandle) override;
28 OSWindowHandle CreateWindow(std::string_view title, IntRect rect, WindowFlags windowFlags, OSWindowHandle parentOSHandle) override;
29 bool DestroyWindow(OSWindowHandle window) override;
31 void AttachContextToWindow(OSWindowHandle window, IWindowContext* context) override;
32 void DetachWindowContext(OSWindowHandle window) override;
33 bool IsWindow(OSWindowHandle window) override { return m_windows.contains(window); }
35 void BringToFront(OSWindowHandle) override {}
36 OSWindowHandle GetWindowUnderMouse() override { return nullptr; }
37 OSWindowHandle GetActiveWindow() override { return nullptr; }
38 uint32_t GetFocusChangeCount() const override { return 0; }
39 void PollEvents(std::function<void(OSWindowHandle, IWindowContext*)> cleanup) override;
41 void WaitForEvents(float timeoutSecs) override;
42 void Wake() override;
43 uint64_t GetEventCount() const override { return m_events.load(); }
44 int2 GetScreenMousePos() override { return {}; }
46 void SetCursor(MouseCursor) override {}
48 float GetWindowDisplayScale(OSWindowHandle) override { return 1.0f; }
49 IntRect GetWindowPixelRect(OSWindowHandle window) override { return GetWindowRect(window); }
50 void SwapBuffers(OSWindowHandle) override {}
52 int2 GetWindowPos(OSWindowHandle window) override { return GetWindowRect(window).position; }
53 int2 GetWindowSize(OSWindowHandle window) override { return GetWindowRect(window).size; }
54 void* GetNativeHandle(OSWindowHandle) override { return nullptr; }
55 bool SetWindowRect(OSWindowHandle window, const IntRect& clientRect) override;
56 void SetWindowVisible(OSWindowHandle, bool) override {}
57 std::vector<MonitorInfo> GetMonitors() const override;
58 int GetMonitorAt(int2) const override { return 0; }
59 int GetMonitorFromWindow(OSWindowHandle) const override { return 0; }
60 uint32_t GetTicks() const override;
61
62 private:
63 struct Window
64 {
65 IntRect rect;
66 IWindowContext* context = nullptr;
67 };
68
69 IntRect m_monitor;
70 float m_refreshHz = 0.0f;
71 std::unordered_map<OSWindowHandle, Window> m_windows;
72 std::unordered_set<OSWindowHandle> m_pendingDestroy;
73 uintptr_t m_nextHandle = 0;
74 std::chrono::steady_clock::time_point m_start = std::chrono::steady_clock::now();
75
76 std::mutex m_wakeMutex;
77 std::condition_variable m_wakeSignal;
78 bool m_woken = false;
79 std::atomic<uint64_t> m_events = 0;
80 };
81
82}
Platform-level input interface: receives raw OS events (keyboard, mouse) and forwards them into the G...
Definition gui_platform_input_handler.h:25
IWindowBackend()
Definition gui_window_backend.h:114
A window's rendering state: made by GraphicsContext::CreateWindowContext for each OS window,...
Definition gui_window_backend.h:72
void DetachWindowContext(OSWindowHandle window) override
Clears the context pointer stored in the OS window, so PollEvents' cleanup callback gets nullptr inst...
int2 GetScreenMousePos() override
The mouse position in screen pixels (SDL: as of the last PollEvents).
Definition gui_null_window_backend.h:44
uint64_t GetEventCount() const override
How many OS events (input, window changes, Wake) the backend has seen; it only goes up,...
Definition gui_null_window_backend.h:43
void PollEvents(std::function< void(OSWindowHandle, IWindowContext *)> cleanup) override
Handles the OS's pending events, delivering input to the attached handlers.
bool DestroyWindow(OSWindowHandle window) override
Queues the window for destruction: the next PollEvents passes its context to cleanup,...
std::vector< MonitorInfo > GetMonitors() const override
Every monitor, the primary first.
int2 GetWindowPos(OSWindowHandle window) override
The client area's top-left in screen pixels.
Definition gui_null_window_backend.h:52
OSWindowHandle CreateWindow(std::string_view title, int2 size, WindowFlags windowFlags, OSWindowHandle parentOSHandle) override
Creates a window whose client area is size pixels, placed by the OS.
int2 GetWindowSize(OSWindowHandle window) override
The client area's size in pixels; {0,0} while minimized.
Definition gui_null_window_backend.h:53
void SetWindowVisible(OSWindowHandle, bool) override
Shows or hides the window; hiding doesn't destroy it.
Definition gui_null_window_backend.h:56
void AttachContextToWindow(OSWindowHandle window, IWindowContext *context) override
Stores the window's context (not owned), for GetWindowContext, for the ID passed with the window's in...
void SwapBuffers(OSWindowHandle) override
Presents for a graphics API that swaps through the window (OpenGL).
Definition gui_null_window_backend.h:50
void AttachInputHandlerToWindow(OSWindowHandle, IPlatformInputHandler *) override
Where the window's input goes (see IPlatformInputHandler); not owned, nullptr for none.
Definition gui_null_window_backend.h:30
uint32_t GetTicks() const override
A millisecond clock (SDL: since SDL started).
void Wake() override
Ends a WaitForEvents early, or the next one when none runs; counts as an event.
MouseButtons GetMouseButtons() override
The mouse buttons held down, wherever the mouse is (SDL: as of the last PollEvents).
void WaitForEvents(float timeoutSecs) override
No OS events come: waits for Wake or the timeout.
bool IsWindow(OSWindowHandle window) override
True while the handle is a live window of this backend; false once it was destroyed (by code or the u...
Definition gui_null_window_backend.h:33
NullWindowBackend(IntRect monitor={ 0, 0, 1920, 1080 }, float refreshHz=0.0f)
monitor is the one monitor GetMonitors reports, in screen pixels, refreshing at refreshHz (0: unknown...
IntRect GetWindowRect(OSWindowHandle window) override
Client area in pixels; {0,0,0,0} while minimized.
OSWindowHandle CreateWindow(std::string_view title, IntRect rect, WindowFlags windowFlags, OSWindowHandle parentOSHandle) override
Creates a window whose client area is rect (screen pixels); otherwise as the size overload.
OSWindowHandle GetActiveWindow() override
The window with the keyboard focus, or nullptr when none of the backend's windows has it.
Definition gui_null_window_backend.h:37
void * GetNativeHandle(OSWindowHandle) override
The OS's own window handle, passed to GraphicsContext::CreateWindowContext (HWND on Windows,...
Definition gui_null_window_backend.h:54
void BringToFront(OSWindowHandle) override
Raises the window above the others and asks the OS for the input focus.
Definition gui_null_window_backend.h:35
void SetTextInputArea(OSWindowHandle, IntRect) override
Where text is being typed in the window (window coordinates), so the IME places its candidate list ne...
Definition gui_null_window_backend.h:47
bool SetWindowRect(OSWindowHandle window, const IntRect &clientRect) override
Moves and resizes the window so its client area is clientRect (screen pixels); the backend accounts f...
float GetWindowDisplayScale(OSWindowHandle) override
The UI scale the OS asks for in this window: pixel density times the monitor's content scale (1....
Definition gui_null_window_backend.h:48
IntRect GetWindowPixelRect(OSWindowHandle window) override
The window's render target: OS position (for OS compositing) and size in physical pixels.
Definition gui_null_window_backend.h:49
uint32_t GetFocusChangeCount() const override
Goes up whenever keyboard focus moves between windows, or to or from another application; open popups...
Definition gui_null_window_backend.h:38
void SetCursor(MouseCursor) override
Shows the system cursor for that shape; MouseCursor::None hides the cursor.
Definition gui_null_window_backend.h:46
int GetMonitorAt(int2) const override
Index into GetMonitors of the monitor holding the screen point pos; 0 (the primary) when no monitor h...
Definition gui_null_window_backend.h:58
IWindowContext * GetWindowContext(OSWindowHandle window) override
The context attached with AttachContextToWindow, or nullptr.
int GetMonitorFromWindow(OSWindowHandle) const override
Index into GetMonitors of the window's monitor; -1 for an unknown window.
Definition gui_null_window_backend.h:59
OSWindowHandle GetWindowUnderMouse() override
The backend's window under the mouse, or nullptr.
Definition gui_null_window_backend.h:36
MouseButtons
Mouse buttons, combined with |.
Definition gui_input_enums.h:38
MouseCursor
Mouse cursor shown over an element (CSS: cursor).
Definition gui_style.h:481
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:14
void * OSWindowHandle
An OS window, opaque; what it points to is up to the window backend.
Definition gui_window_backend.h:37
Definition gui_logging.h:24
Definition gui_base_types.h:406
Integer 2D vector.
Definition gui_base_types.h:18