diff --git a/sfw/render_core/application.cpp b/sfw/render_core/application.cpp index 6452d48..4c3d093 100644 --- a/sfw/render_core/application.cpp +++ b/sfw/render_core/application.cpp @@ -96,10 +96,7 @@ Application::Application() { // TODO add a helper static method memnew(AppWindow()); - - if (!Input::get_singleton()) { - memnew(Input()); - } + memnew(Input()); _init_window(); } diff --git a/sfw/render_core/input/input.cpp b/sfw/render_core/input/input.cpp index a90239d..f623dc5 100644 --- a/sfw/render_core/input/input.cpp +++ b/sfw/render_core/input/input.cpp @@ -13,6 +13,8 @@ #include "render_core/texture.h" #include "render_core/window.h" +#include "render_core/3rd_glfw3.h" + Input *Input::get_singleton() { return singleton; } @@ -1007,6 +1009,48 @@ Input::Input() { } } +void Input::GLFWkeyfunCallback(GLFWwindow *window, int key, int scancode, int action, int mods) { + ERR_PRINT("GLFWkeyfunCallback"); +} +void Input::GLFWcharfunCallback(GLFWwindow *window, unsigned int codepoint) { + ERR_PRINT("GLFWcharfunCallback"); +} +void Input::GLFWcharmodsfunCallback(GLFWwindow *window, unsigned int codepoint, int mods) { + ERR_PRINT("GLFWcharmodsfunCallback"); +} +void Input::GLFWmousebuttonfunCallback(GLFWwindow *window, int button, int action, int mods) { + ERR_PRINT("GLFWmousebuttonfunCallback"); +} +void Input::GLFWcursorposfunCallback(GLFWwindow *window, double xpos, double ypos) { + ERR_PRINT("GLFWcursorposfunCallback"); +} +void Input::GLFWcursorenterfunCallback(GLFWwindow *window, int entered) { + ERR_PRINT("GLFWcursorenterfunCallback"); +} +void Input::GLFWscrollfunCallback(GLFWwindow *window, double xoffset, double yoffset) { + ERR_PRINT("GLFWscrollfunCallback"); +} +void Input::GLFWdropfunCallback(GLFWwindow *window, int path_count, const char *paths[]) { + ERR_PRINT("GLFWdropfunCallback"); +} +void Input::GLFWjoystickfunCallback(int jid, int event) { + ERR_PRINT("GLFWjoystickfunCallback"); +} + +void Input::_setup_window_callbacks() { + GLFWwindow *window = (GLFWwindow *)AppWindow::get_singleton()->get_handle(); + + glfwSetKeyCallback(window, &Input::GLFWkeyfunCallback); + glfwSetCharCallback(window, &Input::GLFWcharfunCallback); + glfwSetCharModsCallback(window, &Input::GLFWcharmodsfunCallback); + glfwSetMouseButtonCallback(window, &Input::GLFWmousebuttonfunCallback); + glfwSetCursorPosCallback(window, &Input::GLFWcursorposfunCallback); + glfwSetCursorEnterCallback(window, &Input::GLFWcursorenterfunCallback); + glfwSetScrollCallback(window, &Input::GLFWscrollfunCallback); + glfwSetDropCallback(window, &Input::GLFWdropfunCallback); + glfwSetJoystickCallback(&Input::GLFWjoystickfunCallback); +} + Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) { JoyEvent event; event.type = TYPE_MAX; diff --git a/sfw/render_core/input/input.h b/sfw/render_core/input/input.h index 69e6408..d5eb952 100644 --- a/sfw/render_core/input/input.h +++ b/sfw/render_core/input/input.h @@ -17,6 +17,7 @@ #include "render_core/input/input_event.h" class Application; +struct GLFWwindow; class Input : public Object { SFW_OBJECT(Input, Object); @@ -182,6 +183,20 @@ public: Input(); + //Called by AppWindow + void _setup_window_callbacks(); + +protected: + static void GLFWkeyfunCallback(GLFWwindow *window, int key, int scancode, int action, int mods); + static void GLFWcharfunCallback(GLFWwindow *window, unsigned int codepoint); + static void GLFWcharmodsfunCallback(GLFWwindow *window, unsigned int codepoint, int mods); + static void GLFWmousebuttonfunCallback(GLFWwindow *window, int button, int action, int mods); + static void GLFWcursorposfunCallback(GLFWwindow *window, double xpos, double ypos); + static void GLFWcursorenterfunCallback(GLFWwindow *window, int entered); + static void GLFWscrollfunCallback(GLFWwindow *window, double xoffset, double yoffset); + static void GLFWdropfunCallback(GLFWwindow *window, int path_count, const char *paths[]); + static void GLFWjoystickfunCallback(int jid, int event); + protected: enum JoyType { TYPE_BUTTON, diff --git a/sfw/render_core/window.cpp b/sfw/render_core/window.cpp index 8b5284d..16df92c 100644 --- a/sfw/render_core/window.cpp +++ b/sfw/render_core/window.cpp @@ -28,6 +28,7 @@ #include "core/ustring.h" #include "core/vector4.h" #include "render_core/application.h" +#include "render_core/input/input.h" /* static volatile float framerate = 0; @@ -187,19 +188,17 @@ void AppWindow::window_hints(unsigned flags) { //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); - -/* -#if defined(_WIN64) || defined(_WIN32) - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); -#else - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); -#endif -*/ - + /* + #if defined(_WIN64) || defined(_WIN32) + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + #else + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + #endif + */ //glfwWindowHint( GLFW_RED_BITS, 8 ); //glfwWindowHint( GLFW_GREEN_BITS, 8 ); @@ -425,6 +424,8 @@ bool AppWindow::create_from_handle(void *handle, float scale, unsigned int flags //fwk_post_init(mode->refreshRate); + Input::get_singleton()->_setup_window_callbacks(); + return true; }