]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[throbber] Change frame sequencer function
authorRay Strode <rstrode@redhat.com>
Thu, 6 May 2010 14:04:26 +0000 (10:04 -0400)
committerRay Strode <rstrode@redhat.com>
Thu, 6 May 2010 14:04:26 +0000 (10:04 -0400)
The throbber has a function for determining which frame
to show based on the current time.  This function was:

  ƒrame(t) = number_of_frames ∙ (⅟₂ sin(t) + ⅟₂)

Which basically oscillates between 0 and number_of_frames - 1,
over and over again.  There are two problems with this function;
  - after it runs through all the frames in order, it then procedes
    to run through them backward.
  - This function also starts in the middle of the set of throbber
    frames.

These problems don't matter for spinfinity, but will look wrong for most
other themes.

The new function is this:

  ƒrame(t) = number_of_frames ∙ (1⁄duration)(t mod duration)

This function solves both problems.  At time 0 it uses frame 0, and
after the last frame it jumps back to the first frame.

src/libply-splash-graphics/ply-throbber.c

index bba639d1d44fe412df2a10f8ab2441adecf4146c..45638b7a91b25733d5451522c590a1163c1c00bc 100644 (file)
 #define FRAMES_PER_SECOND 30
 #endif
 
+#ifndef THROBBER_DURATION
+#define THROBBER_DURATION 2.0
+#endif
+
 struct _ply_throbber
 {
   ply_array_t *frames;
@@ -133,6 +137,7 @@ animate_at_time (ply_throbber_t *throbber,
   int number_of_frames;
   ply_pixel_buffer_t * const * frames;
   bool should_continue;
+  double percent_in_sequence;
 
   number_of_frames = ply_array_get_size (throbber->frames);
 
@@ -140,8 +145,8 @@ animate_at_time (ply_throbber_t *throbber,
     return true;
 
   should_continue = true;
-
-  throbber->frame_number = (.5 * sin (time) + .5) * number_of_frames;
+  percent_in_sequence = fmod (time, THROBBER_DURATION) / THROBBER_DURATION;
+  throbber->frame_number = (int) (number_of_frames * percent_in_sequence);
 
   if (throbber->stop_trigger != NULL)
     {