Index: ChangeLog =================================================================== RCS file: /cvsroot/xforms/xforms/ChangeLog,v retrieving revision 1.100 diff -u -p -r1.100 ChangeLog --- ChangeLog 6 May 2004 12:21:45 -0000 1.100 +++ ChangeLog 6 May 2004 12:28:27 -0000 @@ -1,5 +1,21 @@ 2004-05-06 Angus Leeming + * lib/private/pvaluator.h (repeat_ms, timeout_id, mouse_pos): + new variables. + * lib/include/slider.[ch] (fl_[sg]et_slider_repeat): + * lib/include/counter.[ch] (fl_[sg]et_counter_repeat): + new accessor functions, enabling the user to query and modify the + timeout used to control the behaviour of these widgets when the + mouse is kept pressed down. + + * lib/include/slider.[ch] (handle_mouse): + * lib/include/counter.[ch] (handle_mouse): use a timeout to + control the rate at which the slider/counter is incremented. + Replaces the current strategy which used a simple counter loop and + which has become unusable with today's fast processors. + +2004-05-06 Angus Leeming + * fdesign/fd_spec.c: revert the change made earlier today. Turned out to be used in the demos code... Index: lib/counter.c =================================================================== RCS file: /cvsroot/xforms/xforms/lib/counter.c,v retrieving revision 1.6 diff -u -p -r1.6 counter.c --- lib/counter.c 24 Apr 2003 09:35:34 -0000 1.6 +++ lib/counter.c 6 May 2004 12:28:28 -0000 @@ -53,8 +53,6 @@ enum NONE, OB0 = 1, OB1 = 2, OB2 = 4, OB3 = 8, OB4 = 16, ALL = 31 }; -static int timdel; /* Delay since last value change */ - /* Draws a counter */ static void draw_counter(FL_OBJECT * ob) @@ -187,6 +185,29 @@ calc_mouse_obj(FL_OBJECT * ob, FL_Coord } + +int fl_get_counter_repeat(FL_OBJECT * ob) +{ + SPEC * sp = (SPEC *) ob->spec; + return sp->repeat_ms; +} + + +void fl_set_counter_repeat(FL_OBJECT * ob, int millisec) +{ + SPEC * sp = (SPEC *) ob->spec; + sp->repeat_ms = millisec; +} + + +static void +timeoutCB(int val, void * data) +{ + SPEC * sp = (SPEC *)data; + sp->timeout_id = -1; +} + + /* handles an event on ob */ static int handle_mouse(FL_OBJECT * ob, int event, FL_Coord mx, FL_Coord my) @@ -205,14 +226,15 @@ handle_mouse(FL_OBJECT * ob, int event, calc_mouse_obj(ob, mx, my); if (sp->mouseobj != NONE) changeval = 1; - timdel = 1; + sp->timeout_id = -1; } else if (event == FL_MOUSE && sp->mouseobj != NONE) - changeval = (timdel++ > 10 && (timdel & 1) == 0); + changeval = sp->timeout_id == -1; if (changeval) { double oval = sp->val; + sp->timeout_id = fl_add_timeout(sp->repeat_ms, timeoutCB, sp); if (sp->mouseobj == OB0) sp->val -= sp->lstep; @@ -354,6 +376,10 @@ fl_create_counter(int type, FL_Coord x, sp->mouseobj = NONE; sp->draw_type = ALL; sp->how_return = FL_RETURN_END_CHANGED; + + sp->repeat_ms = 100; + sp->timeout_id = -1; + return ob; } Index: lib/slider.c =================================================================== RCS file: /cvsroot/xforms/xforms/lib/slider.c,v retrieving revision 1.7 diff -u -p -r1.7 slider.c --- lib/slider.c 9 Sep 2003 00:28:25 -0000 1.7 +++ lib/slider.c 6 May 2004 12:28:28 -0000 @@ -296,8 +296,28 @@ get_newvalue(FL_OBJECT * ob, FL_Coord mx return (sp->min + newval * (sp->max - sp->min)); } -static int timdel; -static int mpos; /* < 0 below knob, 0 on knob, > 0 above knob */ + +int fl_get_slider_repeat(FL_OBJECT * ob) +{ + SPEC * sp = (SPEC *) ob->spec; + return sp->repeat_ms; +} + + +void fl_set_slider_repeat(FL_OBJECT * ob, int millisec) +{ + SPEC * sp = (SPEC *) ob->spec; + sp->repeat_ms = millisec; +} + + +static void +timeoutCB(int val, void * data) +{ + SPEC * sp = (SPEC *)data; + sp->timeout_id = -1; +} + /* Handle a mouse position change */ static int @@ -307,17 +327,20 @@ handle_mouse(FL_OBJECT * ob, FL_Coord mx float newval; /* mouse on trough */ - if (mpos && (sp->rdelta + sp->ldelta) > 0.0f) + if (sp->mouse_pos && (sp->rdelta + sp->ldelta) > 0.0f) { - if (timdel++ == 0 || (timdel > 11 && (timdel & 1) == 0)) + if (sp->timeout_id == -1) { + sp->timeout_id = fl_add_timeout(sp->repeat_ms, timeoutCB, sp); if (key == FL_LEFT_MOUSE) - newval = sp->val + mpos * sp->ldelta; + newval = sp->val + sp->mouse_pos * sp->ldelta; else - newval = sp->val + mpos * sp->rdelta; + newval = sp->val + sp->mouse_pos * sp->rdelta; } else + { return 0; + } } else newval = get_newvalue(ob, mx, my); @@ -329,7 +352,7 @@ handle_mouse(FL_OBJECT * ob, FL_Coord mx sp->val = newval; sp->norm_val = (sp->min == sp->max) ? 0.5f : (sp->val - sp->min) / (sp->max - sp->min); - sp->draw_type = mpos ? SLIDER_JUMP : SLIDER_MOTION; + sp->draw_type = sp->mouse_pos ? SLIDER_JUMP : SLIDER_MOTION; fl_redraw_object(ob); return 1; } @@ -395,7 +418,8 @@ handle_it(FL_OBJECT * ob, int event, FL_ } break; case FL_PUSH: - timdel = mpos = 0; + sp->timeout_id = -1; + sp->mouse_pos = 0; sp->start_val = sp->val; sp->offx = sp->offy = 0; lmx = lmy = -1; @@ -421,11 +445,11 @@ handle_it(FL_OBJECT * ob, int event, FL_ else { float newval = get_newvalue(ob, mx, my); - mpos = (newval > sp->val) ? 1 : -1; + sp->mouse_pos = (newval > sp->val) ? 1 : -1; } case FL_MOUSE: /* need to fix get_pos before removing this */ - if (mx == lmx && my == lmy && mpos == 0) + if (mx == lmx && my == lmy && sp->mouse_pos == 0) break; handle_mouse(ob, mx, my, key); @@ -439,6 +463,11 @@ handle_it(FL_OBJECT * ob, int event, FL_ return 1; break; case FL_RELEASE: + + if (sp->timeout_id != -1) { + fl_remove_timeout(sp->timeout_id); + sp->timeout_id = -1; + } if (is_focus(ob->type)) { fl_redraw_object(ob); @@ -491,6 +520,10 @@ create_it(int objclass, int type, FL_Coo sp->slsize *= 1.5; sp->prec = 2; sp->how_return = FL_RETURN_CHANGED; + + sp->repeat_ms = 100; + sp->timeout_id = -1; + sp->mouse_pos = 0; fl_set_object_dblbuffer(ob, 1 /* is_fill(ob->type) || is_nice(ob->type) */ ); Index: lib/include/counter.h =================================================================== RCS file: /cvsroot/xforms/xforms/lib/include/counter.h,v retrieving revision 1.2 diff -u -p -r1.2 counter.h --- lib/include/counter.h 10 Apr 2003 20:46:37 -0000 1.2 +++ lib/include/counter.h 6 May 2004 12:28:28 -0000 @@ -117,5 +117,16 @@ FL_EXPORT void fl_set_counter_filter( FL_VAL_FILTER filter ); +/** Functions to set and get the timeout value used by the + * counter code to control modification of the counter value. + */ +FL_EXPORT int fl_get_counter_repeat( + FL_OBJECT * ob + ); + +FL_EXPORT void fl_set_counter_repeat( + FL_OBJECT * ob, + int millisec + ); #endif Index: lib/include/slider.h =================================================================== RCS file: /cvsroot/xforms/xforms/lib/include/slider.h,v retrieving revision 1.3 diff -u -p -r1.3 slider.h --- lib/include/slider.h 9 Sep 2003 00:28:25 -0000 1.3 +++ lib/include/slider.h 6 May 2004 12:28:28 -0000 @@ -167,6 +167,18 @@ FL_EXPORT void fl_set_slider_filter( FL_VAL_FILTER filter ); +/** Functions to set and get the timeout value used by the + slider code to increment the position of the knob. + */ +FL_EXPORT int fl_get_slider_repeat( + FL_OBJECT *ob + ); + +FL_EXPORT void fl_set_slider_repeat( + FL_OBJECT *ob, + int millisec + ); + #endif Index: lib/private/pvaluator.h =================================================================== RCS file: /cvsroot/xforms/xforms/lib/private/pvaluator.h,v retrieving revision 1.3 diff -u -p -r1.3 pvaluator.h --- lib/private/pvaluator.h 9 Sep 2003 00:28:26 -0000 1.3 +++ lib/private/pvaluator.h 6 May 2004 12:28:29 -0000 @@ -67,6 +67,9 @@ typedef struct int changed; unsigned int mouseobj; int cross_over; /* allow cross over */ + int repeat_ms; + int timeout_id; + int mouse_pos; /* < 0 below knob, 0 on knob, > 0 above knob */ } FL_VALUATOR_SPEC;