Gainput_Multi.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 #if (defined DC_BACKENDS_GAINPUTX11 || defined DC_BACKENDS_GAINPUTWIN32)
33 
34 #ifndef DC_GAINPUT_MULTI_INCLUDED
35 #define DC_GAINPUT_MULTI_INCLUDED
36 
37 #include <gainput/gainput.h>
38 #include <Dynacoe/Backends/InputManager/InputDevice.h>
39 #include <Dynacoe/Backends/InputManager/InputManager.h>
40 #include <vector>
41 
42 /* Gainput backend for Dynacoe
43 
44 
45  Gainput License:
46 
47 
48 Copyright (c) 2013 Johannes Kuhlmann
49 
50 Permission is hereby granted, free of charge, to any person obtaining a copy of this
51 software and associated documentation files (the "Software"), to deal in the Software
52 without restriction, including without limitation the rights to use, copy, modify, merge,
53 publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
54 to whom the Software is furnished to do so, subject to the following conditions:
55 
56 The above copyright notice and this permission notice shall be included in all copies or
57  substantial portions of the Software.
58 
59 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
60 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
62 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
63  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
64 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 
66 */
67 
68 namespace Dynacoe {
69 class Display;
70 class GainputManager : public InputManager {
71  public:
72  GainputManager();
73 
74  // standard interface
75  bool IsSupported(InputType);
76  bool HandleEvents();
77  InputDevice * QueryDevice(int ID);
78  InputDevice * QueryDevice(DefaultDeviceSlots);
79  int QueryAuxiliaryDevices(int * IDs);
80  int MaxDevices();
81 
82  std::string Name();
83  std::string Version();
84  bool Valid();
85 
86  void SetFocus(Display*);
87  Display * GetFocus();
88 
89 
90  private:
91 
92 
93  gainput::InputManager devMan;
94 
95 
96  /* a gainput device is qualified by a dynacoe device and
97  a gainput device manager */
98  struct GainputDevice {
99  GainputDevice(gainput::DeviceId _id, InputDevice * _dev,
100  gainput::InputMap * _buttonMap, gainput::InputMap * _axesMap):
101  id(_id),
102  dev(_dev),
103  buttonMap(_buttonMap),
104  axesMap(_axesMap){}
105 
106  // updates the device
107  void update();
108 
109  gainput::DeviceId id;
110  InputDevice * dev;
111  gainput::InputMap * buttonMap;
112  gainput::InputMap * axesMap;
113  };
114 
115 
116 
117 
118  std::vector<GainputDevice*> devices;
119 
120 
121  void mapKeys();
122  void clearInput();
123  void updateInternalStates();
124  void updateDevice(InputDevice);
125 
126  float mouseX, mouseY; //IDs 0, 1
127  float touchX, touchY; //IDs 2, 3
128 
129  int mouseAxesWheelDown = 100;
130 
131  Display * displayHandle;
132 
133 
134 
135 };
136 }
137 
138 
139 #endif
140 #endif
Definition: AssetID.h:37