TachyonUI 0.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 <chrono>
6#include <unordered_map>
7#include <unordered_set>
8
9namespace tachyon
10{
13
17 class NullWindowBackend final : public IWindowBackend
18 {
19 public:
21 explicit NullWindowBackend(IntRect monitor = { 0, 0, 1920, 1080 });
22
23 OSWindowHandle CreateWindow(std::string_view title, int2 size, WindowFlags windowFlags, OSWindowHandle parentOSHandle) override;
24 OSWindowHandle CreateWindow(std::string_view title, IntRect rect, WindowFlags windowFlags, OSWindowHandle parentOSHandle) override;
25 bool DestroyWindow(OSWindowHandle window) override;
27 void AttachContextToWindow(OSWindowHandle window, IWindowContext* context) override;
28 void DetachWindowContext(OSWindowHandle window) override;
29 bool IsWindow(OSWindowHandle window) override { return m_windows.contains(window); }
31 void BringToFront(OSWindowHandle) override {}
32 OSWindowHandle GetWindowUnderMouse() override { return nullptr; }
33 OSWindowHandle GetActiveWindow() override { return nullptr; }
34 uint32_t GetFocusChangeCount() const override { return 0; }
35 void PollEvents(std::function<void(OSWindowHandle, IWindowContext*)> cleanup) override;
36 int2 GetScreenMousePos() override { return {}; }
38 void SetCursor(MouseCursor) override {}
40 float GetWindowDisplayScale(OSWindowHandle) override { return 1.0f; }
41 IntRect GetWindowPixelRect(OSWindowHandle window) override { return GetWindowRect(window); }
42 void SwapBuffers(OSWindowHandle) override {}
44 int2 GetWindowPos(OSWindowHandle window) override { return GetWindowRect(window).position; }
45 int2 GetWindowSize(OSWindowHandle window) override { return GetWindowRect(window).size; }
46 void* GetNativeHandle(OSWindowHandle) override { return nullptr; }
47 bool SetWindowRect(OSWindowHandle window, const IntRect& clientRect) override;
48 void SetWindowVisible(OSWindowHandle, bool) override {}
49 std::vector<MonitorInfo> GetMonitors() const override;
50 int GetMonitorAt(int2) const override { return 0; }
51 int GetMonitorFromWindow(OSWindowHandle) const override { return 0; }
52 uint32_t GetTicks() const override;
53
54 private:
55 struct Window
56 {
57 IntRect rect;
58 IWindowContext* context = nullptr;
59 };
60
61 IntRect m_monitor;
62 std::unordered_map<OSWindowHandle, Window> m_windows;
63 std::unordered_set<OSWindowHandle> m_pendingDestroy;
64 uintptr_t m_nextHandle = 0;
65 std::chrono::steady_clock::time_point m_start = std::chrono::steady_clock::now();
66 };
67
68}
Platform-level input interface: receives raw OS events (keyboard, mouse) and forwards them into the G...
Definition gui_platform_input_handler.h:24
IWindowBackend()
Definition gui_window_backend.h:107
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:36
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:44
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:45
void SetWindowVisible(OSWindowHandle, bool) override
Shows or hides the window; hiding doesn't destroy it.
Definition gui_null_window_backend.h:48
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:42
void AttachInputHandlerToWindow(OSWindowHandle, IPlatformInputHandler *) override
Where the window's input goes (see IPlatformInputHandler); not owned, nullptr for none.
Definition gui_null_window_backend.h:26
uint32_t GetTicks() const override
A millisecond clock (SDL: since SDL started).
MouseButtons GetMouseButtons() override
The mouse buttons held down, wherever the mouse is (SDL: as of the last PollEvents).
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:29
NullWindowBackend(IntRect monitor={ 0, 0, 1920, 1080 })
monitor is the one monitor GetMonitors reports, in screen pixels.
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:33
void * GetNativeHandle(OSWindowHandle) override
The OS's own window handle, passed to GraphicsContext::CreateWindowContext (HWND on Windows,...
Definition gui_null_window_backend.h:46
void BringToFront(OSWindowHandle) override
Raises the window above the others and asks the OS for the input focus.
Definition gui_null_window_backend.h:31
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:39
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:40
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:41
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:34
void SetCursor(MouseCursor) override
Shows the system cursor for that shape; MouseCursor::None hides the cursor.
Definition gui_null_window_backend.h:38
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:50
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:51
OSWindowHandle GetWindowUnderMouse() override
The backend's window under the mouse, or nullptr.
Definition gui_null_window_backend.h:32
MouseButtons
Mouse buttons, combined with |.
Definition gui_input_enums.h:38
MouseCursor
Mouse cursor shown over an element (CSS: cursor).
Definition gui_style.h:478
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:12
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:407
Integer 2D vector.
Definition gui_base_types.h:19