Setup input callbacks.

This commit is contained in:
Relintai 2024-01-03 14:49:47 +01:00
parent 24568b12ff
commit 1a761c83ca
4 changed files with 74 additions and 17 deletions

View File

@ -96,10 +96,7 @@ Application::Application() {
// TODO add a helper static method
memnew(AppWindow());
if (!Input::get_singleton()) {
memnew(Input());
}
memnew(Input());
_init_window();
}

View File

@ -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;

View File

@ -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,

View File

@ -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;
}