JNGL
input.hpp
Go to the documentation of this file.
1 // Copyright 2012-2022 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
5 #pragma once
6 
7 #include "Vec2.hpp"
8 
9 #include <functional>
10 #include <memory>
11 #include <vector>
12 #if defined(__has_include) && __has_include(<optional>)
13 #include <optional>
14 using std::optional;
15 #else
16 #include <experimental/optional>
18 #endif
19 
20 namespace jngl {
21 
22 namespace key {
24 enum KeyType {
25  Left,
26  Up,
27  Right,
28  Down,
29  PageUp,
30  PageDown,
31  Home,
32  End,
33  BackSpace,
34  Tab,
35  Clear,
36  Return,
37  Pause,
38  Escape,
39  Delete,
40  ControlL,
41  ControlR,
42  CapsLock,
43  AltL,
44  AltR,
45 
48 
51 
52  Space,
53  ShiftL,
54  ShiftR,
55  F1,
56  F2,
57  F3,
58  F4,
59  F5,
60  F6,
61  F7,
62  F8,
63  F9,
64  F10,
65  F11,
66  F12,
67  Any
68 };
69 } // namespace key
70 
72 void setKeyboardVisible(bool);
73 
75 enum KeyboardType { Default, Numpad };
76 
79 
82 
84 void setKeyPressed(const std::string& key, bool);
85 
87 void setKeyPressed(key::KeyType key, bool);
88 
91 
93 bool keyDown(char key);
94 
96 bool keyDown(const std::string& key);
97 
100 
102 bool keyPressed(char key);
103 
106 bool keyPressed(const std::string& key);
107 
108 void setRelativeMouseMode(bool relative);
109 
110 bool getRelativeMouseMode();
111 
112 void setMouseVisible(bool visible);
113 
114 bool isMouseVisible();
115 
118 
122 
128 
131 
134 [[deprecated("Use jngl::getMousePos() instead")]] int getMouseX();
135 
138 [[deprecated("Use jngl::getMousePos() instead")]] int getMouseY();
139 
140 namespace mouse {
142 enum Button { Left, Middle, Right };
143 } // namespace mouse
144 
146 double getMouseWheel();
147 
149 bool mouseDown(mouse::Button button = mouse::Left);
150 
152 void setMouseDown(mouse::Button button, bool);
153 
155 bool mousePressed(mouse::Button button = mouse::Left);
156 
159 
161 void setMouse(Vec2 position);
162 
163 namespace controller {
165 enum Button {
168 
171 
174 
177 
180 
183 
186 
189 
190  A,
191  B,
192  X,
193  Y,
194 
197 
200 
201  LeftTrigger,
202  RightTrigger,
203 
206 
209 
210  DpadUp,
211  DpadDown,
212  DpadLeft,
213  DpadRight,
214  LeftStick,
215  RightStick,
216  Last
217 };
218 } // namespace controller
219 
220 class Controller;
221 
227 
232 void onControllerChanged(std::function<void()> callback);
233 
236 
237 } // namespace jngl
Contains jngl::Vec2 class.
Two-dimensional vector.
Definition: Vec2.hpp:35
Button
Mouse buttons.
Definition: input.hpp:142
@ RightStickY
y axis of right stick, -1 to 1
Definition: input.hpp:185
@ RightStickYInverse
-RightStickY
Definition: input.hpp:188
@ Back
Back, Menu, or Share button.
Definition: input.hpp:208
@ LeftButton
Left shoulder button.
Definition: input.hpp:196
@ RightStickXInverse
-RightStickX
Definition: input.hpp:182
@ LeftStickYInverse
-LeftStickY
Definition: input.hpp:176
@ LeftStickXInverse
-LeftStickX
Definition: input.hpp:170
@ LeftStickX
x axis of left stick, -1 to 1
Definition: input.hpp:167
@ RightStickX
x axis of right stick, -1 to 1
Definition: input.hpp:179
@ Start
Start, or Options button.
Definition: input.hpp:205
@ LeftStickY
y axis of left stick, -1 to 1
Definition: input.hpp:173
@ RightButton
Right shoulder button.
Definition: input.hpp:199
KeyType
Keyboard keys.
Definition: input.hpp:24
@ SuperL
Left Windows key.
Definition: input.hpp:47
@ SuperR
Right Windows key.
Definition: input.hpp:50
JNGL's main namespace.
Definition: App.hpp:10
KeyboardType getKeyboardType()
Currently active type of onscreen keyboard.
bool mousePressed(mouse::Button button=mouse::Left)
Whether button has been pressed since the next to last call to updateInput()
double getMouseWheel()
Returns mouse wheel movement between -100 and 100 (0 if the mousewheel doesn't move)
std::vector< std::shared_ptr< Controller > > getConnectedControllers()
Returns all controllers (gamepads) that are connected.
bool mouseDown(mouse::Button button=mouse::Left)
Returns whether button is currently held down.
void setMouseDown(mouse::Button button, bool)
Overwrite what mouseDown() should return.
void setKeyboardVisible(bool)
Display onscreen keyboard for touch devices.
std::string getTextInput()
Returns a string of characters that have been pressed since the last call to updateInput()
bool isMultitouch()
Returns true when there's more than one finger touching the screen.
bool keyPressed(key::KeyType key)
Whether key has been pressed since the next to last call to updateInput()
bool keyDown(key::KeyType key)
Whether key is down.
void setKeyboardType(KeyboardType)
Type of the onscreen keyboard.
void setKeyPressed(const std::string &key, bool)
Overwrite what keyPressed() should return.
Vec2 getMousePos()
Mouse position in screen coordinates.
optional< Vec2 > getCursorPos()
Returns the position of the mouse pointer if a mouse is connected/available.
void onControllerChanged(std::function< void()> callback)
Specify a function which gets called, whenever a controller gets added or removed.
int getMouseX()
Retrieve mouse position in pixels.
std::vector< jngl::Vec2 > getTouchPositions()
Returns all positions where a finger touches the screen.
int getMouseY()
Retrieve mouse position in pixels.
void setMouse(Vec2 position)
Moves the mouse (does nothing on iOS and Android)
void setMousePressed(jngl::mouse::Button, bool)
Overwrite what mouseDown() should return.
KeyboardType
Whether a normal or a numbers-only keyboard should appear.
Definition: input.hpp:75