From 78e0f9bbe6535cd2acb8003b5ea04a1335861383 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Wed, 21 Jan 2009 00:20:33 +0000 Subject: [PATCH] WIP: Gave dragging a more immediate feeling --- .../timeline/timeline-layout-helper.cpp | 48 +++++++++++++++---- .../timeline/timeline-layout-helper.hpp | 8 +++- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/gui/widgets/timeline/timeline-layout-helper.cpp b/src/gui/widgets/timeline/timeline-layout-helper.cpp index 660f08f4d..e37e3ee91 100644 --- a/src/gui/widgets/timeline/timeline-layout-helper.cpp +++ b/src/gui/widgets/timeline/timeline-layout-helper.cpp @@ -42,6 +42,7 @@ namespace timeline { TimelineLayoutHelper::TimelineLayoutHelper(TimelineWidget &owner) : timelineWidget(owner), totalHeight(0), + dragBranchHeight(0), animating(false) { } @@ -146,6 +147,7 @@ TimelineLayoutHelper::begin_dragging_track( const shared_ptr model_track = draggingTrack->get_model_track(); draggingTrackIter = iterator_from_track(model_track); + dragBranchHeight = measure_branch_height(draggingTrackIter); return draggingTrack; } @@ -206,11 +208,10 @@ TimelineLayoutHelper::drag_to_point(const Gdk::Point &point) const int x_mid = rect.get_x() + rect.get_width() / 2; // Do hit test - if(attempt_drop_upper(iterator, dragPoint, - y, full_width, half_height)) + if(attempt_drop_upper(iterator, y, full_width, half_height)) break; - if(attempt_drop_lower(iterator, dragPoint, + if(attempt_drop_lower(iterator, x_mid, full_width, y_mid, half_height)) break; } @@ -220,9 +221,13 @@ TimelineLayoutHelper::drag_to_point(const Gdk::Point &point) bool TimelineLayoutHelper::attempt_drop_upper( - TrackTree::pre_order_iterator target, const Gdk::Point &point, - const int y, const int full_width, const int half_height) -{ + TrackTree::pre_order_iterator target, const int y, + const int full_width, const int half_height) +{ + const Gdk::Point point(dragPoint.get_x(), + dragPoint.get_y() - dragStartOffset.get_y() + + dragBranchHeight); + if(pt_in_rect(point, Gdk::Rectangle(0, y, full_width, half_height))) { draggingTrackIter = layoutTree.move_before( @@ -232,16 +237,18 @@ TimelineLayoutHelper::attempt_drop_upper( return false; } - bool TimelineLayoutHelper::attempt_drop_lower( - TrackTree::pre_order_iterator target, const Gdk::Point &point, + TrackTree::pre_order_iterator target, const int x_mid, const int full_width, const int y_mid, const int half_height) { const shared_ptr model_track(*target); REQUIRE(model_track); + const Gdk::Point point(dragPoint.get_x(), + dragPoint.get_y() - dragStartOffset.get_y()); + if(!pt_in_rect(point, Gdk::Rectangle(0, y_mid, full_width, half_height))) return false; @@ -324,6 +331,31 @@ TimelineLayoutHelper::iterator_from_track( return iter; } +int +TimelineLayoutHelper::measure_branch_height( + TrackTree::iterator_base parent_iterator) +{ + shared_ptr parent_track = + lookup_timeline_track(*parent_iterator); + + int branch_height = parent_track->get_height() + + TimelineWidget::TrackPadding; + + TrackTree::sibling_iterator iterator; + for(iterator = layoutTree.begin(parent_iterator); + iterator != layoutTree.end(parent_iterator); + iterator++) + { + shared_ptr child_track = + lookup_timeline_track(*iterator); + + if(child_track->get_expanded()) + branch_height += measure_branch_height(iterator); + } + + return branch_height; +} + void TimelineLayoutHelper::update_layout() { diff --git a/src/gui/widgets/timeline/timeline-layout-helper.hpp b/src/gui/widgets/timeline/timeline-layout-helper.hpp index 524be4566..27616f9c7 100644 --- a/src/gui/widgets/timeline/timeline-layout-helper.hpp +++ b/src/gui/widgets/timeline/timeline-layout-helper.hpp @@ -157,6 +157,8 @@ public: **/ TrackTree::pre_order_iterator iterator_from_track( boost::shared_ptr model_track); + + int measure_branch_height(TrackTree::iterator_base parent_iterator); protected: @@ -221,11 +223,11 @@ protected: bool on_animation_tick(); bool -attempt_drop_upper(TrackTree::pre_order_iterator target, const Gdk::Point &point, const int y, const int full_width, const int half_height); +attempt_drop_upper(TrackTree::pre_order_iterator target, const int y, const int full_width, const int half_height); bool -attempt_drop_lower(TrackTree::pre_order_iterator target, const Gdk::Point &point, const int x_mid, const int full_width, const int y_mid, const int half_height); +attempt_drop_lower(TrackTree::pre_order_iterator target, const int x_mid, const int full_width, const int y_mid, const int half_height); protected: @@ -264,6 +266,8 @@ protected: Gdk::Point dragPoint; + int dragBranchHeight; + /** * The connection to the animation timer. * @see begin_animation()