-
Notifications
You must be signed in to change notification settings - Fork 0
/
glfw_lambda_callback_manager.cpp
42 lines (37 loc) · 2.36 KB
/
glfw_lambda_callback_manager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "glfw_lambda_callback_manager.hpp"
GLFWLambdaCallbackManager::GLFWLambdaCallbackManager(GLFWwindow *window, CharCallback char_callback,
KeyCallback key_callback, CursorPosCallback cursor_pos_callback,
MouseButtonCallback mouse_button_callback)
: window_(window), char_callback_(char_callback), key_callback_(key_callback),
cursor_pos_callback_(cursor_pos_callback), mouse_button_callback_(mouse_button_callback) {
glfwSetWindowUserPointer(window, this);
glfwSetCharCallback(window, GLFWLambdaCallbackManager::char_callback_wrapper);
glfwSetKeyCallback(window, GLFWLambdaCallbackManager::key_callback_wrapper);
glfwSetCursorPosCallback(window, GLFWLambdaCallbackManager::cursor_pos_callback_wrapper);
glfwSetMouseButtonCallback(window, GLFWLambdaCallbackManager::mouse_button_callback_wrapper);
}
void GLFWLambdaCallbackManager::char_callback_wrapper(GLFWwindow *window, unsigned int codepoint) {
GLFWLambdaCallbackManager *manager = static_cast<GLFWLambdaCallbackManager *>(glfwGetWindowUserPointer(window));
if (manager && manager->char_callback_) {
manager->char_callback_(codepoint);
}
}
void GLFWLambdaCallbackManager::key_callback_wrapper(GLFWwindow *window, int key, int scancode, int action, int mods) {
GLFWLambdaCallbackManager *manager = static_cast<GLFWLambdaCallbackManager *>(glfwGetWindowUserPointer(window));
if (manager && manager->key_callback_) {
manager->key_callback_(key, scancode, action, mods);
}
}
void GLFWLambdaCallbackManager::cursor_pos_callback_wrapper(GLFWwindow *window, double mouse_position_x,
double mouse_position_y) {
GLFWLambdaCallbackManager *manager = static_cast<GLFWLambdaCallbackManager *>(glfwGetWindowUserPointer(window));
if (manager && manager->cursor_pos_callback_) {
manager->cursor_pos_callback_(mouse_position_x, mouse_position_y);
}
}
void GLFWLambdaCallbackManager::mouse_button_callback_wrapper(GLFWwindow *window, int button, int action, int mods) {
GLFWLambdaCallbackManager *manager = static_cast<GLFWLambdaCallbackManager *>(glfwGetWindowUserPointer(window));
if (manager && manager->mouse_button_callback_) {
manager->mouse_button_callback_(button, action, mods);
}
}