Back to index

unity  6.0.0
Public Member Functions | Public Attributes | Private Attributes
unity::Animator Class Reference

#include <Animator.h>

Inheritance diagram for unity::Animator:
Inheritance graph
[legend]
Collaboration diagram for unity::Animator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Animator (unsigned int default_duration, unsigned int fps_rate=30)
 ~Animator ()
void SetRate (unsigned int fps_rate)
void SetDuration (unsigned int duration)
unsigned int GetRate () const
unsigned int GetDuration () const
double GetProgress () const
bool IsRunning () const
void Start (double start_progress=0.0f)
void Start (unsigned int one_time_duration, double start_progress=0.0f)
bool DoStep ()
void Stop ()

Public Attributes

sigc::signal< void > animation_started
sigc::signal< void > animation_ended
sigc::signal< void, double > animation_updated
sigc::signal< void, double > animation_stopped

Private Attributes

glib::Source::UniquePtr timeout_
int64_t start_time_
unsigned int rate_
unsigned int duration_
unsigned int one_time_duration_
double start_progress_
double progress_

Detailed Description

Definition at line 28 of file Animator.h.


Constructor & Destructor Documentation

unity::Animator::Animator ( unsigned int  default_duration,
unsigned int  fps_rate = 30 
)

Definition at line 25 of file Animator.cpp.

  : start_time_(0)
  , rate_(1)
  , duration_(0)
  , one_time_duration_(0)
  , start_progress_(0.0f)
  , progress_(0.0f)
{
  SetDuration(default_duration);
  SetRate(fps_rate);
}

Here is the call graph for this function:

Definition at line 37 of file Animator.cpp.

{
  Stop();
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 109 of file Animator.cpp.

{
  const gint64 current_time = g_get_monotonic_time();
  const gint64 duration = one_time_duration_ > 0 ? one_time_duration_ : duration_;
  const gint64 end_time = start_time_ + duration;

  if (current_time < end_time && progress_ < 1.0f && duration > 0)
  {
    const double diff_time = current_time - start_time_;
    progress_ = CLAMP(start_progress_ + (diff_time / duration), 0.0f, 1.0f);
    animation_updated.emit(progress_);

    return true;
  }
  else
  {
    progress_ = 1.0f;
    animation_updated.emit(1.0f);
    animation_ended.emit();
    one_time_duration_ = 0;
    timeout_.reset();

    return false;
  }
}

Here is the caller graph for this function:

unsigned int unity::Animator::GetDuration ( ) const

Definition at line 61 of file Animator.cpp.

{
  return (one_time_duration_ > 0 ? one_time_duration_ : duration_) / 1000;
}
double unity::Animator::GetProgress ( ) const

Definition at line 71 of file Animator.cpp.

{
  return progress_;
}
unsigned int unity::Animator::GetRate ( ) const

Definition at line 53 of file Animator.cpp.

{
  if (rate_ != 0)
    return 1000 / rate_;

  return rate_;
}

Definition at line 66 of file Animator.cpp.

{
  return bool(timeout_);
}

Here is the caller graph for this function:

void unity::Animator::SetDuration ( unsigned int  duration)

Definition at line 48 of file Animator.cpp.

{
  duration_ = duration * 1000;
}

Here is the caller graph for this function:

void unity::Animator::SetRate ( unsigned int  fps_rate)

Definition at line 42 of file Animator.cpp.

{
  if (fps_rate != 0)
    rate_ = 1000 / fps_rate;
}

Here is the caller graph for this function:

void unity::Animator::Start ( double  start_progress = 0.0f)

Definition at line 92 of file Animator.cpp.

{
  Start(0, start_progress);
}

Here is the caller graph for this function:

void unity::Animator::Start ( unsigned int  one_time_duration,
double  start_progress = 0.0f 
)

Definition at line 76 of file Animator.cpp.

{
  if (!timeout_ && start_progress < 1.0f)
  {
    if (start_progress < 0.0f)
      start_progress = 0.0f;

    one_time_duration_ = one_time_duration * 1000;
    start_progress_ = start_progress;
    progress_ = start_progress_;
    start_time_ = g_get_monotonic_time();
    timeout_.reset(new glib::Timeout(rate_, sigc::mem_fun(this, &Animator::DoStep)));
    animation_started.emit();
  }
}

Here is the call graph for this function:

Definition at line 97 of file Animator.cpp.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 48 of file Animator.h.

Definition at line 47 of file Animator.h.

sigc::signal<void, double> unity::Animator::animation_stopped

Definition at line 51 of file Animator.h.

sigc::signal<void, double> unity::Animator::animation_updated

Definition at line 50 of file Animator.h.

unsigned int unity::Animator::duration_ [private]

Definition at line 57 of file Animator.h.

unsigned int unity::Animator::one_time_duration_ [private]

Definition at line 58 of file Animator.h.

double unity::Animator::progress_ [private]

Definition at line 60 of file Animator.h.

unsigned int unity::Animator::rate_ [private]

Definition at line 56 of file Animator.h.

Definition at line 59 of file Animator.h.

int64_t unity::Animator::start_time_ [private]

Definition at line 55 of file Animator.h.

Definition at line 54 of file Animator.h.


The documentation for this class was generated from the following files: