Tidied up TimelineLayoutHelper::layout_headers_recursive
This commit is contained in:
parent
c401207dba
commit
e74e55df98
2 changed files with 46 additions and 61 deletions
|
|
@ -144,8 +144,6 @@ TimelineLayoutHelper::get_total_height() const
|
||||||
void
|
void
|
||||||
TimelineLayoutHelper::update_layout()
|
TimelineLayoutHelper::update_layout()
|
||||||
{
|
{
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
// Reset the animation state value, before it gets recalculated
|
// Reset the animation state value, before it gets recalculated
|
||||||
animation_state = Track::NoAnimationState;
|
animation_state = Track::NoAnimationState;
|
||||||
|
|
||||||
|
|
@ -155,10 +153,8 @@ TimelineLayoutHelper::update_layout()
|
||||||
// Do the layout
|
// Do the layout
|
||||||
const int header_width = TimelineWidget::HeaderWidth;
|
const int header_width = TimelineWidget::HeaderWidth;
|
||||||
const int indent_width = TimelineWidget::HeaderIndentWidth;
|
const int indent_width = TimelineWidget::HeaderIndentWidth;
|
||||||
layout_headers_recursive(layoutTree.begin(),
|
totalHeight = layout_headers_recursive(layoutTree.begin(),
|
||||||
offset, animation_state, header_width, indent_width, 0, true);
|
0, header_width, indent_width, 0, true);
|
||||||
|
|
||||||
totalHeight = offset;
|
|
||||||
|
|
||||||
// Signal that the layout has changed
|
// Signal that the layout has changed
|
||||||
timelineWidget.on_layout_changed();
|
timelineWidget.on_layout_changed();
|
||||||
|
|
@ -168,15 +164,16 @@ TimelineLayoutHelper::update_layout()
|
||||||
begin_animation();
|
begin_animation();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
TimelineLayoutHelper::layout_headers_recursive(
|
TimelineLayoutHelper::layout_headers_recursive(
|
||||||
TrackTree::iterator_base parent_iterator,
|
TrackTree::iterator_base parent_iterator,
|
||||||
int &offset, int &common_animation_state,
|
const int branch_offset, const int header_width,
|
||||||
const int header_width, const int indent_width,
|
const int indent_width, const int depth, const bool parent_expanded)
|
||||||
const int depth, const bool parent_expanded)
|
|
||||||
{
|
{
|
||||||
REQUIRE(depth >= 0);
|
REQUIRE(depth >= 0);
|
||||||
|
|
||||||
|
int child_offset = 0;
|
||||||
|
|
||||||
TrackTree::sibling_iterator iterator;
|
TrackTree::sibling_iterator iterator;
|
||||||
for(iterator = layoutTree.begin(parent_iterator);
|
for(iterator = layoutTree.begin(parent_iterator);
|
||||||
iterator != layoutTree.end(parent_iterator);
|
iterator != layoutTree.end(parent_iterator);
|
||||||
|
|
@ -189,7 +186,7 @@ TimelineLayoutHelper::layout_headers_recursive(
|
||||||
lookup_timeline_track(model_track);
|
lookup_timeline_track(model_track);
|
||||||
|
|
||||||
// Is the track animating?
|
// Is the track animating?
|
||||||
const int animation_state =
|
const int track_animation_state =
|
||||||
timeline_track->get_expand_animation_state();
|
timeline_track->get_expand_animation_state();
|
||||||
|
|
||||||
// Is the track going to be shown?
|
// Is the track going to be shown?
|
||||||
|
|
@ -201,12 +198,12 @@ TimelineLayoutHelper::layout_headers_recursive(
|
||||||
|
|
||||||
headerBoxes[timeline_track] = Gdk::Rectangle(
|
headerBoxes[timeline_track] = Gdk::Rectangle(
|
||||||
indent, // x
|
indent, // x
|
||||||
offset, // y
|
branch_offset + child_offset, // y
|
||||||
max( header_width - indent, 0 ), // width
|
max( header_width - indent, 0 ), // width
|
||||||
track_height); // height
|
track_height); // height
|
||||||
|
|
||||||
// Offset for the next header
|
// Offset for the next header
|
||||||
offset += track_height + TimelineWidget::TrackPadding;
|
child_offset += track_height + TimelineWidget::TrackPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recurse to children
|
// Recurse to children
|
||||||
|
|
@ -215,61 +212,50 @@ TimelineLayoutHelper::layout_headers_recursive(
|
||||||
timeline_track->get_expanded())
|
timeline_track->get_expanded())
|
||||||
&& parent_expanded;
|
&& parent_expanded;
|
||||||
|
|
||||||
layout_headers_recursive(iterator, offset, common_animation_state,
|
const int branch_height = layout_headers_recursive(
|
||||||
|
iterator, branch_offset + child_offset,
|
||||||
header_width, indent_width, depth + 1, expand_child);
|
header_width, indent_width, depth + 1, expand_child);
|
||||||
|
|
||||||
// Do collapse animation as necessary
|
// Do collapse animation as necessary
|
||||||
if(animation_state != Track::NoAnimationState)
|
if(track_animation_state != Track::NoAnimationState)
|
||||||
{
|
{
|
||||||
|
// Tick the track expand animation
|
||||||
timeline_track->tick_expand_animation();
|
timeline_track->tick_expand_animation();
|
||||||
|
|
||||||
// Calculate the total height of the branch
|
// Calculate the height of te area which will be
|
||||||
// Get the top and bottom descendants, and use them to get the
|
// shown as expanded
|
||||||
// total height
|
const float a = ((float)track_animation_state /
|
||||||
const shared_ptr<timeline::Track> &first_descendant_track =
|
(float)Track::MaxExpandAnimation);
|
||||||
lookup_timeline_track(
|
child_offset += branch_height * a * a;
|
||||||
*(++TrackTree::pre_order_iterator(iterator)));
|
const int y_limit = branch_offset + child_offset;
|
||||||
const shared_ptr<timeline::Track> &last_descendant_track =
|
|
||||||
lookup_timeline_track(
|
|
||||||
*(--TrackTree::pre_order_iterator(
|
|
||||||
++TrackTree::sibling_iterator(iterator))));
|
|
||||||
|
|
||||||
const Gdk::Rectangle &first_rect =
|
|
||||||
headerBoxes[first_descendant_track];
|
|
||||||
const Gdk::Rectangle &last_rect =
|
|
||||||
headerBoxes[last_descendant_track];
|
|
||||||
|
|
||||||
const int branch_height =
|
|
||||||
(last_rect.get_y() + last_rect.get_height()) -
|
|
||||||
first_rect.get_y();
|
|
||||||
|
|
||||||
// Now we have the branch_height, obscure tracks according to
|
|
||||||
// the animation state
|
|
||||||
const float a = (1.0f - (float)animation_state / (float)Track::MaxExpandAnimation);
|
|
||||||
offset = offset - branch_height * a * a;
|
|
||||||
|
|
||||||
|
// Obscure tracks according to the animation state
|
||||||
TrackTree::pre_order_iterator descendant_iterator(iterator);
|
TrackTree::pre_order_iterator descendant_iterator(iterator);
|
||||||
descendant_iterator++;
|
descendant_iterator++;
|
||||||
TrackTree::sibling_iterator end_iterator(iterator);
|
TrackTree::sibling_iterator end(iterator);
|
||||||
end_iterator++;
|
end++;
|
||||||
|
|
||||||
for(descendant_iterator = layoutTree.begin(parent_iterator);
|
for(descendant_iterator = layoutTree.begin(parent_iterator);
|
||||||
descendant_iterator != end_iterator;
|
descendant_iterator != end;
|
||||||
descendant_iterator++)
|
descendant_iterator++)
|
||||||
{
|
{
|
||||||
const weak_ptr<timeline::Track> &track =
|
const Gdk::Rectangle &rect = headerBoxes[
|
||||||
lookup_timeline_track(*descendant_iterator);
|
lookup_timeline_track(*descendant_iterator)];
|
||||||
const Gdk::Rectangle &rect = headerBoxes[track];
|
|
||||||
if(rect.get_y() + rect.get_height() > offset)
|
if(rect.get_y() + rect.get_height() > y_limit)
|
||||||
headerBoxes.erase(track);
|
headerBoxes.erase(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the global animation state includes this branch's
|
// Make sure the global animation state includes this branch's
|
||||||
// animation state
|
// animation state
|
||||||
common_animation_state = max(
|
animation_state = max(
|
||||||
common_animation_state, animation_state);
|
animation_state, track_animation_state);
|
||||||
}
|
}
|
||||||
|
else // If no animation, just append the normal length
|
||||||
|
child_offset += branch_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return child_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<timeline::Track>
|
shared_ptr<timeline::Track>
|
||||||
|
|
|
||||||
|
|
@ -155,11 +155,12 @@ protected:
|
||||||
* tree.
|
* tree.
|
||||||
* @param[in] parent_iterator The iterator of the parent of the branch
|
* @param[in] parent_iterator The iterator of the parent of the branch
|
||||||
* whose boxes will be laid out.
|
* whose boxes will be laid out.
|
||||||
* @param[in,out] offset The accumulating y-offset value in pixels.
|
* @param[in] branch_offset The y-coordinate of the start of this
|
||||||
* This value should be set to 0 on the first call, and will
|
* branch as measured in pixels from the origin.
|
||||||
* susequently accumulate the offset of each box.
|
|
||||||
* @param[in] header_width The width of the header container widget in
|
* @param[in] header_width The width of the header container widget in
|
||||||
* pixels
|
* pixels.
|
||||||
|
* @param[in] header_width The width of indentation per branch in
|
||||||
|
* pixels.
|
||||||
* @param[in] depth The depth within the tree of tracks. depth = 0 for
|
* @param[in] depth The depth within the tree of tracks. depth = 0 for
|
||||||
* root tracks.
|
* root tracks.
|
||||||
* @param[in] parent_expanded This value is set to true if all of the
|
* @param[in] parent_expanded This value is set to true if all of the
|
||||||
|
|
@ -167,12 +168,10 @@ protected:
|
||||||
* false if any of them are collapsed.
|
* false if any of them are collapsed.
|
||||||
* @see update_layout()
|
* @see update_layout()
|
||||||
**/
|
**/
|
||||||
#warning is_animating not documented
|
int layout_headers_recursive(
|
||||||
void layout_headers_recursive(
|
TrackTree::iterator_base parent_iterator, const int branch_offset,
|
||||||
TrackTree::iterator_base parent_iterator,
|
const int header_width, const int indent_width, const int depth,
|
||||||
int &offset, int &common_animation_state,
|
const bool parent_expanded);
|
||||||
const int header_width, const int indent_width,
|
|
||||||
const int depth, const bool parent_expanded);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper function which calls lookup_timeline_track within the
|
* A helper function which calls lookup_timeline_track within the
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue