Spinning Topp Logo BlackTopp Studios
inc
buttondevice.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 _inputbuttondevice_h
41 #define _inputbuttondevice_h
42 
43 #include "Input/metacode.h"
44 #include "Input/device.h"
45 
46 namespace Mezzanine
47 {
48  namespace Input
49  {
50  ///////////////////////////////////////////////////////////////////////////////
51  /// @brief This is a base class for all input devices with buttons.
52  ///////////////////////////////////////
53  class MEZZ_LIB ButtonDevice : public Device
54  {
55  protected:
56  /// @internal
57  /// @brief A container of indexes being tracked due to state transitions.
58  std::vector<Whole> TransitioningIndexes;
59  /// @internal
60  /// @brief A container of states for each button on the input device.
61  std::vector<Input::ButtonState> Buttons;
62 
63  /// @internal
64  /// @brief Internal implementation of the device update.
65  virtual void UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes) = 0;
66  /// @copydoc Device::VerifySequenceImpl(const MetaCodeContainer& Sequence)
67  virtual void VerifySequenceImpl(const MetaCodeContainer& Sequence) const = 0;
68  /// @internal
69  /// @brief Adds MetaCodes belonging to all the buttons that are currently pressed for this device.
70  virtual void AddPressedButtons(MetaCodeContainer& GeneratedCodes) const = 0;
71  /// @internal
72  /// @brief Updates transitioning buttons.
73  void UpdateButtonTransitions();
74  public:
75  /// @brief Class constructor.
76  ButtonDevice();
77  /// @brief Class destructor.
78  virtual ~ButtonDevice();
79 
80  ///////////////////////////////////////////////////////////////////////////////
81  // Query Methods
82 
83  /// @brief Gets the number of buttons on this device.
84  /// @return Returns a UInt16 representing the number of buttons on this device.
85  UInt16 GetNumButtons() const;
86  /// @brief Gets whether or not a device button is pressed down.
87  /// @remarks This function accepts a button number. Check the number of buttons on this device to get the acceptable range. 1 is the minimum value.
88  /// @param Button The button to check the state of.
89  /// @return Returns whether or not the requested button is pressed down.
90  Boole IsButtonPressed(const UInt16 Button) const;
91  /// @brief Gets whether or not a device button is pressed down.
92  /// @param Button The button to check the state of.
93  /// @return Returns whether or not the requested button is pressed down.
94  Boole IsButtonPressed(const Input::InputCode& Button) const;
95  /// @brief Gets whether or not a device button was pressed this frame.
96  /// @remarks This function accepts a button number. Check the number of buttons on this device to get the acceptable range. 1 is the minimum value.
97  /// @param Button The button to check the state of.
98  /// @return Returns true if the specified button is being pressed this frame, false otherwise.
99  Boole IsButtonPressing(const UInt16 Button) const;
100  /// @brief Gets whether or not a device button was pressed this frame.
101  /// @param Button The button to check the state of.
102  /// @return Returns true if the specified button is being pressed this frame, false otherwise.
103  Boole IsButtonPressing(const Input::InputCode& Button) const;
104  /// @brief Gets whether or not a device button was lifted this frame.
105  /// @remarks This function accepts a button number. Check the number of buttons on this device to get the acceptable range. 1 is the minimum value.
106  /// @param Button The button to check the state of.
107  /// @return Returns true if the specified button is being lifted this frame, false otherwise.
108  Boole IsButtonLifting(const UInt16 Button) const;
109  /// @brief Gets whether or not a device button was lifted this frame.
110  /// @param Button The button to check the state of.
111  /// @return Returns true if the specified button is being lifted this frame, false otherwise.
112  Boole IsButtonLifting(const Input::InputCode& Button) const;
113  /// @brief Gets whether or not a device button was lifted or pressed this frame.
114  /// @param Button The button to check the state of.
115  /// @return Returns true if the requested button is pressing or lifting, false otherwise.
116  Boole IsButtonTransitioning(const UInt16 Button) const;
117  /// @brief Gets whether or not a device button was lifted or pressed this frame.
118  /// @param Button The button to check the state of.
119  /// @return Returns true if the requested button is pressing or lifting, false otherwise.
120  Boole IsButtonTransitioning(const Input::ButtonState& Button) const;
121  /// @brief Checks to see if a button on this device is a specific state.
122  /// @param Button The button to check the state of.
123  /// @param State The button state to check for.
124  /// @return Returns true if the requested button is the specified state, false otherwise.
125  Boole CheckButtonState(const UInt16 Button, const Input::ButtonState& State) const;
126  /// @brief Checks to see if a button on this device is a specific state.
127  /// @param Button The button to check the state of.
128  /// @param State The button state to check for.
129  /// @return Returns true if the requested button is the specified state, false otherwise.
130  Boole CheckButtonState(const Input::InputCode& Button, const Input::ButtonState& State) const;
131  /// @brief Gets the state of the requested button.
132  /// @remarks This function accepts a button number, and as such expects a number from 1 to 20.
133  /// @return Returns the actual state of the requested button.
134  virtual const Input::ButtonState& GetButtonState(const UInt16 Button) const = 0;
135  /// @brief Gets the state of the requested button.
136  /// @return Returns the actual state of the requested button.
137  virtual const Input::ButtonState& GetButtonState(const Input::InputCode& Button) const = 0;
138 
139  ///////////////////////////////////////////////////////////////////////////////
140  // Internal Methods
141 
142  /// @copydoc Device::_Update(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes)
143  void _Update(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes);
144  };//ButtonDevice
145  }//Input
146 }//Mezzanine
147 
148 #endif
InputCode
The InputCode enum defines all the posible types of inputs.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This is a base class for all input devices.
Definition: device.h:55
This is a base class for all input devices with buttons.
Definition: buttondevice.h:53
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
std::vector< Whole > TransitioningIndexes
A container of indexes being tracked due to state transitions.
Definition: buttondevice.h:58
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...
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 ...
The declaration of the User input Device class.
std::vector< Input::ButtonState > Buttons
A container of states for each button on the input device.
Definition: buttondevice.h:61