FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
joystickevent.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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 //
38 
39 #include "joystick.h"
40 
41 namespace FIFE {
42 
45  class JoystickEvent: public InputEvent {
46  public:
55  };
56 
60  InputEvent(),
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 
72  virtual ~JoystickEvent() {}
73 
77 
80  void setType(JoystickEventType type) { m_eventType = type; }
81 
84  int32_t getInstanceId() const { return m_instanceId; }
85 
88  void setInstanceId(int32_t id) { m_instanceId = id; }
89 
92  int8_t getAxis() const { return m_axis; }
93 
96  void setAxis(int8_t axis) { m_axis = axis; }
97 
100  float getAxisValue() const { return m_axisValue; }
101 
104  void setAxisValue(float value) { m_axisValue = value; }
105 
108  int8_t getHat() const { return m_hat; }
109 
112  void setHat(int8_t hat) { m_hat = hat; }
113 
116  int8_t getHatValue() const { return m_hatValue; }
117 
120  void setHatValue(int8_t value) { m_hatValue = value; }
121 
124  int8_t getButton() const { return m_button; }
125 
128  void setButton(int8_t button) { m_button = button; }
129 
132  bool isController() const { return m_controller; }
133 
136  void setController(bool value) { m_controller = value; }
137 
138  virtual void consume() { InputEvent::consume(); }
139  virtual bool isConsumed() const { return InputEvent::isConsumed(); }
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:
157  int32_t m_instanceId;
159  int8_t m_axis;
161  float m_axisValue;
163  int8_t m_hat;
165  int8_t m_hatValue;
167  int8_t m_button;
170  };
171 
172 } //FIFE
173 
174 #endif
JoystickEvent()
Constructor.
Definition: joystickevent.h:59
int8_t getAxis() const
Return the index number of axis for joystick, or the Joystick::ContollerAxis for controller.
Definition: joystickevent.h:92
virtual IEventSource * getSource() const
Gets the source of the event.
Definition: inputevent.h:108
int8_t getButton() const
Return the button index for joystick, or Joystick::ControllerButton for controller.
virtual IEventSource * getSource() const
Gets the source of the event.
Base class for input events (like mouse and keyboard)
Definition: inputevent.h:42
int8_t m_button
Button index.
int8_t getHat() const
Return the hat index.
virtual int32_t getTimeStamp() const
Gets the timestamp of the event.
Definition: inputevent.h:116
virtual std::string getDebugString() const
Gets the debugstring of the event.
Definition: inputevent.h:131
virtual bool isConsumedByWidgets() const
Checks whether event is consumed by widget library.
Definition: inputevent.h:96
virtual ~JoystickEvent()
Destructor.
Definition: joystickevent.h:72
virtual void setTimeStamp(int32_t timestamp)
Sets the timestamp of the event.
Definition: inputevent.h:120
void setHat(int8_t hat)
Sets the hat index.
void setAxis(int8_t axis)
Sets the axis index number or the Joystick::ControllerAxis.
Definition: joystickevent.h:96
JoystickEventType getType() const
Return the event type.
Definition: joystickevent.h:76
virtual void consumedByWidgets()
Marks events as consumed by widget library.
Definition: inputevent.h:92
virtual void consume()
Marks events as consumed.
int8_t m_hat
Hat index.
void setType(JoystickEventType type)
Sets the event type.
Definition: joystickevent.h:80
virtual bool isConsumedByWidgets() const
Checks whether event is consumed by widget library.
bool isController() const
Return true if it is a controller, false if only a joystick.
void setInstanceId(int32_t id)
Sets the instance id of the joystick.
Definition: joystickevent.h:88
virtual int32_t getTimeStamp() const
Gets the timestamp of the event.
int8_t m_axis
Axis index.
int8_t m_hatValue
Hat value.
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: inputevent.h:104
void setController(bool value)
Sets to true if the event is for a controller, otherwise false.
int32_t m_instanceId
Joystick instance id.
float getAxisValue() const
Return the axis value, range is -1.0 to 1.0.
virtual const std::string & getName() const
Gets the name of the event.
virtual void setTimeStamp(int32_t timestamp)
Sets the timestamp of the event.
virtual void consumedByWidgets()
Marks events as consumed by widget library.
Class for Joystick events.
Definition: joystickevent.h:45
bool m_controller
Is gamecontroller.
JoystickEventType m_eventType
Event type.
void setButton(int8_t button)
Sets the button index or Joystick::ControllerButton.
int32_t getInstanceId() const
Return the instance id of the joystick.
Definition: joystickevent.h:84
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: inputevent.h:112
void setHatValue(int8_t value)
Sets the hat value.
void setAxisValue(float value)
Sets the axis value.
virtual void consume()
Marks events as consumed.
Definition: inputevent.h:100
Representation of event source (a thing sending events)
Definition: ieventsource.h:42
virtual std::string getDebugString() const
Gets the debugstring of the event.
int8_t getHatValue() const
Return the hat value, see Joystick::Hat.
virtual void setSource(IEventSource *source)
Sets the source of the event.
virtual bool isConsumed() const
Checks whether event is consumed.
float m_axisValue
Axis value.