VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
GamepadRouter.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 GAMEPADROUTER_H
18 #define GAMEPADROUTER_H
19 
20 #include <set>
21 #include <vector>
22 #include "ControllerEvent.h"
23 #include "ControllerFactory.h"
24 #include "InputRouter.h"
25 #include "JoystickAxisScheme.h"
26 #include "KeyScheme.h"
27 #include "TriggerAxisScheme.h"
28 
34 class GamepadRouter : public InputRouter {
35 public:
42  public:
49  explicit GamepadControllerFactory(
50  const KeyScheme& keyScheme,
51  const JoystickAxisScheme& joystickAxisScheme,
52  const TriggerAxisScheme& triggerAxisScheme
53  );
54 
55  virtual VirtualController* createNewController(int deviceId) const override;
56 
57  virtual bool intersects(const ControllerFactory& otherFactory) const override;
65  bool intersects(const GamepadControllerFactory& otherFactory) const;
66 
67  virtual bool handlesControllerEvent(const ControllerEvent* event) const override;
68 
72  static std::set<KeyCode> sValidKeyCodes;
76  static std::set<JoystickAxisCode> sValidJoystickAxisCodes;
80  static std::set<TriggerAxisCode> sValidTriggerAxisCodes;
81 
82  private:
83  KeyScheme mKeyScheme;
84  JoystickAxisScheme mJoystickAxisScheme;
85  TriggerAxisScheme mTriggerAxisScheme;
86  };
87 
93 
97  static GamepadRouter* getInstance();
98 
99 private:
103  GamepadRouter();
104 
105  // List of GamepadControllerFactories to route by.
106  std::vector<GamepadControllerFactory> mGamepadControllerFactories;
107 
108  // Singleton instance of the GamepadRouter.
109  static GamepadRouter* sInstance;
110 };
111 
112 #endif // GAMEPADROUTER_H
virtual VirtualController * createNewController(int deviceId) const override
Returns a new VirtualController for the specified deviceId.
virtual bool intersects(const ControllerFactory &otherFactory) const override
Returns whether or not this ControllerFactory intersects (i.e. overlaps input schemes) with the speci...
Represents a scheme mapping input trigger axes to output actions.
Definition: TriggerAxisScheme.h:28
static std::set< JoystickAxisCode > sValidJoystickAxisCodes
Set of JoystickAxisCodes valid as input on a gamepad.
Definition: GamepadRouter.h:76
Software represention and state capable of describing almost all physical controllers.
Definition: VirtualController.h:36
Base interface for constructing virtual controllers from a deviceId.
Definition: ControllerFactory.h:34
A platform independent event generated by controller device.
Definition: ControllerEvent.h:34
Factory for constructing VirtualControllers to represent gamepad devices as controllers.
Definition: GamepadRouter.h:41
Represents a scheme mapping input joystick axes to output actions.
Definition: JoystickAxisScheme.h:28
GamepadControllerFactory(const KeyScheme &keyScheme, const JoystickAxisScheme &joystickAxisScheme, const TriggerAxisScheme &triggerAxisScheme)
Constructs a GamepadControllerFactory from input schemes.
static GamepadRouter * getInstance()
Returns the singleton instance of GamepadRouter.
static std::set< TriggerAxisCode > sValidTriggerAxisCodes
Set of TriggerAxisCodes valid as input on a gamepad.
Definition: GamepadRouter.h:80
static std::set< KeyCode > sValidKeyCodes
Set of KeyCodes valid as input on a gamepad.
Definition: GamepadRouter.h:72
Represents a scheme mapping keyboard input to output actions.
Definition: KeyScheme.h:28
Routes gamepad-related ControllerEvents according to inherent GamepadControllerFactory specifications...
Definition: GamepadRouter.h:34
Routes ControllerEvents according to inherent ControllerFactory specifications.
Definition: InputRouter.h:40
bool addGamepadControllerFactory(const GamepadControllerFactory &factory)
Adds the specified GamepadControllerFactory to the list of factories to route by. ...
virtual bool handlesControllerEvent(const ControllerEvent *event) const override
Returns whether or not this ControllerFactory can process the specified event.