Empirical
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
emp::web::Animate Class Reference

An object that, when active, repeatedly calls a function as fast as possible, to a maximum of 60 frames per second. More...

#include <Animate.h>

Public Member Functions

 Animate ()
 
template<typename... W_TYPES>
 Animate (const anim_fun_t &fun, W_TYPES &...targets)
 
template<typename... W_TYPES>
 Animate (const std::function< void(double)> &fun, W_TYPES &...targets)
 
template<typename... W_TYPES>
 Animate (const std::function< void()> &fun, W_TYPES &...targets)
 
virtual ~Animate ()
 
 Animate (const Animate &)=delete
 Do not copy animations directly. More...
 
Animateoperator= (const Animate &)=delete
 
void Start ()
 Start this animation running. More...
 
void Stop ()
 Halt this animation for now. More...
 
void Step ()
 Take a single step in this animation. More...
 
void ToggleActive ()
 Toggle whether this animation is running or paused. More...
 
bool GetActive () const
 Determine if this animation is currently running. More...
 
bool GetDoStep () const
 Determine if this animation is currently in the process of running a single step. More...
 
double GetStartTime () const
 Return the time point that this animation started MOST RECENTLY. More...
 
double GetPrevTime () const
 Determine the time point when this animation last updated a frame. More...
 
double GetCurTime () const
 Get the current time of the animation. More...
 
double GetStepTime () const
 Determine how long the last step between frames took. More...
 
double GetRunTime () const
 Determine the total amount of time that this animation has run. More...
 
int GetFrameCount () const
 Determine how many total frames have existed thus far in this animation. More...
 
void SetCallback (const anim_fun_t &fun)
 
void SetCallback (const std::function< void(double)> &fun)
 
void SetCallback (const std::function< void()> &fun)
 Set a new function for this animation to call when running that takes no arguments. More...
 
Button GetToggleButton (const std::string &but_name, const std::string &start_label="Start", const std::string &stop_label="Stop")
 
Button GetStepButton (const std::string &but_name, const std::string &label="Step")
 

Protected Types

using anim_fun_t = std::function< void(const Animate &)>
 The full version of the animate function takes a const reference to the animate object. More...
 

Protected Member Functions

void LoadTargets ()
 
template<typename... T>
void LoadTargets (const web::Widget &target1, const T &...other_targets)
 
void AdvanceFrame ()
 
virtual void DoFrame ()
 

Protected Attributes

anim_fun_t anim_fun
 Function to repeatedly run for animation. More...
 
emp::vector< web::Widgettargets
 What widgets should be refreshed after each frame? More...
 
bool active
 Is this animation currently running? More...
 
bool do_step
 Should this animation take just a single step? More...
 
size_t callback_id
 Intenral ID for javascript to call back AdvanceFrame() More...
 
double start_time
 At what time did this animation most recently start? More...
 
double prev_time
 What was the time point of the previous frame? More...
 
double cur_time
 What time did the current frame start? More...
 
double run_time
 How much run time has accumulated? More...
 
int frame_count
 How many animation frames have gone by? More...
 
Button toggle_but
 A button to start/stop this animation. More...
 
Button step_but
 A button to advance this animation one step. More...
 

Detailed Description

An object that, when active, repeatedly calls a function as fast as possible, to a maximum of 60 frames per second.

Parameters to the animation function can be:

Control methods: void Start() void Stop() void Step() void ToggleActive()

Access methods: bool GetActive() const bool GetDoStep() const double GetStartTime() const double GetPrevTime() const double GetCurTime() const double GetStepTime() const double GetRunTime() const int GetFrameCount() const

Config methods: void SetCallback(const std::function<void(const Animate &)> & fun) void SetCallback(const std::function<void(double)> & fun) void SetCallback(const std::function<void()> & fun)

Member Typedef Documentation

using emp::web::Animate::anim_fun_t = std::function<void(const Animate &)>
protected

The full version of the animate function takes a const reference to the animate object.

Constructor & Destructor Documentation

emp::web::Animate::Animate ( )
inline

Setup an Animate object to call an anim_fun as fast as possible, at most 60 times a second. Call virtual function DoFrame() if no other functon is provided (which can be overridden if you derive a new class from Animate)

template<typename... W_TYPES>
emp::web::Animate::Animate ( const anim_fun_t fun,
W_TYPES &...  targets 
)
inline

Construct an Animate object with the function to run each animation step and zero or more UI elements that should be updated after each frame.

template<typename... W_TYPES>
emp::web::Animate::Animate ( const std::function< void(double)> &  fun,
W_TYPES &...  targets 
)
inline
template<typename... W_TYPES>
emp::web::Animate::Animate ( const std::function< void()> &  fun,
W_TYPES &...  targets 
)
inline
virtual emp::web::Animate::~Animate ( )
inlinevirtual
emp::web::Animate::Animate ( const Animate )
delete

Do not copy animations directly.

Member Function Documentation

void emp::web::Animate::AdvanceFrame ( )
inlineprotected
virtual void emp::web::Animate::DoFrame ( )
inlineprotectedvirtual

DoFrame() is called by default if no animation function is provided. As such, an animation can be built by deriving a class from Animate and overriding this function.

bool emp::web::Animate::GetActive ( ) const
inline

Determine if this animation is currently running.

double emp::web::Animate::GetCurTime ( ) const
inline

Get the current time of the animation.

bool emp::web::Animate::GetDoStep ( ) const
inline

Determine if this animation is currently in the process of running a single step.

int emp::web::Animate::GetFrameCount ( ) const
inline

Determine how many total frames have existed thus far in this animation.

double emp::web::Animate::GetPrevTime ( ) const
inline

Determine the time point when this animation last updated a frame.

double emp::web::Animate::GetRunTime ( ) const
inline

Determine the total amount of time that this animation has run.

double emp::web::Animate::GetStartTime ( ) const
inline

Return the time point that this animation started MOST RECENTLY.

Button emp::web::Animate::GetStepButton ( const std::string &  but_name,
const std::string &  label = "Step" 
)
inline

Get a step button that will advance this animation one frame.

Parameters
but_nameThe HTML identifier used for this button.
labelThe name shown on the button.
double emp::web::Animate::GetStepTime ( ) const
inline

Determine how long the last step between frames took.

Button emp::web::Animate::GetToggleButton ( const std::string &  but_name,
const std::string &  start_label = "Start",
const std::string &  stop_label = "Stop" 
)
inline

Get a toggle button that will start/stop this animation.

Parameters
but_nameThe HTML identifier used for this button.
start_labelThe name on the button when it will start the animation (default="Start")
stop_labelThe name on the button when it will halt the animation (default="Stop")
void emp::web::Animate::LoadTargets ( )
inlineprotected
template<typename... T>
void emp::web::Animate::LoadTargets ( const web::Widget target1,
const T &...  other_targets 
)
inlineprotected
Animate& emp::web::Animate::operator= ( const Animate )
delete
void emp::web::Animate::SetCallback ( const anim_fun_t fun)
inline

Set a new function for this animation to call when running that takes a const reference to the Animation object as an argument.

void emp::web::Animate::SetCallback ( const std::function< void(double)> &  fun)
inline

Set a new function for this animation to call when running that takes the amount of time since the last frame (a double) as an argument.

void emp::web::Animate::SetCallback ( const std::function< void()> &  fun)
inline

Set a new function for this animation to call when running that takes no arguments.

void emp::web::Animate::Start ( )
inline

Start this animation running.

void emp::web::Animate::Step ( )
inline

Take a single step in this animation.

void emp::web::Animate::Stop ( )
inline

Halt this animation for now.

void emp::web::Animate::ToggleActive ( )
inline

Toggle whether this animation is running or paused.

Member Data Documentation

bool emp::web::Animate::active
protected

Is this animation currently running?

anim_fun_t emp::web::Animate::anim_fun
protected

Function to repeatedly run for animation.

size_t emp::web::Animate::callback_id
protected

Intenral ID for javascript to call back AdvanceFrame()

double emp::web::Animate::cur_time
protected

What time did the current frame start?

bool emp::web::Animate::do_step
protected

Should this animation take just a single step?

int emp::web::Animate::frame_count
protected

How many animation frames have gone by?

double emp::web::Animate::prev_time
protected

What was the time point of the previous frame?

double emp::web::Animate::run_time
protected

How much run time has accumulated?

double emp::web::Animate::start_time
protected

At what time did this animation most recently start?

Button emp::web::Animate::step_but
protected

A button to advance this animation one step.

emp::vector<web::Widget> emp::web::Animate::targets
protected

What widgets should be refreshed after each frame?

Button emp::web::Animate::toggle_but
protected

A button to start/stop this animation.


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