Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Controls.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_CONTROLS_H
22 #define GF_CONTROLS_H
23 
24 #include "Control.h"
25 #include "Gamepad.h"
26 #include "Keyboard.h"
27 #include "Mouse.h"
28 #include "Portability.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
35  /**
36  * @ingroup window
37  * @brief A key control based on keycode.
38  */
39  class GF_API KeycodeKeyControl : public Control {
40  public:
41  /**
42  * @brief Construct a key control.
43  *
44  * @param code The keycode of the key
45  */
47 
48  virtual void processEvent(const Event& event) override;
49 
50  private:
51  Keycode m_code;
52  };
53 
54  /**
55  * @ingroup window
56  * @brief A key control based on scancode.
57  */
59  public:
60  /**
61  * @brief Construct a key control.
62  *
63  * @param code The scancode of the key
64  */
66 
67  virtual void processEvent(const Event& event) override;
68 
69  private:
70  Scancode m_code;
71  };
72 
73  /**
74  * @ingroup window
75  * @brief A mouse button control.
76  */
78  public:
79  /**
80  * @brief Construct a mouse button control.
81  *
82  * @param button The button of the mouse.
83  */
85 
86  virtual void processEvent(const Event& event) override;
87 
88  private:
89  MouseButton m_button;
90  };
91 
92  /**
93  * @ingroup window
94  * @brief A gamepad button control
95  */
97  public:
98  /**
99  * @brief Contruct a gamepad button control.
100  *
101  * @param id The id of the gamepad
102  * @param button The button of the gamepad
103  * @sa gf::Gamepad::open
104  */
106 
107  virtual void processEvent(const Event& event) override;
108 
109  private:
110  GamepadId m_id;
111  GamepadButton m_button;
112  };
113 
114  /**
115  * @ingroup window
116  * @brief A gamepad axis control
117  */
119  public:
120  /**
121  * @brief Construct a gamepad axis control
122  *
123  * @param id The id of the gamepad
124  * @param axis The axis of the gamepad
125  * @param dir The direction of the axis
126  * @sa gf::Gamepad::open, gf::GamepadAxisDirection
127  */
129 
130  virtual void processEvent(const Event& event) override;
131 
132  private:
133  GamepadId m_id;
134  GamepadAxis m_axis;
135  GamepadAxisDirection m_dir;
136  };
137 
138  /**
139  * @ingroup window
140  * @brief A close control.
141  *
142  */
143  class GF_API CloseControl : public Control {
144  public:
145  /**
146  * @brief Construct a close control.
147  */
148  CloseControl();
149 
150  virtual void processEvent(const Event& event) override;
151  };
152 
153 #ifndef DOXYGEN_SHOULD_SKIP_THIS
154 }
155 #endif
156 }
157 
158 #endif // GF_CONTROLS_H
virtual void processEvent(const Event &event) override
Update the state of the control thanks to an event.
GamepadAxisDirection
A gamepad axis direction.
Definition: Gamepad.h:88
GamepadButton
The gamepad buttons.
Definition: Gamepad.h:42
A mouse button control.
Definition: Controls.h:77
GamepadButtonControl(GamepadId id, GamepadButton button)
Contruct a gamepad button control.
ScancodeKeyControl(Scancode code)
Construct a key control.
MouseButtonControl(MouseButton button)
Construct a mouse button control.
Scancode
Scancodes.
Definition: Keyboard.h:66
A gamepad button control.
Definition: Controls.h:96
A physical control.
Definition: Control.h:38
GamepadAxis
The gamepad axis.
Definition: Gamepad.h:70
CloseControl()
Construct a close control.
virtual void processEvent(const Event &event) override
Update the state of the control thanks to an event.
virtual void processEvent(const Event &event) override
Update the state of the control thanks to an event.
Definition: Action.h:34
GamepadAxisControl(GamepadId id, GamepadAxis axis, GamepadAxisDirection dir)
Construct a gamepad axis control.
GamepadId
A gamepad identifier.
Definition: Gamepad.h:120
virtual void processEvent(const Event &event) override
Update the state of the control thanks to an event.
virtual void processEvent(const Event &event) override
Update the state of the control thanks to an event.
KeycodeKeyControl(Keycode code)
Construct a key control.
virtual void processEvent(const Event &event) override
Update the state of the control thanks to an event.
A key control based on keycode.
Definition: Controls.h:39
A key control based on scancode.
Definition: Controls.h:58
A gamepad axis control.
Definition: Controls.h:118
MouseButton
Mouse buttons.
Definition: Mouse.h:36
Defines a system event and its parameters.
Definition: Event.h:115
#define GF_API
Definition: Portability.h:35
A close control.
Definition: Controls.h:143
Keycode
Keycodes.
Definition: Keyboard.h:293