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
jngl::setKeyboardVisible
void setKeyboardVisible(bool)
Display onscreen keyboard for touch devices.
jngl::mousePressed
bool mousePressed(mouse::Button button=mouse::Left)
Whether button has been pressed since the next to last call to updateInput()
std::string
jngl::controller::LeftStickXInverse
@ LeftStickXInverse
-LeftStickX
Definition: input.hpp:157
jngl::key::KeyType
KeyType
Keyboard keys.
Definition: input.hpp:17
functional
jngl::mouse::Button
Button
Mouse buttons.
Definition: input.hpp:129
jngl::controller::LeftStickY
@ LeftStickY
y axis of left stick, -1 to 1
Definition: input.hpp:160
vector
jngl::getConnectedControllers
std::vector< std::shared_ptr< Controller > > getConnectedControllers()
Returns all controllers (gamepads) that are connected.
jngl::getMouseWheel
double getMouseWheel()
Returns mouse wheel movement between -100 and 100 (0 if the mousewheel doesn't move)
jngl::controller::RightStickX
@ RightStickX
x axis of right stick, -1 to 1
Definition: input.hpp:166
jngl::setMouse
void setMouse(Vec2 position)
Moves the mouse (does nothing on iOS and Android)
std::function
jngl::KeyboardType
KeyboardType
Whether a normal or a numbers-only keyboard should appear.
Definition: input.hpp:68
jngl::getTextInput
std::string getTextInput()
Returns a string of characters that have been pressed since the last call to updateInput()
jngl::getMouseX
int getMouseX()
Retrieve mouse position in pixels.
jngl
JNGL's main namespace.
Definition: App.hpp:9
jngl::onControllerChanged
void onControllerChanged(std::function< void()> callback)
Specify a function which gets called, whenever a controller gets added or removed.
Vec2.hpp
jngl::getMousePos
Vec2 getMousePos()
Mouse position in screen coordinates.
jngl::keyPressed
bool keyPressed(key::KeyType key)
Whether key has been pressed since the next to last call to updateInput()
jngl::getMouseY
int getMouseY()
Retrieve mouse position in pixels.
jngl::setKeyboardType
void setKeyboardType(KeyboardType)
Type of the onscreen keyboard.
jngl::controller::RightStickXInverse
@ RightStickXInverse
-RightStickX
Definition: input.hpp:169
jngl::controller::LeftStickYInverse
@ LeftStickYInverse
-LeftStickY
Definition: input.hpp:163
jngl::setKeyPressed
void setKeyPressed(const std::string &key, bool)
Overwrite what keyPressed() should return.
jngl::controller::RightStickYInverse
@ RightStickYInverse
-RightStickY
Definition: input.hpp:175
jngl::key::SuperR
@ SuperR
Right Windows key.
Definition: input.hpp:43
jngl::controller::LeftStickX
@ LeftStickX
x axis of left stick, -1 to 1
Definition: input.hpp:154
jngl::controller::LeftButton
@ LeftButton
Left shoulder button.
Definition: input.hpp:183
jngl::controller::Back
@ Back
Back, Menu, or Share button.
Definition: input.hpp:195
memory
jngl::isMultitouch
bool isMultitouch()
Returns true when there's more than one finger touching the screen.
jngl::key::SuperL
@ SuperL
Left Windows key.
Definition: input.hpp:40
jngl::keyDown
bool keyDown(key::KeyType key)
Whether key is down.
jngl::mouseDown
bool mouseDown(mouse::Button button=mouse::Left)
Returns whether button is currently held down.
jngl::getTouchPositions
std::vector< jngl::Vec2 > getTouchPositions()
Returns all positions where a finger touches the screen.
jngl::Vec2
Two-dimensional vector.
Definition: Vec2.hpp:14
jngl::setMousePressed
void setMousePressed(jngl::mouse::Button, bool)
Overwrite what mouseDown() should return.
jngl::setMouseDown
void setMouseDown(mouse::Button button, bool)
Overwrite what mouseDown() should return.
jngl::controller::Start
@ Start
Start, or Options button.
Definition: input.hpp:192
jngl::getKeyboardType
KeyboardType getKeyboardType()
Currently active type of onscreen keyboard.
jngl::controller::RightButton
@ RightButton
Right shoulder button.
Definition: input.hpp:186
jngl::controller::RightStickY
@ RightStickY
y axis of right stick, -1 to 1
Definition: input.hpp:172