Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
InputManager.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <GLFW/glfw3.h>
4
#include <array>
5
#include <glm/glm.hpp>
6
7
namespace
shkyera
{
8
9
class
InputManager
{
10
public
:
11
enum class
CoordinateSystem
{
ABSOLUTE
,
SCENE
,
RUNTIME
};
12
13
using
Key
=
int
;
14
using
MouseButton
=
int
;
15
16
static
InputManager
&
getInstance
();
17
18
void
setWindow
(
GLFWwindow
*
window
);
19
void
setCoordinateSystem
(
CoordinateSystem
system
, glm::vec2
topLeftCorner
, glm::vec2
bottomRightCorner
);
20
void
update
();
21
22
// Key queries
23
bool
isKeyDown
(
Key
key
)
const
;
// held this frame
24
bool
isKeyUp
(
Key
key
)
const
;
// not held this frame
25
bool
isKeyPressed
(
Key
key
)
const
;
// went down this frame
26
bool
isKeyReleased
(
Key
key
)
const
;
// went up this frame
27
28
// Mouse button queries
29
bool
isMouseButtonDown
(
MouseButton
button
)
const
;
30
bool
isMouseButtonUp
(
MouseButton
button
)
const
;
31
bool
isMouseButtonPressed
(
MouseButton
button
)
const
;
32
bool
isMouseButtonReleased
(
MouseButton
button
)
const
;
33
34
// Mouse position
35
glm::vec2
getMousePosition
(
CoordinateSystem
coordinateSystem
)
const
;
36
glm::vec2
getRelativeMousePosition
(
CoordinateSystem
coordinateSystem
)
const
;
37
bool
isMouseInside
(
CoordinateSystem
coordinteSystem
)
const
;
38
39
private
:
40
InputManager
();
41
42
static
constexpr
int
MAX_KEYS
=
GLFW_KEY_LAST
+ 1;
43
static
constexpr
int
MAX_MOUSE_BUTTONS
=
GLFW_MOUSE_BUTTON_LAST
+ 1;
44
45
GLFWwindow
*
_window
=
nullptr
;
46
47
std::array<bool, MAX_KEYS>
_currentKeyStates
{};
48
std::array<bool, MAX_KEYS>
_previousKeyStates
{};
49
50
std::array<bool, MAX_MOUSE_BUTTONS>
_currentMouseStates
{};
51
std::array<bool, MAX_MOUSE_BUTTONS>
_previousMouseStates
{};
52
53
glm::vec2
_mousePos
{0.0f, 0.0f};
54
55
std::unordered_map<CoordinateSystem, std::pair<glm::vec2, glm::vec2>>
_coordinateSystems
;
56
};
57
58
}
// namespace shkyera
shkyera::InputManager
Definition
InputManager.hpp:9
shkyera::InputManager::_currentMouseStates
std::array< bool, MAX_MOUSE_BUTTONS > _currentMouseStates
Definition
InputManager.hpp:50
shkyera::InputManager::isKeyUp
bool isKeyUp(Key key) const
Definition
InputManager.cpp:55
shkyera::InputManager::isMouseButtonPressed
bool isMouseButtonPressed(MouseButton button) const
Definition
InputManager.cpp:75
shkyera::InputManager::CoordinateSystem
CoordinateSystem
Definition
InputManager.hpp:11
shkyera::InputManager::CoordinateSystem::ABSOLUTE
@ ABSOLUTE
shkyera::InputManager::CoordinateSystem::RUNTIME
@ RUNTIME
shkyera::InputManager::CoordinateSystem::SCENE
@ SCENE
shkyera::InputManager::_previousMouseStates
std::array< bool, MAX_MOUSE_BUTTONS > _previousMouseStates
Definition
InputManager.hpp:51
shkyera::InputManager::isKeyDown
bool isKeyDown(Key key) const
Definition
InputManager.cpp:51
shkyera::InputManager::Key
int Key
Definition
InputManager.hpp:13
shkyera::InputManager::InputManager
InputManager()
Definition
InputManager.cpp:12
shkyera::InputManager::_window
GLFWwindow * _window
Definition
InputManager.hpp:45
shkyera::InputManager::_mousePos
glm::vec2 _mousePos
Definition
InputManager.hpp:53
shkyera::InputManager::MAX_KEYS
static constexpr int MAX_KEYS
Definition
InputManager.hpp:42
shkyera::InputManager::setWindow
void setWindow(GLFWwindow *window)
Definition
InputManager.cpp:19
shkyera::InputManager::isMouseButtonDown
bool isMouseButtonDown(MouseButton button) const
Definition
InputManager.cpp:67
shkyera::InputManager::_coordinateSystems
std::unordered_map< CoordinateSystem, std::pair< glm::vec2, glm::vec2 > > _coordinateSystems
Definition
InputManager.hpp:55
shkyera::InputManager::getMousePosition
glm::vec2 getMousePosition(CoordinateSystem coordinateSystem) const
Definition
InputManager.cpp:83
shkyera::InputManager::isKeyPressed
bool isKeyPressed(Key key) const
Definition
InputManager.cpp:59
shkyera::InputManager::_previousKeyStates
std::array< bool, MAX_KEYS > _previousKeyStates
Definition
InputManager.hpp:48
shkyera::InputManager::_currentKeyStates
std::array< bool, MAX_KEYS > _currentKeyStates
Definition
InputManager.hpp:47
shkyera::InputManager::setCoordinateSystem
void setCoordinateSystem(CoordinateSystem system, glm::vec2 topLeftCorner, glm::vec2 bottomRightCorner)
Definition
InputManager.cpp:23
shkyera::InputManager::getInstance
static InputManager & getInstance()
Definition
InputManager.cpp:7
shkyera::InputManager::update
void update()
Definition
InputManager.cpp:27
shkyera::InputManager::getRelativeMousePosition
glm::vec2 getRelativeMousePosition(CoordinateSystem coordinateSystem) const
Definition
InputManager.cpp:91
shkyera::InputManager::isMouseButtonUp
bool isMouseButtonUp(MouseButton button) const
Definition
InputManager.cpp:71
shkyera::InputManager::MouseButton
int MouseButton
Definition
InputManager.hpp:14
shkyera::InputManager::isMouseInside
bool isMouseInside(CoordinateSystem coordinteSystem) const
Definition
InputManager.cpp:99
shkyera::InputManager::isMouseButtonReleased
bool isMouseButtonReleased(MouseButton button) const
Definition
InputManager.cpp:79
shkyera::InputManager::MAX_MOUSE_BUTTONS
static constexpr int MAX_MOUSE_BUTTONS
Definition
InputManager.hpp:43
shkyera::InputManager::isKeyReleased
bool isKeyReleased(Key key) const
Definition
InputManager.cpp:63
shkyera
Definition
Asset.hpp:6
shkyera::Clock
Definition
Clock.hpp:9
src
InputManager
InputManager.hpp
Generated by
1.9.8
Franciszek Szewczyk © 2023