InputManager.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 
33 #ifndef H_DC_INPUT_MANAGER
34 #define H_DC_INPUT_MANAGER
35 
36 #include <Dynacoe/Backends/InputManager/InputTypes.h>
37 #include <Dynacoe/Backends/Backend.h>
38 #include <cstring>
39 
40 
41 namespace Dynacoe {
42 class Display;
43 class InputDevice;
44 
45 
46 /* Interacts with device drivers to retrieve the requested input information. */
47 
48 class InputManager : public Backend {
49  public:
50  virtual ~InputManager(){};
51 
52  enum InputType {
53  Keyboard = 0x1,
54  Gamepad = 0x01,
55  Mouse = 0x001,
56  Touchpad = 0x0001
57  };
58 
59 
60 
61  enum class DefaultDeviceSlots {
62  Keyboard,
63  Mouse,
64  Touchpad,
65  Pad1,
66  Pad2,
67  Pad3,
68  Pad4,
69  NumDefaultDevices
70  };
71 
72 
73  // Returns if the given InputType is supported
74  // If an input type is not supported, querying the associated device
75  // will result in nullptr
76  virtual bool IsSupported(InputType) = 0;
77 
78 
79  // Updates the state of registered devices.
80  // Returns whether or not there were new input events that were pulled
81  virtual bool HandleEvents() = 0;
82 
83  // Returns a reference to the internally maintained input device.
84  // Do not free or modify the contents of the device. The first few slots
85  // up to DefaultDeviceSlots::NumDefaultDevices will match the device expected
86  virtual InputDevice * QueryDevice(int ID) = 0;
87  virtual InputDevice * QueryDevice(DefaultDeviceSlots) = 0;
88 
89  // Returns the number of additional devices available.
90  // up to MaxDevices(). Typically, any overflow devices that weren't able to
91  // fit in the first 4 slots will be put here.
92  // Given an array of sise MaxDevices(), IDs will be filled
93  // with the index to a device available through QueryDevice that isnt
94  // a default device
95  virtual int QueryAuxiliaryDevices(int * IDs) = 0;
96 
97 
98  // Maximum number of supported. Will always be at least NumDefaultDevices in count
99  virtual int MaxDevices() = 0;
100 
101  // Sets the focus on which to query input from.
102  // On multi-display systems, such as a desktop environment,
103  // input is based around the context of the focused display.
104  // On some implementations, such a distinction (and as a result, this function) is not necessary
105  // may not be necessary, but this will almost
106  // always be necessary for modern environments.
107  // Passing in nullptr should disable input until a
108  // valid display is given.
109  virtual void SetFocus(Display *) = 0;
110 
111  // Returns the current focus. The default is nullptr;
112  virtual Display * GetFocus() = 0;
113 
114 
115 
116 
117 };
118 
119 }
120 
121 #endif
The mouse pointer.
Definition: AssetID.h:37
Keyboard
Enum containing all valid keyboard key inputs.
Definition: InputTypes.h:45