summaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-10-13 19:28:17 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-10-13 20:02:51 +0200
commit9315c26bb248157d0b37ef933e3d16779aed7dd9 (patch)
treef9b7f57c163b431d23c44d86108a2dfc006f3aec /dw
parentf73a9c1a1967318a33cc91f588552574dc7c3f01 (diff)
Repeat page scrolling when holding the button
When the page scroll mode is enabled, pressing and holding the scrollbar will keep scrolling pages on that direction until the mouse button is released.
Diffstat (limited to 'dw')
-rw-r--r--dw/fltkviewport.cc34
-rw-r--r--dw/fltkviewport.hh6
-rw-r--r--dw/types.hh2
3 files changed, 36 insertions, 6 deletions
diff --git a/dw/fltkviewport.cc b/dw/fltkviewport.cc
index e9169495..fc9a0bed 100644
--- a/dw/fltkviewport.cc
+++ b/dw/fltkviewport.cc
@@ -74,6 +74,10 @@ FltkViewport::FltkViewport (int X, int Y, int W, int H, const char *label):
horScrolling = verScrolling = dragScrolling = 0;
scrollbarPageMode = false;
pageOverlap = 50;
+ pageScrolling = core::NONE_CMD;
+
+ pageScrollDelay = 0.300;
+ pageScrollInterval = 0.100;
gadgetOrientation[0] = GADGET_HORIZONTAL;
gadgetOrientation[1] = GADGET_HORIZONTAL;
@@ -296,11 +300,19 @@ int FltkViewport::handle (int event)
case FL_PUSH:
if (vscrollbar->visible() && Fl::event_inside(vscrollbar)) {
if (scrollbarPageMode ^ (bool) Fl::event_shift()) {
- if (Fl::event_button() == FL_LEFT_MOUSE) {
- scroll(core::SCREEN_DOWN_CMD);
- return 1;
- } else if (Fl::event_button() == FL_RIGHT_MOUSE) {
- scroll(core::SCREEN_UP_CMD);
+ if (Fl::event_button() == FL_LEFT_MOUSE)
+ pageScrolling = core::SCREEN_DOWN_CMD;
+ else if (Fl::event_button() == FL_RIGHT_MOUSE)
+ pageScrolling = core::SCREEN_UP_CMD;
+ else
+ pageScrolling = core::NONE_CMD;
+
+ if (pageScrolling != core::NONE_CMD) {
+ scroll(pageScrolling);
+ /* Repeat until released */
+ if (!Fl::has_timeout(repeatPageScroll, this))
+ Fl::add_timeout(pageScrollDelay, repeatPageScroll, this);
+
return 1;
}
}
@@ -363,6 +375,7 @@ int FltkViewport::handle (int event)
break;
case FL_RELEASE:
+ Fl::remove_timeout(repeatPageScroll);
Fl::remove_timeout(selectionScroll);
if (Fl::event_button() == FL_MIDDLE_MOUSE) {
setCursor (core::style::CURSOR_DEFAULT);
@@ -547,6 +560,17 @@ void FltkViewport::selectionScroll (void *data)
Fl::repeat_timeout(0.025, selectionScroll, data);
}
+void FltkViewport::repeatPageScroll ()
+{
+ scroll(pageScrolling);
+ Fl::repeat_timeout(pageScrollInterval, repeatPageScroll, this);
+}
+
+void FltkViewport::repeatPageScroll (void *data)
+{
+ ((FltkViewport *)data)->repeatPageScroll ();
+}
+
void FltkViewport::setScrollbarOnLeft (bool enable)
{
scrollbarOnLeft = enable ? 1 : 0;
diff --git a/dw/fltkviewport.hh b/dw/fltkviewport.hh
index 2cff42d3..0948e2f2 100644
--- a/dw/fltkviewport.hh
+++ b/dw/fltkviewport.hh
@@ -46,6 +46,9 @@ private:
int horScrolling, verScrolling;
bool scrollbarPageMode;
int pageOverlap;
+ enum dw::core::ScrollCommand pageScrolling;
+ float pageScrollInterval;
+ float pageScrollDelay;
Fl_Scrollbar *vscrollbar, *hscrollbar;
@@ -65,6 +68,9 @@ private:
void selectionScroll();
static void selectionScroll(void *vport);
+ void repeatPageScroll ();
+ static void repeatPageScroll (void *data);
+
void updateCanvasWidgets (int oldScrollX, int oldScrollY);
static void draw_area (void *data, int x, int y, int w, int h);
diff --git a/dw/types.hh b/dw/types.hh
index 877593fe..eabf5ce7 100644
--- a/dw/types.hh
+++ b/dw/types.hh
@@ -34,7 +34,7 @@ enum VPosition
enum ScrollCommand {SCREEN_UP_CMD, SCREEN_DOWN_CMD, SCREEN_LEFT_CMD,
SCREEN_RIGHT_CMD, LINE_UP_CMD, LINE_DOWN_CMD,
- LEFT_CMD, RIGHT_CMD, TOP_CMD, BOTTOM_CMD};
+ LEFT_CMD, RIGHT_CMD, TOP_CMD, BOTTOM_CMD, NONE_CMD};
/*
* Different "layers" may be highlighted in a widget.