Overte C++ Documentation
SDL2Manager.h
1 //
2 // SDL2Manager.h
3 // input-plugins/src/input-plugins
4 //
5 // Created by Sam Gondelman on 6/5/15.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi__SDL2Manager_h
13 #define hifi__SDL2Manager_h
14 
15 #include <SDL2/SDL.h>
16 
17 #include <controllers/UserInputMapper.h>
18 #include <input-plugins/InputPlugin.h>
19 #include "Joystick.h"
20 
21 class SDL2Manager : public InputPlugin {
22  Q_OBJECT
23 
24 public:
25  // Plugin functions
26  bool isSupported() const override;
27  const QString getName() const override { return NAME; }
28  const QString getID() const override { return SDL2_ID_STRING; }
29  bool isRunning() const override { return _active && _enabled; }
30  QStringList getSubdeviceNames() override;
31 
32  void init() override;
33  void deinit() override;
34 
36  bool activate() override;
38  void deactivate() override;
39 
40  void pluginFocusOutEvent() override;
41  void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
42 
43  virtual void saveSettings() const override;
44  virtual void loadSettings() override;
45 
46 signals:
47  void joystickAdded(Joystick* joystick);
48  void joystickRemoved(Joystick* joystick);
49 
50 private:
51  SDL_JoystickID getInstanceId(SDL_GameController* controller);
52 
53  int axisInvalid() const { return SDL_CONTROLLER_AXIS_INVALID; }
54  int axisLeftX() const { return SDL_CONTROLLER_AXIS_LEFTX; }
55  int axisLeftY() const { return SDL_CONTROLLER_AXIS_LEFTY; }
56  int axisRightX() const { return SDL_CONTROLLER_AXIS_RIGHTX; }
57  int axisRightY() const { return SDL_CONTROLLER_AXIS_RIGHTY; }
58  int axisTriggerLeft() const { return SDL_CONTROLLER_AXIS_TRIGGERLEFT; }
59  int axisTriggerRight() const { return SDL_CONTROLLER_AXIS_TRIGGERRIGHT; }
60  int axisMax() const { return SDL_CONTROLLER_AXIS_MAX; }
61 
62  int buttonInvalid() const { return SDL_CONTROLLER_BUTTON_INVALID; }
63  int buttonFaceBottom() const { return SDL_CONTROLLER_BUTTON_A; }
64  int buttonFaceRight() const { return SDL_CONTROLLER_BUTTON_B; }
65  int buttonFaceLeft() const { return SDL_CONTROLLER_BUTTON_X; }
66  int buttonFaceTop() const { return SDL_CONTROLLER_BUTTON_Y; }
67  int buttonBack() const { return SDL_CONTROLLER_BUTTON_BACK; }
68  int buttonGuide() const { return SDL_CONTROLLER_BUTTON_GUIDE; }
69  int buttonStart() const { return SDL_CONTROLLER_BUTTON_START; }
70  int buttonLeftStick() const { return SDL_CONTROLLER_BUTTON_LEFTSTICK; }
71  int buttonRightStick() const { return SDL_CONTROLLER_BUTTON_RIGHTSTICK; }
72  int buttonLeftShoulder() const { return SDL_CONTROLLER_BUTTON_LEFTSHOULDER; }
73  int buttonRightShoulder() const { return SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; }
74  int buttonDpadUp() const { return SDL_CONTROLLER_BUTTON_DPAD_UP; }
75  int buttonDpadDown() const { return SDL_CONTROLLER_BUTTON_DPAD_DOWN; }
76  int buttonDpadLeft() const { return SDL_CONTROLLER_BUTTON_DPAD_LEFT; }
77  int buttonDpadRight() const { return SDL_CONTROLLER_BUTTON_DPAD_RIGHT; }
78  int buttonMax() const { return SDL_CONTROLLER_BUTTON_MAX; }
79 
80  int buttonPressed() const { return SDL_PRESSED; }
81  int buttonRelease() const { return SDL_RELEASED; }
82 
83  QMap<SDL_JoystickID, Joystick::Pointer> _openJoysticks;
84  bool _isInitialized { false };
85  static const char* NAME;
86  static const char* SDL2_ID_STRING;
87  QStringList _subdeviceNames;
88 };
89 
90 #endif // hifi__SDL2Manager_h