Unravel Engine C++ Reference
Loading...
Searching...
No Matches
button_state_map.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "button_state.hpp"
4#include <iostream>
5#include <map>
6
7namespace input
8{
10{
11 std::map<unsigned, button_state> map_;
12
13public:
14 void clear()
15 {
16 map_.clear();
17 }
18
19 auto get_state(uint32_t button) const -> button_state
20 {
21 return map_.at(button);
22 }
23
24 auto get_state(uint32_t button, const button_state default_state) const -> button_state
25 {
26 const auto& find = map_.find(button);
27 if(find == map_.end())
28 {
29 return default_state;
30 }
31
32 return find->second;
33 }
34
35 void set_state(uint32_t button, button_state state)
36 {
37 const button_state last_state = get_state(button, button_state::up);
38
39 if(state == button_state::pressed)
40 {
41 if(last_state == button_state::down || last_state == button_state::pressed)
42 {
43 state = button_state::down;
44 }
45 }
46
47 map_[button] = state;
48 }
49
50 void update()
51 {
52 // Update Pressed and Released states to Down and Up
53 for(auto& p : map_)
54 {
55 switch(p.second)
56 {
58 p.second = button_state::down;
59 break;
60
62 p.second = button_state::up;
63 break;
64 default:
65 break;
66 }
67 }
68 }
69};
70} // namespace input
auto get_state(uint32_t button, const button_state default_state) const -> button_state
auto get_state(uint32_t button) const -> button_state
void set_state(uint32_t button, button_state state)