Berserk
InputDevices.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of Berserk Engine project */
3 /* https://github.com/EgorOrachyov/Berserk */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2018 - 2021 Egor Orachyov */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef BERSERK_INPUTDEVICES_HPP
29 #define BERSERK_INPUTDEVICES_HPP
30 
31 #include <core/Config.hpp>
32 #include <core/Typedefs.hpp>
33 #include <core/math/TVecN.hpp>
36 #include <platform/InputDefs.hpp>
37 
38 #include <vector>
39 
41 
51 class Mouse : public RefCnt {
52 public:
53  static const uint32 MAX_BUTTONS = 2;
54 
55  BRK_API ~Mouse() override = default;
56 
58  const Point2f &GetPosition() const { return mPosition; }
59 
61  const Size2f &GetDelta() const { return mDelta; }
62 
64  const StringName &GetName() const { return mName; }
65 
67  InputDeviceState GetState() const { return mState; }
68 
70  const std::vector<InputAction> &GetButtonsStates() const { return mButtons; }
71 
72 protected:
77  std::vector<InputAction> mButtons;
78 };
79 
84 class Keyboard : public RefCnt {
85 public:
86  static const uint32 MAX_KEYS = 100;
87 
88  BRK_API ~Keyboard() override = default;
89 
91  const StringName &GetName() const { return mName; }
92 
94  InputDeviceState GetState() const { return mState; }
95 
97  const std::vector<InputAction> &GetKeysStates() const { return mKeys; }
98 
99 protected:
102  std::vector<InputAction> mKeys;
103 };
104 
109 class Joystick : public RefCnt {
110 public:
111  static const uint32 MAX_BUTTONS = 20;
112  static const uint32 MAX_AXES = 10;
113 
114  BRK_API ~Joystick() override = default;
115 
117  const StringName &GetName() const { return mName; }
118 
120  const StringName &GetGUID() const { return mGUID; }
121 
123  InputDeviceState GetState() const { return mState; }
124 
126  const std::vector<float> &GetAxesStates() const { return mAxes; }
127 
129  const std::vector<InputAction> &GetButtonsStates() const { return mButtons; }
130 
131 protected:
135  std::vector<float> mAxes;
136  std::vector<InputAction> mButtons;
137 };
138 
144 
145 #endif//BERSERK_INPUTDEVICES_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint32_t uint32
Definition: Typedefs.hpp:44
State of the input device (used primary for joysticks)
Joystick (gamepad) device state.
Definition: InputDevices.hpp:109
const StringName & GetGUID() const
Definition: InputDevices.hpp:120
InputDeviceState GetState() const
Definition: InputDevices.hpp:123
const std::vector< float > & GetAxesStates() const
Definition: InputDevices.hpp:126
StringName mGUID
Definition: InputDevices.hpp:133
const std::vector< InputAction > & GetButtonsStates() const
Definition: InputDevices.hpp:129
static const uint32 MAX_AXES
Definition: InputDevices.hpp:112
const StringName & GetName() const
Definition: InputDevices.hpp:117
InputDeviceState mState
Definition: InputDevices.hpp:134
StringName mName
Definition: InputDevices.hpp:132
std::vector< InputAction > mButtons
Definition: InputDevices.hpp:136
BRK_API ~Joystick() override=default
static const uint32 MAX_BUTTONS
Definition: InputDevices.hpp:111
std::vector< float > mAxes
Definition: InputDevices.hpp:135
Keyboard device state.
Definition: InputDevices.hpp:84
static const uint32 MAX_KEYS
Definition: InputDevices.hpp:86
InputDeviceState GetState() const
Definition: InputDevices.hpp:94
StringName mName
Definition: InputDevices.hpp:100
InputDeviceState mState
Definition: InputDevices.hpp:101
const std::vector< InputAction > & GetKeysStates() const
Definition: InputDevices.hpp:97
const StringName & GetName() const
Definition: InputDevices.hpp:91
BRK_API ~Keyboard() override=default
std::vector< InputAction > mKeys
Definition: InputDevices.hpp:102
Mouse device state.
Definition: InputDevices.hpp:51
const Size2f & GetDelta() const
Definition: InputDevices.hpp:61
BRK_API ~Mouse() override=default
InputDeviceState mState
Definition: InputDevices.hpp:76
StringName mName
Definition: InputDevices.hpp:73
const StringName & GetName() const
Definition: InputDevices.hpp:64
std::vector< InputAction > mButtons
Definition: InputDevices.hpp:77
const Point2f & GetPosition() const
Definition: InputDevices.hpp:58
Point2f mPosition
Definition: InputDevices.hpp:74
static const uint32 MAX_BUTTONS
Definition: InputDevices.hpp:53
Size2f mDelta
Definition: InputDevices.hpp:75
const std::vector< InputAction > & GetButtonsStates() const
Definition: InputDevices.hpp:70
InputDeviceState GetState() const
Definition: InputDevices.hpp:67
Reference counted base object.
Definition: RefCnt.hpp:52
Cached shared utf-8 string id.
Definition: StringName.hpp:61
Definition: GLDevice.cpp:46