Simplified the layout animation a little
This commit is contained in:
parent
f3339a538b
commit
05b17a7148
2 changed files with 43 additions and 21 deletions
|
|
@ -42,7 +42,7 @@ const int TimelineLayoutHelper::AnimationTimeout = 20; // 20ms
|
||||||
TimelineLayoutHelper::TimelineLayoutHelper(TimelineWidget &owner) :
|
TimelineLayoutHelper::TimelineLayoutHelper(TimelineWidget &owner) :
|
||||||
timelineWidget(owner),
|
timelineWidget(owner),
|
||||||
totalHeight(0),
|
totalHeight(0),
|
||||||
animation_state(Track::NoAnimationState)
|
is_animating(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ void
|
||||||
TimelineLayoutHelper::update_layout()
|
TimelineLayoutHelper::update_layout()
|
||||||
{
|
{
|
||||||
// Reset the animation state value, before it gets recalculated
|
// Reset the animation state value, before it gets recalculated
|
||||||
animation_state = Track::NoAnimationState;
|
is_animating = false;
|
||||||
|
|
||||||
// Clear previously cached layout
|
// Clear previously cached layout
|
||||||
headerBoxes.clear();
|
headerBoxes.clear();
|
||||||
|
|
@ -160,7 +160,7 @@ TimelineLayoutHelper::update_layout()
|
||||||
timelineWidget.on_layout_changed();
|
timelineWidget.on_layout_changed();
|
||||||
|
|
||||||
// Begin animating as necessary
|
// Begin animating as necessary
|
||||||
if(animation_state != Track::NoAnimationState && !animationTimer)
|
if(is_animating && !animationTimer)
|
||||||
begin_animation();
|
begin_animation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,6 +188,8 @@ TimelineLayoutHelper::layout_headers_recursive(
|
||||||
// Is the track animating?
|
// Is the track animating?
|
||||||
const int track_animation_state =
|
const int track_animation_state =
|
||||||
timeline_track->get_expand_animation_state();
|
timeline_track->get_expand_animation_state();
|
||||||
|
if(track_animation_state != Track::NoAnimationState)
|
||||||
|
is_animating = true;
|
||||||
|
|
||||||
// Is the track going to be shown?
|
// Is the track going to be shown?
|
||||||
if(parent_expanded)
|
if(parent_expanded)
|
||||||
|
|
@ -208,11 +210,10 @@ TimelineLayoutHelper::layout_headers_recursive(
|
||||||
|
|
||||||
// Recurse to children
|
// Recurse to children
|
||||||
const bool expand_child =
|
const bool expand_child =
|
||||||
((animation_state != Track::NoAnimationState) ||
|
(is_animating || timeline_track->get_expanded())
|
||||||
timeline_track->get_expanded())
|
|
||||||
&& parent_expanded;
|
&& parent_expanded;
|
||||||
|
|
||||||
const int branch_height = layout_headers_recursive(
|
int child_branch_height = layout_headers_recursive(
|
||||||
iterator, branch_offset + child_offset,
|
iterator, branch_offset + child_offset,
|
||||||
header_width, indent_width, depth + 1, expand_child);
|
header_width, indent_width, depth + 1, expand_child);
|
||||||
|
|
||||||
|
|
@ -226,8 +227,13 @@ TimelineLayoutHelper::layout_headers_recursive(
|
||||||
// shown as expanded
|
// shown as expanded
|
||||||
const float a = ((float)track_animation_state /
|
const float a = ((float)track_animation_state /
|
||||||
(float)Track::MaxExpandAnimation);
|
(float)Track::MaxExpandAnimation);
|
||||||
child_offset += branch_height * a * a;
|
g_message("branch_height = %d", child_branch_height);
|
||||||
const int y_limit = branch_offset + child_offset;
|
child_branch_height *= a * a;
|
||||||
|
const int y_limit =
|
||||||
|
branch_offset + child_offset + child_branch_height;
|
||||||
|
g_message("track_animation_state = %d", track_animation_state);
|
||||||
|
g_message("branch_height = %d", child_branch_height);
|
||||||
|
g_message("y_limit = %d", y_limit);
|
||||||
|
|
||||||
// Obscure tracks according to the animation state
|
// Obscure tracks according to the animation state
|
||||||
TrackTree::pre_order_iterator descendant_iterator(iterator);
|
TrackTree::pre_order_iterator descendant_iterator(iterator);
|
||||||
|
|
@ -239,20 +245,16 @@ TimelineLayoutHelper::layout_headers_recursive(
|
||||||
descendant_iterator != end;
|
descendant_iterator != end;
|
||||||
descendant_iterator++)
|
descendant_iterator++)
|
||||||
{
|
{
|
||||||
const Gdk::Rectangle &rect = headerBoxes[
|
const weak_ptr<timeline::Track> track =
|
||||||
lookup_timeline_track(*descendant_iterator)];
|
lookup_timeline_track(*descendant_iterator);
|
||||||
|
const Gdk::Rectangle &rect = headerBoxes[track];
|
||||||
|
|
||||||
if(rect.get_y() + rect.get_height() > y_limit)
|
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
|
|
||||||
// animation state
|
|
||||||
animation_state = max(
|
|
||||||
animation_state, track_animation_state);
|
|
||||||
}
|
}
|
||||||
else // If no animation, just append the normal length
|
|
||||||
child_offset += branch_height;
|
child_offset += child_branch_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return child_offset;
|
return child_offset;
|
||||||
|
|
@ -282,7 +284,7 @@ bool
|
||||||
TimelineLayoutHelper::on_animation_tick()
|
TimelineLayoutHelper::on_animation_tick()
|
||||||
{
|
{
|
||||||
update_layout();
|
update_layout();
|
||||||
return animation_state != Track::NoAnimationState;
|
return is_animating;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace timeline
|
} // namespace timeline
|
||||||
|
|
|
||||||
|
|
@ -187,8 +187,14 @@ protected:
|
||||||
boost::shared_ptr<timeline::Track> lookup_timeline_track(
|
boost::shared_ptr<timeline::Track> lookup_timeline_track(
|
||||||
boost::shared_ptr<model::Track> model_track);
|
boost::shared_ptr<model::Track> model_track);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function which kicks off the animation timer.
|
||||||
|
**/
|
||||||
void begin_animation();
|
void begin_animation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The animation timer tick callback.
|
||||||
|
**/
|
||||||
bool on_animation_tick();
|
bool on_animation_tick();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -220,12 +226,26 @@ protected:
|
||||||
**/
|
**/
|
||||||
int totalHeight;
|
int totalHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The connection to the animation timer.
|
||||||
|
* @see begin_animation()
|
||||||
|
* @see on_animation_tick()
|
||||||
|
**/
|
||||||
sigc::connection animationTimer;
|
sigc::connection animationTimer;
|
||||||
|
|
||||||
int animation_state;
|
/**
|
||||||
|
* This value is true if the layout animation should continue.
|
||||||
|
* @remarks This value is recalculated by update_layout()
|
||||||
|
* @see update_layout()
|
||||||
|
* @see on_animation_tick()
|
||||||
|
**/
|
||||||
|
bool is_animating;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The frequencey of animation timer ticks in milliseconds.
|
||||||
|
**/
|
||||||
static const int AnimationTimeout;
|
static const int AnimationTimeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue