MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
controller.h
1 // © Copyright 2010 - 2014 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  /// @class Controller
53  /// @headerfile controller.h
54  /// @brief This class represents a controller input device, such as a gamepad or joystick.
55  /// @details
56  ///////////////////////////////////////
58  {
59  protected:
60  UInt16 Index;
61  String DeviceName;
62  std::vector<Int16> Axes;
63  std::vector<Vector2> Trackballs;
64  std::vector<Input::HatState> Hats;
65  /// @copydoc ButtonDevice::UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes)
66  void UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes);
67  /// @copydoc Device::VerifySequenceImpl(const MetaCodeContainer& Sequence)
68  virtual void VerifySequenceImpl(const MetaCodeContainer& Sequence) const;
69  /// @copydoc Device::AddPressedButtons(MetaCodeContainer& GeneratedCodes) const
70  virtual void AddPressedButtons(MetaCodeContainer& GeneratedCodes) const;
71  public:
72  /// @brief Class constructor.
73  /// @param InternalControl A pointer to the internal struct of this controller.
74  /// @remarks A void pointer is necessary because SDL forward declares it's own struct already and this won't
75  /// compile with two forward declares.
76  Controller(void* InternalControl, int Count);
77  /// @brief Class destructor.
78  virtual ~Controller();
79 
80  ///////////////////////////////////////////////////////////////////////////////
81  // Query Methods
82 
83  /// @brief Gets the device index of this controller.
84  /// @return Returns a UInt16 representing the device index for this controller.
85  UInt16 GetDeviceIndex() const;
86  /// @brief Gets the name of this device.
87  /// @return Returns a const string reference containing the name of this device.
88  const String& GetDeviceName() const;
89  /// @brief Gets the number of Axes on this device.
90  /// @return Returns a UInt16 representing the number of Axes present on this controller.
91  UInt16 GetNumAxes() const;
92  /// @brief Gets the number of Trackballs on this device.
93  /// @return Returns a UInt16 representing the number of Trackballs present on this controller.
94  UInt16 GetNumTrackballs() const;
95  /// @brief Gets the number of Hats on this device.
96  /// @return Returns a UInt16 representing the number of Hats present on this controller.
97  UInt16 GetNumHats() const;
98  /// @brief Gets whether a specific hat is pressed in a specific direction.
99  /// @param WhichWay The hat direction to check for. This value is expected to be 1-6.
100  /// @return Returns true if the specified hat is pressed in the requested direction.
101  bool IsHatPushedInDirection(const UInt16 Hat, const Input::HatState& WhichWay) const;
102  /// @brief This Gets the value of the given joystick axis.
103  /// @param Axis The axis that you want. This value is expected to be 1-20.
104  /// @return An integer with the Value of the joystick axis.
105  Int16 GetAxis(const UInt16 Axis) const;
106  /// @brief Gets the delta movement on the requested trackball.
107  /// @param Trackball The trackball to query. This value is expected to be at least 1.
108  /// @return Returns a vector2 representing the delta movement for the specified trackball.
109  Vector2 GetTrackballDelta(const UInt16 Trackball) const;
110  /// @brief Gets the delta movement on the X axis on the requested trackball.
111  /// @param Trackball The trackball to query. This value is expected to be at least 1.
112  /// @return Returns a Real representing the delta movement on the X axis for the specified trackball.
113  Real GetTrackballDeltaX(const UInt16 Trackball) const;
114  /// @brief Gets the delta movement on the Y axis on the requested trackball.
115  /// @param Trackball The trackball to query. This value is expected to be at least 1.
116  /// @return Returns a Real representing the delta movement on the Y axis for the specified trackball.
117  Real GetTrackballDeltaY(const UInt16 Trackball) const;
118  /// @brief Gets the current state of the requested hat.
119  /// @param Hat The hat to query. This value is expected to be 1-6.
120  /// @return Returns a HatState representing the current state of the specified hat.
121  const Input::HatState& GetHatState(const UInt16 Hat) const;
122  /// @brief This Gets the value of the given joystick axis.
123  /// @param Axis An InputCode representing the axis that you want.
124  /// @return An integer with the Value of the joystick axis.
125  Int16 GetAxis(const Input::InputCode& Axis) const;
126  /// @brief Gets the delta movement on the requested trackball.
127  /// @param Trackball An InputCode representing the trackball to query.
128  /// @return Returns a vector2 representing the delta movement for the specified trackball.
129  /// @throw A @ref InvalidParametersException is thrown if anything other than a controllerball value from the @ref Input enum is passed.
130  Real GetTrackballDelta(const Input::InputCode& Trackball) const;
131  /// @copydoc ButtonDevice::GetButtonState(const UInt16 Button) const
132  virtual const Input::ButtonState& GetButtonState(const UInt16 Button) const;
133  /// @copydoc ButtonDevice::GetButtonState(const Input::InputCode& Button) const
134  virtual const Input::ButtonState& GetButtonState(const Input::InputCode& Button) const;
135  /// @brief Gets the current state of the requested hat.
136  /// @param Hat An InputCode representing the hat to query.
137  /// @return Returns a HatState representing the current state of the specified hat.
138  const Input::HatState& GetHatState(const Input::InputCode& Hat) const;
139 
140  ///////////////////////////////////////////////////////////////////////////////
141  // Configuration Methods
142 
143  ///////////////////////////////////////////////////////////////////////////////
144  // Utility Methods
145  };// ©ontroller
146  }//Input
147 }//Mezzanine
148 
149 #endif