Added callbacks
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <NBGraphics/Window.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace nb {
|
||||
|
||||
using GLFWCodes = GLFWError::Codes;
|
||||
@@ -60,14 +62,14 @@ void OGLWindow::SetHintString(const std::tuple<int, std::string>& hint) {
|
||||
|
||||
GLFWwindow* OGLWindow::MakeCurrent(const std::shared_ptr<OGLWindow>& window) {
|
||||
auto tmp = _currWindow;
|
||||
_currWindow = window->getWindowPtr();
|
||||
if (window) {
|
||||
glfwMakeContextCurrent(_currWindow);
|
||||
_currWindow = window->getWindowPtr();
|
||||
_currArena = window->_arena;
|
||||
} else {
|
||||
glfwMakeContextCurrent(nullptr);
|
||||
_currWindow = nullptr;
|
||||
_currArena = nullptr;
|
||||
}
|
||||
glfwMakeContextCurrent(_currWindow);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -200,14 +202,37 @@ void OGLWindow::setTitle(const std::string& name) {
|
||||
glfwSetWindowTitle(_window_ptr, _title.c_str());
|
||||
}
|
||||
|
||||
/* template<> void OGLWindow::setCallBack<OGLWindow::KEY>( CallbackFunc<int,int,int,int> func) {
|
||||
template<>
|
||||
void OGLWindow::setCallback<OGLWindow::KEY>(std::function<void(OGLWindow*, int, int, int, int)> callback) {
|
||||
CheckForMainThread();
|
||||
auto tmp = makeCurrent();
|
||||
auto tmp_func =
|
||||
[=](GLFWwindow* window, int a, int b, int c, int d){
|
||||
func(this, a, b, c, d);
|
||||
};
|
||||
glfwSetKeyCallback(_window_ptr, tmp_func);
|
||||
} */
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user