Animation

Animation — Functions for handling animation.

Functions

Includes

#include <abydos.h>

Description

Two approaches can be used for handling animations. Either by frame or by time. The latter is usually more convinient for displaying the animation. Abydos can tell you for how long you should display a frame, or how long you should wait before updating the time of the animation and redraw it. But measuring time is beyond the scope of abydos. Basically you do something like this.

1
2
3
4
5
6
7
8
last_time = now();
for(;;){
    abydos_render(ar,cr,0);
    delay(abydos_get_delay(ar));
    this_time = now();
    abydos_add_time(ar,this_time - last_time)
    last_time = this_time;
}

Of course you don't want to use a simple delay in a real application. Instead you should use some kind of event scheduler to get a callback. Please also note that if you need to round the delay time you get from abydos_get_delay() you must round it up. Otherwise the time of the animation will be set to right before the frame change (and the next time it will be rounded down to zero and you will get nowere).

Functions

abydos_get_frame_count ()

int
abydos_get_frame_count (abydos_t *ar);

Get the number of frames of an animation. Some animations may not be based around the concept of frames but are continous to their nature. In this case ABYDOS_FEATURE_SCALABLE_TIME will be set and frames will be placed at reasonable intervals. It is also possible that ABYDOS_FEATURE_SCALABLE_TIME is set for singe frame images (and duration of zero). In that case the image will still be animated somehow, but depending on some external variable (such as the clock time).

retutns: The number of frames.

Parameters

ar

an abydos_t

 

abydos_get_total_duration ()

double
abydos_get_total_duration (abydos_t *ar);

Get the total duration of an animation.

Parameters

ar

an abydos_t

 

Returns

The total duration in seconds.


abydos_get_frame_at_time ()

int
abydos_get_frame_at_time (abydos_t *ar,
                          double sec);

Get the index if the frame at sec . Note that this cannot simply be calculated by dividing sec with the duration of the first frame, since frames may have different duration.

Parameters

ar

an abydos_t

 

sec

time in seconds

 

Returns

The frame index starting at 0.


abydos_get_frame_duration ()

double
abydos_get_frame_duration (abydos_t *ar,
                           int frame);

Get the time (into the animation) at which frame should appear.

Parameters

ar

an abydos_t

 

frame

frame index starting from 0

 

Returns

The time in seconds.


abydos_get_time ()

double
abydos_get_time (abydos_t *ar);

Get the current time into the animation.

Parameters

ar

an abydos_t

 

Returns

The time in seconds.


abydos_get_frame ()

int
abydos_get_frame (abydos_t *ar);

Get the index of the current frame.

Parameters

ar

an abydos_t

 

Returns

The frame index staring at 0.


abydos_set_time ()

cairo_bool_t
abydos_set_time (abydos_t *ar,
                 double sec);

Set the time of the animation in seconds. It will also implicitly set the corresponding frame.

Parameters

ar

an abydos_t

 

sec

time in seconds

 

Returns

True if the the frame has changed.


abydos_add_time ()

cairo_bool_t
abydos_add_time (abydos_t *ar,
                 double sec);

Advance the animation sec seconds. It will also implicitly set the corresponding frame.

Parameters

ar

an abydos_t

 

sec

time in seconds

 

Returns

True if the the frame has changed.


abydos_set_frame ()

void
abydos_set_frame (abydos_t *ar,
                  int frame);

Select frame which will also implicitly set the time of the animation to the time for this frame.

Parameters

ar

an abydos_t

 

frame

frame index starting at 0

 

abydos_set_frame_default ()

void
abydos_set_frame_default (abydos_t *ar);

Selectes the frame that is defined as the default frame (or the first frame if no default frame is defined). Call this function if you intend to show only one frame. (It is currently assumed that you are going to show the animation from beginning to end so the first frame is initially selected, but that may change.)

Parameters

ar

an abydos_t

 

abydos_next_frame ()

void
abydos_next_frame (abydos_t *ar);

Advance the animation one frame and increse the time accordingly.

Parameters

ar

an abydos_t

 

abydos_get_delay ()

double
abydos_get_delay (abydos_t *ar);

Get the amount of time until the next frame in seconds. Note that if this value needs to be rounded for some reason, it must be rounded up (otherwise the next time advancement will land right before the frame change).

Parameters

ar

an abydos_t

 

Returns

Time in seconds.