VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
KeyScheme.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef KEYSCHEME_H
18 #define KEYSCHEME_H
19 
20 #include "ControllerEvent.h"
21 #include "InputScheme.h"
22 #include "KeyCodes.h"
23 
28 class KeyScheme : public InputScheme<KeyCode> {
29 public:
34 
39  explicit KeyScheme(const typename InputScheme<KeyCode>::Map& scheme)
40  : InputScheme<KeyCode>(scheme) { }
41 
46  virtual bool handlesControllerEvent(const ControllerEvent* event) const override {
47  if (event->hasKeyInfo() && !InputScheme<KeyCode>::empty()) {
48  for (const auto& keyStatePair : event->getKeyStates()) {
49  // Will handle if the event has data for a mapped key
50  if (InputScheme<KeyCode>::hasActionFor(keyStatePair.first)) {
51  return true;
52  }
53  }
54  }
55  return false;
56  }
57 };
58 
59 #endif // KEYSCHEME_H
bool empty() const
Returns whether or not the InputScheme contains any mappings.
Definition: InputScheme.h:59
bool hasKeyInfo() const
Returns whether or not this ControllerEvent contains any key press information.
Definition: ControllerEvent.h:75
A platform independent event generated by controller device.
Definition: ControllerEvent.h:34
KeyCode
Key codes used to uniquely identify hardware input keys.
Definition: KeyCodes.h:26
const KeyStates & getKeyStates() const
Returns pressed state changes for all keys contained in this event.
Definition: ControllerEvent.h:90
Represents a scheme mapping keyboard input to output actions.
Definition: KeyScheme.h:28
virtual bool handlesControllerEvent(const ControllerEvent *event) const override
Returns whether or not this KeyScheme would handle event.
Definition: KeyScheme.h:46
KeyScheme()
Constructs an empty KeyScheme.
Definition: KeyScheme.h:33
KeyScheme(const typename InputScheme< KeyCode >::Map &scheme)
Constructs a KeyScheme from the specified scheme.
Definition: KeyScheme.h:39
Represents a scheme mapping generic input "events" to output "actions".
Definition: InputScheme.h:28