TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_input_handler_broadcaster.h
Go to the documentation of this file.
1#pragma once
2
4#include <gui_core/gui_id.h> // ID is passed by value to inline forwarding methods
5#include <gui_core/input/gui_input_enums.h> // KeyCode/KeyModifier/MouseButtons/KeyAction/MouseAction enums
6
7#include <initializer_list>
8#include <vector>
9
10namespace tachyon
11{
14
18 {
19 public:
21
22 explicit InputHandlerBroadcaster(std::initializer_list<IPlatformInputHandler*> handlers)
23 : m_handlers(handlers) {}
24
25 void OnKeyboard(tachyon::ID id, KeyCode key, int repeat, KeyModifier modifiers, KeyAction action) override
26 {
27 for (IPlatformInputHandler* h : m_handlers)
28 if (h) h->OnKeyboard(id, key, repeat, modifiers, action);
29 }
30
31 void OnMouseMove(tachyon::ID id, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers) override
32 {
33 for (IPlatformInputHandler* h : m_handlers)
34 if (h) h->OnMouseMove(id, screenPos, buttons, modifiers);
35 }
36
37 void OnMouseButton(tachyon::ID id, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers, tachyon::MouseAction action) override
38 {
39 for (IPlatformInputHandler* h : m_handlers)
40 if (h) h->OnMouseButton(id, screenPos, buttons, modifiers, action);
41 }
42
43 void OnMouseScroll(tachyon::ID id, tachyon::int2 screenPos, tachyon::float2 scrollOffset, KeyModifier modifiers) override
44 {
45 for (IPlatformInputHandler* h : m_handlers)
46 if (h) h->OnMouseScroll(id, screenPos, scrollOffset, modifiers);
47 }
48
49 void OnTextComposition(tachyon::ID id, std::string_view text, int32_t cursor) override
50 {
51 for (IPlatformInputHandler* h : m_handlers)
52 if (h) h->OnTextComposition(id, text, cursor);
53 }
54
55 void OnFileDrop(tachyon::ID id, tachyon::int2 screenPos, FileDropAction action, std::string_view data) override
56 {
57 for (IPlatformInputHandler* h : m_handlers)
58 if (h) h->OnFileDrop(id, screenPos, action, data);
59 }
60
61 private:
62 std::vector<IPlatformInputHandler*> m_handlers;
63 };
64
65} // namespace tachyon
Platform-level input interface: receives raw OS events (keyboard, mouse) and forwards them into the G...
Definition gui_platform_input_handler.h:24
void OnFileDrop(tachyon::ID id, tachyon::int2 screenPos, FileDropAction action, std::string_view data) override
A drag from another application over window id: it came, moved to screenPos (screen pixels),...
Definition gui_input_handler_broadcaster.h:55
void OnMouseButton(tachyon::ID id, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers, tachyon::MouseAction action) override
A mouse button went down or up; buttons are those held down after the change.
Definition gui_input_handler_broadcaster.h:37
void OnMouseMove(tachyon::ID id, tachyon::int2 screenPos, tachyon::MouseButtons buttons, KeyModifier modifiers) override
The mouse moved over window id; screenPos in screen pixels, buttons those held down.
Definition gui_input_handler_broadcaster.h:31
InputHandlerBroadcaster(std::initializer_list< IPlatformInputHandler * > handlers)
Definition gui_input_handler_broadcaster.h:22
void OnTextComposition(tachyon::ID id, std::string_view text, int32_t cursor) override
IME composition (pre-edit) text, UTF-8, shown but not yet committed; empty when composing ends.
Definition gui_input_handler_broadcaster.h:49
void OnKeyboard(tachyon::ID id, KeyCode key, int repeat, KeyModifier modifiers, KeyAction action) override
A key went down or up (key is its KeyCode, repeat nonzero for an auto-repeat), or a character was typ...
Definition gui_input_handler_broadcaster.h:25
void OnMouseScroll(tachyon::ID id, tachyon::int2 screenPos, tachyon::float2 scrollOffset, KeyModifier modifiers) override
The wheel turned, by scrollOffset notches; positive y is away from the user (scrolls up).
Definition gui_input_handler_broadcaster.h:43
KeyCode
Keys by what the keyboard layout makes them, not by position.
Definition gui_input_enums.h:106
KeyAction
A keyboard event: a key down or up, or a typed character (KeyChar).
Definition gui_input_enums.h:50
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
Definition gui_logging.h:24
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
Definition gui_base_types.h:121
Integer 2D vector.
Definition gui_base_types.h:19