MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
keyboard.cpp
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 _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  {
54  this->Buttons.resize(Input::KEY_LAST,Input::BUTTON_UP);
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(Exception::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