lxgui
Loading...
Searching...
No Matches
input_source.hpp
1#ifndef LXGUI_INPUT_SOURCE_HPP
2#define LXGUI_INPUT_SOURCE_HPP
3
4#include "lxgui/gui_vector2.hpp"
5#include "lxgui/input_keys.hpp"
6#include "lxgui/lxgui.hpp"
7#include "lxgui/utils.hpp"
8#include "lxgui/utils_signal.hpp"
9#include "lxgui/utils_string.hpp"
10
11#include <array>
12#include <string>
13#include <vector>
14
15namespace lxgui::input {
16
39class source {
40public:
41 struct key_state {
42 std::array<bool, key_number> is_key_down = {};
43 };
44
45 struct mouse_state {
46 std::array<bool, mouse_button_number> is_button_down = {};
48 float wheel = 0.0f;
49 };
50
52 source() = default;
53
55 virtual ~source() = default;
56
57 // Non-copiable, non-movable
58 source(const source&) = delete;
59 source(source&&) = delete;
60 source& operator=(const source&) = delete;
61 source& operator=(source&&) = delete;
62
64 const key_state& get_key_state() const;
65
67 const mouse_state& get_mouse_state() const;
68
74
79 virtual utils::ustring get_clipboard_content() = 0;
80
85 virtual void set_clipboard_content(const utils::ustring& content) = 0;
86
93 virtual void set_mouse_cursor(const std::string& file_name, const gui::vector2i& hot_spot) = 0;
94
96 virtual void reset_mouse_cursor() = 0;
97
107 virtual float get_interface_scaling_factor_hint() const;
108
116
124
132
140
147
154
161
168 utils::signal<void(std::uint32_t)> on_text_entered;
169
176
177protected:
180
182};
183
184} // namespace lxgui::input
185
186#endif
The base class for input source implementation.
utils::signal< void(input::mouse_button, const gui::vector2f &)> on_mouse_pressed
Signal triggered when a mouse button is pressed.
utils::signal< void(input::key)> on_key_pressed
Signal triggered when a keyboard key is pressed.
virtual void reset_mouse_cursor()=0
Sets the mouse cursor back to the default (arrow).
virtual void set_clipboard_content(const utils::ustring &content)=0
Replace the content of the clipboard.
virtual utils::ustring get_clipboard_content()=0
Retrieve a copy of the clipboard content.
utils::signal< void(std::uint32_t)> on_text_entered
Signal triggered when text is entered.
const gui::vector2ui & get_window_dimensions() const
Get the window size (in pixels)
gui::vector2ui window_dimensions_
utils::signal< void(float, const gui::vector2f &)> on_mouse_wheel
Signal triggered when the mouse wheel is moved.
const mouse_state & get_mouse_state() const
Returns the mouse state of this input source.
virtual ~source()=default
Destructor.
utils::signal< void(input::key)> on_key_pressed_repeat
Signal triggered when a keyboard key is long-pressed and repeats.
virtual float get_interface_scaling_factor_hint() const
Return the interface scaling factor suggested by the operating system.
source()=default
Constructor.
utils::signal< void(const gui::vector2ui &)> on_window_resized
Signal triggered whenever the window is resized or changes resolution.
const key_state & get_key_state() const
Returns the keyboard state of this input source.
source & operator=(const source &)=delete
virtual void set_mouse_cursor(const std::string &file_name, const gui::vector2i &hot_spot)=0
Sets the mouse cursor to a given image on disk.
source(source &&)=delete
source(const source &)=delete
source & operator=(source &&)=delete
utils::signal< void(input::key)> on_key_released
Signal triggered when a keyboard key is released.
utils::signal< void(input::mouse_button, const gui::vector2f &)> on_mouse_released
Signal triggered when a mouse button is released.
utils::signal< void(const gui::vector2f &, const gui::vector2f &)> on_mouse_moved
Signal triggered when the mouse moves.
Generic class for observing and triggering events.
std::array< bool, key_number > is_key_down
std::array< bool, mouse_button_number > is_button_down