From 2b7f6320deb863e1a5d748715845c12136486f0f Mon Sep 17 00:00:00 2001 From: hgn Date: Sat, 8 Nov 2025 16:40:20 +0000 Subject: [PATCH] fixers --- source/engine/model_entity.h | 6 +++-- source/graphics/graphics_software.c | 4 ++++ source/graphics/ui.c | 35 +++++++++++++---------------- source/graphics/vg_graphics.h | 20 +++++++++++++++++ 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/source/engine/model_entity.h b/source/engine/model_entity.h index e2c07cd..be0c9c0 100644 --- a/source/engine/model_entity.h +++ b/source/engine/model_entity.h @@ -40,12 +40,13 @@ enum entity_alias k_editer_property = 34, k_editer_item = 35, - k_ent_flame = 200, + k_ent_flame = 200, // FIXME: Move thiese into own file per-game. k_ent_waterfall = 201, k_ent_rb2 = 202, k_ent_heatpipe = 203, k_ent_waterlevel = 204, k_ent_viewstone = 205, + k_ent_gauge = 206, k_ent_max }; @@ -83,7 +84,8 @@ static const char *_entity_alias_str[] = [k_ent_script] = "ent_script", [k_ent_atom] = "ent_atom", [k_ent_cutscene] = "ent_cutscene", - [k_ent_light] = "ent_light" + [k_ent_light] = "ent_light", + [k_ent_max] = NULL }; static inline u32 mdl_entity_id_type( u32 entity_id ) diff --git a/source/graphics/graphics_software.c b/source/graphics/graphics_software.c index 87c913e..1dd8d71 100644 --- a/source/graphics/graphics_software.c +++ b/source/graphics/graphics_software.c @@ -16,6 +16,10 @@ void _graphics_viewport( i16 x, i16 y, i16 w, i16 h ) _graphics.viewport[2] = w; _graphics.viewport[3] = h; } +void _graphics_get_viewport_rect( i16 rect[4] ) +{ + rect_copy( _graphics.viewport, rect ); +} void _graphics_push_blendmode( enum blending_mode mode ) { diff --git a/source/graphics/ui.c b/source/graphics/ui.c index c196f4f..6ca6b68 100644 --- a/source/graphics/ui.c +++ b/source/graphics/ui.c @@ -63,31 +63,21 @@ void _ui_get_mouse_co( i16 out_co[2] ) out_co[1] = _ui.mouse_co[1]; } +// FIXME BAD void _ui_set_encoding( enum ui_text_encoding encoding ) { _ui.text_encoding = encoding; } +enum ui_text_encoding _ui_get_encoding(void) +{ + return _ui.text_encoding; +} b8 ui_inside_rect( i16 rect[4], i16 co[2] ) { return (co[0] >= rect[0]) && (co[1] >= rect[1]) && (co[0] < rect[0]+rect[2]) && (co[1] < rect[1]+rect[3]); } -struct ui_string_decoder -{ - /* source */ - const c8 *string; - enum ui_text_encoding encoding; - - /* internal */ - u32 buffer_offset, character_index; - u32 utf8_counter; - - /* read from these */ - i16 grid_co[2]; - u32 c; -}; - void ui_string_decode_init( struct ui_string_decoder *decoder, const c8 *string, enum ui_text_encoding encoding ) { zero_buffer( decoder, sizeof(struct ui_string_decoder) ); @@ -148,7 +138,7 @@ u32 text_decoder_line_count( struct ui_string_decoder *decoder ) { struct ui_string_decoder copy = *decoder; while( ui_string_decode( © ) ){} - return copy.grid_co[1]; + return copy.grid_co[1]+1; } void _ui_text( i16 rect[4], const c8 *text, enum ui_align align, union colour colour ) @@ -169,21 +159,25 @@ void _ui_text( i16 rect[4], const c8 *text, enum ui_align align, union colour co if( align & k_ui_align_y_center ) { - text_root[1] += rect[3]/2 - text_decoder_line_count( &decoder )/2; - text_root[1] += kerning[2]; + text_root[1] += (rect[3] - text_decoder_line_count( &decoder )*kerning[1])/2; + //text_root[1] += kerning[2]; ???? } b8 align_x = (align & (k_ui_align_x_center|k_ui_align_x_right))? 1:0; - while( ui_string_decode( &decoder ) ) + +decode_loop: { if( align_x && (align & (k_ui_align_x_center|k_ui_align_x_right)) ) { i16 line_width = text_decoder_line_width( &decoder ) * kerning[0]; - if( align & k_ui_align_x_center ) text_root[0] = rect[0] + (rect[2]/2 - line_width/2); + if( align & k_ui_align_x_center ) text_root[0] = rect[0] + (rect[2] - line_width)/2; else text_root[0] = rect[0] + (rect[2] - line_width); align_x = 0; } + if( !ui_string_decode( &decoder ) ) + return; + if( decoder.c == '\n' ) align_x = 1; else @@ -194,6 +188,7 @@ void _ui_text( i16 rect[4], const c8 *text, enum ui_align align, union colour co _graphics_glyph( char_root, decoder.c, 1, colour ); } } + goto decode_loop; //rect_copy( temp_area, clipping_area ); } diff --git a/source/graphics/vg_graphics.h b/source/graphics/vg_graphics.h index 863f1df..a21b8e4 100644 --- a/source/graphics/vg_graphics.h +++ b/source/graphics/vg_graphics.h @@ -1,3 +1,4 @@ +#pragma once /* Basic graphics * ------------------------------------------------------------------------------------------------------------------ */ @@ -41,6 +42,7 @@ enum blending_mode void _graphics_set_target( struct graphics_target *target ); void _graphics_viewport( i16 x, i16 y, i16 w, i16 h ); +void _graphics_get_viewport_rect( i16 rect[4] ); void _graphics_pixel_unclipped( i16 co[2], union colour colour ); void _graphics_pixel( i16 co[2], union colour colour ); void _graphics_push_blendmode( enum blending_mode mode ); @@ -118,6 +120,24 @@ enum ui_text_encoding k_ui_text_utf8 }; void _ui_set_encoding( enum ui_text_encoding encoding ); +enum ui_text_encoding _ui_get_encoding(void); // FIXME BAD +struct ui_string_decoder +{ + /* source */ + const c8 *string; + enum ui_text_encoding encoding; + + /* internal */ + u32 buffer_offset, character_index; + u32 utf8_counter; + + /* read from these */ + i16 grid_co[2]; + u32 c; +}; +u32 text_decoder_line_count( struct ui_string_decoder *decoder ); +void ui_string_decode_init( struct ui_string_decoder *decoder, const c8 *string, enum ui_text_encoding encoding ); +b8 ui_string_decode( struct ui_string_decoder *decoder ); enum ui_align { -- 2.25.1