new font/ui fixes
authorhgn <hgodden00@gmail.com>
Sat, 4 Dec 2021 15:25:29 +0000 (15:25 +0000)
committerhgn <hgodden00@gmail.com>
Sat, 4 Dec 2021 15:25:29 +0000 (15:25 +0000)
fishladder.c
fishladder_resources.h
textures/ascii.png [new file with mode: 0644]
vg/vg.h
vg/vg_console.h
vg/vg_input.h
vg/vg_ui.h

index f2c8acd8938aa4920ecf1b583f035755f4abbc29..74a39ce4de1bcd955e8c5db78b89b5ca3e6222b9 100644 (file)
                        
                Medium levels:
                        Reverse order
+               
+               New things to program:
+                       UI text element renderer (SDF)
+                       Particle system thing for ball collision
+                       Level descriptions / titles
+                       Row Gridlines for I/O
+                       Play button / Speed controller
                        
                        
+       After release:
+               
 */
 
 const char *level_pack_1[] = { 
@@ -2309,5 +2318,5 @@ void vg_render(void)
 
 void vg_ui(void)
 {
-       ui_test();
+       
 }
index 4e48534bc82bcf2f6ff0a00d2eb891924d135f67..023c329d4f2ec2ff04a93f66343288d7e845c225 100644 (file)
@@ -6,8 +6,9 @@ vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.qoi" };
 vg_tex2d tex_wood =                    { .path = "textures/wood.qoi" };
 vg_tex2d tex_background =      { .path = "textures/background.qoi" };
 vg_tex2d tex_ball_noise =  { .path = "textures/bnoise.qoi" };
+vg_tex2d tex_monofur   =  { .path = "textures/ascii.qoi" };
 
-vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_background, &tex_ball_noise };
+vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_background, &tex_ball_noise, &tex_monofur };
 
 // AUDIO
 // ===========================================================================================================
@@ -94,6 +95,8 @@ static void resource_load_main(void)
        // Textures
        vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
        
+       ui_override_font( tex_monofur.name, 3 );
+       
        // Audio
        sfx_set_init( &audio_tile_mod, NULL );
        sfx_set_init( &audio_splitter, NULL );
diff --git a/textures/ascii.png b/textures/ascii.png
new file mode 100644 (file)
index 0000000..523184d
Binary files /dev/null and b/textures/ascii.png differ
diff --git a/vg/vg.h b/vg/vg.h
index 2c86d4d3b596749469f7550c84947acca1118f6e..c792527fce16a2c2ed6086f79965f19017578dae 100644 (file)
--- a/vg/vg.h
+++ b/vg/vg.h
@@ -248,23 +248,13 @@ static void vg_init( int argc, char *argv[], const char *window_name )
                        
                        {
                                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 );
+                               ui_set_mouse( &ui_global_ctx, vg_mouse[0], vg_mouse[1], vg_get_button_state( "primary" ) );
                                
                                vg_ui();
                                vg_console_draw();
                                vg_debugtools_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 );
                        }
                        
index 0e974f83b0223e2d87f257a0cd41b7357aa81467..48dee1a4a0fbd36d4f625fdab7c0f25dfc9da7f4 100644 (file)
@@ -42,7 +42,7 @@ struct vg_console
        int enabled;
        int scale;
 }
-vg_console = { .scale = 1 };
+vg_console = { .scale = 2 };
 
 static int vg_console_enabled(void) { return vg_console.enabled; }
 
@@ -102,8 +102,8 @@ static void vg_console_draw( void )
                int start = VG_MIN( vg_console.cursor_pos, vg_console.cursor_user ),
                         end   = VG_MAX( vg_console.cursor_pos, vg_console.cursor_user );
                
-               ui_global_ctx.cursor[0] = start * 6 * vg_console.scale;
-               ui_global_ctx.cursor[2] = (start == end? 1: (end-start)) * 6 * vg_console.scale;
+               ui_global_ctx.cursor[0] = start * ui_glyph_spacing_x * vg_console.scale + 2;
+               ui_global_ctx.cursor[2] = (start == end? 0.2f: (float)(end-start)) * (float)ui_glyph_spacing_x * (float)vg_console.scale;
                
                ui_fill_rect( &ui_global_ctx, ui_global_ctx.cursor, 0x66ffffff );
        }
index 62dd4b15b39f381737d9a4f03f42da746541fd0f..69865427ba75c5f4ae76f1a1fd87467dd09b00e9 100644 (file)
@@ -89,6 +89,14 @@ static inline int vg_get_button_up( const char *button )
        return bind->prev & (bind->value ^ bind->prev) && !vg_console_enabled();
 }
 
+static inline int vg_get_button_state( const char *button )
+{
+       if( vg_get_button( button ) ) return 2;
+       if( vg_get_button_down( button ) ) return 1;
+       if( vg_get_button_up( button ) ) return 3;
+       return 0;
+}
+
 static inline int key_is_keyboard( int const id )
 {
        vg_static_assert( GLFW_MOUSE_BUTTON_LAST < GLFW_KEY_SPACE, "GLFW: Mouse has too many buttons" );
index bf9adc85549d761ecbd833c5df438aa1ad1c3b31..56ece6b85d75fb7897e7b8cfbf593ec54a62c28b 100644 (file)
@@ -87,7 +87,9 @@ struct ui_ctx
 // ===========================================================================================================
 
 // Opengl
-GLuint ui_glyph_texture;
+int ui_glyph_override = 0;
+ui_px ui_glyph_spacing_x = 6;
+GLuint ui_glyph_texture = 0;
 GLuint ui_vao;
 GLuint ui_vbo;
 GLuint ui_ebo;
@@ -101,9 +103,20 @@ ui_ctx ui_global_ctx = { .padding = 8 };
 // Initialization
 // ===========================================================================================================
 
+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 font
+       // Load default font
+       if( !ui_glyph_override )
        {
                u32 compressed[] = {
                        #include "fonts/weiholmir.h"
@@ -180,7 +193,8 @@ static void ui_default_init(void)
 
 static void ui_default_free(void)
 {
-       glDeleteTextures( 1, &ui_glyph_texture );
+       if( !ui_glyph_override )        
+               glDeleteTextures( 1, &ui_glyph_texture );
        
        glDeleteVertexArrays( 1, &ui_vao );
        glDeleteBuffers( 1, &ui_vbo );
@@ -425,7 +439,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]){ 66, 66, 66, 66 } );
+       return ui_fill_rect_uv( ctx, rect, colour, (ui_px[4]){ 66, 72-66, 66, 72-66 } );
 }
 
 static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, int alignment )
@@ -459,7 +473,7 @@ 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, 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],72-glyph_base[1],glyph_base[0]+7,72-(glyph_base[1]+7)} );
                }
                else if( c == '\x1B' )
                {
@@ -498,7 +512,7 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, int alignment )
                        }
                }
                
-               text_cursor[0] += 6*scale;
+               text_cursor[0] += ui_glyph_spacing_x*scale;
        }
 }
 
@@ -602,8 +616,6 @@ static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group )
        {
                ui_capture_mouse( ctx, __COUNTER__ );
                
-               //ui_fill_rect( ctx, ctx->cursor, 0xff333333 );
-               
                // Drag bar
                ctx->cursor[3] = 25;            
                ui_new_node( ctx );
@@ -653,100 +665,3 @@ static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group )
        
        return 1;
 }
-
-static void ui_test(void)
-{
-       /*
-               +------------------------------------------------------+
-               | Central Market                                    [x]|
-               +------+--------------+-+------------------------------+
-               | Buy  | Balance      |#| [filters] [favorites]        |
-               | <>_  | () 2,356     |#|----------------------------+-+
-               |------|--------------|#| [] potion of madness     4 |#| 
-               | Sell | \ Main sword |#|----------------------------|#|
-               | _*^  |--------------|#| [] Balance of time      23 | |
-               |------| * Side arm   |#|----------------------------| |
-               | 235  |--------------| | [] Strength          5,300 | |
-               |      | () Sheild    | |----------------------------| |
-               |      |--------------| | [] Bewilder          2,126 | |
-               |      [ & Spells     ] |----------------------------| |
-               |      |--------------| | [] Eternal flames        6 | |
-               +------+--------------+-+----------------------------+-+
-       */
-
-       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 );
-       
-       /*
-       static struct ui_window window =
-       {
-               .transform = { 20, 20, 500, 350 },
-               .title = "Central Market"
-       };
-       
-       if( ui_window( &ui_global_ctx, &window, __COUNTER__ ) )
-       {
-               // Contents
-               //ui_text( &ui_global_ctx, "A slice of heaven. O for awesome, this chocka \nfull cuzzie is as rip-off as a cracker.\nMeanwhile, in behind the bicycle shed, Hercules Morse,\nas big as a horse and Mrs Falani were up to no \ngood with a bunch of crook pikelets. Meanwhile, \nat the black singlet woolshed party, not even au,\nsort your drinking out.", 1, 0 );
-               ui_global_ctx.cursor[2] = 75;
-               ui_fill_y( &ui_global_ctx );
-               
-               ui_new_node( &ui_global_ctx );
-               {
-                       ui_global_ctx.cursor[3] = 75;
-                       
-                       if( ui_button( &ui_global_ctx, __COUNTER__ ) )
-                               vg_info( "Buy\n" );
-                       {
-                               ui_rect_pad( ui_global_ctx.cursor, 4 );
-                               ui_text( &ui_global_ctx, "Buy", 2, 0 );
-                       }
-                       ui_end_down( &ui_global_ctx );
-                       
-                       if( ui_button( &ui_global_ctx, __COUNTER__ ) )
-                               vg_info( "Sell\n" );
-                       {
-                               ui_rect_pad( ui_global_ctx.cursor, 4 );
-                               ui_text( &ui_global_ctx, "Sell", 2, 0 );
-                       }
-                       ui_end_down( &ui_global_ctx );
-               }
-               ui_end_right( &ui_global_ctx );
-               
-               ui_global_ctx.cursor[2] = 200;
-               ui_new_node( &ui_global_ctx );
-               {
-               
-               }
-               ui_end_right( &ui_global_ctx );
-       }
-       ui_end( &ui_global_ctx );
-       */
-       
-       ui_rect rbf;
-       ui_rect_copy( ui_global_ctx.cursor, rbf );
-       
-       ui_global_ctx.cursor[0] = 6;
-       ui_global_ctx.cursor[3] = 21;
-       ui_fill_x( &ui_global_ctx );
-       ui_align_bottom( &ui_global_ctx );
-       ui_text( &ui_global_ctx, "Marble computer build 2 -- development version -- (C) Harry Godden 2021\nAknowledgements: 'credits' in console (`)", 1, 0 );
-       
-       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 );
-       
-       ui_rect_copy( rbf, ui_global_ctx.cursor );
-}