Fix vertical canvas autoscroll when dragging track heights. Fixes #3240.
authorCarl Hetherington <carl@carlh.net>
Tue, 29 Jun 2010 19:08:19 +0000 (19:08 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 29 Jun 2010 19:08:19 +0000 (19:08 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7327 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_canvas.cc
gtk2_ardour/editor_canvas_events.cc
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_drag.h
gtk2_ardour/editor_mouse.cc
gtk2_ardour/public_editor.h
gtk2_ardour/time_axis_view.cc

index d8540f24076615cf7f24bc5698235740a56d9ab0..e11029589d3ac623b423005dec7ab0ff6ea72c39 100644 (file)
@@ -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;
 
index f81a212d9b39dc2dee2c58b3d1ff7372741e6bc3..c4203efa1c97cc8f89efce52bdc61e64d79c0a8a 100644 (file)
@@ -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);
index 212da05c0c4bd6438b867bd15d001653d8f51f4f..7b13f665844c65e1ea848cc45cea15c1bdc8b200 100644 (file)
@@ -546,37 +546,35 @@ Editor::drop_regions (const RefPtr<Gdk::DragContext>& /*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;
index bf84eb20e9c4ee58c9c6e3da3cf13e451aae01ce..105ed4ac1f233dd16e828c55affbcef6c01590af 100644 (file)
@@ -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;
                }
index 6d6b368b3add4bf46f9aa73a2b5ec78bd6a26d0f..e1870a21eb8f11c572dce82d5f6e242128839d3f 100644 (file)
@@ -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);
index fb5ef3da9e80c201da46b8b59543fae6d7375cff..f1634ffb646e11e447d7314db8d7d915bca57326 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <gdk/gdk.h>
 #include <stdint.h>
+#include <bitset>
 
 #include "ardour/types.h"
 
index d23e07d393a550a699d08c23e90de7d847adec37..55a7e6887fa7d0b34a508378d79d2db4490a956b 100644 (file)
@@ -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;
                }
        }
 
index bb498a8c4f4eff0c6f89b04697a6cce54911ad5d..52fb601f8dae68a32f2567d33200effcc457e1e5 100644 (file)
@@ -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;
index 978ce6debba905a3eb99df60f7f7f7f4bebbcd9a..58dbd595bfca32a74d49cb969147341e4eaf004b 100644 (file)
@@ -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;