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
7
namespace
input
8
{
9
class
button_state_map
10
{
11
std::map<unsigned, button_state> map_;
12
13
public
:
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
{
57
case
button_state::pressed
:
58
p
.second =
button_state::down
;
59
break
;
60
61
case
button_state::released
:
62
p
.second =
button_state::up
;
63
break
;
64
default
:
65
break
;
66
}
67
}
68
}
69
};
70
}
// namespace input
button_state.hpp
input::button_state_map
Definition
button_state_map.hpp:10
input::button_state_map::get_state
auto get_state(uint32_t button, const button_state default_state) const -> button_state
Definition
button_state_map.hpp:24
input::button_state_map::get_state
auto get_state(uint32_t button) const -> button_state
Definition
button_state_map.hpp:19
input::button_state_map::clear
void clear()
Definition
button_state_map.hpp:14
input::button_state_map::update
void update()
Definition
button_state_map.hpp:50
input::button_state_map::set_state
void set_state(uint32_t button, button_state state)
Definition
button_state_map.hpp:35
input
Definition
action_id.hpp:5
input::button_state
button_state
Definition
button_state.hpp:6
input::button_state::released
@ released
input::button_state::up
@ up
input::button_state::pressed
@ pressed
input::button_state::down
@ down
input::input_type::button
@ button
input::key_code::p
@ p
input::key_code::find
@ find
UnravelEngine
UnravelEngine
engine
engine
input
action_map
button_state_map.hpp
Generated by
1.12.0