cleaner version of previous commit's fix for AutomationRangeDrag y fraction computation
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 10 Jul 2012 15:58:09 +0000 (15:58 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 10 Jul 2012 15:58:09 +0000 (15:58 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@13013 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_drag.h

index 8157011c5a9be9a30a7c711f38c4309d2e90df0b..42af2bb9fcbcfd5eba95f61a97c91e0daaee5fa6 100644 (file)
@@ -4106,7 +4106,7 @@ AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AutomationTimeAxisView
        , _nothing_to_drag (false)
 {
        DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
-       track_view = atv;
+       y_origin = atv->y_position();
        setup (atv->lines ());
 }
 
@@ -4120,7 +4120,7 @@ AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AudioRegionView* rv, l
 
        list<boost::shared_ptr<AutomationLine> > lines;
        lines.push_back (rv->get_gain_line ());
-       track_view = &rv->get_time_axis_view();
+       y_origin = rv->get_time_axis_view().y_position();
        setup (lines);
 }
 
@@ -4162,6 +4162,12 @@ AutomationRangeDrag::setup (list<boost::shared_ptr<AutomationLine> > const & lin
        /* Now ::lines contains the AutomationLines that somehow overlap our drag */
 }
 
+double
+AutomationRangeDrag::y_fraction (boost::shared_ptr<AutomationLine> line, double global_y) const
+{
+       return 1.0 - ((global_y - y_origin) / line->height());
+}
+
 void
 AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 {
@@ -4170,7 +4176,7 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        /* Get line states before we start changing things */
        for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
                i->state = &i->line->get_state ();
-               i->original_fraction = 1 - ((_drags->current_pointer_y() - track_view->y_position()) / i->line->height());
+               i->original_fraction = y_fraction (i->line, _drags->current_pointer_y());
        }
 
        if (_ranges.empty()) {
@@ -4276,7 +4282,7 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        }
 
        for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
-               i->line->start_drag_multiple (i->points, 1 - ((_drags->current_pointer_y() - track_view->y_position()) / i->line->height ()), i->state);
+               i->line->start_drag_multiple (i->points, y_fraction (i->line, _drags->current_pointer_y()), i->state);
        }
 }
 
@@ -4288,7 +4294,7 @@ AutomationRangeDrag::motion (GdkEvent*, bool /*first_move*/)
        }
 
        for (list<Line>::iterator l = _lines.begin(); l != _lines.end(); ++l) {
-               float const f = 1 - ((_drags->current_pointer_y() - track_view->y_position()) / l->line->height());
+               float const f = y_fraction (l->line, _drags->current_pointer_y());
 
                /* we are ignoring x position for this drag, so we can just pass in anything */
                l->line->drag_motion (0, f, true, false);
index 61273559654cd80e333081f9103be0855e4d1b46..217755585694612015b85cda227f9c016590edae 100644 (file)
@@ -957,7 +957,8 @@ public:
 
 private:
        void setup (std::list<boost::shared_ptr<AutomationLine> > const &);
-       
+        double y_fraction (boost::shared_ptr<AutomationLine>, double global_y_position) const;
+
        std::list<ARDOUR::AudioRange> _ranges;
 
        /** A line that is part of the drag */
@@ -970,7 +971,7 @@ private:
        };
 
        std::list<Line> _lines;
-        TimeAxisView* track_view;
+        double y_origin;
        bool _nothing_to_drag;
 };