From: hgn Date: Tue, 23 Apr 2024 20:30:54 +0000 (+0100) Subject: bad char X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=HEAD;hp=cc5c184b1264d2e33398c1a4c03e75fb42ca04f5 bad char --- diff --git a/src/fonts/vg_font_thin_3.png b/src/fonts/vg_font_thin_3.png index ad1f1f4..d3239dd 100644 Binary files a/src/fonts/vg_font_thin_3.png and b/src/fonts/vg_font_thin_3.png differ diff --git a/src/fonts/vg_font_thin_3.xcf b/src/fonts/vg_font_thin_3.xcf index 20f4098..66e8368 100644 Binary files a/src/fonts/vg_font_thin_3.xcf and b/src/fonts/vg_font_thin_3.xcf differ diff --git a/vg_build_font.h b/vg_build_font.h index 5278ca1..e743b46 100644 --- a/vg_build_font.h +++ b/vg_build_font.h @@ -111,6 +111,7 @@ void vg_build_default_font(void) vg_build_font_face_run( &small, 'a', 'z', 0, 28 ); vg_build_font_face_run( &small, '0', '9', 208,14 ); vg_build_font_face_run( &small, 0x7f, 0xa4, 0,42 ); + vg_build_font_face_run( &small, 0xb0, 0xb3, 208,28 ); vg_build_write_font_face( fp, &small ); vg_font_face large = @@ -123,11 +124,12 @@ void vg_build_default_font(void) vg_build_font_face_run( &large, '!', '/', 12, 56 ); vg_build_font_face_run( &large, '[', '`', 192,56 ); vg_build_font_face_run( &large, '{', '~', 264,56 ); - vg_build_font_face_run( &large, ':', '@', 324,56 ); + vg_build_font_face_run( &large, ':', '@', 312,56 ); vg_build_font_face_run( &large, 'A', 'Z', 0, 77 ); vg_build_font_face_run( &large, 'a', 'z', 0, 98 ); vg_build_font_face_run( &large, '0', '9', 312,77 ); vg_build_font_face_run( &large, 0x7f, 0xa4, 0,119 ); + vg_build_font_face_run( &large, 0xb0, 0xb3, 312,98 ); vg_build_write_font_face( fp, &large ); vg_font_face title = @@ -152,6 +154,7 @@ void vg_build_default_font(void) vg_build_font_face_run( &title, 0x7f, 0x88, 120,350 ); vg_build_font_face_run( &title, 0x93, 0x98, 360,350 ); vg_build_font_face_run( &title, 0x99, 0xa4, 0,392 ); + vg_build_font_face_run( &title, 0xb0, 0xb2, 288,392 ); vg_build_write_font_face( fp, &title ); fclose( fp ); diff --git a/vg_engine.c b/vg_engine.c index 1723c70..fe3a7e9 100644 --- a/vg_engine.c +++ b/vg_engine.c @@ -141,9 +141,6 @@ static void _vg_process_events(void) v2_zero( vg.mouse_wheel ); v2_zero( vg.mouse_delta ); - /* Update input */ - vg_process_inputs(); - /* SDL event loop */ SDL_Event event; while( SDL_PollEvent( &event ) ){ @@ -221,6 +218,7 @@ static void _vg_process_events(void) } SDL_GetMouseState( &vg.mouse_pos[0], &vg.mouse_pos[1] ); + vg_process_inputs(); } static void _vg_gameloop_update(void) diff --git a/vg_imgui.c b/vg_imgui.c index 51792ff..bb4f46f 100644 --- a/vg_imgui.c +++ b/vg_imgui.c @@ -740,7 +740,8 @@ void ui_prerender(void) return; } - if( ui_click_down(UI_MOUSE_LEFT)||ui_click_down(UI_MOUSE_MIDDLE) ) + if( ui_click_down(UI_MOUSE_LEFT)||ui_click_down(UI_MOUSE_MIDDLE)|| + ui_click_down(UI_MOUSE_RIGHT) ) { vg_ui.mouse_click[0] = vg_ui.mouse[0]; vg_ui.mouse_click[1] = vg_ui.mouse[1]; @@ -838,7 +839,7 @@ u32 ui_ntext( ui_rect rect, const char *str, u32 len, ui_px scale, text_cursor[0] -= vg_ui.font->sx*scale; ui_rect glyph; - ui_text_glyph( vg_ui.font, '\xb6' /*FIXME*/, glyph ); + ui_text_glyph( vg_ui.font, '\xb1' /*FIXME*/, glyph ); ui_fill_rect( text_cursor, 0x00ffffff, glyph ); text_cursor[0] += vg_ui.font->sx*scale; } @@ -997,92 +998,100 @@ void ui_defocus_all(void) vg_ui.focused_control_type = k_ui_control_none; } -/* TODO: split this out into a formatless button and one that auto fills */ -enum ui_button_state ui_colourbutton( ui_rect rect, - enum ui_scheme_colour colour, - enum ui_scheme_colour hover_colour, - enum ui_scheme_colour hi_colour, - bool const fill ) +enum ui_button_state ui_button_base( ui_rect rect ) { int clickup= ui_click_up(UI_MOUSE_LEFT), click = ui_clicking(UI_MOUSE_LEFT) | clickup, target = ui_inside_rect( rect, vg_ui.mouse_click ) && click, hover = ui_inside_rect( rect, vg_ui.mouse ); - u32 col_base = vg_ui.scheme[ colour ], - col_highlight = vg_ui.scheme[ hi_colour? hi_colour: k_ui_fg ], - col_hover = vg_ui.scheme[ hover_colour? hover_colour: - colour + k_ui_brighter ]; - - if( vg_ui.focused_control_type != k_ui_control_none ){ + if( vg_ui.focused_control_type != k_ui_control_none ) + { clickup = 0; click = 0; target = 0; hover = 0; } - if( hover ){ + if( hover ) vg_ui.cursor = k_ui_cursor_hand; - } - if( click ){ - if( target ){ - if( hover ){ - if( clickup ){ + if( click ) + { + if( target ) + { + if( hover ) + { + if( clickup ) + { vg_ui.ignore_input_frames = 2; ui_defocus_all(); - - if( fill ) { - ui_fill( rect, col_highlight ); - rect_copy( rect, vg_ui.click_fader ); - rect_copy( rect, vg_ui.click_fader_end ); - vg_ui.click_fader_end[3] = 0; - ui_rect_center( rect, vg_ui.click_fader_end ); - vg_ui.click_fade_opacity = 1.0f; - } - return k_ui_button_click; } - else{ - if( fill ) ui_fill( rect, col_highlight ); - return k_ui_button_holding_inside; - } + else return k_ui_button_holding_inside; } - else{ - if( fill ) ui_fill( rect, col_base ); - ui_outline( rect, 1, col_highlight, 0 ); - return k_ui_button_holding_outside; - } - } - else{ - if( fill ) ui_fill( rect, col_base ); - return k_ui_button_none; + else return k_ui_button_holding_outside; } + else return k_ui_button_none; } - else{ - if( hover ){ - if( fill ) ui_fill( rect, col_hover ); - return k_ui_button_hover; - } - else{ - if( fill ) ui_fill( rect, col_base ); - return k_ui_button_none; - } + else + { + if( hover ) return k_ui_button_hover; + else return k_ui_button_none; + } +} + +/* TODO: split this out into a formatless button and one that auto fills */ +enum ui_button_state ui_colourbutton( ui_rect rect, + enum ui_scheme_colour colour, + enum ui_scheme_colour hover_colour, + enum ui_scheme_colour hi_colour ) +{ + enum ui_button_state state = ui_button_base( rect ); + + u32 col_base = vg_ui.scheme[ colour ], + col_highlight = vg_ui.scheme[ hi_colour? hi_colour: k_ui_fg ], + col_hover = vg_ui.scheme[ hover_colour? hover_colour: + colour + k_ui_brighter ]; + + if( state == k_ui_button_click ) + { + ui_fill( rect, col_highlight ); + rect_copy( rect, vg_ui.click_fader ); + rect_copy( rect, vg_ui.click_fader_end ); + vg_ui.click_fader_end[3] = 0; + ui_rect_center( rect, vg_ui.click_fader_end ); + vg_ui.click_fade_opacity = 1.0f; + } + else if( state == k_ui_button_holding_inside ) + { + ui_fill( rect, col_highlight ); } + else if( state == k_ui_button_holding_outside ) + { + ui_fill( rect, col_base ); + ui_outline( rect, 1, col_highlight, 0 ); + } + else if( state == k_ui_button_hover ) + { + ui_fill( rect, col_hover ); + } + else ui_fill( rect, col_base ); + + return state; } enum ui_button_state ui_colourbutton_text( ui_rect rect, const char *string, ui_px scale, - enum ui_scheme_colour colour ){ - enum ui_button_state state = ui_colourbutton( rect, colour, 0, 0, 1 ); - ui_rect t = { 0,0, ui_text_line_width( string )*scale, 14*scale }; - ui_rect_center( rect, t ); + enum ui_scheme_colour colour ) +{ + enum ui_button_state state = ui_colourbutton( rect, colour, 0, 0 ); u32 text_colour = ui_colourcont(colour); if( state == k_ui_button_holding_inside ) text_colour = colour; - ui_text( t, string, scale, k_ui_align_left, text_colour ); + ui_text( rect, string, scale, k_ui_align_middle_center, text_colour ); return state; } @@ -1190,6 +1199,14 @@ void ui_postrender(void) * ----------------------------------------------------------------------------- */ +enum ui_button_state ui_checkbox_base( ui_rect box, i32 *data ) +{ + enum ui_button_state state = ui_button_base( box ); + if( state == k_ui_button_click ) + *data = (*data) ^ 0x1; + return state; +} + int ui_checkbox( ui_rect inout_panel, const char *str_label, i32 *data ) { ui_rect rect, label, box; @@ -1197,12 +1214,34 @@ int ui_checkbox( ui_rect inout_panel, const char *str_label, i32 *data ) ui_split( rect, k_ui_axis_v, -rect[3], 0, label, box ); ui_text( label, str_label, k_ui_scale, k_ui_align_middle_left, 0 ); + + enum ui_button_state state = ui_checkbox_base( box, data ); - int changed = ui_colourbutton( box, k_ui_bg, 0, 0, 1 )==1; - if( changed ) - *data = (*data) ^ 0x1; + if( state == k_ui_button_holding_inside ) + { + ui_fill( box, ui_colour(k_ui_bg+2) ); + ui_outline( box, 1, ui_colour(k_ui_fg), 0 ); + } + else if( state == k_ui_button_holding_outside ) + { + ui_fill( box, ui_colour(k_ui_bg) ); + ui_outline( box, 1, ui_colour(k_ui_fg), 0 ); + } + else if( state == k_ui_button_hover ) + { + ui_fill( box, ui_colour(k_ui_bg) ); + ui_outline( box, 1, ui_colour(k_ui_fg), 0 ); + } + else + { + ui_fill( box, ui_colour(k_ui_bg) ); + ui_outline( box, 1, ui_colour(k_ui_bg+4), 0 ); + } + + bool changed = (state == k_ui_button_click); - if( *data ){ + if( *data ) + { ui_rect_pad( box, (ui_px[2]){4,4} ); ui_fill( box, ui_colour( k_ui_orange ) ); } @@ -1292,57 +1331,67 @@ static void ui_enum_post(void){ * ----------------------------------------------------------------------------- */ -static enum ui_button_state _ui_slider( - ui_rect box, f32 min, f32 max, f32 *value, const char *format ) +enum ui_button_state ui_slider_base( + ui_rect box, f32 min, f32 max, f32 *value, f32 *out_t ) { - f32 t; - - enum ui_button_state - mask_using = - k_ui_button_holding_inside | - k_ui_button_holding_outside | - k_ui_button_click, - mask_brighter = - mask_using | k_ui_button_hover, - state = ui_colourbutton( box, k_ui_bg, k_ui_bg+2, k_ui_bg+3, 1 ); + enum ui_button_state mask_using = + k_ui_button_holding_inside | + k_ui_button_holding_outside | + k_ui_button_click, + state = ui_button_base( box ); - if( state & mask_using ){ - t = vg_clampf( (f32)(vg_ui.mouse[0] - box[0]) / (f32)( box[2] ), - 0.0f, 1.0f ); + f32 t; + if( state & mask_using ) + { + t = vg_clampf( (f32)(vg_ui.mouse[0] - box[0]) / (f32)( box[2] ), 0,1 ); *value = vg_lerpf( min, max, t ); } else t = vg_clampf( (*value - min) / (max-min), 0.0f, 1.0f ); - - ui_rect line = { box[0], box[1], t * (f32)box[2], box[3] }; - ui_fill( line, ui_colour(state&mask_brighter? k_ui_bg+4: k_ui_bg+2) ); - ui_outline( box, 1, ui_colour(state? k_ui_fg+3: k_ui_bg+3), 0 ); + *out_t = t; + + return state; +} +void ui_slider_text( ui_rect box, const char *format, f32 value ) +{ /* TODO: replace this one day with our own function */ char buf[32]; - snprintf( buf, sizeof(buf), format? format: "%.2f", *value ); + snprintf( buf, sizeof(buf), format? format: "%.2f", value ); ui_text( box, buf, 1, k_ui_align_middle_center, 0 ); - - return state; } -bool ui_slider( ui_rect inout_panel, const char *str_label, - f32 min, f32 max, f32 *value, const char *format ) +bool ui_slider_standard( ui_rect box, f32 min, f32 max, f32 *value, + const char *format ) { - ui_rect rect, label, box; - ui_standard_widget( inout_panel, rect, 1 ); - ui_label( rect, str_label, k_ui_scale, 0, box ); + f32 t; enum ui_button_state mask_using = k_ui_button_holding_inside | k_ui_button_holding_outside | - k_ui_button_click; + k_ui_button_click, + mask_brighter = mask_using | k_ui_button_hover, + state = ui_slider_base( box, min, max, value, &t ); - if( _ui_slider( box, min, max, value, format ) & mask_using ) - return 1; - else - return 0; + ui_rect line = { box[0], box[1], t * (f32)box[2], box[3] }; + ui_fill( line, ui_colour(state&mask_brighter? k_ui_bg+4: k_ui_bg+2) ); + + ui_fill( (ui_rect){ box[0]+line[2], box[1], box[2]-line[2], box[3] }, + ui_colour( k_ui_bg ) ); + ui_outline( box, 1, ui_colour(state? k_ui_fg+3: k_ui_bg+3), 0 ); + ui_slider_text( box, NULL, *value ); + + return (state & mask_using) && 1; +} + +bool ui_slider( ui_rect inout_panel, const char *str_label, + f32 min, f32 max, f32 *value ) +{ + ui_rect rect, label, box; + ui_standard_widget( inout_panel, rect, 1 ); + ui_label( rect, str_label, k_ui_scale, 0, box ); + return ui_slider_standard( box, min, max, value, NULL ); } /* @@ -1367,8 +1416,9 @@ void ui_colourpicker( ui_rect inout_panel, const char *str_label, v4f value ) enum ui_button_state modified = 0x00; - for( u32 i=0; i<4; i ++ ){ - modified |= _ui_slider( sliders[i], 0.0f, 1.0f, hsv+i, + for( u32 i=0; i<4; i ++ ) + { + modified |= ui_slider_standard( sliders[i], 0.0f, 1.0f, hsv+i, (const char *[]){ "hue %.2f", "sat %.2f", "lum %.2f", @@ -1378,7 +1428,7 @@ void ui_colourpicker( ui_rect inout_panel, const char *str_label, v4f value ) ui_rect preview, square; ui_split_ratio( left, k_ui_axis_v, 0.8f, 8, square, preview ); - u32 state = ui_colourbutton( square, 0, 0, 0, 0 ); + u32 state = ui_button_base( square ); modified |= state; enum ui_button_state @@ -1387,7 +1437,8 @@ void ui_colourpicker( ui_rect inout_panel, const char *str_label, v4f value ) k_ui_button_holding_outside | k_ui_button_click; - if( state & mask_using ){ + if( state & mask_using ) + { for( u32 i=0; i<2; i ++ ){ hsv[1+i] = vg_clampf( (f32)(vg_ui.mouse[i] - square[i]) / (f32)(square[2+i]), @@ -1398,7 +1449,8 @@ void ui_colourpicker( ui_rect inout_panel, const char *str_label, v4f value ) } if( modified & (k_ui_button_click|k_ui_button_holding_inside| - k_ui_button_holding_outside) ){ + k_ui_button_holding_outside) ) + { vg_hsv_rgb( hsv, value ); value[3] = hsv[3]; } @@ -1437,7 +1489,8 @@ void ui_colourpicker( ui_rect inout_panel, const char *str_label, v4f value ) * ----------------------------------------------------------------------------- */ -static void _ui_textbox_make_selection( int *start, int *end ){ +static void _ui_textbox_make_selection( int *start, int *end ) +{ *start = VG_MIN( vg_ui.textbox.cursor_pos, vg_ui.textbox.cursor_user ); *end = VG_MAX( vg_ui.textbox.cursor_pos, vg_ui.textbox.cursor_user ); } @@ -1455,7 +1508,8 @@ void _ui_textbox_move_cursor( int *cursor0, int *cursor1, *cursor1 = *cursor0; } -static int _ui_textbox_makeroom( int datastart, int length ){ +static int _ui_textbox_makeroom( int datastart, int length ) +{ int move_to = VG_MIN( datastart+length, vg_ui.textbox.len-1 ); int move_amount = strlen( vg_ui.textbuf )-datastart; int move_end = VG_MIN( move_to+move_amount, vg_ui.textbox.len-1 ); @@ -1494,7 +1548,8 @@ int _ui_textbox_delete_char( int direction ) return start; } -static void _ui_textbox_to_clipboard(void){ +static void _ui_textbox_to_clipboard(void) +{ int start, end; _ui_textbox_make_selection( &start, &end ); char buffer[512]; @@ -1506,7 +1561,8 @@ static void _ui_textbox_to_clipboard(void){ } } -static void _ui_textbox_change_callback(void){ +static void _ui_textbox_change_callback(void) +{ if( vg_ui.textbox.callbacks.change ){ vg_ui.textbox.callbacks.change( vg_ui.textbuf, vg_ui.textbox.len ); @@ -1518,7 +1574,8 @@ static void _ui_textbox_change_callback(void){ } void ui_start_modal( const char *message, u32 options ); -static void _ui_textbox_clipboard_paste(void){ +static void _ui_textbox_clipboard_paste(void) +{ if( !SDL_HasClipboardText() ) return; diff --git a/vg_imgui.h b/vg_imgui.h index 82468e3..8ec0330 100644 --- a/vg_imgui.h +++ b/vg_imgui.h @@ -262,24 +262,30 @@ void ui_standard_widget( ui_rect inout_panel, ui_rect out_rect, ui_px count ); void ui_info( ui_rect inout_panel, const char *text ); void ui_image( ui_rect rect, GLuint image ); void ui_defocus_all(void); + +enum ui_button_state ui_button_base( ui_rect rect ); enum ui_button_state ui_colourbutton( ui_rect rect, enum ui_scheme_colour colour, enum ui_scheme_colour hover_colour, - enum ui_scheme_colour hi_colour, - bool const fill ); + enum ui_scheme_colour hi_colour ); enum ui_button_state ui_colourbutton_text( ui_rect rect, const char *string, ui_px scale, enum ui_scheme_colour colour ); enum ui_button_state ui_button_text( ui_rect rect, const char *string, ui_px scale ); enum ui_button_state ui_button( ui_rect inout_panel, const char *string ); + void ui_postrender(void); +enum ui_button_state ui_checkbox_base( ui_rect box, i32 *data ); int ui_checkbox( ui_rect inout_panel, const char *str_label, i32 *data ); void ui_enum( ui_rect inout_panel, const char *str_label, struct ui_enum_opt *options, u32 len, i32 *value ); +enum ui_button_state ui_slider_base( ui_rect box, f32 min, f32 max, f32 *value, + f32 *out_t ); bool ui_slider( ui_rect inout_panel, const char *str_label, - f32 min, f32 max, f32 *value, const char *format ); + f32 min, f32 max, f32 *value ); +void ui_slider_text( ui_rect box, const char *format, f32 value ); void ui_colourpicker( ui_rect inout_panel, const char *str_label, v4f value ); int ui_textbox( ui_rect inout_panel, const char *label, char *buf, u32 len, u32 lines, u32 flags, diff --git a/vg_input.c b/vg_input.c index 74732f4..d4e51bc 100644 --- a/vg_input.c +++ b/vg_input.c @@ -128,13 +128,33 @@ void vg_input_device_event( SDL_Event *ev ) } } +static void vg_input_set_active_controller( int index, const char *why ) +{ + if( vg_input.active_controller_index != index ) + { + vg_input.display_input_type = + SDL_GameControllerGetType( vg_input.controllers[index].handle ); + vg_input.active_controller_index = index; + vg_info( "Switching controller index to #%d. (%s)\n", index, why ); + } + + if( vg_input.display_input_method != k_input_method_controller ) + { + vg_input.display_input_method = k_input_method_controller; + vg_info( "Switching input method to controller. (%s)\n", why ); + } +} + void vg_input_controller_event( SDL_Event *ev ) { - if( ev->type == SDL_CONTROLLERAXISMOTION ){ - for( int i=0; itype == SDL_CONTROLLERAXISMOTION ) + { + for( int i=0; icaxis.which == esta->instance_id ){ + if( ev->caxis.which == esta->instance_id ) + { float value = (float)ev->caxis.value / 32767.0f; if( ev->caxis.axis == SDL_CONTROLLER_AXIS_LEFTX || @@ -146,6 +166,8 @@ void vg_input_controller_event( SDL_Event *ev ) high = vg_maxf( 0.0f, fabsf(value) - deadz ); value = vg_signf(value) * (high / (1.0f-deadz)); + if( fabsf(value) > 0.5f ) + vg_input_set_active_controller( i, "Stick pushed >|0.5|" ); } esta->axises[ ev->caxis.axis ] = value; @@ -153,50 +175,26 @@ void vg_input_controller_event( SDL_Event *ev ) } } } - else if( ev->type == SDL_CONTROLLERBUTTONDOWN ){ - struct vg_controller *active = NULL; - - if( vg_input.active_controller_index >= 0 ) - active = &vg_input.controllers[vg_input.active_controller_index]; - - if( !active || (ev->cbutton.which != active->instance_id) ){ - active = NULL; - vg_input.active_controller_index = -1; - vg_input.display_input_method = k_input_method_kbm; - - for( int i=0; icbutton.which ){ - active = &vg_input.controllers[i]; - vg_input.active_controller_index = i; - vg_input.display_input_type = - SDL_GameControllerGetType(active->handle); - break; - } - } - - if( active ){ - vg_info( "Switching active controller index to #%d\n", - vg_input.active_controller_index ); - } - else{ - vg_error( "Input out of range (SDL_JoystickID#%d)\n", - ev->cbutton.which ); - } - } - - if( active ){ - if( vg_input.display_input_method != k_input_method_controller ){ - vg_input.display_input_method = k_input_method_controller; - vg_info( "display_input: k_input_method_controller\n" ); + else if( ev->type == SDL_CONTROLLERBUTTONDOWN ) + { + for( int i=0; iinstance_id == ev->cbutton.which ) + { + vg_input_set_active_controller( i, "Button press" ); + esta->buttons[ ev->cbutton.button ] = 1; + break; } - active->buttons[ ev->cbutton.button ] = 1; } } - else if( ev->type == SDL_CONTROLLERBUTTONUP ){ - for( int i=0; itype == SDL_CONTROLLERBUTTONUP ) + { + for( int i=0; icbutton.which == esta->instance_id ){ + if( ev->cbutton.which == esta->instance_id ) + { esta->buttons[ ev->cbutton.button ] = 0; break; } @@ -210,10 +208,13 @@ void vg_process_inputs(void) vg_input.sdl_keys = SDL_GetKeyboardState( &count ); vg_input.sdl_mouse = SDL_GetMouseState(NULL,NULL); - if( vg_input.display_input_method != k_input_method_kbm ){ + if( vg_input.display_input_method != k_input_method_kbm ) + { /* check for giving keyboard priority */ - for( int i=0; i 64.0f ) + { + vg_input.display_input_method = k_input_method_kbm; + vg_input.hidden_mouse_travel = 0.0f; + vg_info( "display_input: k_input_method_kbm (mouse move)\n" ); } } + else + vg_input.hidden_mouse_travel = 0.0f; } void async_vg_input_init( void *payload, u32 size ) diff --git a/vg_input.h b/vg_input.h index a203123..1636e07 100644 --- a/vg_input.h +++ b/vg_input.h @@ -47,6 +47,7 @@ struct vg_input { const u8 *sdl_keys; u32 sdl_mouse; + f32 hidden_mouse_travel; struct vg_controller{ SDL_GameController *handle; /* handle for controller. NULL if unused */ diff --git a/vg_string.c b/vg_string.c index 1261f5b..ef29ef3 100644 --- a/vg_string.c +++ b/vg_string.c @@ -69,37 +69,49 @@ static i32 vg_str_dynamic_grow( vg_str *str ) } } -void vg_strcat( vg_str *str, const char *append ) +static void _vg_strcatch( vg_str *str, char c ) { - if( !append || (str->i == -1) ) return; - - i32 max = vg_str_storage( str ), - i = 0; + if( str->i == -1 ) return; -append: - if( str->i == max ){ + i32 max = vg_str_storage( str ); + if( str->i == max ) + { if( str->len == -1 ) max = vg_str_dynamic_grow( str ); - else{ + else + { str->i = -1; str->buffer[ max-1 ] = '\0'; return; } } - char c = append[ i ++ ]; - str->buffer[ str->i ] = c; + str->buffer[ str->i ++ ] = c; +} + +void vg_strcat( vg_str *str, const char *append ) +{ + if( !append || (str->i == -1) ) return; + + i32 i = 0; + +append:; + char c = append[ i ++ ]; + _vg_strcatch( str, c ); if( c == '\0' ) + { + str->i --; return; - - str->i ++; - goto append; + } + else goto append; } void vg_strcatch( vg_str *str, char c ) { - vg_strcat( str, (char[]){ c, '\0' } ); + _vg_strcatch( str, c ); + _vg_strcatch( str, '\x00' ); + str->i --; } /*