MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
buttondevice.h
1 // © Copyright 2010 - 2012 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  /// @class ButtonDevice
52  /// @headerfile buttondevice.h
53  /// @brief This is a base class for all input devices with buttons.
54  /// @details
55  ///////////////////////////////////////
56  class MEZZ_LIB ButtonDevice : public Device
57  {
58  protected:
59  std::vector<Whole> TransitioningIndexes;
60  std::vector<Input::ButtonState> Buttons;
61  /// @internal
62  /// @brief Internal implementation of the device update.
63  virtual void UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes) = 0;
64  /// @copydoc Device::VerifySequenceImpl(const MetaCodeContainer& Sequence)
65  virtual void VerifySequenceImpl(const MetaCodeContainer& Sequence) const = 0;
66  /// @internal
67  /// @brief Adds MetaCodes belonging to all the buttons that are currently pressed for this device.
68  virtual void AddPressedButtons(MetaCodeContainer& GeneratedCodes) const = 0;
69  /// @internal
70  /// @brief Updates transitioning buttons.
71  void UpdateButtonTransitions();
72  public:
73  /// @brief Class constructor.
74  ButtonDevice();
75  /// @brief Class destructor.
76  virtual ~ButtonDevice();
77 
78  ///////////////////////////////////////////////////////////////////////////////
79  // Query Methods
80 
81  /// @brief Gets the number of buttons on this device.
82  /// @return Returns a UInt16 representing the number of buttons on this device.
83  UInt16 GetNumButtons() const;
84  /// @brief Gets whether or not a device button is pressed down.
85  /// @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.
86  /// @param Button The button to check the state of.
87  /// @return Returns whether or not the requested button is pressed down.
88  bool IsButtonPressed(const UInt16 Button) const;
89  /// @brief Gets whether or not a device button is pressed down.
90  /// @param Button The button to check the state of.
91  /// @return Returns whether or not the requested button is pressed down.
92  bool IsButtonPressed(const Input::InputCode& Button) const;
93  /// @brief Gets whether or not a device button was pressed this frame.
94  /// @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.
95  /// @param Button The button to check the state of.
96  /// @return Returns true if the specified button is being pressed this frame, false otherwise.
97  bool IsButtonPressing(const UInt16 Button) const;
98  /// @brief Gets whether or not a device button was pressed this frame.
99  /// @param Button The button to check the state of.
100  /// @return Returns true if the specified button is being pressed this frame, false otherwise.
101  bool IsButtonPressing(const Input::InputCode& Button) const;
102  /// @brief Gets whether or not a device button was lifted this frame.
103  /// @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.
104  /// @param Button The button to check the state of.
105  /// @return Returns true if the specified button is being lifted this frame, false otherwise.
106  bool IsButtonLifting(const UInt16 Button) const;
107  /// @brief Gets whether or not a device button was lifted this frame.
108  /// @param Button The button to check the state of.
109  /// @return Returns true if the specified button is being lifted this frame, false otherwise.
110  bool IsButtonLifting(const Input::InputCode& Button) const;
111  /// @brief Gets whether or not a device button was lifted or pressed this frame.
112  /// @param Button The button to check the state of.
113  /// @return Returns true if the requested button is pressing or lifting, false otherwise.
114  bool IsButtonTransitioning(const UInt16 Button) const;
115  /// @brief Gets whether or not a device button was lifted or pressed this frame.
116  /// @param Button The button to check the state of.
117  /// @return Returns true if the requested button is pressing or lifting, false otherwise.
118  bool IsButtonTransitioning(const Input::ButtonState& Button) const;
119  /// @brief Checks to see if a button on this device is a specific state.
120  /// @param Button The button to check the state of.
121  /// @param State The button state to check for.
122  /// @return Returns true if the requested button is the specified state, false otherwise.
123  bool CheckButtonState(const UInt16 Button, const Input::ButtonState& State) const;
124  /// @brief Checks to see if a button on this device is a specific state.
125  /// @param Button The button to check the state of.
126  /// @param State The button state to check for.
127  /// @return Returns true if the requested button is the specified state, false otherwise.
128  bool CheckButtonState(const Input::InputCode& Button, const Input::ButtonState& State) const;
129  /// @brief Gets the state of the requested button.
130  /// @remarks This function accepts a button number, and as such expects a number from 1 to 20.
131  /// @return Returns the actual state of the requested button.
132  virtual const Input::ButtonState& GetButtonState(const UInt16 Button) const = 0;
133  /// @brief Gets the state of the requested button.
134  /// @return Returns the actual state of the requested button.
135  virtual const Input::ButtonState& GetButtonState(const Input::InputCode& Button) const = 0;
136 
137  ///////////////////////////////////////////////////////////////////////////////
138  // Internal Methods
139 
140  /// @copydoc Device::_Update(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes)
141  void _Update(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes);
142  };//ButtonDevice
143  }//Input
144 }//Mezzanine
145 
146 #endif