support mouse again
authorhgn <hgodden00@gmail.com>
Fri, 7 Nov 2025 02:01:03 +0000 (02:01 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 7 Nov 2025 02:01:03 +0000 (02:01 +0000)
source/engine/vg_engine.c
source/engine/vg_input.c
source/engine/vg_input.h
source/engine/vg_ui.c
source/foundation/keyvalues.c

index e9039eea1a29c7086dedab5af760669af2a472a1..f46a860695ce35b2d4843d9306d170667233f6a5 100644 (file)
@@ -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<<k_input_layer_ui ) )
          {
             const u8 *utf8_text = (const u8 *)ev->text;
index 88e2a07dceff37126a5f934b3fef19f2d3d25724..24acafb7ad03b6c89e472906cf90210c8c1e2c3b 100644 (file)
@@ -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; i<stretchy_count( &_bind_allocator ); i ++ )
    {
@@ -602,20 +600,6 @@ static void _input_callback_buttonlike( enum input_device device, i32 id, enum b
    }
 }
 
-void _input_keyboard_event( SDL_KeyboardEvent *ev )
-{
-   enum 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 );
-}
-
 void _input_init(void)
 {
 #if 0
index 1e058a439a9ab0377e48aa49320e5186f9cd49c9..b8d423770b92a2c8aa58f058ddfa48a8beefa484 100644 (file)
@@ -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 );
index c5bd3d485f4ca3f1aa7c623f27867b9b18a9d2ef..c4bcd2b5e0b4f69e590d91c4a08ef2894d64f894 100644 (file)
@@ -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 );
index 941433a81074377939d51ef8ac78ff4ace30f4c7..fd62e04145d264d30c4357066c477cb5a04f857d 100644 (file)
@@ -239,9 +239,9 @@ b8 keyvalues_read_i32s( struct keyvalues *kvs, u32 root_offset, const c8 *key, i
 
    for( u32 i=0; i<len; i ++ )
    {
-      i64 value = 0;
-      if( string_parse_i64( &s, &value ) == k_string_parse_ok ) 
-         out_values[ i ] = (i32)value;
+      i64 result_value = 0;
+      if( string_parse_i64( &s, &result_value ) == k_string_parse_ok ) 
+         out_values[ i ] = (i32)result_value;
       else
       {
          good = 0;