On 17 Jun 2008, at 18:28, Jane wrote:
> Works great, thank you. I came up with a slightly improved version:
>
> int
> Slider::handle(int ev)
> {
>     // do the base-class actions
>     int res = Fl_Slider::handle(ev);
>
>     // now check for wheel-mouse events & if we are below the pointer
>     if (ev == FL_MOUSEWHEEL && this == Fl::belowmouse())
>     {
>         // for wheel - use dy
>         int dy = Fl::event_dy();
>         double v1 = value(); // current value

If it were me, I'd evaluate:

        double v2 = clamp(increment(v1, dy));

at this point, and use it in the subsequent comparison, and to set  
the value if required.
Just to save evaluating increment(...) twice.


>         if (v1 == clamp(increment(v1, dy))) // save midi bandwidth :)
>             return 1;
>         v1 = increment(v1, dy); // change
>         value(v1); // update widget
>         do_callback(); // trigger callback
>         return 1; // say we ate this event
>     }
>     return res;
> } // handle
>
>
> (I also backported FLTK 1.1.9 to Debian/etch, anyone interested?)  
> *Happy* :)


./configure ; make ; make install - who needs package managers!?   ;-)

(Well, actually, ./configure --enable-threads --enable-xft usually!)




> I tried to make a SpinnerM class (Spinner with Mousewheel support)  
> but failed.
>
> int
> SpinnerM::handle(int ev)
> {
>     int res = Fl_Spinner::handle(ev);
>     if (ev == FL_MOUSEWHEEL && this == Fl::belowmouse())
>     {
>         int dy = Fl::event_dy();
>         double v1 = value();

I'd suggest you get the step() size here and use that to scale dy  
accordingly, so that the scroll-wheel matches the range and step of  
the spinner better.


>         if (v1 + dy == minimum() || v1 + dy == maximum())
>             return 1;
>         value(v1 + dy);
>         do_callback();
>         return 1;
>     }
>     return res;
> }
>
>
> It never enters the if(). Is there no FL_MOUSEWHEEL event for  
> spinners?

It's not the FL_MOUSEWHEEL that fails, it's the belowmouse(). If you  
remove that from the test, it works OK.
Not sure why that doesn't work right - may be a bug. Presumably it's  
because a spinner is a composite widget, not a straightforward  
valuator, I guess. Still, it's odd it doesn't work right.



_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to