From d3390549a8d896744baf82a15e7824c837bcc254 Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 7 Nov 2025 02:01:03 +0000 Subject: [PATCH] support mouse again --- source/engine/vg_engine.c | 28 +++++++++++++++++++++++++--- source/engine/vg_input.c | 28 ++++++---------------------- source/engine/vg_input.h | 9 ++++++++- source/engine/vg_ui.c | 6 ------ source/foundation/keyvalues.c | 6 +++--- 5 files changed, 42 insertions(+), 35 deletions(-) diff --git a/source/engine/vg_engine.c b/source/engine/vg_engine.c index e9039ee..f46a860 100644 --- a/source/engine/vg_engine.c +++ b/source/engine/vg_engine.c @@ -8,6 +8,7 @@ #include "vg_engine.h" #include "vg_ui.h" #include "vg_audio.h" +#include "vg_graphics.h" // TODO: temp #include "console_system.h" @@ -289,14 +290,35 @@ L_new_frame:; SDL_Quit(); _normal_exit(); } - else if( e.type == SDL_EVENT_KEY_DOWN || e.type == SDL_EVENT_KEY_UP ) + else if( (e.type == SDL_EVENT_KEY_DOWN) || (e.type == SDL_EVENT_KEY_UP) ) { - _input_keyboard_event( (SDL_KeyboardEvent *)&e ); + // FIXME: HANDLE MODIFIERS INTERNALLY, NOT USING SDL's ev->mod + SDL_KeyboardEvent *ev = (SDL_KeyboardEvent *)&e; + enum input_button_action action; + if( ev->type == SDL_EVENT_KEY_DOWN ) + { + if( ev->repeat ) action = k_button_os_repeat; + else action = k_button_down; + } + else action = k_button_up; + _input_callback_buttonlike( k_input_device_keyboard, ev->key, action, ev->mod ); + } + else if( (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN) || (e.type == SDL_EVENT_MOUSE_BUTTON_UP) ) + { + SDL_MouseButtonEvent *ev = (SDL_MouseButtonEvent *)&e; + enum input_button_action action; + if( ev->type == SDL_EVENT_MOUSE_BUTTON_DOWN ) action = k_button_down; + else action = k_button_up; + _input_callback_buttonlike( k_input_device_mouse, ev->button, action, 0 ); // FIXME: MODIFIERS + } + else if( e.type == SDL_EVENT_MOUSE_MOTION ) + { + SDL_MouseMotionEvent *ev = (SDL_MouseMotionEvent *)&e; + _ui_set_mouse( ev->x, ev->y ); } else if( e.type == SDL_EVENT_TEXT_INPUT ) { SDL_TextInputEvent *ev = (SDL_TextInputEvent*)&e; - if( _input_layer_filter( 1<text; diff --git a/source/engine/vg_input.c b/source/engine/vg_input.c index 88e2a07..24acafb 100644 --- a/source/engine/vg_input.c +++ b/source/engine/vg_input.c @@ -17,6 +17,11 @@ _input_aliases[] = { "SHIFT", k_input_device_modifier, .key = SDL_KMOD_LSHIFT }, { "CONTROL", k_input_device_modifier, .key = SDL_KMOD_LCTRL }, { "ALT", k_input_device_modifier, .key = SDL_KMOD_LALT }, + + { "MOUSE_LEFT", k_input_device_mouse, .key = SDL_BUTTON_LEFT }, + { "MOUSE_RIGHT", k_input_device_mouse, .key = SDL_BUTTON_RIGHT }, + { "MOUSE_MIDDLE", k_input_device_mouse, .key = SDL_BUTTON_MIDDLE }, + { "ENTER", k_input_device_keyboard, .key = SDLK_RETURN }, { "ESCAPE", k_input_device_keyboard, .key = SDLK_ESCAPE }, { "BACKSPACE", k_input_device_keyboard, .key = SDLK_BACKSPACE }, @@ -543,14 +548,7 @@ i32 _input_unbind_ccmd( struct console_arguments *args ) return -1; } -enum button_action -{ - k_button_down, - k_button_os_repeat, - k_button_up -}; - -static void _input_callback_buttonlike( enum input_device device, i32 id, enum button_action action, u32 mods ) +void _input_callback_buttonlike( enum input_device device, i32 id, enum input_button_action action, u32 mods ) { for( u32 i=0; itype == SDL_EVENT_KEY_DOWN ) - { - if( ev->repeat ) - action = k_button_os_repeat; - else - action = k_button_down; - } - else action = k_button_up; - _input_callback_buttonlike( k_input_device_keyboard, ev->key, action, ev->mod ); -} - void _input_init(void) { #if 0 diff --git a/source/engine/vg_input.h b/source/engine/vg_input.h index 1e058a4..b8d4237 100644 --- a/source/engine/vg_input.h +++ b/source/engine/vg_input.h @@ -1,3 +1,4 @@ +#pragma once #include "SDL3/SDL.h" enum input_type @@ -25,7 +26,13 @@ struct input_info enum input_id; -void _input_keyboard_event( SDL_KeyboardEvent *ev ); +enum input_button_action +{ + k_button_down, + k_button_os_repeat, + k_button_up +}; +void _input_callback_buttonlike( enum input_device device, i32 id, enum input_button_action action, u32 mods ); u8 _input_button_down( enum input_id id, b8 allow_repeats ); u8 _input_button_up( enum input_id id ); diff --git a/source/engine/vg_ui.c b/source/engine/vg_ui.c index c5bd3d4..c4bcd2b 100644 --- a/source/engine/vg_ui.c +++ b/source/engine/vg_ui.c @@ -32,12 +32,6 @@ void _engine_ui_pre_render(void) { ASSERT_CRITICAL( _engine.w <= 1920 ); ASSERT_CRITICAL( _engine.h <= 1080 ); - - f64 x = 0, y = 0; -#if 0 - glfwGetCursorPos( _engine.window_handle, &x, &y ); -#endif - _ui_set_mouse( x, y ); _ui_update(); _graphics_set_target( &_ui_surface ); diff --git a/source/foundation/keyvalues.c b/source/foundation/keyvalues.c index 941433a..fd62e04 100644 --- a/source/foundation/keyvalues.c +++ b/source/foundation/keyvalues.c @@ -239,9 +239,9 @@ b8 keyvalues_read_i32s( struct keyvalues *kvs, u32 root_offset, const c8 *key, i for( u32 i=0; i