Added layout code from TimelineHeaderContainer

This commit is contained in:
Joel Holdsworth 2009-01-01 13:31:34 +00:00
parent 0f3b290b6d
commit ac28251915
2 changed files with 127 additions and 9 deletions

View file

@ -48,7 +48,7 @@ TimelineLayoutHelper::clone_tree_from_sequence()
REQUIRE(sequence); REQUIRE(sequence);
layoutTree.clear(); layoutTree.clear();
tree< shared_ptr<model::Track> >::iterator_base iterator = TrackTree::iterator_base iterator =
layoutTree.set_head(sequence); layoutTree.set_head(sequence);
add_branch(iterator, sequence); add_branch(iterator, sequence);
@ -56,20 +56,91 @@ TimelineLayoutHelper::clone_tree_from_sequence()
void void
TimelineLayoutHelper::add_branch( TimelineLayoutHelper::add_branch(
lumiera::tree< shared_ptr<model::Track> >::iterator_base TrackTree::iterator_base parent_iterator,
parent_iterator,
shared_ptr<model::Track> parent) shared_ptr<model::Track> parent)
{ {
BOOST_FOREACH(shared_ptr<model::Track> child, BOOST_FOREACH(shared_ptr<model::Track> child,
parent->get_child_tracks()) parent->get_child_tracks())
{ {
tree< shared_ptr<model::Track> >::iterator_base TrackTree::iterator_base child_iterator =
child_iterator =
layoutTree.append_child(parent_iterator, child); layoutTree.append_child(parent_iterator, child);
add_branch(child_iterator, child); add_branch(child_iterator, child);
} }
} }
void
TimelineLayoutHelper::update_layout()
{
// Make sure the style are loaded
//read_styles();
// Clear previously cached layout
headerBoxes.clear();
// Start at minus-the-scroll offset
int offset = 0;//-timelineWidget->get_y_scroll_offset();
//const Allocation container_allocation = get_allocation();
const int header_width = 100;//container_allocation.get_width();
const int indent_width = 10;
layout_headers_recursive(layoutTree.begin(),
offset, header_width, indent_width, 0, true);
}
void
TimelineLayoutHelper::layout_headers_recursive(
TrackTree::iterator_base parent_iterator,
int &offset, const int header_width, const int indent_width,
const int depth, bool parent_expanded)
{
REQUIRE(depth >= 0);
TrackTree::sibling_iterator iterator;
for(iterator = layoutTree.begin(parent_iterator);
iterator != layoutTree.end(parent_iterator);
iterator++)
{
const shared_ptr<model::Track> &model_track = *iterator;
REQUIRE(model_track);
shared_ptr<timeline::Track> timeline_track =
lookup_timeline_track(model_track);
if(parent_expanded)
{
// Calculate and store the box of the header
const int track_height = timeline_track->get_height();
const int indent = depth * indent_width;
headerBoxes[timeline_track] = Gdk::Rectangle(
indent, // x
offset, // y
max( header_width - indent, 0 ), // width
track_height); // height
// Offset for the next header
offset += track_height + TimelineWidget::TrackPadding;
}
layout_headers_recursive(iterator, offset, header_width,
indent_width, depth + 1,
timeline_track->get_expanded() && parent_expanded);
}
}
shared_ptr<timeline::Track>
TimelineLayoutHelper::lookup_timeline_track(
shared_ptr<model::Track> model_track)
{
REQUIRE(model_track != NULL);
shared_ptr<timeline::Track> timeline_track =
timelineWidget.lookup_timeline_track(model_track);
ENSURE(timeline_track);
return timeline_track;
}
} // namespace timeline } // namespace timeline
} // namespace widgets } // namespace widgets
} // namespace gui } // namespace gui

View file

@ -51,21 +51,68 @@ class Track;
*/ */
class TimelineLayoutHelper : public boost::noncopyable class TimelineLayoutHelper : public boost::noncopyable
{ {
public:
typedef lumiera::tree< boost::shared_ptr<model::Track> > TrackTree;
public: public:
TimelineLayoutHelper(TimelineWidget &owner); TimelineLayoutHelper(TimelineWidget &owner);
protected: protected:
void clone_tree_from_sequence(); void clone_tree_from_sequence();
void add_branch( void add_branch(TrackTree::iterator_base parent_iterator,
lumiera::tree< boost::shared_ptr<model::Track> >::iterator_base
parent_iterator,
boost::shared_ptr<model::Track> parent); boost::shared_ptr<model::Track> parent);
/**
* Recaculates the track layout from layoutTree.
**/
void update_layout();
/**
* Recursively lays out all the controls in the header widget.
* /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
*
* * @param track The parent track object which will be recursed into.
* @param offset A shared value used to accumulate the y-offset of
* header widgets.
* @param header_width The width of this widget in pixels.
* !!!!!!!!!!! indent_width
* @param depth The depth within the tree of track.
**/
void layout_headers_recursive(
TrackTree::iterator_base parent_iterator,
int &offset, const int header_width, const int indent_width,
const int depth, bool parent_expanded);
/**
* A helper function which calls lookup_timeline_track within the
* parent timeline widget, but also applies lots of data consistency
* checks in the process.
* @param model_track The model track to look up in the parent widget.
* @return Returns the track found, or returns NULL if no matching
* track was found.
* @remarks If the return value is going to be NULL, an ENSURE will
* fail.
**/
boost::shared_ptr<timeline::Track> lookup_timeline_track(
boost::shared_ptr<model::Track> model_track);
protected: protected:
TimelineWidget &timelineWidget; TimelineWidget &timelineWidget;
lumiera::tree< boost::shared_ptr<model::Track> > layoutTree; TrackTree layoutTree;
/**
* A map of tracks to the rectangles of their headers.
* @remarks This map is used as a cache, so that the rectangles don't
* need to be perpetually recalculated. This cache is regenerated by
* the layout_headers method.
**/
std::map<boost::weak_ptr<timeline::Track>, Gdk::Rectangle>
headerBoxes;
}; };
} // namespace timeline } // namespace timeline