From bcd5dababea8702bb846037f52124264cf9e6db5 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Fri, 2 Jan 2009 12:17:19 +0000 Subject: [PATCH] Transitioned TimelineBody drawing code to use the TimelineLayoutHelper --- src/gui/widgets/timeline/timeline-body.cpp | 44 ++++++++++++------- src/gui/widgets/timeline/timeline-body.hpp | 2 +- .../timeline/timeline-layout-helper.cpp | 16 +++++++ .../timeline/timeline-layout-helper.hpp | 2 + 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/gui/widgets/timeline/timeline-body.cpp b/src/gui/widgets/timeline/timeline-body.cpp index 06a4801c2..d6ee18eba 100644 --- a/src/gui/widgets/timeline/timeline-body.cpp +++ b/src/gui/widgets/timeline/timeline-body.cpp @@ -287,26 +287,46 @@ TimelineBody::draw_tracks(Cairo::RefPtr cr) REQUIRE(timelineWidget->sequence); // Prepare + TimelineLayoutHelper &layout_helper = timelineWidget->layoutHelper; + const TimelineLayoutHelper::TrackTree &layout_tree = + layout_helper.get_layout_tree(); const Allocation allocation = get_allocation(); // Save the view matrix Cairo::Matrix view_matrix; cr->get_matrix(view_matrix); - // Translate the view by the scroll distance - cr->translate(0, -get_vertical_offset()); - - // Interate drawing each track - BOOST_FOREACH( shared_ptr model_track, - timelineWidget->sequence->get_child_tracks() ) - draw_track_recursive(cr, model_track, allocation.get_width()); + // Iterate drawing each track + TimelineLayoutHelper::TrackTree::pre_order_iterator iterator; + for(iterator = ++layout_tree.begin(); // ++ so we skip the sequence root + iterator != layout_tree.end(); + iterator++) + { + const shared_ptr model_track(*iterator); + const shared_ptr timeline_track = + timelineWidget->lookup_timeline_track(*iterator); + + optional rect = + layout_helper.get_track_header_rect(timeline_track); + + // Is this track visible? + if(rect) + { + // Translate to the top of the track + cr->set_matrix(view_matrix); + cr->translate(0, rect->get_y()); + + // Draw the track + draw_track(cr, model_track, allocation.get_width()); + } + } // Restore the view matrix cr->set_matrix(view_matrix); } void -TimelineBody::draw_track_recursive(Cairo::RefPtr cr, +TimelineBody::draw_track(Cairo::RefPtr cr, shared_ptr model_track, const int view_width) const { REQUIRE(cr); @@ -329,14 +349,6 @@ TimelineBody::draw_track_recursive(Cairo::RefPtr cr, cr->save(); timeline_track->draw_track(cr, &timelineWidget->get_view_window()); cr->restore(); - - // Shift for the next track - cr->translate(0, height + TimelineWidget::TrackPadding); - - // Recurse drawing into children - BOOST_FOREACH( shared_ptr child, - model_track->get_child_tracks() ) - draw_track_recursive(cr, child, view_width); } void diff --git a/src/gui/widgets/timeline/timeline-body.hpp b/src/gui/widgets/timeline/timeline-body.hpp index 2489ee7de..12ec6c5a9 100644 --- a/src/gui/widgets/timeline/timeline-body.hpp +++ b/src/gui/widgets/timeline/timeline-body.hpp @@ -118,7 +118,7 @@ private: */ void draw_tracks(Cairo::RefPtr cr); - void draw_track_recursive(Cairo::RefPtr cr, + void draw_track(Cairo::RefPtr cr, boost::shared_ptr track, const int view_width) const; /** diff --git a/src/gui/widgets/timeline/timeline-layout-helper.cpp b/src/gui/widgets/timeline/timeline-layout-helper.cpp index 0274c2d12..011869d70 100644 --- a/src/gui/widgets/timeline/timeline-layout-helper.cpp +++ b/src/gui/widgets/timeline/timeline-layout-helper.cpp @@ -107,6 +107,22 @@ TimelineLayoutHelper::header_from_point(const Gdk::Point &point) return shared_ptr(); } +boost::weak_ptr +TimelineLayoutHelper::track_from_y(const int y) +{ + std::pair, Gdk::Rectangle> pair; + BOOST_FOREACH( pair, headerBoxes ) + { + // Hit test the rectangle + const Gdk::Rectangle &rect = pair.second; + if(y >= rect.get_y() && y < rect.get_y() + rect.get_height()) + return pair.first; + } + + // No track was found - return an empty pointer + return shared_ptr(); +} + int TimelineLayoutHelper::get_total_height() const { diff --git a/src/gui/widgets/timeline/timeline-layout-helper.hpp b/src/gui/widgets/timeline/timeline-layout-helper.hpp index 61ce80e52..566ad1f02 100644 --- a/src/gui/widgets/timeline/timeline-layout-helper.hpp +++ b/src/gui/widgets/timeline/timeline-layout-helper.hpp @@ -72,6 +72,8 @@ public: boost::weak_ptr header_from_point( const Gdk::Point &point); + boost::weak_ptr track_from_y(const int y); + int get_total_height() const; protected: