input joy sleep wake, revisit string cat code
authorhgn <hgodden00@gmail.com>
Thu, 18 Apr 2024 21:06:39 +0000 (22:06 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 18 Apr 2024 21:06:39 +0000 (22:06 +0100)
src/fonts/vg_font_thin_3.png
src/fonts/vg_font_thin_3.xcf
vg_build_font.h
vg_input.c
vg_string.c

index 18139a2944e86c8b77988d05d92aa7f33bd06a2c..7bb79d888dd3a15ffa48c230284788e0fb001830 100644 (file)
Binary files a/src/fonts/vg_font_thin_3.png and b/src/fonts/vg_font_thin_3.png differ
index 1e40c461bac84e22cad69ef8a585c43c5388a91e..43aa0bf167c282bfc209efc9151d02b70139c97a 100644 (file)
Binary files a/src/fonts/vg_font_thin_3.xcf and b/src/fonts/vg_font_thin_3.xcf differ
index 5ee5e10b77a8132da5a34526d4e72bcdacfaa26f..48aba86823f59421e301c2b47f692d4e23118641 100644 (file)
@@ -111,7 +111,7 @@ void vg_build_default_font(void)
    vg_build_font_face_run( &small, 'a', 'z', 0,  28 );
    vg_build_font_face_run( &small, '0', '9', 208,14 );
    vg_build_font_face_run( &small, 0x7f, 0xa4, 0,42 );
-   vg_build_font_face_run( &small, 0xb0, 0xb2, 208,28 );
+   vg_build_font_face_run( &small, 0xb0, 0xb3, 208,28 );
    vg_build_write_font_face( fp, &small );
 
    vg_font_face large =
@@ -129,7 +129,7 @@ void vg_build_default_font(void)
    vg_build_font_face_run( &large, 'a', 'z', 0,  98  );
    vg_build_font_face_run( &large, '0', '9', 312,77  );
    vg_build_font_face_run( &large, 0x7f, 0xa4, 0,119 );
-   vg_build_font_face_run( &large, 0xb0, 0xb2, 312,98 );
+   vg_build_font_face_run( &large, 0xb0, 0xb3, 312,98 );
    vg_build_write_font_face( fp, &large );
    
    vg_font_face title =
index c536c1f2ab2fd23446a2ca4778ef2ebc2a3f0d98..d4e51bc6b77ca3c3c974a4cf9fa7e9156ac2a6c0 100644 (file)
@@ -128,13 +128,33 @@ void vg_input_device_event( SDL_Event *ev )
    }
 }
 
+static void vg_input_set_active_controller( int index, const char *why )
+{
+   if( vg_input.active_controller_index != index )
+   {
+      vg_input.display_input_type = 
+         SDL_GameControllerGetType( vg_input.controllers[index].handle );
+      vg_input.active_controller_index = index;
+      vg_info( "Switching controller index to #%d. (%s)\n", index, why );
+   }
+
+   if( vg_input.display_input_method != k_input_method_controller )
+   {
+      vg_input.display_input_method = k_input_method_controller;
+      vg_info( "Switching input method to controller. (%s)\n", why );
+   }
+}
+
 void vg_input_controller_event( SDL_Event *ev )
 {
-   if( ev->type == SDL_CONTROLLERAXISMOTION ){
-      for( int i=0; i<VG_MAX_CONTROLLERS; i++ ){
+   if( ev->type == SDL_CONTROLLERAXISMOTION )
+   {
+      for( int i=0; i<VG_MAX_CONTROLLERS; i++ )
+      {
          struct vg_controller *esta = &vg_input.controllers[i];
 
-         if( ev->caxis.which == esta->instance_id ){
+         if( ev->caxis.which == esta->instance_id )
+         {
             float value = (float)ev->caxis.value / 32767.0f;
 
             if( ev->caxis.axis == SDL_CONTROLLER_AXIS_LEFTX ||
@@ -146,6 +166,8 @@ void vg_input_controller_event( SDL_Event *ev )
                      high    = vg_maxf( 0.0f, fabsf(value) - deadz );
                
                value = vg_signf(value) * (high / (1.0f-deadz));
+               if( fabsf(value) > 0.5f )
+                  vg_input_set_active_controller( i, "Stick pushed >|0.5|" );
             }
 
             esta->axises[ ev->caxis.axis ] = value;
@@ -153,50 +175,26 @@ void vg_input_controller_event( SDL_Event *ev )
          }
       }
    }
-   else if( ev->type == SDL_CONTROLLERBUTTONDOWN ){
-      struct vg_controller *active = NULL;
-
-      if( vg_input.active_controller_index >= 0 )
-         active = &vg_input.controllers[vg_input.active_controller_index];
-
-      if( !active || (ev->cbutton.which != active->instance_id) ){
-         active = NULL;
-         vg_input.active_controller_index = -1;
-         vg_input.display_input_method = k_input_method_kbm;
-
-         for( int i=0; i<VG_MAX_CONTROLLERS; i++ ){
-            if( vg_input.controllers[i].instance_id == ev->cbutton.which ){
-               active = &vg_input.controllers[i];
-               vg_input.active_controller_index = i;
-               vg_input.display_input_type = 
-                  SDL_GameControllerGetType(active->handle);
-               break;
-            }
-         }
-         
-         if( active ){
-            vg_info( "Switching active controller index to #%d\n", 
-                       vg_input.active_controller_index );
-         }
-         else{
-            vg_error( "Input out of range (SDL_JoystickID#%d)\n", 
-                       ev->cbutton.which );
-         }
-      }
-
-      if( active ){
-         if( vg_input.display_input_method != k_input_method_controller ){
-            vg_input.display_input_method = k_input_method_controller;
-            vg_info( "display_input: k_input_method_controller\n" );
+   else if( ev->type == SDL_CONTROLLERBUTTONDOWN )
+   {
+      for( int i=0; i<VG_MAX_CONTROLLERS; i++ )
+      {
+         struct vg_controller *esta = &vg_input.controllers[i];
+         if( esta->instance_id == ev->cbutton.which )
+         {
+            vg_input_set_active_controller( i, "Button press" );
+            esta->buttons[ ev->cbutton.button ] = 1;
+            break;
          }
-         active->buttons[ ev->cbutton.button ] = 1;
       }
    }
-   else if( ev->type == SDL_CONTROLLERBUTTONUP ){
-      for( int i=0; i<VG_MAX_CONTROLLERS; i++ ){
+   else if( ev->type == SDL_CONTROLLERBUTTONUP )
+   {
+      for( int i=0; i<VG_MAX_CONTROLLERS; i++ )
+      {
          struct vg_controller *esta = &vg_input.controllers[i];
-
-         if( ev->cbutton.which == esta->instance_id ){
+         if( ev->cbutton.which == esta->instance_id )
+         {
             esta->buttons[ ev->cbutton.button ] = 0;
             break;
          }
index 1261f5b9479e79ea77b6989772bbcfaa42501194..ef29ef3be597ef7e84b01ddfbee600b22bf38680 100644 (file)
@@ -69,37 +69,49 @@ static i32 vg_str_dynamic_grow( vg_str *str )
    }
 }
 
-void vg_strcat( vg_str *str, const char *append )
+static void _vg_strcatch( vg_str *str, char c )
 {
-   if( !append || (str->i == -1) ) return;
-
-   i32 max = vg_str_storage( str ),
-       i   = 0;
+   if( str->i == -1 ) return;
 
-append:
-   if( str->i == max ){
+   i32 max = vg_str_storage( str );
+   if( str->i == max )
+   {
       if( str->len == -1 )
          max = vg_str_dynamic_grow( str );
-      else{
+      else
+      {
          str->i = -1;
          str->buffer[ max-1 ] = '\0';
          return;
       }
    }
 
-   char c = append[ i ++ ];
-   str->buffer[ str->i ] = c;
+   str->buffer[ str->i ++ ] = c;
+}
+
+void vg_strcat( vg_str *str, const char *append )
+{
+   if( !append || (str->i == -1) ) return;
+
+   i32 i = 0;
+
+append:;
+   char c = append[ i ++ ]; 
+   _vg_strcatch( str, c );
 
    if( c == '\0' )
+   {
+      str->i --;
       return;
-
-   str->i ++;
-   goto append;
+   }
+   else goto append;
 }
 
 void vg_strcatch( vg_str *str, char c )
 {
-   vg_strcat( str, (char[]){ c, '\0' } );
+   _vg_strcatch( str, c );
+   _vg_strcatch( str, '\x00' );
+   str->i --;
 }
 
 /*