From: hgn Date: Fri, 17 Nov 2023 03:57:04 +0000 (+0000) Subject: binding visibility X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=3f8eb36bc705028519cd9e047b24f9b0e97f368e binding visibility --- diff --git a/submodules/SDL_GameControllerDB b/submodules/SDL_GameControllerDB index 6ed8d05..c5b4df0 160000 --- a/submodules/SDL_GameControllerDB +++ b/submodules/SDL_GameControllerDB @@ -1 +1 @@ -Subproject commit 6ed8d054340ee8a93a684e11360b66cd8a5c168e +Subproject commit c5b4df0e1061175cb11e3ebbf8045178339864a5 diff --git a/submodules/anyascii b/submodules/anyascii index 44e971c..eb5332d 160000 --- a/submodules/anyascii +++ b/submodules/anyascii @@ -1 +1 @@ -Subproject commit 44e971c774d9ec67ca6c1f16c5a476724821ab63 +Subproject commit eb5332d0b5e48d58397e6f27475a18e058330d23 diff --git a/submodules/qoi b/submodules/qoi index b8d77df..dfc056e 160000 --- a/submodules/qoi +++ b/submodules/qoi @@ -1 +1 @@ -Subproject commit b8d77df1e80b652a57f0b7270449b179a6b91f40 +Subproject commit dfc056e813c98d307238d35f7f041a725d699dfc diff --git a/submodules/stb b/submodules/stb index 8b5f1f3..5736b15 160000 --- a/submodules/stb +++ b/submodules/stb @@ -1 +1 @@ -Subproject commit 8b5f1f37b5b75829fc72d38e7b5d4bcbf8a26d55 +Subproject commit 5736b15f7ea0ffb08dd38af21067c314d6a3aae9 diff --git a/vg_input.h b/vg_input.h index 9c5be84..cd7130d 100644 --- a/vg_input.h +++ b/vg_input.h @@ -23,12 +23,8 @@ enum vg_input_op { vg_mouse, vg_joy_button, vg_joy_axis, - - /* hacky constants */ - vg_0_0f, - vg_0_5f, - vg_1_0f, - vg_2_0f, + vg_joy_ls, + vg_joy_rs, /* modes */ vg_mode_mul, @@ -40,6 +36,7 @@ enum vg_input_op { /* control */ vg_index, vg_end, + vg_gui_visible, /* math */ vg_normalize @@ -207,10 +204,6 @@ static void vg_input_controller_event( SDL_Event *ev ) value = vg_signf(value) * (high / (1.0f-deadz)); } - else if( ev->caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT || - ev->caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT ){ - value = 0.5f + value*0.5f; - } esta->axises[ ev->caxis.axis ] = value; break; @@ -370,6 +363,10 @@ static void vg_input_apply_to_f32( vg_input_op mode, f32 data, else vg_fatal_error( "mode not supported for destination type (%d)", mode ); } +/* + * Run an input program. out_result must point to memory with sufficient + * storage respective to the size set by type. + */ static void vg_exec_input_program( enum vg_input_type type, vg_input_op *ops, void *out_result ){ u8 *out_button = NULL; @@ -396,9 +393,8 @@ static void vg_exec_input_program( enum vg_input_type type, vg_input_op *ops, next_code:; vg_input_op op = ops[ pc ++ ]; - if( (op >= vg_mode_mul) && (op <= vg_mode_max) ){ + if( (op >= vg_mode_mul) && (op <= vg_mode_max) ) mode = op; - } else if( (op == vg_keyboard) || (op == vg_mouse) || (op == vg_joy_button) ){ u8 state = 0; @@ -421,22 +417,218 @@ next_code:; else vg_input_apply_to_f32( mode, state, &out_joy[index] ); } - else if( (op >= vg_0_0f) && (op <= vg_2_0f) ){ - f32 value = (f32)(op - vg_0_5f) * 0.5f; - vg_input_apply_to_f32( mode, value, &out_joy[index] ); + else if( (op == vg_joy_ls) || (op == vg_joy_rs) ){ + if( type == k_vg_input_type_joy_v2f ){ + vg_input_apply_to_f32( mode, + vg_controller_axis( op==vg_joy_ls? SDL_CONTROLLER_AXIS_LEFTX: + SDL_CONTROLLER_AXIS_RIGHTX), + &out_joy[0] ); + vg_input_apply_to_f32( mode, + vg_controller_axis( op==vg_joy_ls? SDL_CONTROLLER_AXIS_LEFTY: + SDL_CONTROLLER_AXIS_RIGHTY), + &out_joy[1] ); + } } - else if( op == vg_index ){ + else if( op == vg_index ) index = ops[pc ++]; - } - else if( op == vg_end ){ + else if( op == vg_end ) return; - } - else if( op == vg_normalize ){ + else if( op == vg_normalize ) v2_normalize( out_joy ); + else if( op == vg_gui_visible ) + pc ++; + else + vg_fatal_error( "unknown op\n" ); + + goto next_code; +} + +/* + * Get vendor specific button glyphs based on SDL button ID + */ +static const char *controller_button_str( SDL_GameControllerButton button ){ + static const char *controller_glyphs[ SDL_CONTROLLER_BUTTON_MAX ][2] = { + /* xbox/generic playstation */ + [ SDL_CONTROLLER_BUTTON_A ] = { "\x1e\x85","\x1e\x82" }, + [ SDL_CONTROLLER_BUTTON_B ] = { "\x1e\x86","\x1e\x81" }, + [ SDL_CONTROLLER_BUTTON_X ] = { "\x1e\x83","\x1e\x7f" }, + [ SDL_CONTROLLER_BUTTON_Y ] = { "\x1e\x84","\x1e\x80" }, + [ SDL_CONTROLLER_BUTTON_LEFTSTICK ] = { "\x87", "\x87" }, + [ SDL_CONTROLLER_BUTTON_RIGHTSTICK ] = { "\x8b", "\x8b" }, + [ SDL_CONTROLLER_BUTTON_LEFTSHOULDER ] = { "\x91", "\x91" }, + [ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ]= { "\x92", "\x92" }, + [ SDL_CONTROLLER_BUTTON_DPAD_LEFT ] = { "\x1e\x93","\x1e\x93" }, + [ SDL_CONTROLLER_BUTTON_DPAD_UP ] = { "\x1e\x94","\x1e\x94" }, + [ SDL_CONTROLLER_BUTTON_DPAD_RIGHT ] = { "\x1e\x95","\x1e\x95" }, + [ SDL_CONTROLLER_BUTTON_DPAD_DOWN ] = { "\x1e\x96","\x1e\x96" }, + [ SDL_CONTROLLER_BUTTON_GUIDE ] = { "\x91", "\x91" }, + }; + + if( vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS3 || + vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS4 || + vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS5 ) + { + return controller_glyphs[ button ][ 1 ]; } + else if( vg_input.display_input_type == + SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO || + vg_input.display_input_type == + SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT || + vg_input.display_input_type == + SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR || + vg_input.display_input_type == + SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT ) + { + return NULL; + } + else + return controller_glyphs[ button ][ 0 ]; +} + +/* + * Cat keyboard key string. special_glyphs include SR glyphs + */ +static void vg_keyboard_key_string( vg_str *str, u32 key, int special_glyphs ){ + if( (key >= SDLK_a) && (key <= SDLK_z) ){ + key = (key-SDLK_a)+(u32)'A'; + + if( special_glyphs ){ + vg_strcatch( str, '\x1f' ); + vg_strcatch( str, key ); + vg_strcatch( str, ' ' ); + } + else + vg_strcatch( str, key ); + } + else if( (key == SDLK_LSHIFT) || (key == SDLK_RSHIFT) ) + vg_strcat( str, special_glyphs? "\x9e": "shift" ); + else if( (key == SDLK_LCTRL) || (key == SDLK_RCTRL) ) + vg_strcat( str, special_glyphs? "\x9f": "ctrl" ); + else if( (key == SDLK_LALT) || (key == SDLK_RALT) ) + vg_strcat( str, special_glyphs? "\xa0": "alt" ); + else if( key == SDLK_SPACE ) + vg_strcat( str, special_glyphs? "\xa1": "space" ); + else if( (key == SDLK_RETURN) || (key == SDLK_RETURN2) ) + vg_strcat( str, special_glyphs? "\xa2": "return" ); + else if( key == SDLK_ESCAPE ) + vg_strcat( str, special_glyphs? "\xa3": "escape" ); + else if( key == SDLK_RIGHT ) + vg_strcat( str, special_glyphs? "\x1f\x95 ": "right" ); + else if( key == SDLK_LEFT ) + vg_strcat( str, special_glyphs? "\x1f\x93 ": "left" ); + else if( key == SDLK_UP ) + vg_strcat( str, special_glyphs? "\x1f\x94 ": "up" ); + else if( key == SDLK_DOWN ) + vg_strcat( str, special_glyphs? "\x1f\x96 ": "down" ); else { - vg_fatal_error( "unknown op\n" ); + vg_strcat( str, "keyboard key #" ); + vg_strcati32( str, key ); } +} + +/* + * Cat mouse button string. special_glyphs include SR glyphs + */ +static void vg_mouse_button_string( vg_str *str, u32 button, + int special_glyphs ){ + if ( button == SDL_BUTTON_LEFT ) + vg_strcat( str, special_glyphs? "\x99": "left mouse" ); + else if( button == SDL_BUTTON_RIGHT ) + vg_strcat( str, special_glyphs? "\x9a": "right mouse" ); + else if( button == SDL_BUTTON_MIDDLE ) + vg_strcat( str, special_glyphs? "\x9c": "middle mouse" ); + else{ + vg_strcat( str, "mouse button #" ); + vg_strcati32( str, button ); + } +} + +/* + * Cat string represeinting single axis + */ +static void vg_joy_axis_string( vg_str *str, + SDL_GameControllerAxis axis, int special_glyphs ){ + if( axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT ) + vg_strcat( str, special_glyphs?"\x8f":"left trigger" ); + else if( axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT ) + vg_strcat( str, special_glyphs?"\x90":"right trigger" ); + else if( axis == SDL_CONTROLLER_AXIS_LEFTX ) + vg_strcat( str, special_glyphs?"\x88":"left stick horizontal" ); + else if( axis == SDL_CONTROLLER_AXIS_LEFTY ) + vg_strcat( str, special_glyphs?"\x89":"left stick vertical" ); + else if( axis == SDL_CONTROLLER_AXIS_RIGHTX ) + vg_strcat( str, special_glyphs?"\x8c":"right stick horizontal" ); + else if( axis == SDL_CONTROLLER_AXIS_RIGHTY ) + vg_strcat( str, special_glyphs?"\x8d":"right stick vertical" ); + else{ + vg_strcat( str, "axis " ); + vg_strcati32( str, axis ); + } +} + +/* + * Cat string represeinting whole joystick + */ +static void vg_joy_string( vg_str *str, vg_input_op op, int special_glyphs ){ + if( op == vg_joy_ls ) + vg_strcat( str, special_glyphs? "\x87": "left stick" ); + else + vg_strcat( str, special_glyphs? "\x8b": "right stick" ); +} + +/* + * Convert an input program into a readable string + */ +static void vg_input_string( vg_str *str, vg_input_op *ops, int glyphs ){ + u32 pc = 0; + int applicable = 0, visible = 1; + +next_code:; + vg_input_op op = ops[ pc ++ ]; + + if( (op == vg_keyboard) || (op == vg_mouse) ){ + if( (vg_input.display_input_method == k_input_method_kbm) && visible ){ + applicable = 1; + + if( op == vg_keyboard ) + vg_keyboard_key_string( str, ops[pc], glyphs ); + else + vg_mouse_button_string( str, ops[pc], glyphs ); + } + else applicable = 0; + pc ++; + } + else if( (op == vg_joy_button) || (op == vg_joy_axis) ){ + if( (vg_input.display_input_method == k_input_method_controller) + && visible ){ + applicable = 1; + + if( op == vg_joy_button ) + vg_strcat( str, controller_button_str(ops[pc]) ); + else + vg_joy_axis_string( str, ops[pc], glyphs ); + } + else applicable = 0; + pc ++; + } + else if( (op == vg_joy_ls) || (op == vg_joy_rs) ){ + if( (vg_input.display_input_method == k_input_method_controller) + && visible ){ + applicable = 1; + vg_joy_string( str, op, glyphs ); + } + else applicable = 0; + } + else if( op == vg_mode_mul ){ + if( applicable && visible ) + vg_strcat( str, " + " ); + } + else if( op == vg_index ) + pc ++; + else if( op == vg_gui_visible ) + visible = ops[pc++]; + else if( op == vg_end ) + return; goto next_code; }