#include "vg_engine.h"
#include "vg_ui.h"
#include "vg_audio.h"
+#include "vg_graphics.h"
// TODO: temp
#include "console_system.h"
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;
{ "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 },
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 ++ )
{
}
}
-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
+#pragma once
#include "SDL3/SDL.h"
enum input_type
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 );
{
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 );
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;