From: hgn Date: Mon, 11 Mar 2024 15:24:32 +0000 (+0000) Subject: slider api change X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=2c7ca232199368af22640bf3e59f07575009d8cb;hp=0dc955d83db73c25f74ca1f6917632415d5c36ee;p=vg.git slider api change --- diff --git a/vg_imgui.c b/vg_imgui.c index 21936cc..08209b7 100644 --- a/vg_imgui.c +++ b/vg_imgui.c @@ -704,6 +704,14 @@ int ui_click_up( u32 mask ) return 0; } +void ui_set_mouse_pos( ui_px x, ui_px y ) +{ + SDL_WarpMouseInWindow( vg.window, x, y ); + vg_ui.mouse[0] = x; + vg_ui.mouse[1] = y; + vg_ui.mouse_pos_overriden = 1; +} + void ui_prerender(void) { int x, y; @@ -711,8 +719,12 @@ void ui_prerender(void) vg_ui.mouse_state[0] = SDL_GetMouseState( &x, &y ); vg_ui.mouse_delta[0] = x-vg_ui.mouse[0]; vg_ui.mouse_delta[1] = y-vg_ui.mouse[1]; - vg_ui.mouse[0] = x; - vg_ui.mouse[1] = y; + + if( !vg_ui.mouse_pos_overriden ) + { + vg_ui.mouse[0] = x; + vg_ui.mouse[1] = y; + } vg_ui.cur_vert = 0; vg_ui.cur_indice = 0; @@ -721,13 +733,16 @@ void ui_prerender(void) vg_ui.focused_control_hit = 0; vg_ui.cursor = k_ui_cursor_default; vg_ui.wants_mouse = 0; + vg_ui.mouse_pos_overriden = 0; - if( vg_ui.ignore_input_frames ){ + if( vg_ui.ignore_input_frames ) + { vg_ui.ignore_input_frames --; 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) ) + { vg_ui.mouse_click[0] = vg_ui.mouse[0]; vg_ui.mouse_click[1] = vg_ui.mouse[1]; } @@ -1284,13 +1299,22 @@ static enum ui_button_state _ui_slider( return state; } -void ui_slider( ui_rect inout_panel, const char *str_label, +bool ui_slider( ui_rect inout_panel, const char *str_label, 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 ); - _ui_slider( box, min, max, value, format ); + + enum ui_button_state mask_using = + k_ui_button_holding_inside | + k_ui_button_holding_outside | + k_ui_button_click; + + if( _ui_slider( box, min, max, value, format ) & mask_using ) + return 1; + else + return 0; } /* diff --git a/vg_imgui.h b/vg_imgui.h index 4e725a8..f2d4f05 100644 --- a/vg_imgui.h +++ b/vg_imgui.h @@ -192,6 +192,7 @@ struct vg_imgui ui_px mouse[2], mouse_delta[2], mouse_click[2]; u32 mouse_state[2]; u32 ignore_input_frames; + bool mouse_pos_overriden; int wants_mouse; ui_rect click_fader, click_fader_end; @@ -248,6 +249,7 @@ int ui_inside_rect( ui_rect rect, ui_px co[2] ); int ui_click_down( u32 mask ); int ui_clicking( u32 mask ); int ui_click_up( u32 mask ); +void ui_set_mouse_pos( ui_px x, ui_px y ); void ui_prerender(void); u32 ui_colour( enum ui_scheme_colour id ); @@ -285,7 +287,7 @@ void ui_postrender(void); 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 ); -void ui_slider( ui_rect inout_panel, const char *str_label, +bool ui_slider( ui_rect inout_panel, const char *str_label, f32 min, f32 max, f32 *value, const char *format ); void ui_colourpicker( ui_rect inout_panel, const char *str_label, v4f value ); int ui_textbox( ui_rect inout_panel, const char *label,