From: hgn Date: Sat, 4 Dec 2021 15:25:29 +0000 (+0000) Subject: new font/ui fixes X-Git-Url: https://harrygodden.com/git/?p=fishladder.git;a=commitdiff_plain;h=499bcabb125cdf2618a6be89ccade08b007254f3 new font/ui fixes --- diff --git a/fishladder.c b/fishladder.c index f2c8acd..74a39ce 100644 --- a/fishladder.c +++ b/fishladder.c @@ -21,8 +21,17 @@ 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(); + } diff --git a/fishladder_resources.h b/fishladder_resources.h index 4e48534..023c329 100644 --- a/fishladder_resources.h +++ b/fishladder_resources.h @@ -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 index 0000000..523184d Binary files /dev/null and b/textures/ascii.png differ diff --git a/vg/vg.h b/vg/vg.h index 2c86d4d..c792527 100644 --- 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 ); } diff --git a/vg/vg_console.h b/vg/vg_console.h index 0e974f8..48dee1a 100644 --- a/vg/vg_console.h +++ b/vg/vg_console.h @@ -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 ); } diff --git a/vg/vg_input.h b/vg/vg_input.h index 62dd4b1..6986542 100644 --- a/vg/vg_input.h +++ b/vg/vg_input.h @@ -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" ); diff --git a/vg/vg_ui.h b/vg/vg_ui.h index bf9adc8..56ece6b 100644 --- a/vg/vg_ui.h +++ b/vg/vg_ui.h @@ -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 ); -}