Unravel Engine C++ Reference
Loading...
Searching...
No Matches
os_mouse.cpp
Go to the documentation of this file.
1#include "os_mouse.hpp"
3namespace input
4{
5// ----------------------------------------------------------------------------
7{
8 return button_state_map_.get_state(button, button_state::up);
9}
10
11// ----------------------------------------------------------------------------
13{
14 return button_state_map_;
15}
16
17auto os_mouse::get_axis_value(uint32_t axis) const -> float
18{
19 if(!is_input_allowed())
20 {
21 return 0.0f;
22 }
23 const auto& find = axis_map_.find(axis);
24
25 if(find == axis_map_.end())
26 {
27 return 0.0f;
28 }
29
30 return find->second;
31}
32
33// ----------------------------------------------------------------------------
35{
36 return get_button_state(static_cast<uint32_t>(mouse_button::left_button));
37}
38
39// ----------------------------------------------------------------------------
41{
42 return get_button_state(static_cast<uint32_t>(mouse_button::middle_button));
43}
44
45// ----------------------------------------------------------------------------
46auto os_mouse::get_name() const -> const std::string&
47{
48 static const std::string name = "Mouse";
49 return name;
50}
51
52// ----------------------------------------------------------------------------
54{
55 return position_;
56}
57
58// ----------------------------------------------------------------------------
60{
61 return get_button_state(static_cast<uint32_t>(mouse_button::right_button));
62}
63
64// ----------------------------------------------------------------------------
65auto os_mouse::get_scroll() const -> float
66{
67 return scroll_;
68}
69
70// ----------------------------------------------------------------------------
71auto os_mouse::is_down(uint32_t button) const -> bool
72{
73 if(!is_input_allowed())
74 {
75 return false;
76 }
77 const button_state state = get_button_state(button);
78 return (state == button_state::down || state == button_state::pressed);
79}
80
81// ----------------------------------------------------------------------------
82auto os_mouse::is_pressed(uint32_t button) const -> bool
83{
84 if(!is_input_allowed())
85 {
86 return false;
87 }
88 return get_button_state(button) == button_state::pressed;
89}
90
91auto os_mouse::is_released(uint32_t button) const -> bool
92{
93 if(!is_input_allowed())
94 {
95 return false;
96 }
97 return get_button_state(button) == button_state::released;
98}
99
100// ----------------------------------------------------------------------------
102{
103 axis_map_[int(mouse_axis::x)] = float(pos.x - position_.x);
104 axis_map_[int(mouse_axis::y)] = float(position_.y - pos.y);
105
106 position_ = pos;
107}
108
109// ----------------------------------------------------------------------------
111{
112 axis_map_[int(mouse_axis::scroll)] = scroll - scroll_;
113
114 scroll_ = scroll;
115}
116
117// ----------------------------------------------------------------------------
119{
120 button_state_map_.update();
121
122 scroll_ = 0;
123
124 for(auto& kvp : axis_map_)
125 {
126 kvp.second = 0.0f;
127 }
128}
129} // namespace input
auto get_middle_button_state() const -> button_state override
Definition os_mouse.cpp:40
auto get_position() const -> coord override
Definition os_mouse.cpp:53
auto get_name() const -> const std::string &override
Definition os_mouse.cpp:46
auto get_left_button_state() const -> button_state override
Definition os_mouse.cpp:34
auto get_button_state(uint32_t button) const -> button_state override
Definition os_mouse.cpp:6
void set_scroll(float scroll)
Definition os_mouse.cpp:110
auto get_scroll() const -> float override
Definition os_mouse.cpp:65
auto is_pressed(uint32_t button) const -> bool override
Definition os_mouse.cpp:82
auto get_axis_value(uint32_t axis) const -> float override
Definition os_mouse.cpp:17
auto is_down(uint32_t button) const -> bool override
Definition os_mouse.cpp:71
auto is_released(uint32_t button) const -> bool override
Definition os_mouse.cpp:91
auto get_right_button_state() const -> button_state override
Definition os_mouse.cpp:59
auto get_button_state_map() -> button_state_map &
Definition os_mouse.cpp:12
void set_position(coord pos)
Definition os_mouse.cpp:101
std::string name
Definition hub.cpp:27