|
@@ -2,7 +2,8 @@
|
|
|
|
|
|
#include "rendering/Window.h"
|
|
|
|
|
|
-Window::Window(const WindowOptions& options) : window(nullptr) {
|
|
|
+Window::Window(TextInput& textInput, const WindowOptions& options)
|
|
|
+ : textInput(textInput), window(nullptr) {
|
|
|
glfwDefaultWindowHints();
|
|
|
glfwWindowHint(GLFW_VISIBLE, 0);
|
|
|
glfwWindowHint(GLFW_RESIZABLE, 1);
|
|
@@ -25,6 +26,10 @@ Window::Window(const WindowOptions& options) : window(nullptr) {
|
|
|
std::cout << "could not create window\n";
|
|
|
return;
|
|
|
}
|
|
|
+ glfwSetWindowUserPointer(window, this);
|
|
|
+ glfwSetKeyCallback(window, keyCallback);
|
|
|
+ glfwSetCharCallback(window, charCallback);
|
|
|
+
|
|
|
glfwMakeContextCurrent(window);
|
|
|
glfwSwapInterval(options.vsync);
|
|
|
}
|
|
@@ -70,4 +75,19 @@ Size Window::getFramebufferSize() const {
|
|
|
|
|
|
bool Window::isKeyDown(int key) const {
|
|
|
return glfwGetKey(window, key) == GLFW_PRESS;
|
|
|
+}
|
|
|
+
|
|
|
+void Window::keyCallback(GLFWwindow* w, int key, int scancode, int action,
|
|
|
+ int mods) {
|
|
|
+ void* p = glfwGetWindowUserPointer(w);
|
|
|
+ if(p != nullptr) {
|
|
|
+ static_cast<Window*>(p)->textInput.onKeyEvent(key, scancode, action,
|
|
|
+ mods);
|
|
|
+ }
|
|
|
+}
|
|
|
+void Window::charCallback(GLFWwindow* w, unsigned int codepoint) {
|
|
|
+ void* p = glfwGetWindowUserPointer(w);
|
|
|
+ if(p != nullptr) {
|
|
|
+ static_cast<Window*>(p)->textInput.onCharEvent(codepoint);
|
|
|
+ }
|
|
|
}
|