Made animation time based not tick based

This commit is contained in:
Joel Holdsworth 2009-01-05 00:05:14 +00:00
parent 8db54f1179
commit 43897d214d
3 changed files with 25 additions and 11 deletions

View file

@ -271,9 +271,9 @@ TimelineLayoutHelper::lookup_timeline_track(
void void
TimelineLayoutHelper::begin_animation() TimelineLayoutHelper::begin_animation()
{ {
animationTimer = Glib::signal_timeout().connect( animationTimer = Glib::signal_idle().connect(
sigc::mem_fun(this, &TimelineLayoutHelper::on_animation_tick), sigc::mem_fun(this, &TimelineLayoutHelper::on_animation_tick),
AnimationTimeout); Glib::PRIORITY_DEFAULT);
} }
bool bool

View file

@ -37,7 +37,10 @@ namespace widgets {
namespace timeline { namespace timeline {
const int Track::NoAnimationState = -1; const int Track::NoAnimationState = -1;
const int Track::MaxExpandAnimation = 10; const int Track::MaxExpandAnimation = 65536;
const double Track::ExpandAnimationPeriod = 0.15;
Glib::Timer Track::timer;
Track::Track(TimelineWidget &timeline_widget, Track::Track(TimelineWidget &timeline_widget,
shared_ptr<model::Track> track) : shared_ptr<model::Track> track) :
@ -50,6 +53,9 @@ Track::Track(TimelineWidget &timeline_widget,
{ {
REQUIRE(model_track); REQUIRE(model_track);
// Ensure that the timer is running
timer.start();
titleMenuButton.set_relief(RELIEF_HALF); titleMenuButton.set_relief(RELIEF_HALF);
buttonBar.append(enableButton); buttonBar.append(enableButton);
@ -126,6 +132,8 @@ Track::expand_collapse(ExpandDirection direction)
expanded = false; expanded = false;
expandAnimationState = MaxExpandAnimation; expandAnimationState = MaxExpandAnimation;
} }
lastTickTime = timer.elapsed();
} }
int int
@ -147,19 +155,23 @@ Track::tick_expand_animation()
return; return;
} }
const double delta = MaxExpandAnimation * (timer.elapsed() - lastTickTime) / ExpandAnimationPeriod;
if(expandDirection == Expand) if(expandDirection == Expand)
{ {
expandAnimationState++; expandAnimationState += delta;
if(expandAnimationState >= MaxExpandAnimation) if(expandAnimationState >= MaxExpandAnimation)
expandAnimationState = NoAnimationState; expandAnimationState = NoAnimationState;
} }
else else
{ {
expandAnimationState--; expandAnimationState -= delta;
if(expandAnimationState <= 0) if(expandAnimationState <= 0)
expandAnimationState = NoAnimationState; expandAnimationState = NoAnimationState;
} }
lastTickTime = timer.elapsed();
ENSURE((expandAnimationState >= 0 && ENSURE((expandAnimationState >= 0 &&
expandAnimationState <= MaxExpandAnimation) || expandAnimationState <= MaxExpandAnimation) ||
expandAnimationState == NoAnimationState); expandAnimationState == NoAnimationState);

View file

@ -77,6 +77,7 @@ public:
public: public:
static const int NoAnimationState; static const int NoAnimationState;
static const int MaxExpandAnimation; static const int MaxExpandAnimation;
static const double ExpandAnimationPeriod;
private: private:
//----- Internals -----// //----- Internals -----//
@ -97,10 +98,11 @@ protected:
private: private:
bool expanded; bool expanded;
ExpandDirection expandDirection; ExpandDirection expandDirection;
int expandAnimationState; double expandAnimationState;
static Glib::Timer timer;
double lastTickTime;
//----- Header Widgets ------// //----- Header Widgets ------//