From 7898aabcaa08659cd0bee5bba61df4503b7fadc7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 29 Jun 2010 19:08:19 +0000 Subject: Fix vertical canvas autoscroll when dragging track heights. Fixes #3240. git-svn-id: svn://localhost/ardour2/branches/3.0@7327 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.cc | 1 - gtk2_ardour/editor.h | 12 ++++++++---- gtk2_ardour/editor_canvas.cc | 17 +++++++---------- gtk2_ardour/editor_canvas_events.cc | 1 + gtk2_ardour/editor_drag.cc | 2 +- gtk2_ardour/editor_drag.h | 1 + gtk2_ardour/editor_mouse.cc | 3 --- gtk2_ardour/public_editor.h | 5 +++++ gtk2_ardour/time_axis_view.cc | 15 +++++++++++++++ 9 files changed, 38 insertions(+), 19 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index d8540f2407..e11029589d 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -384,7 +384,6 @@ Editor::Editor () for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) { _global_port_matrix[*i] = 0; } - allow_vertical_scroll = false; no_save_visual = false; resize_idle_id = -1; diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index f81a212d9b..c4203efa1c 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -447,6 +447,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void begin_reversible_command (std::string cmd_name); void commit_reversible_command (); + DragManager* drags () const { + return _drags; + } + + void maybe_autoscroll (bool, bool); + /* handy cursors for everyone to use */ static Gdk::Cursor* cross_hair_cursor; @@ -941,8 +947,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD int _scroll_callbacks; double _canvas_width; - double _canvas_height; - double full_canvas_height; + double _canvas_height; ///< height of the visible area of the track canvas + double full_canvas_height; ///< full height of the canvas bool track_canvas_map_handler (GdkEventAny*); @@ -1685,8 +1691,6 @@ public: bool autoscroll_canvas (); void start_canvas_autoscroll (int x, int y); void stop_canvas_autoscroll (); - void maybe_autoscroll (GdkEventMotion*, bool); - bool allow_vertical_scroll; /* trimming */ void point_trim (GdkEvent *, nframes64_t); diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 212da05c0c..7b13f66584 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -546,37 +546,35 @@ Editor::drop_regions (const RefPtr& /*context*/, } void -Editor::maybe_autoscroll (GdkEventMotion* event, bool allow_vert) +Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert) { nframes64_t rightmost_frame = leftmost_frame + current_page_frames(); bool startit = false; + double ty = _drags->current_pointer_y() - get_trackview_group_vertical_offset (); + autoscroll_y = 0; autoscroll_x = 0; - if (event->y < canvas_timebars_vsize && allow_vert) { + if (ty < canvas_timebars_vsize && allow_vert) { autoscroll_y = -1; startit = true; - } else if (event->y > _canvas_height) { + } else if (ty > _canvas_height && allow_vert) { autoscroll_y = 1; startit = true; } - if (_drags->current_pointer_frame() > rightmost_frame) { + if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) { if (rightmost_frame < max_frames) { autoscroll_x = 1; startit = true; } - } else if (_drags->current_pointer_frame() < leftmost_frame) { + } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) { if (leftmost_frame > 0) { autoscroll_x = -1; startit = true; } } - if (!allow_vertical_scroll) { - autoscroll_y = 0; - } - if ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0)) { stop_canvas_autoscroll (); } @@ -739,7 +737,6 @@ Editor::start_canvas_autoscroll (int dx, int dy) void Editor::stop_canvas_autoscroll () { - if (autoscroll_timeout_tag >= 0) { g_source_remove (autoscroll_timeout_tag); autoscroll_timeout_tag = -1; diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index bf84eb20e9..105ed4ac1f 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -111,6 +111,7 @@ Editor::track_canvas_scroll (GdkEventScroll* ev) current_stepping_trackview->step_height (false); return true; } else { + cout << "down line\n"; scroll_tracks_down_line (); return true; } diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 6d6b368b3a..e1870a21eb 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -303,7 +303,7 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll) if (event->motion.state & Gdk::BUTTON1_MASK || event->motion.state & Gdk::BUTTON2_MASK) { if (!from_autoscroll) { - _editor->maybe_autoscroll (&event->motion, allow_vertical_autoscroll ()); + _editor->maybe_autoscroll (true, allow_vertical_autoscroll ()); } motion (event, _move_threshold_passed != old_move_threshold_passed); diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index fb5ef3da9e..f1634ffb64 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -24,6 +24,7 @@ #include #include +#include #include "ardour/types.h" diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index d23e07d393..55a7e6887f 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -1038,9 +1038,6 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp if (pointer_window == track_canvas->get_bin_window()) { track_canvas->window_to_world (x, y, wx, wy); - allow_vertical_scroll = true; - } else { - allow_vertical_scroll = false; } } diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index bb498a8c4f..52fb601f8d 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -79,6 +79,7 @@ class MarkerTimeAxis; class ImageFrameView; class ImageFrameTimeAxis; class MarkerView; +class DragManager; /// Representation of the interface of the Editor class @@ -360,6 +361,10 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulDestructible { virtual Gtkmm2ext::TearOff* mouse_mode_tearoff () const = 0; virtual Gtkmm2ext::TearOff* tools_tearoff () const = 0; + virtual DragManager* drags () const = 0; + virtual void maybe_autoscroll (bool, bool) = 0; + virtual void stop_canvas_autoscroll () = 0; + /// Singleton instance, set up by Editor::Editor() static PublicEditor* _instance; diff --git a/gtk2_ardour/time_axis_view.cc b/gtk2_ardour/time_axis_view.cc index 978ce6debb..58dbd595bf 100644 --- a/gtk2_ardour/time_axis_view.cc +++ b/gtk2_ardour/time_axis_view.cc @@ -52,6 +52,7 @@ #include "rgb_macros.h" #include "utils.h" #include "streamview.h" +#include "editor_drag.h" #include "i18n.h" @@ -1242,6 +1243,7 @@ TimeAxisView::resizer_button_press (GdkEventButton* event) bool TimeAxisView::resizer_button_release (GdkEventButton*) { + _editor.stop_canvas_autoscroll (); _resize_drag_start = -1; return true; } @@ -1256,6 +1258,19 @@ bool TimeAxisView::resizer_motion (GdkEventMotion* ev) { if (_resize_drag_start >= 0) { + /* (ab)use the DragManager to do autoscrolling; adjust the event coordinates + into the trackview space that DragManager::motion_handler is expecting, + and then fake a DragManager motion event so that when maybe_autoscroll + asks DragManager for the current pointer position it will get the correct + answers. + */ + int tx, ty; + resizer.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty); + ev->y = ty + _editor.get_canvas_timebars_vsize (); + _editor.drags()->motion_handler ((GdkEvent *) ev, false); + _editor.maybe_autoscroll (false, true); + + /* now do the actual TAV resize */ int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start); _editor.add_to_idle_resize (this, delta); _resize_drag_start = ev->y_root; -- cgit v1.2.3