TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_input_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4#include <vector>
9
10namespace tachyon
11{
14
15 class ScrollManagement;
16 class ElementStorage;
17 class GUIStateManager;
18 class TabChainManager;
19 class ITextSystem;
20
29
33 {
34 public:
35 InputManager() = default;
36 ~InputManager() = default;
37
40 void OnKeyboard(tachyon::ID windowId, KeyCode key, int repeat, KeyModifier modifiers, KeyAction action) override;
41 void OnMouseMove(tachyon::ID windowId, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers) override;
42 void OnMouseButton(tachyon::ID windowId, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers, MouseAction action) override;
43 void OnMouseScroll(tachyon::ID windowId, tachyon::int2 screenPos, tachyon::float2 scrollOffset, KeyModifier modifiers) override;
44 void OnTextComposition(tachyon::ID, std::string_view, int32_t) override {} // the text editor shows it
45 void OnFileDrop(tachyon::ID windowId, tachyon::int2 screenPos, FileDropAction action, std::string_view data) override;
47
49 const FileDrag* GetFileDrag() const { return m_fileDrag.windowID != ID::Invalid() ? &m_fileDrag : nullptr; }
52 std::vector<FileDrop> TakeFileDrops() { return std::exchange(m_fileDrops, {}); }
53
57 {
58 if (h) m_globalHandlers.push_back(std::move(h));
59 }
60
63 {
64 if (m_globalHandlers.empty()) return false;
65 m_globalHandlers.pop_back();
66 return true;
67 }
68
70 void ConsumeKey();
71
73 const std::vector<RecordedInputEvent>& GetRecordedEvents() const { return m_recordedEvents; }
75 void ConsumeEvent(size_t index) { if (index < m_recordedEvents.size()) m_recordedEvents[index].consumed = true; }
76
78 MouseButtons GetCurrentButtons() const { return m_currentButtons; }
83
86 void UpdatePreHover(GUIStateManager& guiStateManager);
87
91 void SynthesizeMissingMouseEvents(int2 screenPos,MouseButtons lastPhysicalButtons, MouseButtons physicalButtons);
92
95 void Process(GUIStateManager& guiStateManager,
96 ElementStorage& elementStorage,
97 TabChainManager& tabChainManager,
98 ITextSystem* textSystem,
99 ID overID);
100
103 void Dispatch(GUIStateManager& guiStateManager, ElementStorage& storage);
104
105 private:
106 static bool IsMouseEvent(EventType type);
107 static bool IsKeyboardEvent(EventType type);
108
109 void DispatchSingleEvent(RecordedInputEvent& recorded, GUIStateManager& guiStateManager, ElementStorage& storage);
110
112 int2 m_prevScreenPos {};
113 MouseButtons m_currentButtons { MouseButtons::None };
114 ID m_prevFocusedID = ID::Invalid();
115
116 std::vector<RecordedInputEvent> m_recordedEvents;
117 std::vector<EventHandler> m_globalHandlers;
118
119 FileDrag m_fileDrag;
120 FileDrop m_dropping;
121 std::vector<FileDrop> m_fileDrops;
122 };
123
124}
The frame's element tree.
Definition gui_element_storage.h:100
Owns the per-frame state objects and runs their BeginFrame / EndFrame in order.
Definition gui_state_manager.h:65
Platform-level input interface: receives raw OS events (keyboard, mouse) and forwards them into the G...
Definition gui_platform_input_handler.h:24
Text and icon registration, measurement, rendering and editing.
Definition gui_text_system.h:178
bool IsDragAbandoned(MouseButtons button=MouseButtons::Left) const
Whether a drag held with button was left behind: the button is up and no release is queued for this f...
void Process(GUIStateManager &guiStateManager, ElementStorage &elementStorage, TabChainManager &tabChainManager, ITextSystem *textSystem, ID overID)
Per-frame input processing: tab navigation, text editor focus, dispatch to element handlers,...
void ConsumeEvent(size_t index)
Marks recorded event index as consumed, for something that acted on it while building.
Definition gui_input_manager.h:75
const FileDrag * GetFileDrag() const
The drag from another application over one of the app's windows now; null when there's none.
Definition gui_input_manager.h:49
void UpdatePreHover(GUIStateManager &guiStateManager)
Updates the drag position from the latest recorded mouse event; call before hover resolution and GUIS...
const std::vector< RecordedInputEvent > & GetRecordedEvents() const
This frame's recorded events, e.g. to read them before Process.
Definition gui_input_manager.h:73
void Dispatch(GUIStateManager &guiStateManager, ElementStorage &storage)
Dispatches each recorded event to elements by capture / focus / hover rules, then clears the events.
void OnTextComposition(tachyon::ID, std::string_view, int32_t) override
IPlatformInputHandler: record OS events for this frame's dispatch.
Definition gui_input_manager.h:44
std::vector< FileDrop > TakeFileDrops()
The drops from other applications since the last call, oldest first.
Definition gui_input_manager.h:52
void ConsumeKey()
Marks the most recently recorded keyboard event as consumed, so Dispatch skips it.
void SynthesizeMissingMouseEvents(int2 screenPos, MouseButtons lastPhysicalButtons, MouseButtons physicalButtons)
Detects mouse button presses the OS swallowed (e.g.
void OnMouseScroll(tachyon::ID windowId, tachyon::int2 screenPos, tachyon::float2 scrollOffset, KeyModifier modifiers) override
IPlatformInputHandler: record OS events for this frame's dispatch.
void OnKeyboard(tachyon::ID windowId, KeyCode key, int repeat, KeyModifier modifiers, KeyAction action) override
IPlatformInputHandler: record OS events for this frame's dispatch.
MouseButtons GetCurrentButtons() const
Mouse buttons held as of the last recorded button event.
Definition gui_input_manager.h:78
void PushGlobalHandler(EventHandler h)
Pushes a global handler.
Definition gui_input_manager.h:56
void OnMouseMove(tachyon::ID windowId, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers) override
IPlatformInputHandler: record OS events for this frame's dispatch.
void OnFileDrop(tachyon::ID windowId, tachyon::int2 screenPos, FileDropAction action, std::string_view data) override
IPlatformInputHandler: record OS events for this frame's dispatch.
void OnMouseButton(tachyon::ID windowId, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers, MouseAction action) override
IPlatformInputHandler: record OS events for this frame's dispatch.
bool PopGlobalHandler()
Pops the last pushed global handler; false when there is none.
Definition gui_input_manager.h:62
Scroll containers' offsets (pixels), kept across frames by ID behind handles.
Definition gui_scroll_management.h:33
Tracks the next/prev tab targets around the focused element, rebuilt each frame during construction a...
Definition gui_tab_chain_manager.h:18
KeyCode
Keys by what the keyboard layout makes them, not by position.
Definition gui_input_enums.h:106
EventType
The kind of input event the GUI dispatches to element handlers.
Definition gui_input_enums.h:75
KeyAction
A keyboard event: a key down or up, or a typed character (KeyChar).
Definition gui_input_enums.h:50
std::function< bool(ElementEvent &&input)> EventHandler
Element-level input handler used by the immediate-mode dispatcher; returns true when it consumed the ...
Definition gui_input_handler_func.h:35
KeyModifier
Modifier keys held, combined with |.
Definition gui_input_enums.h:26
FileDropAction
A step of a drag from another application (files, text) over one of the app's windows.
Definition gui_input_enums.h:65
MouseButtons
Mouse buttons, combined with |.
Definition gui_input_enums.h:38
MouseAction
Whether a mouse button went down or up.
Definition gui_input_enums.h:58
@ None
Definition gui_input_enums.h:76
@ None
Definition gui_input_enums.h:39
@ Left
Definition gui_input_enums.h:40
Definition gui_logging.h:24
A drag from another application, of files or text, over one of the app's windows.
Definition gui_input_state.h:62
tachyon::ID windowID
Definition gui_input_state.h:63
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
Snapshot of input state for a single recorded OS event.
Definition gui_input_state.h:17
A single OS input event recorded for dispatch this frame.
Definition gui_input_manager.h:23
bool consumed
already handled; Dispatch skips it
Definition gui_input_manager.h:27
EventType type
Definition gui_input_manager.h:24
tachyon::ID windowId
OS window that received the event.
Definition gui_input_manager.h:26
InputState state
Definition gui_input_manager.h:25
Definition gui_base_types.h:121
Integer 2D vector.
Definition gui_base_types.h:19