Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
actions.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020 WerWolv
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#include <functional>
20#include <string>
21#include <aurore/core/audio.hpp>
22#include <aurore/core/input.hpp>
23
24namespace aurore
25{
26
27class View;
28
29typedef std::function<bool(View*)> ActionListener;
30
31typedef int ActionIdentifier;
32
33typedef int AuroreKeyCode;
34
36{
38 int mod {};
39
40 explicit AuroreKeyCombination(const int key)
41 {
42 if (key == AURORE_KBD_KEY_UNKNOWN)
43 {
45 return;
46 }
47 code = static_cast<AuroreKeyboardScancode>(key & 0xFFFF);
48 mod = static_cast<AuroreKeyboardModifiers>((key >> 16) & 0xFFFF);
49 }
50
56
58 : code(code)
59 , mod(mod)
60 {
61 }
62
63 operator int() const
64 {
65 return mod << 16 | code;
66 }
67
68 bool operator==(const int a) const
69 {
70 return (mod << 16 | code) == a;
71 }
72
73 bool operator!=(const int a) const
74 {
75 return (mod << 16 | code) != a;
76 }
77};
78
80{
81 public:
82 explicit AuroreKeyState(const AuroreKeyCombination keyComb)
83 : key(keyComb)
84 {
85 }
86
88 bool pressed {};
90
91 [[nodiscard]] int getModifiers() const
92 {
93 return this->key.mod;
94 }
95
96 [[nodiscard]] AuroreKeyboardScancode getScancode() const
97 {
98 return this->key.code;
99 }
100};
101
102#define ACTION_NONE -1
103
110
112{
113 public:
114 Action(const int button, const ActionIdentifier identifier, const std::string& hintText,
115 const bool available, const bool hidden, const bool allowRepeating, const Sound sound, const ActionListener& actionListener)
116 {
117 this->type = ACTION_COUNT;
118 this->button = button;
119 this->identifier = identifier;
120 this->hintText = hintText;
121 this->available = available;
122 this->hidden = hidden;
123 this->allowRepeating = allowRepeating;
124 this->sound = sound;
125 this->actionListener = actionListener;
126 }
127
128 virtual ~Action() = default;
129
130 virtual bool operator==(const ControllerButton other) const
131 {
132 return this->type == ACTION_GAMEPAD && this->button == other;
133 }
134
135 virtual bool operator==(const AuroreKeyCode other) const
136 {
137 return this->type == ACTION_KEYBOARD && this->button == other;
138 }
139
140 [[nodiscard]] ActionIdentifier getIdentifier() const
141 {
142 return this->identifier;
143 }
144
145 [[nodiscard]] ActionType getType() const
146 {
147 return this->type;
148 }
149
150 [[nodiscard]] int getButton() const
151 {
152 return this->button;
153 }
154
155 [[nodiscard]] std::string getHintText() const
156 {
157 return this->hintText;
158 }
159
160 void setHintText(const std::string& hintText)
161 {
162 this->hintText = hintText;
163 }
164
165 [[nodiscard]] bool isAvailable() const
166 {
167 return this->available;
168 }
169
170 void setAvailable(const bool isAvailable)
171 {
172 this->available = isAvailable;
173 }
174
175 [[nodiscard]] bool isHidden() const
176 {
177 return this->hidden;
178 }
179
180 void setHidden(const bool hidden)
181 {
182 this->hidden = hidden;
183 }
184
185 [[nodiscard]] bool isAllowRepeating() const
186 {
187 return this->allowRepeating;
188 }
189
190 [[nodiscard]] Sound getSound() const
191 {
192 return this->sound;
193 }
194
195 [[nodiscard]] ActionListener getActionListener() const
196 {
197 return this->actionListener;
198 }
199
200 protected:
202 int button {};
204 std::string hintText {};
205 bool available {};
206 bool hidden {};
210};
211
212class KeyboardAction final : public Action
213{
214 public:
221};
222
223class GamepadAction final : public Action
224{
225 public:
232};
233
234} // namespace aurore
Definition actions.hpp:112
bool hidden
Definition actions.hpp:206
virtual ~Action()=default
bool allowRepeating
Definition actions.hpp:207
ActionIdentifier getIdentifier() const
Definition actions.hpp:140
ActionListener getActionListener() const
Definition actions.hpp:195
ActionListener actionListener
Definition actions.hpp:209
ActionType getType() const
Definition actions.hpp:145
virtual bool operator==(const AuroreKeyCode other) const
Definition actions.hpp:135
std::string getHintText() const
Definition actions.hpp:155
void setHintText(const std::string &hintText)
Definition actions.hpp:160
std::string hintText
Definition actions.hpp:204
bool isAllowRepeating() const
Definition actions.hpp:185
void setAvailable(const bool isAvailable)
Definition actions.hpp:170
ActionType type
Definition actions.hpp:201
virtual bool operator==(const ControllerButton other) const
Definition actions.hpp:130
void setHidden(const bool hidden)
Definition actions.hpp:180
int button
Definition actions.hpp:202
ActionIdentifier identifier
Definition actions.hpp:203
Sound sound
Definition actions.hpp:208
bool available
Definition actions.hpp:205
bool isAvailable() const
Definition actions.hpp:165
Sound getSound() const
Definition actions.hpp:190
Action(const int button, const ActionIdentifier identifier, const std::string &hintText, const bool available, const bool hidden, const bool allowRepeating, const Sound sound, const ActionListener &actionListener)
Definition actions.hpp:114
bool isHidden() const
Definition actions.hpp:175
int getButton() const
Definition actions.hpp:150
Definition actions.hpp:80
bool pressed
Definition actions.hpp:88
int getModifiers() const
Definition actions.hpp:91
Time repeatingStop
Definition actions.hpp:89
AuroreKeyCombination key
Definition actions.hpp:87
AuroreKeyboardScancode getScancode() const
Definition actions.hpp:96
AuroreKeyState(const AuroreKeyCombination keyComb)
Definition actions.hpp:82
Definition actions.hpp:224
GamepadAction(const ControllerButton button, const ActionIdentifier identifier, const std::string &hintText, const bool available, const bool hidden, const bool allowRepeating, const Sound sound, const ActionListener &actionListener)
Definition actions.hpp:226
Definition actions.hpp:213
KeyboardAction(const AuroreKeyCode button, const ActionIdentifier identifier, const std::string &hintText, const bool available, const bool hidden, const bool allowRepeating, const Sound sound, const ActionListener &actionListener)
Definition actions.hpp:215
Definition view.hpp:232
Definition actions.hpp:25
AuroreKeyboardScancode
Definition input.hpp:44
@ AURORE_KBD_KEY_UNKNOWN
Definition input.hpp:46
AuroreKeyboardModifiers
Definition input.hpp:33
@ AURORE_KBD_MODIFIER_NONE
Definition input.hpp:34
int ActionIdentifier
Definition actions.hpp:31
ControllerButton
Definition input.hpp:179
int AuroreKeyCode
Definition actions.hpp:33
ActionType
Definition actions.hpp:105
@ ACTION_KEYBOARD
Definition actions.hpp:107
@ ACTION_COUNT
Definition actions.hpp:108
@ ACTION_GAMEPAD
Definition actions.hpp:106
Sound
Definition audio.hpp:23
retro_time_t Time
Definition time.hpp:31
std::function< bool(View *)> ActionListener
Definition actions.hpp:29
Definition actions.hpp:36
bool operator==(const int a) const
Definition actions.hpp:68
AuroreKeyCombination(const AuroreKeyboardScancode code, const int mod)
Definition actions.hpp:57
AuroreKeyCombination(const int key)
Definition actions.hpp:40
AuroreKeyCombination(const AuroreKeyboardScancode code)
Definition actions.hpp:51
bool operator!=(const int a) const
Definition actions.hpp:73
int mod
Definition actions.hpp:38
AuroreKeyboardScancode code
Definition actions.hpp:37