mirror of
https://github.com/Relintai/sfw.git
synced 2025-02-19 23:14:19 +01:00
Setup input callbacks.
This commit is contained in:
parent
24568b12ff
commit
1a761c83ca
@ -96,10 +96,7 @@ Application::Application() {
|
|||||||
|
|
||||||
// TODO add a helper static method
|
// TODO add a helper static method
|
||||||
memnew(AppWindow());
|
memnew(AppWindow());
|
||||||
|
|
||||||
if (!Input::get_singleton()) {
|
|
||||||
memnew(Input());
|
memnew(Input());
|
||||||
}
|
|
||||||
|
|
||||||
_init_window();
|
_init_window();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include "render_core/texture.h"
|
#include "render_core/texture.h"
|
||||||
#include "render_core/window.h"
|
#include "render_core/window.h"
|
||||||
|
|
||||||
|
#include "render_core/3rd_glfw3.h"
|
||||||
|
|
||||||
Input *Input::get_singleton() {
|
Input *Input::get_singleton() {
|
||||||
return 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) {
|
Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) {
|
||||||
JoyEvent event;
|
JoyEvent event;
|
||||||
event.type = TYPE_MAX;
|
event.type = TYPE_MAX;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "render_core/input/input_event.h"
|
#include "render_core/input/input_event.h"
|
||||||
|
|
||||||
class Application;
|
class Application;
|
||||||
|
struct GLFWwindow;
|
||||||
|
|
||||||
class Input : public Object {
|
class Input : public Object {
|
||||||
SFW_OBJECT(Input, Object);
|
SFW_OBJECT(Input, Object);
|
||||||
@ -182,6 +183,20 @@ public:
|
|||||||
|
|
||||||
Input();
|
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:
|
protected:
|
||||||
enum JoyType {
|
enum JoyType {
|
||||||
TYPE_BUTTON,
|
TYPE_BUTTON,
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "core/ustring.h"
|
#include "core/ustring.h"
|
||||||
#include "core/vector4.h"
|
#include "core/vector4.h"
|
||||||
#include "render_core/application.h"
|
#include "render_core/application.h"
|
||||||
|
#include "render_core/input/input.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static volatile float framerate = 0;
|
static volatile float framerate = 0;
|
||||||
@ -187,7 +188,6 @@ void AppWindow::window_hints(unsigned flags) {
|
|||||||
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
|
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
@ -200,7 +200,6 @@ void AppWindow::window_hints(unsigned flags) {
|
|||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//glfwWindowHint( GLFW_RED_BITS, 8 );
|
//glfwWindowHint( GLFW_RED_BITS, 8 );
|
||||||
//glfwWindowHint( GLFW_GREEN_BITS, 8 );
|
//glfwWindowHint( GLFW_GREEN_BITS, 8 );
|
||||||
//glfwWindowHint( GLFW_BLUE_BITS, 8 );
|
//glfwWindowHint( GLFW_BLUE_BITS, 8 );
|
||||||
@ -425,6 +424,8 @@ bool AppWindow::create_from_handle(void *handle, float scale, unsigned int flags
|
|||||||
|
|
||||||
//fwk_post_init(mode->refreshRate);
|
//fwk_post_init(mode->refreshRate);
|
||||||
|
|
||||||
|
Input::get_singleton()->_setup_window_callbacks();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user