This source file includes following definitions.
- slide_duration_
- Reset
- Reset
- Show
- Hide
- SetSlideDuration
- GetCurrentValue
- AnimateToState
#include "ui/gfx/animation/slide_animation.h"
#include <math.h>
namespace gfx {
static const int kDefaultFrameRateHz = 60;
static const int kDefaultDurationMs = 120;
SlideAnimation::SlideAnimation(AnimationDelegate* target)
: LinearAnimation(kDefaultFrameRateHz, target),
target_(target),
tween_type_(Tween::EASE_OUT),
showing_(false),
value_start_(0),
value_end_(0),
value_current_(0),
slide_duration_(kDefaultDurationMs) {
}
SlideAnimation::~SlideAnimation() {
}
void SlideAnimation::Reset() {
Reset(0);
}
void SlideAnimation::Reset(double value) {
Stop();
showing_ = static_cast<bool>(value == 1);
value_current_ = value;
}
void SlideAnimation::Show() {
if (showing_)
return;
showing_ = true;
value_start_ = value_current_;
value_end_ = 1.0;
if (slide_duration_ == 0) {
AnimateToState(1.0);
return;
} else if (value_current_ == value_end_) {
return;
}
SetDuration(static_cast<int>(slide_duration_ * (1 - value_current_)));
Start();
}
void SlideAnimation::Hide() {
if (!showing_)
return;
showing_ = false;
value_start_ = value_current_;
value_end_ = 0.0;
if (slide_duration_ == 0) {
AnimateToState(0.0);
return;
} else if (value_current_ == value_end_) {
return;
}
SetDuration(static_cast<int>(slide_duration_ * value_current_));
Start();
}
void SlideAnimation::SetSlideDuration(int duration) {
slide_duration_ = duration;
}
double SlideAnimation::GetCurrentValue() const {
return value_current_;
}
void SlideAnimation::AnimateToState(double state) {
if (state > 1.0)
state = 1.0;
state = Tween::CalculateValue(tween_type_, state);
value_current_ = value_start_ + (value_end_ - value_start_) * state;
if (tween_type_ == Tween::EASE_OUT_SNAP &&
fabs(value_current_ - value_end_) <= 0.06)
value_current_ = value_end_;
if ((value_end_ >= value_start_ && value_current_ > value_end_) ||
(value_end_ < value_start_ && value_current_ < value_end_)) {
value_current_ = value_end_;
}
}
}