Mouse position

This commit is contained in:
David Gonzalez Martin 2024-11-30 04:30:44 -06:00 committed by David
parent 64ddc68a51
commit 85a832653a
3 changed files with 18 additions and 0 deletions

View File

@ -239,8 +239,12 @@ strlit("/usr/share/fonts/TTF/FiraSans-Regular.ttf")
{ {
graphics_poll_events(); graphics_poll_events();
auto mouse_position = graphics_window_cursor_position_get(window);
print("Mouse position: ({f64}, {f64})\n", mouse_position.x, mouse_position.y);
auto frame_window_size = renderer_window_frame_begin(renderer, render_window); auto frame_window_size = renderer_window_frame_begin(renderer, render_window);
window_command_begin(render_window); window_command_begin(render_window);
window_bind_pipeline(render_window, pipeline_index); window_bind_pipeline(render_window, pipeline_index);

View File

@ -15,6 +15,12 @@ STRUCT(GraphicsWindowCreate)
GraphicsWindowSize size; GraphicsWindowSize size;
}; };
STRUCT(GraphicsCursorPosition)
{
f64 x;
f64 y;
};
typedef struct GraphicsWindow GraphicsWindow; typedef struct GraphicsWindow GraphicsWindow;
EXPORT void graphics_init(u8 should_use_x11); EXPORT void graphics_init(u8 should_use_x11);
@ -23,6 +29,7 @@ EXPORT u8 graphics_window_should_close(GraphicsWindow* window);
EXPORT void graphics_poll_events(); EXPORT void graphics_poll_events();
EXPORT GraphicsWindowSize graphics_window_size_get(GraphicsWindow* window); EXPORT GraphicsWindowSize graphics_window_size_get(GraphicsWindow* window);
EXPORT void graphics_window_consume_resize(GraphicsWindow* window); EXPORT void graphics_window_consume_resize(GraphicsWindow* window);
EXPORT GraphicsCursorPosition graphics_window_cursor_position_get(GraphicsWindow* window);
#ifdef __linux__ #ifdef __linux__
typedef unsigned long XID; typedef unsigned long XID;

View File

@ -81,6 +81,13 @@ GraphicsWindowSize graphics_window_size_get(GraphicsWindow* window)
return result; return result;
} }
GraphicsCursorPosition graphics_window_cursor_position_get(GraphicsWindow* window)
{
GraphicsCursorPosition result;
glfwGetCursorPos(window->handle, &result.x, &result.y);
return result;
}
#ifdef _WIN32 #ifdef _WIN32
HANDLE graphics_win32_window_get(GraphicsWindow* window) HANDLE graphics_win32_window_get(GraphicsWindow* window)
{ {