Fl_Roller can now be controlled via the mouse wheel (STR #3120).

This commit is contained in:
Matthias Melcher 2019-02-04 23:12:02 +01:00
parent 67f0bf6fee
commit 0cac8d52e3
3 changed files with 67 additions and 46 deletions

View File

@ -102,6 +102,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2019
Other Improvements Other Improvements
- (add new items here) - (add new items here)
- Fl_Roller can now be controlled via the mouse wheel (STR #3120).
- Tooltips hide by themselves after 12 seconds (STR #2584). - Tooltips hide by themselves after 12 seconds (STR #2584).
- Added widget visibility indicator to Fluid (STR #2669). - Added widget visibility indicator to Fluid (STR #2669).
- Added Fl_Input_::append() method (STR #2953). - Added Fl_Input_::append() method (STR #2953).

View File

@ -29,6 +29,11 @@
/** /**
The Fl_Roller widget is a "dolly" control commonly used to The Fl_Roller widget is a "dolly" control commonly used to
move 3D objects. move 3D objects.
The Roller can be controlled by clicking an ddragging the mouse, by the
corresponding arrow keys when the roller has the keyboard focus, or by the
mousewheels when the mouse pointer is positioned over the roller widget.
<P ALIGN=CENTER>\image html Fl_Roller.png <P ALIGN=CENTER>\image html Fl_Roller.png
\image latex Fl_Roller.png "Fl_Roller" width=4cm \image latex Fl_Roller.png "Fl_Roller" width=4cm
*/ */

View File

@ -27,53 +27,68 @@ int Fl_Roller::handle(int event) {
static int ipos; static int ipos;
int newpos = horizontal() ? Fl::event_x() : Fl::event_y(); int newpos = horizontal() ? Fl::event_x() : Fl::event_y();
switch (event) { switch (event) {
case FL_PUSH: case FL_PUSH:
if (Fl::visible_focus()) { if (Fl::visible_focus()) {
Fl::focus(this); Fl::focus(this);
redraw(); redraw();
} }
handle_push(); handle_push();
ipos = newpos; ipos = newpos;
return 1;
case FL_DRAG:
handle_drag(clamp(round(increment(previous_value(),newpos-ipos))));
return 1;
case FL_RELEASE:
handle_release();
return 1;
case FL_KEYBOARD :
switch (Fl::event_key()) {
case FL_Up:
if (horizontal()) return 0;
handle_drag(clamp(increment(value(),-1)));
return 1;
case FL_Down:
if (horizontal()) return 0;
handle_drag(clamp(increment(value(),1)));
return 1;
case FL_Left:
if (!horizontal()) return 0;
handle_drag(clamp(increment(value(),-1)));
return 1;
case FL_Right:
if (!horizontal()) return 0;
handle_drag(clamp(increment(value(),1)));
return 1;
default:
return 0;
}
// break not required because of switch...
case FL_FOCUS :
case FL_UNFOCUS :
if (Fl::visible_focus()) {
redraw();
return 1; return 1;
} else return 0; case FL_DRAG:
case FL_ENTER : handle_drag(clamp(round(increment(previous_value(),newpos-ipos))));
case FL_LEAVE : return 1;
return 1; case FL_RELEASE:
default: handle_release();
return 0; return 1;
case FL_MOUSEWHEEL :
if (Fl::belowmouse()==this) {
if (horizontal()) {
if (Fl::e_dx!=0) {
handle_drag(clamp(round(increment(value(),-Fl::e_dx))));
}
} else {
if (Fl::e_dy!=0) {
handle_drag(clamp(round(increment(value(),-Fl::e_dy))));
}
}
return 1;
} else {
return 0;
}
case FL_KEYBOARD :
switch (Fl::event_key()) {
case FL_Up:
if (horizontal()) return 0;
handle_drag(clamp(increment(value(),-1)));
return 1;
case FL_Down:
if (horizontal()) return 0;
handle_drag(clamp(increment(value(),1)));
return 1;
case FL_Left:
if (!horizontal()) return 0;
handle_drag(clamp(increment(value(),-1)));
return 1;
case FL_Right:
if (!horizontal()) return 0;
handle_drag(clamp(increment(value(),1)));
return 1;
default:
return 0;
}
// break not required because of switch...
case FL_FOCUS :
case FL_UNFOCUS :
if (Fl::visible_focus()) {
redraw();
return 1;
} else return 0;
case FL_ENTER :
case FL_LEAVE :
return 1;
default:
return 0;
} }
} }