diff options
author | corvid <corvid@lavabit.com> | 2012-11-05 00:30:16 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2012-11-05 00:30:16 +0000 |
commit | 953f81e651465603f537270859732ccee038ea52 (patch) | |
tree | d0e7cc96af223264c85cd6bc6793b4cb6bc816c8 | |
parent | 256fc10e8e58c44baf1fe9c5ea0d65649199b116 (diff) |
scroll when cursor is outside of viewport during selection
-rw-r--r-- | dw/fltkviewport.cc | 41 | ||||
-rw-r--r-- | dw/fltkviewport.hh | 3 |
2 files changed, 38 insertions, 6 deletions
diff --git a/dw/fltkviewport.cc b/dw/fltkviewport.cc index 19e28854..2dcc199b 100644 --- a/dw/fltkviewport.cc +++ b/dw/fltkviewport.cc @@ -275,7 +275,9 @@ int FltkViewport::handle (int event) break; case FL_DRAG: - if (dragScrolling && Fl::event_button() == FL_MIDDLE_MOUSE) { + if (Fl::event_inside(this)) + Fl::remove_timeout(selectionScroll); + if (dragScrolling) { scroll(dragX - Fl::event_x(), dragY - Fl::event_y()); dragX = Fl::event_x(); dragY = Fl::event_y(); @@ -286,6 +288,11 @@ int FltkViewport::handle (int event) } else if (horScrolling) { hscrollbar->handle(event); return 1; + } else if (!Fl::event_inside(this)) { + mouse_x = Fl::event_x(); + mouse_y = Fl::event_y(); + if (!Fl::has_timeout(selectionScroll, this)) + Fl::add_timeout(0.025, selectionScroll, this); } break; @@ -294,6 +301,7 @@ int FltkViewport::handle (int event) break; case FL_RELEASE: + Fl::remove_timeout(selectionScroll); if (Fl::event_button() == FL_MIDDLE_MOUSE) { setCursor (core::style::CURSOR_DEFAULT); } else if (verScrolling) { @@ -310,10 +318,6 @@ int FltkViewport::handle (int event) mouse_y = Fl::event_y(); positionChanged(); break; - - case FL_LEAVE: - mouse_x = mouse_y = -1; - break; } return FltkWidgetView::handle (event); @@ -332,7 +336,8 @@ void FltkViewport::setCanvasSize (int width, int ascent, int descent) */ void FltkViewport::positionChanged () { - if (mouse_x != -1 && dragScrolling == false) + if (!dragScrolling && mouse_x >= x() && mouse_x < x()+w() && mouse_y >= y() + && mouse_y < y()+h()) (void)theLayout->motionNotify (this, translateViewXToCanvasX (mouse_x), translateViewYToCanvasY (mouse_y), @@ -425,6 +430,30 @@ void FltkViewport::scroll (core::ScrollCommand cmd) } } +/* + * Scrolling in response to selection where the cursor is outside the view. + */ +void FltkViewport::selectionScroll () +{ + int dx = 0, dy = 0; + + if (mouse_x < x()) + dx = -hscrollbar->linesize (); + else if (mouse_x >= x() + w()) + dx = hscrollbar->linesize (); + if (mouse_y < y()) + dy = -vscrollbar->linesize (); + else if (mouse_y >= y() + h()) + dy = vscrollbar->linesize (); + scroll (dx, dy); +} + +void FltkViewport::selectionScroll (void *data) +{ + ((FltkViewport *)data)->selectionScroll (); + Fl::repeat_timeout(0.025, selectionScroll, data); +} + void FltkViewport::setViewportSize (int width, int height, int hScrollbarThickness, int vScrollbarThickness) diff --git a/dw/fltkviewport.hh b/dw/fltkviewport.hh index 3df1dccb..1569a7d8 100644 --- a/dw/fltkviewport.hh +++ b/dw/fltkviewport.hh @@ -39,6 +39,9 @@ private: static void hscrollbarCallback (Fl_Widget *hscrollbar, void *viewportPtr); static void vscrollbarCallback (Fl_Widget *vscrollbar, void *viewportPtr); + void selectionScroll(); + static void selectionScroll(void *vport); + void updateCanvasWidgets (int oldScrollX, int oldScrollY); static void draw_area (void *data, int x, int y, int w, int h); |