console viewer
authorhgn <hgodden00@gmail.com>
Tue, 2 Nov 2021 05:45:38 +0000 (05:45 +0000)
committerhgn <hgodden00@gmail.com>
Tue, 2 Nov 2021 05:45:38 +0000 (05:45 +0000)
vg/vg.h
vg/vg_console.h
vg/vg_debug.h
vg/vg_ui.h

diff --git a/vg/vg.h b/vg/vg.h
index 90d8f7010ce685b53c1ecf8ed24960d415e6edeb..b0119ecf03458ac0f3c2abe0c6a3d895c04cb336 100644 (file)
--- a/vg/vg.h
+++ b/vg/vg.h
@@ -192,6 +192,9 @@ static void vg_init( int argc, char *argv[], const char *window_name )
        const unsigned char* glver = glGetString( GL_VERSION );
        vg_success( "Load setup complete, OpenGL version: %s\n", glver );
        
+       vg_console_init();
+       vg_register_exit( &vg_console_free, "Console" );
+       
        vg_run_gfx_diagnostics();
        
        for( int id = 0; id <= GLFW_JOYSTICK_LAST; id ++ )
@@ -212,7 +215,7 @@ static void vg_init( int argc, char *argv[], const char *window_name )
        vg_register_exit( &vg_lines_free, "vg_lines_free" );
        ui_default_init();
        vg_register_exit( &ui_default_free, "UI" );
-       
+               
        vg_register();
        vg_register_exit( &vg_free, "vg_free" );
        
@@ -242,7 +245,26 @@ static void vg_init( int argc, char *argv[], const char *window_name )
                        
                        vg_lines_drawall((float*)vg_pv);
                        
-                       vg_ui();
+                       {
+                               ui_begin( &ui_global_ctx, vg_window_x, vg_window_y );
+               
+                               // TODO: Find a more elegent form for this
+                               int mouse_state = 0;
+                               if( vg_get_button( "primary" ) ) mouse_state = 2;
+                               if( vg_get_button_down( "primary" ) ) mouse_state = 1;
+                               if( vg_get_button_up( "primary" ) ) mouse_state = 3;
+                                       
+                               ui_set_mouse( &ui_global_ctx, vg_mouse[0], vg_mouse[1], mouse_state );
+                               
+                               vg_ui();
+                               vg_console_draw();
+                               
+                               ui_resolve( &ui_global_ctx );
+                               m3x3f view = M3X3_IDENTITY;
+                               m3x3_translate( view, (v3f){ -1.0f, 1.0f, 0.0f } );
+                               m3x3_scale( view, (v3f){ 1.0f/((float)vg_window_x*0.5f), -1.0f/((float)vg_window_y*0.5f), 1.0f } );     
+                               ui_draw( &ui_global_ctx );
+                       }
                        
                        glfwSwapBuffers( vg_window );
                        
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..1a4813c7d7437ce1dc0ba2eebdfe6b41dcd7238c 100644 (file)
@@ -0,0 +1,79 @@
+struct vg_console
+{
+       struct vg_convar
+       {
+               void *data;
+               const char *name;
+               
+               enum vg_convar_dtype
+               {
+                       k_convar_dtype_i32,
+                       k_convar_dtype_u32,
+                       k_convar_dtype_f32
+               } 
+               data_type;
+       } 
+       *convars;
+       
+       char lines[16][512];
+       u32 current, len;
+}
+vg_console;
+
+static void vg_convar_push( struct vg_convar cv )
+{
+       arrpush( vg_console.convars, cv ); 
+}
+
+static void vg_console_draw( void )
+{      
+       int ptr = vg_console.current - vg_console.len;
+       if( ptr <= 0 )
+               ptr += vg_list_size( vg_console.lines );
+       ptr --;
+       
+       ui_global_ctx.cursor[0] = 0;
+       ui_global_ctx.cursor[1] = 0;
+       ui_global_ctx.cursor[3] = vg_console.len*8;
+       ui_fill_x( &ui_global_ctx );
+       
+       ui_new_node( &ui_global_ctx );
+       {               
+               ui_fill_rect( &ui_global_ctx, ui_global_ctx.cursor, 0x77333333 );
+       
+               ui_global_ctx.cursor[3] = 8;
+               ui_align_bottom( &ui_global_ctx ); 
+               
+               for( int i = 0; i < vg_console.len; i ++ )
+               {
+                       ui_text( &ui_global_ctx, vg_console.lines[ptr], 1, 0 );
+                       ui_global_ctx.cursor[1] -= 8;
+               
+                       ptr --;
+                       if( ptr < 0 )
+                               ptr = vg_list_size( vg_console.lines )-1;
+               }
+       }
+       ui_end_down( &ui_global_ctx );
+}
+
+void vg_console_println( const char *str )
+{
+       if( vg_console.len < vg_list_size( vg_console.lines ) )
+               vg_console.len ++;
+       
+       strcpy( vg_console.lines[ vg_console.current ++ ], str );
+       
+       if( vg_console.current >= vg_list_size( vg_console.lines ) )
+               vg_console.current = 0;
+}
+
+static void vg_console_init(void)
+{
+       vg_log_callback = vg_console_println;
+}
+
+static void vg_console_free(void)
+{
+       arrfree( vg_console.convars );
+}
index 333aed82ddc819b694a28315312e183962912903..0f6f28ac0a0399fe0599fbb4f8fc717277251f7d 100644 (file)
@@ -1,5 +1,9 @@
+int sfx_debug = 0;
+
 static void sfx_internal_debug_overlay(void)
 {
+       if( !sfx_debug ) return;
+
        // Grab values
        struct sound_info
        {
@@ -44,16 +48,6 @@ static void sfx_internal_debug_overlay(void)
 
        // UI part
        // ========
-
-       ui_begin( &ui_global_ctx, vg_window_x, vg_window_y );
-       
-       // TODO: Find a more elegent form for this
-       int mouse_state = 0;
-       if( vg_get_button( "primary" ) ) mouse_state = 2;
-       if( vg_get_button_down( "primary" ) ) mouse_state = 1;
-       if( vg_get_button_up( "primary" ) ) mouse_state = 3;
-               
-       ui_set_mouse( &ui_global_ctx, vg_mouse[0], vg_mouse[1], mouse_state );
        
        // Draw audio stack 
        for( int i = 0; i < num_systems; i ++ )
@@ -91,13 +85,4 @@ static void sfx_internal_debug_overlay(void)
                ui_end_down( &ui_global_ctx );
                ui_global_ctx.cursor[1] += 1;
        }
-       
-       ui_resolve( &ui_global_ctx );
-       
-       m3x3f view = M3X3_IDENTITY;
-       m3x3_translate( view, (v3f){ -1.0f, 1.0f, 0.0f } );
-       m3x3_scale( view, (v3f){ 1.0f/((float)vg_window_x*0.5f), -1.0f/((float)vg_window_y*0.5f), 1.0f } );
-       vg_lines_drawall( (float*)view );
-       
-       ui_draw( &ui_global_ctx );
 }
index 74ecc97988771f70a4a4f03d8e696fbec7ed0034..87821ec107d636662b86b36b06c63a2af1a67fa2 100644 (file)
@@ -437,6 +437,8 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, int alignment )
        text_cursor[2] = 7*scale;
        text_cursor[3] = 7*scale;
 
+       u32 current_colour = 0xffffffff;
+
        const char *_c = str;
        char c;
        while( (c = *(_c ++)) )
@@ -457,7 +459,43 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, int alignment )
                        glyph_base[0] *= 7;
                        glyph_base[1] *= 7;
                        
-                       ui_fill_rect_uv( ctx, text_cursor, 0xffffffff, (ui_px[4]){glyph_base[0],glyph_base[1],glyph_base[0]+7,glyph_base[1]+7} );
+                       ui_fill_rect_uv( ctx, text_cursor, current_colour, (ui_px[4]){glyph_base[0],glyph_base[1],glyph_base[0]+7,glyph_base[1]+7} );
+               }
+               else if( c == '\x1B' )
+               {
+                       _c ++;
+                       u16 colour_id = 0;
+                       for( int i = 0; i < 3; i ++ )
+                       {
+                               if( _c[i] )
+                               {
+                                       if( _c[i] == 'm' )
+                                       {
+                                               _c = _c + i + 1;
+                                               
+                                               switch( colour_id )
+                                               {
+                                                       case '0': current_colour = 0xffffffff; break;
+                                                       case '3'|'1'<<8: current_colour = 0xff1fee20; break;
+                                                       case '3'|'2'<<8: current_colour = 0xff37e420; break;
+                                                       case '3'|'3'<<8: current_colour = 0xff0ed8e2; break;
+                                                       case '3'|'4'<<8: current_colour = 0xfff15010; break;
+                                                       case '3'|'5'<<8: current_colour = 0xffee20ee; break;
+                                                       case '3'|'6'<<8: current_colour = 0xffeeee20; break;
+                                                       case '3'|'7'<<8: current_colour = 0xffffffff; break;
+                                               }
+                                               
+                                               break;
+                                       }
+                                       
+                                       colour_id |= _c[i] << (i*8);
+                               } 
+                               else
+                               {
+                                       _c = _c +i;
+                                       break;
+                               }
+                       }
                }
                
                text_cursor[0] += 6*scale;