From: hgn Date: Sun, 26 May 2024 14:08:39 +0000 (+0100) Subject: ui api X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=9b1506f510e7eb8e1db853cc49b675c00cfde67c;p=fishladder.git ui api --- diff --git a/fishladder_vg1.c b/fishladder_vg1.c index 0908357..ee16e5e 100644 --- a/fishladder_vg1.c +++ b/fishladder_vg1.c @@ -3544,11 +3544,11 @@ image_composite: draw_mesh( 0, 2 ); } -void _mc_vg1_ui(void) { - - ui_px const unit_scale_px = 4*vg_ui.font->spacing; - +void _mc_vg1_ui( ui_context *ctx ) +{ #if 0 + ui_px const unit_scale_px = 4*vg_ui.ctx.font->spacing; + if( world.pCmpLevel ){ for( int i = 0; i < vg_list_size( world.pCmpLevel->strings ); i ++ ){ struct world_string *wstr = &world.pCmpLevel->strings[i]; @@ -3572,13 +3572,16 @@ void _mc_vg1_ui(void) { u32 sum = 0; // re-create level scores - for( int i = 0; i < vg_list_size( career_packs ); i ++ ){ + for( int i = 0; i < vg_list_size( career_packs ); i ++ ) + { struct career_level_pack *set = &career_packs[i]; - for( int j = 0; j < set->count; j ++ ){ + for( int j = 0; j < set->count; j ++ ) + { struct cmp_level *lvl = &set->pack[j]; - if( lvl->completed_score && !lvl->is_tutorial ){ + if( lvl->completed_score && !lvl->is_tutorial ) + { char num[10]; snprintf( num, 9, "%d", lvl->completed_score ); sum += lvl->completed_score; @@ -3595,7 +3598,7 @@ void _mc_vg1_ui(void) { pos[1] = 2.0f - pos[1]; pos[1] *= (f32)vg.window_y * 0.5f; - ui_text( (ui_rect){ pos[0]-100, pos[1], 200, 24 }, num, 1, + ui_text( ctx, (ui_rect){ pos[0]-100, pos[1], 200, 24 }, num, 1, k_ui_align_center, 0xffcccccc ); } } @@ -3613,17 +3616,20 @@ void _mc_vg1_ui(void) { char tot[32]; snprintf( tot, 31, "%u", sum ); - vg_ui.font = &vg_ui_font_big; - ui_text( (ui_rect){ pos[0]-100, pos[1], 200, 24 }, tot, 1, + ctx->font = &vgf_default_large; + ui_text( ctx, (ui_rect){ pos[0]-100, pos[1], 200, 24 }, tot, 1, k_ui_align_center, 0xffcccccc ); - vg_ui.font = &vg_ui_font_small; + ctx->font = &vgf_default_small; - if( world.pCmpLevel ){ - vg_ui.font = &vg_ui_font_big; - ui_text( (ui_rect){ 0, 0, vg.window_x, 28 }, world.pCmpLevel->title, + if( world.pCmpLevel ) + { + ctx->font = &vgf_default_large; + ui_text( ctx, + (ui_rect){ 0, 0, vg.window_x, 28 }, world.pCmpLevel->title, 1, k_ui_align_middle_center, 0 ); - vg_ui.font = &vg_ui_font_small; - ui_text( (ui_rect){ 0, 28,vg.window_x, 14 }, world.pCmpLevel->description, + ctx->font = &vgf_default_small; + ui_text( ctx, + (ui_rect){ 0, 28,vg.window_x, 14 }, world.pCmpLevel->description, 1, k_ui_align_middle_center, 0 ); } } diff --git a/input.h b/input.h index 164d5f2..0001e9f 100644 --- a/input.h +++ b/input.h @@ -4,7 +4,7 @@ #include "vg/vg_input.h" #include "vg/vg_m.h" #include "vg/vg_tex.h" -#include "vg/vg_imgui.h" +#include "vg/vg_ui/imgui.h" enum sr_bind{ k_srbind_primary = 0, diff --git a/marblecomp.c b/marblecomp.c index 4720933..9123f4e 100644 --- a/marblecomp.c +++ b/marblecomp.c @@ -154,9 +154,10 @@ void vg_render(void) vg_lines_drawall(); } -void vg_gui(void) +void vg_gui( ui_context *ctx ) { if( marblecomp.op == k_mc_op_clientloading ) return; - vg_ui.wants_mouse = 1; - _mc_vg1_ui(); + + ui_capture_mouse( ctx, 1 ); + _mc_vg1_ui( ctx ); } diff --git a/marblecomp_settings.h b/marblecomp_settings.h index 47ebfbc..400860d 100644 --- a/marblecomp_settings.h +++ b/marblecomp_settings.h @@ -46,14 +46,14 @@ void vg_game_settings_init(void) ui_settings_enum_init( &mc_settings.music ); } -void vg_game_settings_gui( ui_rect panel ) +void vg_game_settings_gui( ui_context *ctx, ui_rect panel ) { ui_rect rq; - ui_standard_widget( panel, rq, 1 ); + ui_standard_widget( ctx, panel, rq, 1 ); ui_rect opt, display; ui_split_ratio( rq, k_ui_axis_v, 0.5f, 16, opt, display ); - vg_settings_enum( &mc_settings.colourscheme, opt ); + vg_settings_enum( ctx, &mc_settings.colourscheme, opt ); ui_rect blocks[4]; ui_split_ratio( display, k_ui_axis_v, 0.5f, 2, blocks[0], blocks[2] ); @@ -61,27 +61,28 @@ void vg_game_settings_gui( ui_rect panel ) ui_split_ratio( blocks[2], k_ui_axis_v, 0.5f, 2, blocks[2], blocks[3] ); v3f *set = colour_sets[ mc_settings.colourscheme.new_value ]; - for( u32 i=0; i<4; i ++ ){ + for( u32 i=0; i<4; i ++ ) + { u32 rgb = 0xff000000; for( u32 j=0; j < 3; j ++ ) rgb |= (u32)(set[i][j]*255.0f) << j * 8; - - ui_fill( blocks[i], rgb ); + ui_fill( ctx, blocks[i], rgb ); } - ui_standard_widget( panel, rq, 1 ); - vg_settings_enum( &mc_settings.theme, rq ); + ui_standard_widget( ctx, panel, rq, 1 ); + vg_settings_enum( ctx, &mc_settings.theme, rq ); - ui_standard_widget( panel, rq, 1 ); - vg_settings_enum( &mc_settings.bloom, rq ); + ui_standard_widget( ctx, panel, rq, 1 ); + vg_settings_enum( ctx, &mc_settings.bloom, rq ); - ui_standard_widget( panel, rq, 1 ); - vg_settings_enum( &mc_settings.vignette, rq ); + ui_standard_widget( ctx, panel, rq, 1 ); + vg_settings_enum( ctx, &mc_settings.vignette, rq ); - ui_standard_widget( panel, rq, 1 ); - vg_settings_enum( &mc_settings.music, rq ); + ui_standard_widget( ctx, panel, rq, 1 ); + vg_settings_enum( ctx, &mc_settings.music, rq ); - if( vg_settings_apply_button( panel, 1 ) ){ + if( vg_settings_apply_button( ctx, panel, 1 ) ) + { marblecomp.colour_set = mc_settings.colourscheme.new_value; marblecomp.world_theme = mc_settings.theme.new_value; marblecomp.bloom = mc_settings.bloom.new_value; @@ -90,16 +91,20 @@ void vg_game_settings_gui( ui_rect panel ) audio_lock(); marblecomp.music = mc_settings.music.new_value; - if( marblecomp.music ){ - if( !marblecomp.music_channel ){ + if( marblecomp.music ) + { + if( !marblecomp.music_channel ) + { marblecomp.music_channel = audio_get_first_idle_channel(); audio_channel_init( marblecomp.music_channel, &audio_music[0], AUDIO_FLAG_LOOP ); audio_channel_fadein( marblecomp.music_channel, 0.25f ); } } - else{ - if( marblecomp.music_channel ){ + else + { + if( marblecomp.music_channel ) + { marblecomp.music_channel = audio_channel_fadeout( marblecomp.music_channel, 0.25f ); }