JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1// Copyright 2012-2022 Jan Niklas Hasse <jhasse@bixense.com>
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>
14using std::optional;
15#else
16#include <experimental/optional>
18#endif
19
20namespace jngl {
21
22namespace key {
24enum 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
73
75enum KeyboardType { Default, Numpad };
76
79
82
84void setKeyPressed(const std::string& key, bool);
85
88
91
93bool keyDown(char key);
94
96bool keyDown(const std::string& key);
97
100
102bool keyPressed(char key);
103
106bool keyPressed(const std::string& key);
107
108void setRelativeMouseMode(bool relative);
109
110bool getRelativeMouseMode();
111
113void setMouseVisible(bool visible);
114
120
123
127
133
136
139[[deprecated("Use jngl::getMousePos() instead")]] int getMouseX();
140
143[[deprecated("Use jngl::getMousePos() instead")]] int getMouseY();
144
145namespace mouse {
147enum Button { Left, Middle, Right };
148} // namespace mouse
149
152
154bool mouseDown(mouse::Button button = mouse::Left);
155
157void setMouseDown(mouse::Button button, bool);
158
160bool mousePressed(mouse::Button button = mouse::Left);
161
164
166void setMouse(Vec2 position);
167
168namespace controller {
170enum Button {
173
176
179
182
185
188
191
194
195 A,
196 B,
197 X,
198 Y,
199
202
205
206 LeftTrigger,
207 RightTrigger,
208
211
214
215 DpadUp,
216 DpadDown,
217 DpadLeft,
218 DpadRight,
219 LeftStick,
220 RightStick,
221 Last
222};
223} // namespace controller
224
225class Controller;
226
232
237void onControllerChanged(std::function<void()> callback);
238
241
242} // namespace jngl
Contains jngl::Vec2 class.
Two-dimensional vector.
Definition: Vec2.hpp:32
Button
Mouse buttons.
Definition: input.hpp:147
@ RightStickY
y axis of right stick, -1 to 1
Definition: input.hpp:190
@ RightStickYInverse
-RightStickY
Definition: input.hpp:193
@ Back
Back, Menu, or Share button.
Definition: input.hpp:213
@ LeftButton
Left shoulder button.
Definition: input.hpp:201
@ RightStickXInverse
-RightStickX
Definition: input.hpp:187
@ LeftStickYInverse
-LeftStickY
Definition: input.hpp:181
@ LeftStickXInverse
-LeftStickX
Definition: input.hpp:175
@ LeftStickX
x axis of left stick, -1 to 1
Definition: input.hpp:172
@ RightStickX
x axis of right stick, -1 to 1
Definition: input.hpp:184
@ Start
Start, or Options button.
Definition: input.hpp:210
@ LeftStickY
y axis of left stick, -1 to 1
Definition: input.hpp:178
@ RightButton
Right shoulder button.
Definition: input.hpp:204
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: Achievement.hpp:10
int getMouseX()
Retrieve mouse position in pixels.
double getMouseWheel()
Returns mouse wheel movement between -100 and 100 (0 if the mousewheel doesn't move)
bool keyDown(key::KeyType key)
Whether key is down.
int getMouseY()
Retrieve mouse position in pixels.
KeyboardType getKeyboardType()
Currently active type of onscreen keyboard.
std::vector< jngl::Vec2 > getTouchPositions()
Returns all positions where a finger touches the screen.
void onControllerChanged(std::function< void()> callback)
Specify a function which gets called, whenever a controller gets added or removed.
void setMouse(Vec2 position)
Moves the mouse (does nothing on iOS and Android)
std::string getTextInput()
Returns a string of characters that have been pressed since the last call to updateInput()
bool mousePressed(mouse::Button button=mouse::Left)
Whether button has been pressed since the next to last call to updateInput()
bool isMultitouch()
Returns true when there's more than one finger touching the screen.
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.
void setKeyboardType(KeyboardType)
Type of the onscreen keyboard.
void setKeyPressed(const std::string &key, bool)
Overwrite what keyPressed() should return.
bool keyPressed(key::KeyType key)
Whether key has been pressed since the next to last call to updateInput()
void setMouseVisible(bool visible)
By default the mouse cursor of the OS is visible and can be hidden by passing false.
std::vector< std::shared_ptr< Controller > > getConnectedControllers()
Returns all controllers (gamepads) that are connected.
void setMousePressed(jngl::mouse::Button, bool)
Overwrite what mouseDown() should return.
Vec2 getMousePos()
Mouse position in screen coordinates.
KeyboardType
Whether a normal or a numbers-only keyboard should appear.
Definition: input.hpp:75
bool isMouseVisible()
Returns whether the mouse cursor of the OS is currently visible.
optional< Vec2 > getCursorPos()
Returns the position of the mouse pointer if a mouse is connected/available.