Misc stuff (before the storm) vg3
authorhgn <hgodden00@gmail.com>
Wed, 3 Sep 2025 19:32:29 +0000 (19:32 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 3 Sep 2025 19:32:29 +0000 (19:32 +0000)
vg.hconf
vg_build.h
vg_io.c
vg_kv.c
vg_log.h
vg_string.c
vg_string.h
vg_ui/imgui.c
vg_ui/imgui.h
vg_ui/imgui_impl_opengl.c

index f11f84bd8af007ddbbe39564cd671710ebd4b9a2..e1e8a477a7dbb03931f128ad906a532e4ef815f5 100644 (file)
--- a/vg.hconf
+++ b/vg.hconf
 #  include "vg/vg_shader.h"
 #  include "src.generated/vg.shaders.h"
 #  include "vg/vg_tex.h"
+# endif
+
+# if defined( VG_ENGINE ) || defined( VG_IMGUI )
 #  include "vg/vg_font.h"
 #  include "vg/vg_ui/imgui.h"
+# endif
+
+# if defined( VG_ENGINE )
 #  include "vg/vg_ui/imgui_impl_opengl.h"
 #  include "vg/vg_ui/filebrowser.h"
 #  include "vg/vg_ui/console.h"
index 86705fcc2987f100566fb219a8e0eccfeef3369b..ad88c76026a541db1a4000275ceccb5c8304531c 100644 (file)
@@ -432,7 +432,7 @@ vg_make_app( struct vg_project *proj,
    vg_strcat( &conf->defines, "\\\n" );
    vg_strcat( &conf->include, "-I. -I./vg -I./vg/dep " );
 
-   vg_strcat( &conf->library, "-L. -L/usr/lib/x86_64-linux-gnu " );
+   vg_strcat( &conf->library, "-L. -L/usr/lib" );
    vg_strcat( &conf->link, "-lm " );
 
    /* compile all the components 
diff --git a/vg_io.c b/vg_io.c
index e778989150e7a872ea072cd55ff90cb1a64e81d8..b2fc61cc2859c95580ae2eb7b71b0a45d58f0c04 100644 (file)
--- a/vg_io.c
+++ b/vg_io.c
@@ -311,7 +311,7 @@ void *vg_file_read( vg_stack_allocator *stack, const char *path, u32 *size, bool
       u64 current = 0;
 
       /* read in chunks */
-      for( u32 i=0; 1; i++ )
+      while(1)
       {
          vg_stack_extend_last( stack, +VG_FILE_IO_CHUNK_SIZE );
          u64 l = fread( buffer + current, 1, VG_FILE_IO_CHUNK_SIZE, f );
diff --git a/vg_kv.c b/vg_kv.c
index d8fb48768ce1bc0089afa5f806a0b824672b7b84..7af1fa0f5e012ccb45f235ae62480109a807bd02 100644 (file)
--- a/vg_kv.c
+++ b/vg_kv.c
@@ -146,8 +146,6 @@ u32 vg_kv_find( vg_kvs *kvs, u32 root_offset, const c8 *key )
    while( child_offset )
    {
       vg_kv *kv = vg_stack_pointer( kvs->stack, child_offset );
-      u32 key_length;
-      const c8 *child_key = vg_kv_key( kvs, child_offset, &key_length );
       if( ((kv->key_info ^ hash) & 0xFFFFF) == 0 )
       {
          u32 key_length;
index 6c788b047337aeb3c0fbc0f88b86b574327fd2b4..138efb825ec767cb54d2c7a591af875a06189170 100644 (file)
--- a/vg_log.h
+++ b/vg_log.h
@@ -30,7 +30,8 @@
  */
 
 #define KNRM  "\x1B[0m"
-#define KBLK  "\x1B[30m"
+//#define KBLK  "\x1B[30m"
+#define KBLK  "\x1B[0m"
 #define KRED  "\x1B[31m"
 #define KGRN  "\x1B[32m"
 #define KYEL  "\x1B[33m"
index 2425a7f50e5af99ab18546f10f708e0bf14bc35c..175e5252f39fcd01bcf029774da3a883351cc88f 100644 (file)
@@ -12,6 +12,12 @@ i32 vg_str_storage( vg_str *str )
    else return str->len;
 }
 
+void vg_strclip( vg_str *str, i32 i )
+{
+   str->buffer[i] = '\0';
+   str->i = i;
+}
+
 /*
  * Reset string. If len is 0 (dynamically allocated), buffer must be either 
  * NULL or be acquired from malloc or realloc
@@ -137,18 +143,21 @@ bool vg_str_flushfd( vg_str *str, int fd )
    return good;
 }
 
+c8 vg_str_character( vg_str *str, i32 index )
+{
+   return str->buffer[ index ];
+}
+
 /*
  * Returns pointer to last instance of character
  */
-c8 *vg_strch( vg_str *str, c8 c )
-{
-   c8 *ptr = NULL;
-   for( i32 i=0; i<str->i; i++ ){
+i32 vg_strch( vg_str *str, i32 start, c8 c )
+{  
+   i32 last_index = -1;
+   for( i32 i=start; i<str->i; i++ )
       if( str->buffer[i] == c )
-         ptr = str->buffer+i;
-   }
-
-   return ptr;
+         last_index = i;
+   return last_index;
 }
 
 u32 vg_strcpy( const c8 *src, c8 *dst )
@@ -245,6 +254,7 @@ bool vg_str_eq( const c8 *s1, const c8 *s2 )
    return 0;
 }
 
+#if defined( VG_UTF8 )
 static u32 utf8_byte0_byte_count( u8 c80 )
 {
    for( u32 k=2; k<4; k++ )
@@ -296,11 +306,7 @@ u32 str_utf8_collapse( const c8 *str, c8 *buf, u32 length )
    buf[j] = 0x00;
    return j;
 }
-
-
-
-
-
+#endif
 
 const c8 *vg_strp_info_str[] = 
 {
index 8ad1bdcdd5d4ae0ac930fd07e6556e1b3876457d..c84942719e2e24846752ff50ce83d3afed1c4789 100644 (file)
@@ -30,6 +30,7 @@ i32 vg_str_storage( vg_str *str );
  */
 void vg_strnull( vg_str *str, c8 *buffer, i32 len );
 void vg_strfree( vg_str *str );
+void vg_strclip( vg_str *str, i32 i );
 
 /*
  * Append null terminated string to vg_str 
@@ -52,11 +53,12 @@ void vg_strcatf64( vg_str *str, f64 value, u64 base, u32 decimal_places );
  * Returns 1 if string did not overflow while building
  */
 int vg_strgood( vg_str *str );
+c8 vg_str_character( vg_str *str, i32 index );
 
 /*
  * Returns pointer to last instance of c8acter
  */
-c8 *vg_strch( vg_str *str, c8 c );
+i32 vg_strch( vg_str *str, i32 start, c8 c );
 
 enum strncpy_behaviour
 {
index 160f76bdc1ea006b8115359057e460e8bb3fe855..95c33a8bb6e92d198a777540574edbeccb5f5f67 100644 (file)
@@ -66,8 +66,7 @@ ui_vert *ui_fill( ui_context *ctx, ui_rect rect, u32 colour )
    return ui_fill_rect( ctx, rect, colour, (ui_px[4]){ 4,4,4,4 } );
 }
 
-void ui_outline( ui_context *ctx, 
-                 ui_rect rect, ui_px thickness, u32 colour, u32 mask )
+void ui_outline( ui_context *ctx, ui_rect rect, ui_px thickness, u32 colour, u32 mask )
 {
    /* this if far from ideal but stops us from crashing */
    if( (ctx->cur_vert + 8 > ctx->max_verts) || 
@@ -102,7 +101,7 @@ void ui_outline( ui_context *ctx,
    vertices[7].co[1] = vertices[3].co[1]+thickness;
 
        u16 start = ctx->cur_vert;
-   u32 mesh[] = { 0,5,4, 0,1,5, 1,6,5, 1,2,6, 2,7,6, 2,3,7, 3,4,7, 3,0,4 };
+   u32 mesh[] = { 0,5,4,0,1,5, 1,6,5,1,2,6, 2,7,6,2,3,7, 3,4,7,3,0,4 };
 
    if( !mask ) 
       mask = UI_TOP|UI_LEFT|UI_BOTTOM|UI_RIGHT;
@@ -653,14 +652,14 @@ void ui_spacer( ui_context *ctx, ui_rect inout_panel )
    ui_fill( ctx, inner, ui_colour( ctx, k_ui_bg+6 ) );
 }
 
-void ui_image( ui_context *ctx, ui_rect rect, vg_tex *tex, bool flip )
+void ui_image( ui_context *ctx, ui_rect rect, void *image_resource, bool flip )
 {
    ui_flush( ctx, k_ui_shader_colour, NULL );
    if( flip )
       ui_fill_rect( ctx, rect, 0xffffffff, (ui_px[4]){ 0,0,256,256 } );
    else
       ui_fill_rect( ctx, rect, 0xffffffff, (ui_px[4]){ 0,256,256,0 } );
-   ui_flush( ctx, k_ui_shader_image, tex );
+   ui_flush( ctx, k_ui_shader_image, image_resource );
 }
 
 void ui_defocus_all( ui_context *ctx )
@@ -1585,8 +1584,7 @@ void _ui_textbox_enter( ui_context *ctx )
  *
  * input coordinates go in co[0], co[1], and the result index is in co[2]
  */
-static void _ui_textbox_calc_index_from_grid( ui_context *ctx,
-                                              int co[3], int wrap_length )
+static void _ui_textbox_calc_index_from_grid( ui_context *ctx, int co[3], int wrap_length )
 {
    int i[3] = {0,0,0};
 
@@ -1695,7 +1693,8 @@ int ui_textbox( ui_context *ctx, ui_rect inout_panel, const char *label,
 
    /* allow instant transitions from textbox->textbox */
    if( (ctx->focused_control_type != k_ui_control_none) &&
-       (ctx->focused_control_type != k_ui_control_textbox) ){
+       (ctx->focused_control_type != k_ui_control_textbox) )
+   {
       clickup = 0;
       clickdown = 0;
       click = 0;
@@ -1771,7 +1770,6 @@ int ui_textbox( ui_context *ctx, ui_rect inout_panel, const char *label,
          }
 
          ui_outline( ctx, rect, -2, ctx->scheme[ k_ui_orange ], 0 );
-
          ui_rect cursor;
 
          int c0 = ctx->textbox.cursor_pos,
@@ -1833,8 +1831,7 @@ int ui_textbox( ui_context *ctx, ui_rect inout_panel, const char *label,
                cursor[2] = (float)(chars)*(float)ctx->font->sx;
             }
 
-            if( (ctx->click_fade_opacity<=0.0f) && 
-                 ui_clip( rect, cursor, cursor ) )
+            if( (ctx->click_fade_opacity<=0.0f) && ui_clip( rect, cursor, cursor ) )
             {
                ui_fill( ctx, cursor, col_cursor );
             }
index ed840e007f55010c0a0780436e620ebb5e16bc77..67fd0ddccefc1d417df344a3a4a9435d241a70c6 100644 (file)
@@ -226,14 +226,9 @@ struct ui_batch_shader_data_hsv
    f32 hue;
 };
 
-struct ui_batch_shader_data_image
-{
-   void *resource;
-};
-
 struct ui_batch_shader_data_image_gradient
 {
-   vg_tex *tex;
+   void *image_resource;
    bool log;
    f32 scale;
 };
@@ -311,7 +306,7 @@ void ui_panel( ui_context *ctx, ui_rect in_rect, ui_rect out_panel );
 void ui_label( ui_context *ctx, ui_rect rect, const char *text, ui_px size, ui_px gap, ui_rect r );
 void ui_info( ui_context *ctx, ui_rect inout_panel, const char *text );
 void ui_spacer( ui_context *ctx, ui_rect inout_panel );
-void ui_image( ui_context *ctx, ui_rect rect, vg_tex *tex, bool flip );
+void ui_image( ui_context *ctx, ui_rect rect, void *image_resource, bool flip );
 
 enum ui_button_state ui_button_base( ui_context *ctx, ui_rect rect );
 
index 3d2ba35b287454dc71252e2f0931fa43ec7748fa..b26475ebc3fa5ed99b5adb996816799c7d45d92e 100644 (file)
@@ -86,7 +86,7 @@ void ui_impl_render_batch( ui_context *ctx, ui_batch *batch, enum ui_shader shad
       glBindTexture( GL_TEXTURE_2D, vg_ui.tex_glyphs );
       shader_vgui_uTexGlyphs( 0 );
 
-      vg_tex_bind( GL_TEXTURE_2D, vg_ui.tex_bg, 1 );
+      vg_tex_bind( GL_TEXTURE_2D, (vg_tex *)vg_ui.tex_bg, 1 );
       shader_vgui_uTexBG( 1 );
       shader_vgui_uSpread( vg_ui.frosting );
       shader_vgui_uBGInverseRatio( vg_ui.bg_inverse_ratio );
@@ -98,7 +98,7 @@ void ui_impl_render_batch( ui_context *ctx, ui_batch *batch, enum ui_shader shad
       shader_vgui_image_uPv( vg_ui.pv );
       shader_vgui_image_uTexImage( 0 );
       shader_vgui_image_uColour( vg_ui.colour );
-      vg_tex_bind( GL_TEXTURE_2D, shader_data, 0 );
+      vg_tex_bind( GL_TEXTURE_2D, (vg_tex *)shader_data, 0 );
    }
    else if( shader == k_ui_shader_grad )
    {
@@ -110,7 +110,7 @@ void ui_impl_render_batch( ui_context *ctx, ui_batch *batch, enum ui_shader shad
       struct ui_batch_shader_data_image_gradient *inf = shader_data;
       shader_vgui_image_grad_uLog( inf->log );
       shader_vgui_image_grad_uScale( inf->scale );
-      vg_tex_bind( GL_TEXTURE_2D, inf->tex, 0 );
+      vg_tex_bind( GL_TEXTURE_2D, (vg_tex *)inf->tex, 0 );
    }
    else if( shader == k_ui_shader_hsv )
    {