diff --git a/src/g_hslider.c b/src/g_hslider.c index 8826d837f10d6f13c8c6fd0daaec08fc07f7018a..cf1c4339f3f1231d01482d3c810a37ea8dd66738 100644 --- a/src/g_hslider.c +++ b/src/g_hslider.c @@ -33,6 +33,9 @@ static void hslider_draw_select(t_hslider* x,t_glist* glist); t_widgetbehavior hslider_widgetbehavior; static t_class *hslider_class; +static double last; +static int is_last_float = 0; + /* widget helper functions */ static void hslider_draw_update(t_gobj *client, t_glist *glist) @@ -350,6 +353,9 @@ static void hslider__clickhook(t_scalehandle *sh, t_floatarg f, t_floatarg xxx, if (sh->h_dragx || sh->h_dragy) { + double width_change_ratio = (double)(x->x_gui.x_w + sh->h_dragx - x->x_gui.scale_offset_x)/(double)x->x_gui.x_w; + x->x_val = x->x_val * width_change_ratio; + x->x_gui.x_w = x->x_gui.x_w + sh->h_dragx - x->x_gui.scale_offset_x; if (x->x_gui.x_w < SCALE_HSLD_MINWIDTH) x->x_gui.x_w = SCALE_HSLD_MINWIDTH; @@ -671,8 +677,12 @@ static void hslider_bang(t_hslider *x) if(x->x_lin0_log1) out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01); - else - out = (double)(x->x_val)*0.01*x->x_k + x->x_min; + else { + if (is_last_float && last <= x->x_max && last >= x->x_min) + out = last; + else + out = (double)(x->x_val)*0.01*x->x_k + x->x_min; + } if((out < 1.0e-10)&&(out > -1.0e-10)) out = 0.0; outlet_float(x->x_gui.x_obj.ob_outlet, out); @@ -720,6 +730,7 @@ static void hslider_dialog(t_hslider *x, t_symbol *s, int argc, t_atom *argv) static void hslider_motion(t_hslider *x, t_floatarg dx, t_floatarg dy) { + is_last_float = 0; int old = x->x_val; if(x->x_gui.x_fsf.x_finemoved) @@ -842,12 +853,18 @@ static void hslider_steady(t_hslider *x, t_floatarg f) static void hslider_float(t_hslider *x, t_floatarg f) { double out; + is_last_float = 1; + last = f; hslider_set(x, f); if(x->x_lin0_log1) out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01); else - out = (double)(x->x_val)*0.01*x->x_k + x->x_min; + if (f <= x->x_max && f >= x->x_min) { + out = f; + //x->x_val = f; + } else + out = (double)(x->x_val)*0.01*x->x_k + x->x_min; if((out < 1.0e-10)&&(out > -1.0e-10)) out = 0.0; if(x->x_gui.x_fsf.x_put_in2out)