Fix some bugs in autoscroll when dragging regions.
authorCarl Hetherington <carl@carlh.net>
Wed, 6 Jan 2010 01:14:56 +0000 (01:14 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 6 Jan 2010 01:14:56 +0000 (01:14 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6460 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_canvas.cc
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_drag.h

index 0b19b2c86ea3e4f2251594c85ca60ce107a8f072..7df20c610ba540e4afc28797d4b2e1f3766d7884 100644 (file)
@@ -551,7 +551,7 @@ void
 Editor::maybe_autoscroll (GdkEventMotion* event, bool allow_vert)
 {
        nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
-       nframes64_t frame = _drag->adjusted_current_frame (0);
+       pair<nframes64_t, nframes64_t> frames = _drag->extent ();
        bool startit = false;
 
        autoscroll_y = 0;
@@ -564,14 +564,14 @@ Editor::maybe_autoscroll (GdkEventMotion* event, bool allow_vert)
                startit = true;
        }
 
-       if (frame > rightmost_frame) {
+       if (frames.second > rightmost_frame) {
 
                if (rightmost_frame < max_frames) {
                        autoscroll_x = 1;
                        startit = true;
                }
 
-       } else if (frame < leftmost_frame) {
+       } else if (frames.first < leftmost_frame) {
                if (leftmost_frame > 0) {
                        autoscroll_x = -1;
                        startit = true;
@@ -613,10 +613,13 @@ Editor::autoscroll_canvas ()
        assert (_drag);
 
        if (autoscroll_x_distance != 0) {
+
+               pair<nframes64_t, nframes64_t> const e = _drag->extent ();
+               
                if (autoscroll_x > 0) {
-                       autoscroll_x_distance = (unit_to_frame (_drag->current_pointer_x()) - (leftmost_frame + current_page_frames())) / 3;
+                       autoscroll_x_distance = (e.second - (leftmost_frame + current_page_frames())) / 3;
                } else if (autoscroll_x < 0) {
-                       autoscroll_x_distance = (leftmost_frame - unit_to_frame (_drag->current_pointer_x())) / 3;
+                       autoscroll_x_distance = (leftmost_frame - e.first) / 3;
 
                }
        }
@@ -702,7 +705,7 @@ Editor::autoscroll_canvas ()
        Gdk::ModifierType mask;
        canvas_window->get_pointer (x, y, mask);
        ev.type = GDK_MOTION_NOTIFY;
-       ev.state &= Gdk::BUTTON1_MASK;
+       ev.state = Gdk::BUTTON1_MASK;
        ev.x = x;
        ev.y = y;
 
index 6345d8fd28976e233913e6e006e811799514d2ee..e50386428dcef8f0c3fd3a3446327fe13a1d9da0 100644 (file)
@@ -242,6 +242,12 @@ Drag::break_drag ()
        }
 }
 
+pair<nframes64_t, nframes64_t>
+Drag::extent () const
+{
+       nframes64_t const f = adjusted_current_frame (0);
+       return make_pair (f, f);
+}
 
 RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
        : Drag (e, i),
@@ -257,6 +263,14 @@ RegionDrag::region_going_away (RegionView* v)
        _views.remove (v);
 }
 
+pair<nframes64_t, nframes64_t>
+RegionDrag::extent () const
+{
+       nframes64_t const f = adjusted_current_frame (0);
+       return make_pair (f, f + _primary->region()->length ());
+}
+
+
 RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b)
        : RegionDrag (e, i, p, v),
          _dest_trackview (0),
index bfca141c67210e26f896bc5169f77940588df0de..941833d0c06a582bb02bb7ded5a0916186d8867a 100644 (file)
@@ -120,6 +120,11 @@ public:
                return true;
        }
 
+       /** @return current x extent of the thing being dragged; ie
+        *  a pair of (leftmost_position, rightmost_position)
+        */
+       virtual std::pair<nframes64_t, nframes64_t> extent () const;
+
 protected:
 
        double grab_x () const {
@@ -180,6 +185,8 @@ public:
        RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
        virtual ~RegionDrag () {}
 
+       std::pair<nframes64_t, nframes64_t> extent () const;
+
 protected:
 
        RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag