Better callbacks

This commit is contained in:
NaifBanana
2026-10-12 00:51:50 -05:00
parent b9e8144519
commit e6a5c9e805
3 changed files with 169 additions and 56 deletions
-33
View File
@@ -202,37 +202,4 @@ void OGLWindow::setTitle(const std::string& name) {
glfwSetWindowTitle(_window_ptr, _title.c_str());
}
template<>
void OGLWindow::setCallback<OGLWindow::KEY>(std::function<void(OGLWindow*, int, int, int, int)> callback) {
CheckForMainThread();
auto tmp = makeCurrent();
static auto this_ptr = this;
static auto tmp_callback = callback;
glfwSetKeyCallback(_window_ptr, [](GLFWwindow*, int a, int b, int c, int d){
tmp_callback(this_ptr, a, b, c, d);
});
}
template<>
void OGLWindow::setCallback<OGLWindow::MOUSE_BUTTON>(std::function<void(OGLWindow*, int, int, int)> callback) {
CheckForMainThread();
auto tmp = makeCurrent();
static auto this_ptr = this;
static auto tmp_callback = callback;
glfwSetMouseButtonCallback(_window_ptr, [](GLFWwindow*, int a, int b, int c){
tmp_callback(this_ptr, a, b, c);
});
}
template<>
void OGLWindow::setCallback<OGLWindow::CURSOR_POS>(std::function<void(OGLWindow*, double, double)> callback) {
CheckForMainThread();
auto tmp = makeCurrent();
static auto this_ptr = this;
static auto tmp_callback = callback;
glfwSetCursorPosCallback(_window_ptr, [](GLFWwindow*, double a, double b){
tmp_callback(this_ptr, a, b);
});
}
};