Spinning Topp Logo BlackTopp Studios
inc
keyboard.cpp
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 _inputkeyboard_cpp
41 #define _inputkeyboard_cpp
42 
43 #include "Input/keyboard.h"
44 #include "exception.h"
45 
46 #include <limits>
47 
48 namespace Mezzanine
49 {
50  namespace Input
51  {
53  {
55  }
56 
58  {
59  }
60 
61  void Keyboard::UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes)
62  {
63  for( Whole X = 0 ; X < DeltaCodes.size() ; ++X )
64  {
65  this->TransitioningIndexes.push_back( DeltaCodes[X].GetCode() );
66  this->Buttons.at( DeltaCodes[X].GetCode() ) = static_cast<Input::ButtonState>(DeltaCodes[X].GetMetaValue());
67  }
68  this->Sequences.Update(DeltaCodes,GeneratedCodes);
69  }
70 
71  void Keyboard::VerifySequenceImpl(const MetaCodeContainer& Sequence) const
72  {
73  for( ConstMetaCodeIterator MCIt = Sequence.begin() ; MCIt != Sequence.end() ; ++MCIt )
74  {
75  if( !MCIt->IsKeyboardEvent() )
76  { MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Non-Keyboard MetaCode detected when attempting to insert an Input Sequence into Keyboard input device."); }
77  }
78  }
79 
80  void Keyboard::AddPressedButtons(MetaCodeContainer& GeneratedCodes) const
81  {
82  for( UInt32 Index = 0 ; Index < this->Buttons.size() ; ++Index )
83  {
84  if( this->Buttons.at(Index) == Input::BUTTON_DOWN )
85  GeneratedCodes.push_back( MetaCode(Input::BUTTON_DOWN,static_cast<Input::InputCode>(Input::KEY_FIRST + Index),GetDeviceIndex()) );
86  }
87  }
88 
89  ///////////////////////////////////////////////////////////////////////////////
90  // Query Methods
91 
93  { return std::numeric_limits<UInt16>::max(); }
94 
96  { return this->Buttons.at( Button - 1 ); }
97 
99  { return this->Buttons.at(Button); }
100 
101  ///////////////////////////////////////////////////////////////////////////////
102  // Configuration Methods
103 
104  ///////////////////////////////////////////////////////////////////////////////
105  // Utility Methods
106  }//Input
107 }//Mezzanine
108 
109 #endif
InputCode
The InputCode enum defines all the posible types of inputs.
void AddPressedButtons(MetaCodeContainer &GeneratedCodes) const
Definition: keyboard.cpp:80
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
SequenceContainer Sequences
A container for storing and detecting input sequences for an input device.
Definition: device.h:60
This implements the exception hiearchy for Mezzanine.
UInt16 GetDeviceIndex() const
Gets the device index of this controller.
Definition: keyboard.cpp:92
void UpdateImpl(const MetaCodeContainer &DeltaCodes, MetaCodeContainer &GeneratedCodes)
Internal implementation of the device update.
Definition: keyboard.cpp:61
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
std::vector< Whole > TransitioningIndexes
A container of indexes being tracked due to state transitions.
Definition: buttondevice.h:58
The last Keyboard InputCode, all Keys values will be less than this, and all Events will be larger th...
Thrown when parameters are checked at runtime and found invalid.
Definition: exception.h:108
Input::MetaCode::ConstMetaCodeIterator ConstMetaCodeIterator
Const Iterator type for convenient MetaCode storage.
Definition: metacode.h:355
This Determines the kind of user input.
Definition: metacode.h:93
Input::MetaCode::MetaCodeContainer MetaCodeContainer
Convenience datatype for storage of MetaCodes.
Definition: metacode.h:351
const Input::ButtonState & GetButtonState(const UInt16 Button) const
Definition: keyboard.cpp:95
virtual ~Keyboard()
Class destructor.
Definition: keyboard.cpp:57
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 ...
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Keyboard()
Class constructor.
Definition: keyboard.cpp:52
void Update(const MetaCodeContainer &NormalCodes, MetaCodeContainer &SequenceCodes)
Adds provided codes to the cache if necessary and checks for sequences that have been met...
void VerifySequenceImpl(const MetaCodeContainer &Sequence) const
Definition: keyboard.cpp:71
std::vector< Input::ButtonState > Buttons
A container of states for each button on the input device.
Definition: buttondevice.h:61