VOX
A little voxel engine
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "define.hpp"
4
5#include <GLFW/glfw3.h>
6
7#include <queue>
8#include <mutex>
9
10class Input
11{
12
13public:
14
15 enum class KeyState
16 {
17 RELEASED = GLFW_RELEASE,
18 PRESSED = GLFW_PRESS,
19 REPEATED = GLFW_REPEAT,
20 NONE
21 };
22
28 Input(GLFWwindow* glfwWindow);
29
33 ~Input();
34
41 KeyState getKeyState(int key);
42
49 KeyState getMouseButtonState(int button);
50
57 void getCursorPos(double & xpos, double & ypos);
58
60 {
61 std::lock_guard lock(m_cursor_mutex);
62 return m_cursor_captured;
63 }
64
71 void getScroll(double & xoffset, double & yoffset);
72
73private:
74
75 std::queue<KeyState> m_key_state[GLFW_KEY_LAST];
76 std::mutex m_key_state_mutex;
77
78 std::queue<KeyState> m_mouse_button_state[GLFW_MOUSE_BUTTON_LAST];
79 std::mutex m_mouse_button_state_mutex;
80
81 double m_cursor_x;
82 double m_cursor_y;
83 bool m_cursor_captured = false;
84 std::mutex m_cursor_mutex;
85
86 double m_scroll_x;
87 double m_scroll_y;
88 std::mutex m_scroll_mutex;
89
90 GLFWwindow* m_window;
91
101 static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
102
111 static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
112
120 static void cursorPosCallback(GLFWwindow* window, double xpos, double ypos);
121
129 static void mouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
130
131};
Definition: input.hpp:11
KeyState
Definition: input.hpp:16
KeyState getKeyState(int key)
Get the key state.
Definition: input.cpp:23
bool isCursorCaptured()
Definition: input.hpp:59
void getScroll(double &xoffset, double &yoffset)
Get the scroll values.
Definition: input.cpp:64
void getCursorPos(double &xpos, double &ypos)
Get the cursor position.
Definition: input.cpp:57
~Input()
Destroy the Input object.
Definition: input.cpp:18
KeyState getMouseButtonState(int button)
Get the mouse button state.
Definition: input.cpp:38