add working input interface

This commit is contained in:
NishiOwO 2025-04-20 16:45:58 +09:00
parent 817c5c4c65
commit 432874d09b
No known key found for this signature in database
GPG Key ID: 27EF69B208EB9343
25 changed files with 152 additions and 7 deletions

View File

@ -1,4 +1,5 @@
#define GF_EXPOSE_CLIENT
#define GF_EXPOSE_DRAW
#include <gf_pre.h>
@ -10,6 +11,7 @@
/* Engine */
#include <gf_draw.h>
#include <gf_log.h>
#include <gf_input.h>
/* Standard */
#include <stdlib.h>
@ -29,11 +31,14 @@ gf_client_t* gf_client_create(gf_engine_t* engine, const char* title) {
gf_client_destroy(client);
return NULL;
}
client->input = gf_input_create(engine);
gf_draw_set_input(client->draw, client->input);
return client;
}
void gf_client_destroy(gf_client_t* client) {
if(client->draw != NULL) gf_draw_destroy(client->draw);
if(client->input != NULL) gf_input_destroy(client->input);
gf_log_function(client->engine, "Destroyed client interface", "");
free(client);
}

View File

@ -121,3 +121,5 @@ void gf_draw_destroy(gf_draw_t* draw) {
gf_log_function(draw->engine, "Destroyed drawing interface", "");
free(draw);
}
void gf_draw_set_input(gf_draw_t* draw, gf_input_t* input) { draw->input = input; }

View File

@ -1,4 +1,6 @@
#define GF_EXPOSE_GUI
#define GF_EXPOSE_DRAW
#define GF_EXPOSE_INPUT
#include <gf_pre.h>

View File

@ -1,3 +1,5 @@
#define GF_EXPOSE_INPUT
#include <gf_pre.h>
/* External library */
@ -6,5 +8,24 @@
#include <gf_input.h>
/* Engine */
#include <gf_log.h>
/* Standard */
#include <stdlib.h>
#include <string.h>
gf_input_t* gf_input_create(gf_engine_t* engine) {
gf_input_t* input = malloc(sizeof(*input));
memset(input, 0, sizeof(input));
input->engine = engine;
input->mouse_x = 0;
input->mouse_y = 0;
return input;
}
void gf_input_destroy(gf_input_t* input) {
gf_log_function(input->engine, "Destroyed input interface", "");
free(input);
}

View File

@ -1,5 +1,6 @@
#define GF_EXPOSE_DRAW_PLATFORM
#define GF_EXPOSE_DRAW
#define GF_EXPOSE_INPUT
#include <gf_pre.h>
@ -13,6 +14,7 @@
#include <gf_draw_driver.h>
#include <gf_log.h>
#include <gf_draw.h>
#include <gf_input.h>
/* Standard */
#include <string.h>
@ -36,6 +38,14 @@ void gf_glfw_size(GLFWwindow* window, int w, int h) {
gf_draw_reshape(draw);
}
void gf_glfw_cursor(GLFWwindow* window, double x, double y) {
gf_draw_t* draw = (gf_draw_t*)glfwGetWindowUserPointer(window);
if(draw->input != NULL) {
draw->input->mouse_x = x;
draw->input->mouse_y = y;
}
}
int gf_draw_platform_has_extension(gf_draw_t* draw, const char* query) {
const char* ext = NULL;
const char* ptr;
@ -76,6 +86,7 @@ gf_draw_platform_t* gf_draw_platform_create(gf_engine_t* engine, gf_draw_t* draw
}
glfwSetWindowUserPointer(platform->window, draw);
glfwSetCursorPosCallback(platform->window, gf_glfw_cursor);
glfwSetWindowSizeCallback(platform->window, gf_glfw_size);
glfwMakeContextCurrent(platform->window);

View File

@ -1,5 +1,6 @@
#define GF_EXPOSE_DRAW_PLATFORM
#define GF_EXPOSE_DRAW
#define GF_EXPOSE_INPUT
#include <gf_pre.h>
@ -11,6 +12,7 @@
/* Engine */
#include <gf_draw_driver.h>
#include <gf_input.h>
#include <gf_log.h>
#include <gf_draw.h>
@ -158,6 +160,11 @@ int gf_draw_platform_step(gf_draw_t* draw) {
XNextEvent(draw->platform->display, &event);
if(event.type == Expose) {
break;
} else if(event.type == MotionNotify) {
if(draw->input != NULL) {
draw->input->mouse_x = event.xmotion.x;
draw->input->mouse_y = event.xmotion.y;
}
} else if(event.type == ConfigureNotify) {
draw->x = event.xconfigure.x;
draw->y = event.xconfigure.y;

View File

@ -16,6 +16,7 @@
/* Engine */
#include <gf_type/core.h>
#include <gf_type/input.h>
/* Standard */
@ -35,6 +36,14 @@ GF_EXPORT gf_draw_t* gf_draw_create(gf_engine_t* engine, const char* title);
*/
GF_EXPORT void gf_draw_destroy(gf_draw_t* draw);
/**
* @~english
* @brief Set input interface
* @param draw Drawing interface
* @param input Input interface
*/
GF_EXPORT void gf_draw_set_input(gf_draw_t* draw, gf_input_t* input);
/**
* @~english
* @brief Draw frame (common part)

View File

@ -19,6 +19,7 @@
#include <gf_type/texture.h>
#include <gf_type/graphic.h>
#include <gf_type/core.h>
#include <gf_type/input.h>
/* Standard */

View File

@ -14,7 +14,23 @@
#include <gf_type/input.h>
/* Engine */
#include <gf_type/core.h>
/* Standard */
/**
* @~english
* @brief Create input interface
* @param engine Engine instance
* @return Input interface
*/
GF_EXPORT gf_input_t* gf_input_create(gf_engine_t* engine);
/**
* @~english
* @brief Destroy input interface
* @param input Input interface
*/
GF_EXPORT void gf_input_destroy(gf_input_t* input);
#endif

View File

@ -11,11 +11,14 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_CLIENT
typedef struct gf_client_t gf_client_t;
/* External library */
/* Engine */
#include <gf_type/core.h>
#include <gf_type/draw.h>
#include <gf_type/input.h>
/* Standard */
@ -29,10 +32,14 @@
*
* @var gf_client_t::draw
* @brief Drawing interface
*
* @var gf_client_t::input
* @brief Input interface
*/
GF_DECLARE_TYPE(client, {
gf_engine_t* engine;
gf_draw_t* draw;
gf_input_t* input;
});
#else
typedef void gf_client_t;

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_CORE
typedef struct gf_engine_t gf_engine_t;
/* External library */
/* Engine */

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_DRAW
typedef struct gf_draw_t gf_draw_t;
/* External library */
/* Engine */
@ -21,6 +23,7 @@
#include <gf_type/math.h>
#include <gf_type/gui.h>
#include <gf_type/font.h>
#include <gf_type/input.h>
/* Standard */
@ -32,6 +35,9 @@
* @var gf_draw_t::engine
* @brief Engine instance
*
* @var gf_draw_t::input
* @brief Input interface
*
* @var gf_draw_t::platform
* @brief Platform-dependent part of drawing driver
*
@ -83,6 +89,7 @@
*/
GF_DECLARE_TYPE(draw, {
gf_engine_t* engine;
gf_input_t* input;
gf_draw_platform_t* platform;
gf_draw_driver_t* driver;
gf_gui_t* gui;

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_DRAW_DRIVER
typedef struct gf_draw_driver_t gf_draw_driver_t;
/* External library */
#if defined(DRV_OPENGL)
#include <gf_opengl.h>

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_DRAW_PLATFORM
typedef struct gf_draw_platform_t gf_draw_platform_t;
/* External library */
#if defined(DRV_OPENGL)
#include <gf_opengl.h>

View File

@ -11,6 +11,10 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_FONT
typedef struct gf_font_bbox_t gf_font_bbox_t;
typedef struct gf_font_glyph_t gf_font_glyph_t;
typedef struct gf_font_t gf_font_t;
/* External library */
/* Engine */

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_GRAPHIC
typedef struct gf_graphic_color_t gf_graphic_color_t;
/* External library */
/* Engine */

View File

@ -17,6 +17,12 @@
typedef int gf_gui_id_t;
#ifdef GF_EXPOSE_GUI
typedef struct gf_gui_button_t gf_gui_button_t;
typedef struct gf_gui_t gf_gui_t;
typedef struct gf_gui_component_t gf_gui_component_t;
typedef union gf_gui_union_t gf_gui_union_t;
/* External library */
/* Engine */

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_INPUT
typedef struct gf_input_t gf_input_t;
/* External library */
/* Engine */
@ -18,7 +20,28 @@
#include <gf_type/core.h>
/* Standard */
/**
* @struct gf_input_t
* @~english
* @brief Input interface
*
* @var gf_input_t::engine
* @brief Engine instance
*
* @var gf_input_t::mouse_x
* @brief X coord of mouse
*
* @var gf_input_t::mouse_y
* @brief Y coord of mouse
*/
GF_DECLARE_TYPE(input, {
gf_engine_t* engine;
int mouse_x;
int mouse_y;
});
#else
typedef void gf_input_t;
#endif
#endif

View File

@ -11,6 +11,9 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_MESH
typedef struct gf_mesh_triangle_t gf_mesh_triangle_t;
typedef struct gf_mesh_t gf_mesh_t;
/* External library */
/* Engine */
@ -20,17 +23,17 @@
/* Standard */
/**
* @struct gf_triangle_t
* @struct gf_mesh_triangle_t
* @~english
* @brief Triangle
*
* @var gf_triangle_t::points
* @var gf_mesh_triangle_t::points
* @brief Triangle points
*
* @var gf_triangle_t::color
* @var gf_mesh_triangle_t::color
* @brief Triangle color
*/
GF_DECLARE_TYPE(triangle, {
GF_DECLARE_TYPE(mesh_triangle, {
gf_math_vector_t points[3];
gf_graphic_color_t color;
});
@ -47,12 +50,12 @@ GF_DECLARE_TYPE(triangle, {
* @brief Triangle count
*/
GF_DECLARE_TYPE(mesh, {
gf_triangle_t* triangles;
int triangle_count;
gf_mesh_triangle_t* triangles;
int triangle_count;
});
#else
typedef void gf_mesh_t;
typedef void gf_triangle_t;
typedef void gf_mesh_triangle_t;
#endif
#endif

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_MODEL
typedef struct gf_model_t gf_model_t;
/* External library */
/* Engine */

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_PHYSICS
typedef struct gf_physics_t gf_physics_t;
/* External library */
#include <ode/ode.h>

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_SERVER
typedef struct gf_server_t gf_server_t;
/* External library */
/* Engine */

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_TEXTURE
typedef struct gf_texture_t gf_texture_t;
/* External library */
/* Engine */

View File

@ -11,6 +11,9 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_THREAD
typedef struct gf_thread_context_t gf_thread_context_t;
typedef struct gf_thread_t gf_thread_t;
/* External library */
#if defined(THREAD_POSIX)
#include <pthread.h>

View File

@ -11,6 +11,8 @@
#include <gf_macro.h>
#ifdef GF_EXPOSE_VERSION
typedef struct gf_version_t gf_version_t;
/* External library */
/* Engine */