summaryrefslogtreecommitdiff
path: root/src/gui/base.cpp
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-08-11 19:10:16 +0200
committeraura <nw@moneybot.cc>2026-08-11 19:10:16 +0200
commit17c07b5f884453130d8be3a6d91d730d80d4f8ae (patch)
tree6ec11e5e5f7f0be9ed899196c2897aa76a907de2 /src/gui/base.cpp
parent1aa17de9188790f049c0edc4281597cb4e535627 (diff)
parent0a9d7ce6a0764a87766ebb23cc1ece4c26c8c678 (diff)
Merge remote-tracking branch 'origin/day'
Diffstat (limited to 'src/gui/base.cpp')
-rw-r--r--src/gui/base.cpp70
1 files changed, 51 insertions, 19 deletions
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 ) {