Spinning Topp Logo BlackTopp Studios
inc
controller.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _inputcontroller_h
41 #define _inputcontroller_h
42 
43 #include "vector2.h"
44 #include "Input/inputenumerations.h"
45 #include "Input/buttondevice.h"
46 
47 namespace Mezzanine
48 {
49  namespace Input
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @brief This class represents a controller input device, such as a gamepad or joystick.
53  ///////////////////////////////////////
55  {
56  protected:
57  /// @internal
58  /// @brief Container storing the states for each axis on the controller.
59  std::vector<Int16> Axes;
60  /// @internal
61  /// @brief Container storing the states for each trackball on the controller.
62  std::vector<Vector2> Trackballs;
63  /// @internal
64  /// @brief Container storing the states for each hat on the controller.
65  std::vector<Input::HatState> Hats;
66  /// @internal
67  /// @brief The name of the controller device.
69  /// @internal
70  /// @brief The index of the controller device.
72 
73  /// @copydoc ButtonDevice::UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes)
74  void UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes);
75  /// @copydoc Device::VerifySequenceImpl(const MetaCodeContainer& Sequence)
76  virtual void VerifySequenceImpl(const MetaCodeContainer& Sequence) const;
77  /// @copydoc Device::AddPressedButtons(MetaCodeContainer& GeneratedCodes) const
78  virtual void AddPressedButtons(MetaCodeContainer& GeneratedCodes) const;
79  public:
80  /// @brief Class constructor.
81  /// @param InternalControl A pointer to the internal struct of this controller.
82  /// @remarks A void pointer is necessary because SDL forward declares it's own struct already and this won't
83  /// compile with two forward declares.
84  Controller(void* InternalControl, int Count);
85  /// @brief Class destructor.
86  virtual ~Controller();
87 
88  ///////////////////////////////////////////////////////////////////////////////
89  // Query Methods
90 
91  /// @brief Gets the device index of this controller.
92  /// @return Returns a UInt16 representing the device index for this controller.
93  UInt16 GetDeviceIndex() const;
94  /// @brief Gets the name of this device.
95  /// @return Returns a const string reference containing the name of this device.
96  const String& GetDeviceName() const;
97  /// @brief Gets the number of Axes on this device.
98  /// @return Returns a UInt16 representing the number of Axes present on this controller.
99  UInt16 GetNumAxes() const;
100  /// @brief Gets the number of Trackballs on this device.
101  /// @return Returns a UInt16 representing the number of Trackballs present on this controller.
102  UInt16 GetNumTrackballs() const;
103  /// @brief Gets the number of Hats on this device.
104  /// @return Returns a UInt16 representing the number of Hats present on this controller.
105  UInt16 GetNumHats() const;
106  /// @brief Gets whether a specific hat is pressed in a specific direction.
107  /// @param WhichWay The hat direction to check for. This value is expected to be 1-6.
108  /// @return Returns true if the specified hat is pressed in the requested direction.
109  Boole IsHatPushedInDirection(const UInt16 Hat, const Input::HatState& WhichWay) const;
110  /// @brief This Gets the value of the given joystick axis.
111  /// @param Axis The axis that you want. This value is expected to be 1-20.
112  /// @return An integer with the Value of the joystick axis.
113  Int16 GetAxis(const UInt16 Axis) const;
114  /// @brief Gets the delta movement on the requested trackball.
115  /// @param Trackball The trackball to query. This value is expected to be at least 1.
116  /// @return Returns a vector2 representing the delta movement for the specified trackball.
117  Vector2 GetTrackballDelta(const UInt16 Trackball) const;
118  /// @brief Gets the delta movement on the X axis on the requested trackball.
119  /// @param Trackball The trackball to query. This value is expected to be at least 1.
120  /// @return Returns a Real representing the delta movement on the X axis for the specified trackball.
121  Real GetTrackballDeltaX(const UInt16 Trackball) const;
122  /// @brief Gets the delta movement on the Y axis on the requested trackball.
123  /// @param Trackball The trackball to query. This value is expected to be at least 1.
124  /// @return Returns a Real representing the delta movement on the Y axis for the specified trackball.
125  Real GetTrackballDeltaY(const UInt16 Trackball) const;
126  /// @brief Gets the current state of the requested hat.
127  /// @param Hat The hat to query. This value is expected to be 1-6.
128  /// @return Returns a HatState representing the current state of the specified hat.
129  const Input::HatState& GetHatState(const UInt16 Hat) const;
130  /// @brief This Gets the value of the given joystick axis.
131  /// @param Axis An InputCode representing the axis that you want.
132  /// @return An integer with the Value of the joystick axis.
133  Int16 GetAxis(const Input::InputCode& Axis) const;
134  /// @brief Gets the delta movement on the requested trackball.
135  /// @param Trackball An InputCode representing the trackball to query.
136  /// @return Returns a vector2 representing the delta movement for the specified trackball.
137  /// @throw A @ref InvalidParametersException is thrown if anything other than a controllerball value from the @ref Input enum is passed.
138  Real GetTrackballDelta(const Input::InputCode& Trackball) const;
139  /// @copydoc ButtonDevice::GetButtonState(const UInt16 Button) const
140  virtual const Input::ButtonState& GetButtonState(const UInt16 Button) const;
141  /// @copydoc ButtonDevice::GetButtonState(const Input::InputCode& Button) const
142  virtual const Input::ButtonState& GetButtonState(const Input::InputCode& Button) const;
143  /// @brief Gets the current state of the requested hat.
144  /// @param Hat An InputCode representing the hat to query.
145  /// @return Returns a HatState representing the current state of the specified hat.
146  const Input::HatState& GetHatState(const Input::InputCode& Hat) const;
147 
148  ///////////////////////////////////////////////////////////////////////////////
149  // Configuration Methods
150 
151  ///////////////////////////////////////////////////////////////////////////////
152  // Utility Methods
153  };// Controller
154  }//Input
155 }//Mezzanine
156 
157 #endif
InputCode
The InputCode enum defines all the posible types of inputs.
This class represents a controller input device, such as a gamepad or joystick.
Definition: controller.h:54
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This is a base class for all input devices with buttons.
Definition: buttondevice.h:53
String DeviceName
The name of the controller device.
Definition: controller.h:68
std::vector< Input::HatState > Hats
Container storing the states for each hat on the controller.
Definition: controller.h:65
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
int16_t Int16
An 16-bit integer.
Definition: datatypes.h:120
Input::MetaCode::MetaCodeContainer MetaCodeContainer
Convenience datatype for storage of MetaCodes.
Definition: metacode.h:351
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
UInt16 Index
The index of the controller device.
Definition: controller.h:71
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
ButtonState
An Optional listing of value that can be used in a metacode to represent the information of a button ...
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
std::vector< Int16 > Axes
Container storing the states for each axis on the controller.
Definition: controller.h:59
HatState
An optional listing of the possible states a hat on a controller can take.
std::vector< Vector2 > Trackballs
Container storing the states for each trackball on the controller.
Definition: controller.h:62