patch up things from text changes
[fishladder.git] / vg / vg_ui.h
index f6693cbcd7e3320be1d4aef22a9a2abae929dc1a..b8f826c297dc1a07ac51cd216f118707c3eac1a2 100644 (file)
@@ -17,7 +17,7 @@ SHADER_DEFINE( shader_ui,
        "void main()"
        "{"
                "gl_Position = vec4( uPv * vec3( a_co, 1.0 ), 1.0 );"
-               "aTexCoords = a_uv * 0.01388888888;"
+               "aTexCoords = a_uv * 0.0078125;"
                "aColour = a_colour;"
                
                "aWsp = a_co;"
@@ -148,9 +148,8 @@ struct ui_ctx
 // ===========================================================================================================
 
 // Opengl
-int ui_glyph_override = 0;
-ui_px ui_glyph_spacing_x = 6;
-GLuint ui_glyph_texture = 0;
+static ui_px ui_glyph_spacing_x = 9;
+static GLuint ui_glyph_texture = 0;
 
 ui_colourset ui_default_colours = {
        .main = 0xff00ff00,
@@ -224,53 +223,40 @@ static void ui_context_free( ui_ctx *ctx )
        free( ctx->indices );
 }
 
-static void ui_override_font( GLuint new_tex, ui_px space_x )
-{
-       if( ui_glyph_texture )
-               glDeleteTextures( 1, &ui_glyph_texture );
-       
-       ui_glyph_texture = new_tex;
-       ui_glyph_override = 1;
-       ui_glyph_spacing_x = space_x;
-}
-
 static void ui_default_init(void)
 {
        // Load default font
-       if( !ui_glyph_override )
-       {
-               u32 compressed[] = {
-                       #include "fonts/weiholmir.h"
-               };
-       
-               u32 pixels = 0, total = 72*72, data = 0;
-               u8 *image = malloc( total );
-               
-               while( pixels < total )
-               {
-                       for( int b = 31; b >= 0; b-- )
-                       {
-                               image[ pixels ++ ] = (compressed[data] & (0x1 << b))? 0xff: 0x00;
-                               
-                               if( pixels >= total )
-                               {
-                                       total = 0;
-                                       break;
-                               }
-                       }
-                       data++;
-               }
-               
-               glGenTextures( 1, &ui_glyph_texture );
-               glBindTexture( GL_TEXTURE_2D, ui_glyph_texture );
-               
-               glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, 72, 72, 0, GL_RED, GL_UNSIGNED_BYTE, image );
-               
-               vg_tex2d_clamp();
-               vg_tex2d_nearest();
-               
-               free( image );
-       }
+   u32 compressed[] = {
+      #include "vg/vg_pxfont.h"
+   };
+
+   u32 pixels = 0, total = 256*256, data = 0;
+   u8 *image = malloc( total );
+   
+   while( pixels < total )
+   {
+      for( int b = 31; b >= 0; b-- )
+      {
+         image[ pixels ++ ] = (compressed[data] & (0x1 << b))? 0xff: 0x00;
+         
+         if( pixels >= total )
+         {
+            total = 0;
+            break;
+         }
+      }
+      data++;
+   }
+   
+   glGenTextures( 1, &ui_glyph_texture );
+   glBindTexture( GL_TEXTURE_2D, ui_glyph_texture );
+   
+   glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, 256, 256, 0, GL_RED, GL_UNSIGNED_BYTE, image );
+   
+   vg_tex2d_clamp();
+   vg_tex2d_nearest();
+   
+   free( image );
        
        // Setup OpenGL memory
        SHADER_INIT( shader_ui );
@@ -279,8 +265,7 @@ static void ui_default_init(void)
 
 static void ui_default_free(void)
 {
-       if( !ui_glyph_override )        
-               glDeleteTextures( 1, &ui_glyph_texture );
+   glDeleteTextures( 1, &ui_glyph_texture );
        
        ui_context_free( &ui_global_ctx );
 }
@@ -567,7 +552,7 @@ static struct ui_vert *ui_fill_rect_uv( ui_ctx *ctx, ui_rect rect, u32 colour, u
 
 static struct ui_vert *ui_fill_rect( ui_ctx *ctx, ui_rect rect, u32 colour )
 {
-       return ui_fill_rect_uv( ctx, rect, colour, (ui_px[4]){ 4,124,4,124 } );
+       return ui_fill_rect_uv( ctx, rect, colour, (ui_px[4]){ 4,4, 4,4 } );
 }
 
 static void ui_text( ui_ctx *ctx, const char *str, ui_px scale )
@@ -576,8 +561,8 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale )
 
        text_cursor[0] = ctx->cursor[0];
        text_cursor[1] = ctx->cursor[1];
-       text_cursor[2] = 7*scale;
-       text_cursor[3] = 7*scale;
+       text_cursor[2] = 8*scale;
+       text_cursor[3] = 14*scale;
 
        u32 current_colour = 0x00ffffff;
 
@@ -587,21 +572,21 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale )
        {
                if( c == '\n' )
                {
-                       text_cursor[1] += 10*scale;
+                       text_cursor[1] += 14*scale;
                        text_cursor[0] = ctx->cursor[0];
                        continue;
                }
                else if( c >= 33 && c <= 126 )
                {
                        u8 glyph_base[2];
-                       u8 glyph_index = c - 32;
-                       glyph_base[0] = glyph_index%10;
-                       glyph_base[1] = (glyph_index-glyph_base[0])/10;
+                       u8 glyph_index = c;
+                       glyph_base[0] = glyph_index & 0xf;
+                       glyph_base[1] = (glyph_index-glyph_base[0])>>4;
                        
-                       glyph_base[0] *= 7;
-                       glyph_base[1] *= 7;
+                       glyph_base[0] *= 8;
+                       glyph_base[1] *= 8;
                        
-                       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} );
+                       ui_fill_rect_uv( ctx, text_cursor, current_colour, (ui_px[4]){glyph_base[0]+2,glyph_base[1]+1,glyph_base[0]+6,glyph_base[1]+8} );
                }
                else if( c == '\x1B' )
                {
@@ -640,7 +625,7 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale )
                        }
                }
                
-               text_cursor[0] += 6*scale;
+               text_cursor[0] += 9*scale;
        }
 }