Debian Codegraph @

engine/core/eventchannel/joystick/joystickevent.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_EVENTCHANNEL_JOYSTICKEVENT_H
23 #define FIFE_EVENTCHANNEL_JOYSTICKEVENT_H
24
25 // Standard C++ library includes
26 //
27
28 // 3rd party library includes
29 //
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 //
36 #include "eventchannel/base/inputevent.h"
37 #include "eventchannel/source/ieventsource.h"
38
39 #include "joystick.h"
40
41 namespace FIFE {
42
43 /** Class for Joystick events
44 */
45 class JoystickEvent: public InputEvent {
46 public:
47 enum JoystickEventType {
48 UNKNOWN_EVENT = 0,
49 AXIS_MOTION,
50 HAT_MOTION,
51 BUTTON_PRESSED,
52 BUTTON_RELEASED,
53 DEVICE_ADDED,
54 DEVICE_REMOVED
55 };
56
57 /** Constructor
58 */
59 JoystickEvent():
60 InputEvent(),
61 m_eventType(UNKNOWN_EVENT),
62 m_instanceId(-1),
63 m_axis(-1),
64 m_axisValue(0),
65 m_hat(-1),
66 m_hatValue(-1),
67 m_button(-1),
68 m_controller(false) {}
69
70 /** Destructor.
71 */
72 virtual ~JoystickEvent() {}
73
74 /** Return the event type.
75 */
76 JoystickEventType getType() const { return m_eventType; }
77
78 /** Sets the event type.
79 */
80 void setType(JoystickEventType type) { m_eventType = type; }
81
82 /** Return the instance id of the joystick.
83 */
84 int32_t getInstanceId() const { return m_instanceId; }
85
86 /** Sets the instance id of the joystick.
87 */
88 void setInstanceId(int32_t id) { m_instanceId = id; }
89
90 /** Return the index number of axis for joystick, or the Joystick::ContollerAxis for controller.
91 */
92 int8_t getAxis() const { return m_axis; }
93
94 /** Sets the axis index number or the Joystick::ControllerAxis.
95 */
96 void setAxis(int8_t axis) { m_axis = axis; }
97
98 /** Return the axis value, range is -1.0 to 1.0.
99 */
100 float getAxisValue() const { return m_axisValue; }
101
102 /** Sets the axis value.
103 */
104 void setAxisValue(float value) { m_axisValue = value; }
105
106 /** Return the hat index.
107 */
108 int8_t getHat() const { return m_hat; }
109
110 /** Sets the hat index.
111 */
112 void setHat(int8_t hat) { m_hat = hat; }
113
114 /** Return the hat value, see Joystick::Hat.
115 */
116 int8_t getHatValue() const { return m_hatValue; }
117
118 /** Sets the hat value.
119 */
120 void setHatValue(int8_t value) { m_hatValue = value; }
121
122 /** Return the button index for joystick, or Joystick::ControllerButton for controller.
123 */
124 int8_t getButton() const { return m_button; }
125
126 /** Sets the button index or Joystick::ControllerButton.
127 */
128 void setButton(int8_t button) { m_button = button; }
129
130 /** Return true if it is a controller, false if only a joystick.
131 */
132 bool isController() const { return m_controller; }
133
134 /** Sets to true if the event is for a controller, otherwise false.
135 */
136 void setController(bool value) { m_controller = value; }
137
138 virtual void consume() { InputEvent::consume(); }
139 virtual bool isConsumed() const { return InputEvent::isConsumed(); }
140 virtual void consumedByWidgets() { InputEvent::consumedByWidgets(); }
141 virtual bool isConsumedByWidgets() const { return InputEvent::isConsumedByWidgets(); }
142 virtual IEventSource* getSource() const { return InputEvent::getSource(); }
143 virtual void setSource(IEventSource* source) { InputEvent::setSource(source); }
144 virtual int32_t getTimeStamp() const { return InputEvent::getTimeStamp(); }
145 virtual void setTimeStamp(int32_t timestamp ) { InputEvent::setTimeStamp(timestamp); }
146
147 virtual const std::string& getName() const {
148 const static std::string eventName("JostickEvent");
149 return eventName;
150 }
151 virtual std::string getDebugString() const { return InputEvent::getDebugString(); }
152
153 private:
154 //! Event type
155 JoystickEventType m_eventType;
156 //! Joystick instance id
157 int32_t m_instanceId;
158 //! Axis index
159 int8_t m_axis;
160 //! Axis value
161 float m_axisValue;
162 //! Hat index
163 int8_t m_hat;
164 //! Hat value
165 int8_t m_hatValue;
166 //! Button index
167 int8_t m_button;
168 //! Is gamecontroller
169 bool m_controller;
170 };
171
172 } //FIFE
173
174 #endif