lxgui
Loading...
Searching...
No Matches
input_sdl_source.hpp
1#ifndef LXGUI_INPUT_SDL_SOURCE_HPP
2#define LXGUI_INPUT_SDL_SOURCE_HPP
3
4#include "lxgui/gui_vector2.hpp"
5#include "lxgui/input_source.hpp"
6#include "lxgui/utils.hpp"
7
8#include <chrono>
9#include <memory>
10#include <unordered_map>
11
12struct SDL_Window;
13struct SDL_Renderer;
14struct SDL_Cursor;
15union SDL_Event;
16
17namespace lxgui::input { namespace sdl {
18
20class source final : public input::source {
21public:
28 explicit source(SDL_Window* win, SDL_Renderer* rdr, bool initialise_sdl_image);
29
30 source(const source&) = delete;
31 source& operator=(const source&) = delete;
32
33 utils::ustring get_clipboard_content() override;
34 void set_clipboard_content(const utils::ustring& content) override;
35
36 void on_sdl_event(const SDL_Event& event);
37
38 void set_mouse_cursor(const std::string& file_name, const gui::vector2i& hot_spot) override;
39 void reset_mouse_cursor() override;
40
41 float get_interface_scaling_factor_hint() const override;
42
43private:
44 gui::vector2ui get_window_pixel_size_() const;
45 void update_pixel_per_unit_();
46 input::key from_sdl_(int sdl_key) const;
47
48 SDL_Window* window_ = nullptr;
49 SDL_Renderer* renderer_ = nullptr;
50
51 float pixels_per_unit_ = 1.0f;
52
53 using wrapped_cursor = std::unique_ptr<SDL_Cursor, void (*)(SDL_Cursor*)>;
54 std::unordered_map<std::string, wrapped_cursor> cursor_map_;
55};
56
57}} // namespace lxgui::input::sdl
58
59#endif
SDL implementation of input::source.
void set_clipboard_content(const utils::ustring &content) override
Replace the content of the clipboard.
void on_sdl_event(const SDL_Event &event)
void reset_mouse_cursor() override
Sets the mouse cursor back to the default (arrow).
source(SDL_Window *win, SDL_Renderer *rdr, bool initialise_sdl_image)
Initializes this input source.
void set_mouse_cursor(const std::string &file_name, const gui::vector2i &hot_spot) override
Sets the mouse cursor to a given image on disk.
utils::ustring get_clipboard_content() override
Retrieve a copy of the clipboard content.
source & operator=(const source &)=delete
float get_interface_scaling_factor_hint() const override
Return the interface scaling factor suggested by the operating system.
source(const source &)=delete
The base class for input source implementation.
Holds 2D coordinates.