JNGL
input.hpp
Go to the documentation of this file.
1 // Copyright 2012-2020 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 
13 namespace jngl {
14 
15 namespace key {
17 enum KeyType {
18  Left,
19  Up,
20  Right,
21  Down,
22  PageUp,
23  PageDown,
24  Home,
25  End,
26  BackSpace,
27  Tab,
28  Clear,
29  Return,
30  Pause,
31  Escape,
32  Delete,
33  ControlL,
34  ControlR,
35  CapsLock,
36  AltL,
37  AltR,
38 
41 
44 
45  Space,
46  ShiftL,
47  ShiftR,
48  F1,
49  F2,
50  F3,
51  F4,
52  F5,
53  F6,
54  F7,
55  F8,
56  F9,
57  F10,
58  F11,
59  F12,
60  Any
61 };
62 } // namespace key
63 
65 void setKeyboardVisible(bool);
66 
68 enum KeyboardType { Default, Numpad };
69 
72 
75 
77 void setKeyPressed(const std::string& key, bool);
78 
80 void setKeyPressed(key::KeyType key, bool);
81 
84 
86 bool keyDown(char key);
87 
89 bool keyDown(const std::string& key);
90 
93 
95 bool keyPressed(char key);
96 
99 bool keyPressed(const std::string& key);
100 
101 void setRelativeMouseMode(bool relative);
102 
103 bool getRelativeMouseMode();
104 
105 void setMouseVisible(bool visible);
106 
107 bool isMouseVisible();
108 
111 
115 
118 
121 [[deprecated("Use jngl::getMousePos() instead")]] int getMouseX();
122 
125 [[deprecated("Use jngl::getMousePos() instead")]] int getMouseY();
126 
127 namespace mouse {
129 enum Button { Left, Middle, Right };
130 } // namespace mouse
131 
133 double getMouseWheel();
134 
136 bool mouseDown(mouse::Button button = mouse::Left);
137 
139 void setMouseDown(mouse::Button button, bool);
140 
142 bool mousePressed(mouse::Button button = mouse::Left);
143 
146 
148 void setMouse(Vec2 position);
149 
150 namespace controller {
152 enum Button {
155 
158 
161 
164 
167 
170 
173 
176 
177  A,
178  B,
179  X,
180  Y,
181 
184 
187 
188  LeftTrigger,
189  RightTrigger,
190 
193 
196 
197  DpadUp,
198  DpadDown,
199  DpadLeft,
200  DpadRight,
201  LeftStick,
202  RightStick,
203  Last
204 };
205 } // namespace controller
206 
207 class Controller;
208 
214 
219 void onControllerChanged(std::function<void()> callback);
220 
223 
224 } // namespace jngl
Contains jngl::Vec2 class.
Two-dimensional vector.
Definition: Vec2.hpp:35
Button
Mouse buttons.
Definition: input.hpp:129
@ RightStickY
y axis of right stick, -1 to 1
Definition: input.hpp:172
@ RightStickYInverse
-RightStickY
Definition: input.hpp:175
@ Back
Back, Menu, or Share button.
Definition: input.hpp:195
@ LeftButton
Left shoulder button.
Definition: input.hpp:183
@ RightStickXInverse
-RightStickX
Definition: input.hpp:169
@ LeftStickYInverse
-LeftStickY
Definition: input.hpp:163
@ LeftStickXInverse
-LeftStickX
Definition: input.hpp:157
@ LeftStickX
x axis of left stick, -1 to 1
Definition: input.hpp:154
@ RightStickX
x axis of right stick, -1 to 1
Definition: input.hpp:166
@ Start
Start, or Options button.
Definition: input.hpp:192
@ LeftStickY
y axis of left stick, -1 to 1
Definition: input.hpp:160
@ RightButton
Right shoulder button.
Definition: input.hpp:186
KeyType
Keyboard keys.
Definition: input.hpp:17
@ SuperL
Left Windows key.
Definition: input.hpp:40
@ SuperR
Right Windows key.
Definition: input.hpp:43
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.
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:68