diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-10-13 13:59:01 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-10-13 13:59:01 +0200 |
| commit | 58b13b868e9be35e2b516a72a736b8c61178467a (patch) | |
| tree | 3e28043094070c79871fe35c67943581e307d738 | |
| parent | b1321bb97e254a5aa4d5ed6eef03d89a3892d1f9 (diff) | |
FLUID: allow mousewheel events on coordinate input
MACOS: make sure that even small mouse wheel deltas count at least as 1 unit
| -rw-r--r-- | fluid/custom_widgets.cxx | 16 | ||||
| -rw-r--r-- | fluid/custom_widgets.h | 2 | ||||
| -rw-r--r-- | src/Fl_cocoa.mm | 9 |
3 files changed, 25 insertions, 2 deletions
diff --git a/fluid/custom_widgets.cxx b/fluid/custom_widgets.cxx index 170ef44a2..f409e9761 100644 --- a/fluid/custom_widgets.cxx +++ b/fluid/custom_widgets.cxx @@ -292,3 +292,19 @@ void Fluid_Coord_Input::value(int v) { fl_snprintf(buf, sizeof(buf), "%d", v); text(buf); } + +/** + Allow vertical mouse dragging and mouse wheel to interactively change the value. + */ +int Fluid_Coord_Input::handle(int event) { + switch (event) { + case FL_MOUSEWHEEL: + if (Fl::event_dy()) { + value( value() - Fl::event_dy() ); + set_changed(); + do_callback(FL_REASON_CHANGED); + } + return 1; + } + return Fl_Input::handle(event); +} diff --git a/fluid/custom_widgets.h b/fluid/custom_widgets.h index 8a464ae82..36abc1414 100644 --- a/fluid/custom_widgets.h +++ b/fluid/custom_widgets.h @@ -83,6 +83,8 @@ public: vars_ = vars; vars_user_data_ = user_data; } + + int handle(int) override; }; #endif diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 744b831d7..3927ebb45 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -991,8 +991,13 @@ static void cocoaMouseWheelHandler(NSEvent *theEvent) Fl::first_window(window); // Under OSX, mousewheel deltas are floats, but fltk only supports ints. float s = Fl::screen_driver()->scale(0); - int dx = roundf([theEvent deltaX] / s); - int dy = roundf([theEvent deltaY] / s); + float edx = [theEvent deltaX]; + float edy = [theEvent deltaY]; + int dx = roundf(edx / s); + int dy = roundf(edy / s); + // make sure that even small wheel movements count at least as one unit + if (edx>0.0f) dx++; else if (edx<0.0f) dx--; + if (edy>0.0f) dy++; else if (edy<0.0f) dy--; // allow both horizontal and vertical movements to be processed by the widget if (dx) { Fl::e_dx = -dx; |
