From 2973df584978d9aae6f164ce0204179c8a28b3ae Mon Sep 17 00:00:00 2001 From: 2lag <96544487+2lag@users.noreply.github.com> Date: Sat, 8 Aug 2026 17:33:36 +0200 Subject: console, textbox changes, some other shit --- src/gui/base.cpp | 70 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 19 deletions(-) (limited to 'src/gui/base.cpp') diff --git a/src/gui/base.cpp b/src/gui/base.cpp index 79299de..153d82b 100644 --- a/src/gui/base.cpp +++ b/src/gui/base.cpp @@ -110,6 +110,23 @@ void gui_free( GUI_BASE* node ) { delete node; } +void gui_shutdown() { + _gui.callbacks.clear(); + _gui.clip_rects.clear(); + _gui.cur_view = 0; + _gui.cur_window = 0; + + while( _gui.windows.size ) { + GUI_WINDOW* wnd = _gui.windows[ + _gui.windows.size - 1 + ]; + gui_free( wnd ); + } + _gui.batch = 0; + _gui.fonts.jpn12.glfnt = 0; + _gui.fonts.jpn16.glfnt = 0; +} + I32 gui_relx( GUI_BASE* node ) { I32 x = node->x; for( GUI_BASE* p = node->parent; !!p; p = p->parent ) { @@ -283,47 +300,62 @@ GL_FONT* gui_font_from_idx( U32 fnt ) { return pfnt->glfnt; } -void gui_draw_str_internal( I32 x, I32 y, U8 align, U32 fnt, CLR col, const char* str ) { +void gui_draw_get_str_bounds_internal( I32* w, I32* h, U32 fnt, const char* buf ) { GL_FONT* pfnt = gui_font_from_idx( fnt ); if( !pfnt ) return; - I32 w; - gui_draw_get_str_bounds( &w, 0, fnt, str ); - switch( align ) { - case ALIGN_R: x -= w; break; - case ALIGN_C: x -= (I32)( w * 0.5f ); break; - } - - gl_font_draw( pfnt, _gui.batch, { (F32)x, (F32)y }, str, col ); + VEC2 dim = gl_font_dim( pfnt, buf ); + if( w ) *w = dim.x; + if( h ) *h = dim.y; } -void gui_draw_str( I32 x, I32 y, U8 align, U32 fnt, CLR col, const char* fmt, ... ) { +void gui_draw_get_str_bounds( I32* w, I32* h, U32 fnt, const char *fmt, ... ) { va_list args; va_start( args, fmt ); char buf[GUI_STR_BUF_MAX]; - vsprintf( buf, fmt, args ); + I32 result = vsnprintf( + buf, sizeof( buf ), + fmt, args + ); va_end( args ); - gui_draw_str_internal( x, y, align, fnt, col, buf ); + if( result < 0 ) + return; + + buf[sizeof( buf ) - 1] = 0; + gui_draw_get_str_bounds_internal( w, h, fnt, buf ); } -void gui_draw_get_str_bounds_internal( I32* w, I32* h, U32 fnt, const char* buf ) { +void gui_draw_str_internal( I32 x, I32 y, U8 align, U32 fnt, CLR col, const char* str ) { GL_FONT* pfnt = gui_font_from_idx( fnt ); if( !pfnt ) return; - VEC2 dim = gl_font_dim( pfnt, buf ); - if( w ) *w = dim.x; - if( h ) *h = dim.y; + I32 w; + gui_draw_get_str_bounds_internal( &w, 0, fnt, str ); + switch( align ) { + case ALIGN_R: x -= w; break; + case ALIGN_C: x -= (I32)( w * 0.5f ); break; + } + + gl_font_draw( pfnt, _gui.batch, { (F32)x, (F32)y }, str, col ); } -void gui_draw_get_str_bounds( I32* w, I32* h, U32 fnt, const char *fmt, ... ) { +void gui_draw_str( I32 x, I32 y, U8 align, U32 fnt, CLR col, const char* fmt, ... ) { va_list args; va_start( args, fmt ); char buf[GUI_STR_BUF_MAX]; - vsprintf( buf, fmt, args ); + I32 result = vsnprintf( + buf, sizeof( buf ), + fmt, args + ); va_end( args ); - gui_draw_get_str_bounds_internal( w, h, fnt, buf ); + if( result < 0 ) + return; + + buf[sizeof( buf ) - 1] = 0; + + gui_draw_str_internal( x, y, align, fnt, col, buf ); } void gui_draw_get_clip( I32 *x, I32 *y, I32 *w, I32 *h ) { -- cgit v1.2.3