diff --git a/engine/gf_client.c b/engine/gf_client.c index a67018a..01a367b 100644 --- a/engine/gf_client.c +++ b/engine/gf_client.c @@ -1,4 +1,5 @@ #define GF_EXPOSE_CLIENT +#define GF_EXPOSE_DRAW #include @@ -10,6 +11,7 @@ /* Engine */ #include #include +#include /* Standard */ #include @@ -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); } diff --git a/engine/gf_draw_common.c b/engine/gf_draw_common.c index 1200f7b..13fe4f0 100644 --- a/engine/gf_draw_common.c +++ b/engine/gf_draw_common.c @@ -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; } diff --git a/engine/gf_gui.c b/engine/gf_gui.c index 7306bf6..1df23d8 100644 --- a/engine/gf_gui.c +++ b/engine/gf_gui.c @@ -1,4 +1,6 @@ #define GF_EXPOSE_GUI +#define GF_EXPOSE_DRAW +#define GF_EXPOSE_INPUT #include diff --git a/engine/gf_input.c b/engine/gf_input.c index b560743..9ed1bc5 100644 --- a/engine/gf_input.c +++ b/engine/gf_input.c @@ -1,3 +1,5 @@ +#define GF_EXPOSE_INPUT + #include /* External library */ @@ -6,5 +8,24 @@ #include /* Engine */ +#include /* Standard */ +#include +#include + +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); +} diff --git a/engine/graphic/opengl/glfw/gf_draw.c b/engine/graphic/opengl/glfw/gf_draw.c index 269de0a..62a1de8 100644 --- a/engine/graphic/opengl/glfw/gf_draw.c +++ b/engine/graphic/opengl/glfw/gf_draw.c @@ -1,5 +1,6 @@ #define GF_EXPOSE_DRAW_PLATFORM #define GF_EXPOSE_DRAW +#define GF_EXPOSE_INPUT #include @@ -13,6 +14,7 @@ #include #include #include +#include /* Standard */ #include @@ -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); diff --git a/engine/graphic/opengl/glx/gf_draw.c b/engine/graphic/opengl/glx/gf_draw.c index fb1e7ea..be483b1 100644 --- a/engine/graphic/opengl/glx/gf_draw.c +++ b/engine/graphic/opengl/glx/gf_draw.c @@ -1,5 +1,6 @@ #define GF_EXPOSE_DRAW_PLATFORM #define GF_EXPOSE_DRAW +#define GF_EXPOSE_INPUT #include @@ -11,6 +12,7 @@ /* Engine */ #include +#include #include #include @@ -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; diff --git a/engine/include/gf_draw.h b/engine/include/gf_draw.h index f486c2f..1eeea24 100644 --- a/engine/include/gf_draw.h +++ b/engine/include/gf_draw.h @@ -16,6 +16,7 @@ /* Engine */ #include +#include /* 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) diff --git a/engine/include/gf_draw_driver.h b/engine/include/gf_draw_driver.h index ea05fdb..700c14f 100644 --- a/engine/include/gf_draw_driver.h +++ b/engine/include/gf_draw_driver.h @@ -19,6 +19,7 @@ #include #include #include +#include /* Standard */ diff --git a/engine/include/gf_input.h b/engine/include/gf_input.h index cdf27f2..9c52681 100644 --- a/engine/include/gf_input.h +++ b/engine/include/gf_input.h @@ -14,7 +14,23 @@ #include /* Engine */ +#include /* 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 diff --git a/engine/include/gf_type/client.h b/engine/include/gf_type/client.h index 43beceb..17b34ef 100644 --- a/engine/include/gf_type/client.h +++ b/engine/include/gf_type/client.h @@ -11,11 +11,14 @@ #include #ifdef GF_EXPOSE_CLIENT +typedef struct gf_client_t gf_client_t; + /* External library */ /* Engine */ #include #include +#include /* 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; diff --git a/engine/include/gf_type/core.h b/engine/include/gf_type/core.h index bd2171d..2d7d918 100644 --- a/engine/include/gf_type/core.h +++ b/engine/include/gf_type/core.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_CORE +typedef struct gf_engine_t gf_engine_t; + /* External library */ /* Engine */ diff --git a/engine/include/gf_type/draw.h b/engine/include/gf_type/draw.h index 4326c3d..8d4999a 100644 --- a/engine/include/gf_type/draw.h +++ b/engine/include/gf_type/draw.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_DRAW +typedef struct gf_draw_t gf_draw_t; + /* External library */ /* Engine */ @@ -21,6 +23,7 @@ #include #include #include +#include /* 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; diff --git a/engine/include/gf_type/draw_driver.h b/engine/include/gf_type/draw_driver.h index 4c75c34..fd55909 100644 --- a/engine/include/gf_type/draw_driver.h +++ b/engine/include/gf_type/draw_driver.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_DRAW_DRIVER +typedef struct gf_draw_driver_t gf_draw_driver_t; + /* External library */ #if defined(DRV_OPENGL) #include diff --git a/engine/include/gf_type/draw_platform.h b/engine/include/gf_type/draw_platform.h index a55dd6f..6336d4d 100644 --- a/engine/include/gf_type/draw_platform.h +++ b/engine/include/gf_type/draw_platform.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_DRAW_PLATFORM +typedef struct gf_draw_platform_t gf_draw_platform_t; + /* External library */ #if defined(DRV_OPENGL) #include diff --git a/engine/include/gf_type/font.h b/engine/include/gf_type/font.h index 0d160c1..e3f2557 100644 --- a/engine/include/gf_type/font.h +++ b/engine/include/gf_type/font.h @@ -11,6 +11,10 @@ #include #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 */ diff --git a/engine/include/gf_type/graphic.h b/engine/include/gf_type/graphic.h index 08587fd..cd732f6 100644 --- a/engine/include/gf_type/graphic.h +++ b/engine/include/gf_type/graphic.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_GRAPHIC +typedef struct gf_graphic_color_t gf_graphic_color_t; + /* External library */ /* Engine */ diff --git a/engine/include/gf_type/gui.h b/engine/include/gf_type/gui.h index 2d381d5..93cb1b8 100644 --- a/engine/include/gf_type/gui.h +++ b/engine/include/gf_type/gui.h @@ -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 */ diff --git a/engine/include/gf_type/input.h b/engine/include/gf_type/input.h index cc0135e..30805ee 100644 --- a/engine/include/gf_type/input.h +++ b/engine/include/gf_type/input.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_INPUT +typedef struct gf_input_t gf_input_t; + /* External library */ /* Engine */ @@ -18,7 +20,28 @@ #include /* 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 diff --git a/engine/include/gf_type/mesh.h b/engine/include/gf_type/mesh.h index 843d073..95c4962 100644 --- a/engine/include/gf_type/mesh.h +++ b/engine/include/gf_type/mesh.h @@ -11,6 +11,9 @@ #include #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 diff --git a/engine/include/gf_type/model.h b/engine/include/gf_type/model.h index 91517df..e518668 100644 --- a/engine/include/gf_type/model.h +++ b/engine/include/gf_type/model.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_MODEL +typedef struct gf_model_t gf_model_t; + /* External library */ /* Engine */ diff --git a/engine/include/gf_type/physics.h b/engine/include/gf_type/physics.h index 59d1310..9e5be81 100644 --- a/engine/include/gf_type/physics.h +++ b/engine/include/gf_type/physics.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_PHYSICS +typedef struct gf_physics_t gf_physics_t; + /* External library */ #include diff --git a/engine/include/gf_type/server.h b/engine/include/gf_type/server.h index 96bcbe8..ed19fe1 100644 --- a/engine/include/gf_type/server.h +++ b/engine/include/gf_type/server.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_SERVER +typedef struct gf_server_t gf_server_t; + /* External library */ /* Engine */ diff --git a/engine/include/gf_type/texture.h b/engine/include/gf_type/texture.h index a34bd74..9c5b53b 100644 --- a/engine/include/gf_type/texture.h +++ b/engine/include/gf_type/texture.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_TEXTURE +typedef struct gf_texture_t gf_texture_t; + /* External library */ /* Engine */ diff --git a/engine/include/gf_type/thread.h b/engine/include/gf_type/thread.h index 44da0e1..8dfc5d7 100644 --- a/engine/include/gf_type/thread.h +++ b/engine/include/gf_type/thread.h @@ -11,6 +11,9 @@ #include #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 diff --git a/engine/include/gf_type/version.h b/engine/include/gf_type/version.h index cd1c7c4..3513b1a 100644 --- a/engine/include/gf_type/version.h +++ b/engine/include/gf_type/version.h @@ -11,6 +11,8 @@ #include #ifdef GF_EXPOSE_VERSION +typedef struct gf_version_t gf_version_t; + /* External library */ /* Engine */