]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Add a throbber to the splash screen and build spinfinity
authorRay Strode <rstrode@redhat.com>
Wed, 28 May 2008 12:41:39 +0000 (08:41 -0400)
committerRay Strode <rstrode@redhat.com>
Wed, 28 May 2008 13:25:28 +0000 (09:25 -0400)
src/splash-plugins/spinfinity/Makefile.am
src/splash-plugins/spinfinity/spinfinity.c
src/splash-plugins/spinfinity/throbber-34.png [deleted file]
src/splash-plugins/spinfinity/throbber-35.png [deleted file]
src/splash-plugins/spinfinity/throbber-36.png [deleted file]
src/splash-plugins/spinfinity/throbber-37.png [deleted file]
src/splash-plugins/spinfinity/throbber.c [new file with mode: 0644]
src/splash-plugins/spinfinity/throbber.h [new file with mode: 0644]

index d39314b509e21126be17d2630f4a24d495d1f7e2..8461b9a7bc895fb85cad34a6162eee224d7c4e5f 100644 (file)
@@ -13,10 +13,48 @@ spinfinity_la_LIBADD = $(PLYMOUTH_LIBS) ../../libply/libply.la
 spinfinity_la_SOURCES = $(srcdir)/../../ply-boot-splash-plugin.h             \
                             $(srcdir)/../../ply-window.h                     \
                             $(srcdir)/../../ply-window.c                     \
+                            $(srcdir)/throbber.h                             \
+                            $(srcdir)/throbber.c                             \
                             $(srcdir)/spinfinity.c
 
+throbber_frames =                                                            \
+                    throbber-00.png                                          \
+                    throbber-01.png                                          \
+                    throbber-02.png                                          \
+                    throbber-03.png                                          \
+                    throbber-04.png                                          \
+                    throbber-05.png                                          \
+                    throbber-06.png                                          \
+                    throbber-07.png                                          \
+                    throbber-08.png                                          \
+                    throbber-09.png                                          \
+                    throbber-10.png                                          \
+                    throbber-11.png                                          \
+                    throbber-12.png                                          \
+                    throbber-13.png                                          \
+                    throbber-14.png                                          \
+                    throbber-15.png                                          \
+                    throbber-16.png                                          \
+                    throbber-17.png                                          \
+                    throbber-18.png                                          \
+                    throbber-19.png                                          \
+                    throbber-20.png                                          \
+                    throbber-21.png                                          \
+                    throbber-22.png                                          \
+                    throbber-23.png                                          \
+                    throbber-24.png                                          \
+                    throbber-25.png                                          \
+                    throbber-26.png                                          \
+                    throbber-27.png                                          \
+                    throbber-28.png                                          \
+                    throbber-29.png                                          \
+                    throbber-30.png                                          \
+                    throbber-31.png                                          \
+                    throbber-32.png                                          \
+                    throbber-33.png
+
 plymouthdir = $(datadir)/plymouth
-plymouth_DATA = bullet.png entry.png lock.png box.png
+plymouth_DATA = bullet.png entry.png lock.png box.png $(throbber_frames)
 
 EXTRA_DIST = $(plymouth_DATA)
 MAINTAINERCLEANFILES = Makefile.in
index bf48da6d43dcaed647059343dc57732e539f6d36..618e2d47ac412cdf8a5922569e66298ec19bc829 100644 (file)
@@ -49,6 +49,8 @@
 #include "ply-utils.h"
 #include "ply-window.h"
 
+#include "throbber.h"
+
 #include <linux/kd.h>
 
 #ifndef FRAMES_PER_SECOND
@@ -74,12 +76,10 @@ struct _ply_boot_splash_plugin
   ply_window_t *window;
 
   entry_t *entry;
+  throbber_t *throbber;
 
   ply_boot_splash_password_answer_handler_t password_answer_handler;
   void *password_answer_data;
-
-  double start_time;
-  double now;
 };
 
 static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin);
@@ -92,7 +92,6 @@ create_plugin (void)
 
   srand ((int) ply_get_timestamp ());
   plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));
-  plugin->start_time = 0.0;
 
   plugin->frame_buffer = ply_frame_buffer_new (NULL);
   plugin->logo_image = ply_image_new (PLYMOUTH_IMAGE_DIR "fedora-logo.png");
@@ -101,6 +100,8 @@ create_plugin (void)
   plugin->entry_image = ply_image_new (PLYMOUTH_IMAGE_DIR "entry.png");
   plugin->box_image = ply_image_new (PLYMOUTH_IMAGE_DIR "box.png");
 
+  plugin->throbber = throbber_new ("throbber-");
+
   return plugin;
 }
 
@@ -140,20 +141,16 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
   ply_image_free (plugin->box_image);
   ply_image_free (plugin->lock_image);
   ply_frame_buffer_free (plugin->frame_buffer);
+  throbber_free (plugin->throbber);
   free (plugin);
 }
 
 static void
-animate_at_time (ply_boot_splash_plugin_t *plugin,
-                 double                    time)
+draw_logo (ply_boot_splash_plugin_t *plugin)
 {
   ply_frame_buffer_area_t logo_area;
   uint32_t *logo_data;
   long width, height;
-  static double last_opacity = 0.0;
-  double opacity = 0.0;
-
-  ply_frame_buffer_pause_updates (plugin->frame_buffer);
 
   width = ply_image_get_width (plugin->logo_image);
   height = ply_image_get_height (plugin->logo_image);
@@ -164,61 +161,38 @@ animate_at_time (ply_boot_splash_plugin_t *plugin,
   logo_area.width = width;
   logo_area.height = height;
 
-
-  opacity = .5 * sin ((time / 5) * (2 * M_PI)) + .8;
-  opacity = CLAMP (opacity, 0, 1.0);
-
-  if (fabs (opacity - last_opacity) <= DBL_MIN)
-    {
-      ply_frame_buffer_unpause_updates (plugin->frame_buffer);
-      return;
-    }
-
-  last_opacity = opacity;
-
+  ply_frame_buffer_pause_updates (plugin->frame_buffer);
   ply_frame_buffer_fill_with_color (plugin->frame_buffer, &logo_area,
                                     0.0, 0.43, .71, 1.0);
-  ply_frame_buffer_fill_with_argb32_data_at_opacity (plugin->frame_buffer, 
-                                                     &logo_area, 0, 0,
-                                                     logo_data, opacity);
+  ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, 
+                                          &logo_area, 0, 0,
+                                          logo_data);
   ply_frame_buffer_unpause_updates (plugin->frame_buffer);
 }
 
 static void
-on_timeout (ply_boot_splash_plugin_t *plugin)
+start_animation (ply_boot_splash_plugin_t *plugin)
 {
-  double sleep_time;
 
-  ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_GRAPHICS);
-  plugin->now = ply_get_timestamp ();
+  long width, height;
+  ply_frame_buffer_area_t area;
+  assert (plugin != NULL);
+  assert (plugin->loop != NULL);
 
-  animate_at_time (plugin,
-                   plugin->now - plugin->start_time);
+  ply_frame_buffer_fill_with_color (plugin->frame_buffer, NULL,
+                                    0.0, 0.43, .71, 1.0);
 
-  sleep_time = 1.0 / FRAMES_PER_SECOND;
-  sleep_time = MAX (sleep_time - (ply_get_timestamp () - plugin->now),
-                    0.005);
+  draw_logo (plugin);
 
-  ply_event_loop_watch_for_timeout (plugin->loop, 
-                                    sleep_time,
-                                    (ply_event_loop_timeout_handler_t)
-                                    on_timeout, plugin);
-}
+  ply_frame_buffer_get_size (plugin->frame_buffer, &area);
 
-static void
-start_animation (ply_boot_splash_plugin_t *plugin)
-{
-  assert (plugin != NULL);
-  assert (plugin->loop != NULL);
-    
-  ply_event_loop_watch_for_timeout (plugin->loop, 
-                                    1.0 / FRAMES_PER_SECOND,
-                                    (ply_event_loop_timeout_handler_t)
-                                    on_timeout, plugin);
-
-  plugin->start_time = ply_get_timestamp ();
-  ply_frame_buffer_fill_with_color (plugin->frame_buffer, NULL, 
-                                    0.0, 0.43, .71, 1.0);
+  width = throbber_get_width (plugin->throbber);
+  height = throbber_get_height (plugin->throbber);
+  throbber_start (plugin->throbber,
+                  plugin->loop,
+                  plugin->frame_buffer,
+                  area.width / 2.0 - width / 2.0,
+                  area.width / 2.0 - height / 2.0);
 }
 
 static void
@@ -228,7 +202,9 @@ stop_animation (ply_boot_splash_plugin_t *plugin)
 
   assert (plugin != NULL);
   assert (plugin->loop != NULL);
-    
+
+  throbber_stop (plugin->throbber);
+
   for (i = 0; i < 10; i++)
     {
       ply_frame_buffer_fill_with_color (plugin->frame_buffer, NULL,
@@ -246,13 +222,6 @@ stop_animation (ply_boot_splash_plugin_t *plugin)
 
   ply_frame_buffer_fill_with_color (plugin->frame_buffer, NULL,
                                     0.0, 0.0, 0.0, 1.0);
-
-  if (plugin->loop != NULL)
-    {
-      ply_event_loop_stop_watching_for_timeout (plugin->loop,
-                                                (ply_event_loop_timeout_handler_t)
-                                                on_timeout, plugin);
-    }
 }
 
 static void
diff --git a/src/splash-plugins/spinfinity/throbber-34.png b/src/splash-plugins/spinfinity/throbber-34.png
deleted file mode 100644 (file)
index ce5b8bd..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-# spinfinity_la-ply-window.lo - a libtool object file
-# Generated by ltmain.sh - GNU libtool 1.5.24 (1.1220.2.456 2007/06/24 02:25:32)
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# Name of the PIC object.
-pic_object='.libs/spinfinity_la-ply-window.o'
-
-# Name of the non-PIC object.
-non_pic_object='spinfinity_la-ply-window.o'
-
diff --git a/src/splash-plugins/spinfinity/throbber-35.png b/src/splash-plugins/spinfinity/throbber-35.png
deleted file mode 100644 (file)
index a7b5abe..0000000
Binary files a/src/splash-plugins/spinfinity/throbber-35.png and /dev/null differ
diff --git a/src/splash-plugins/spinfinity/throbber-36.png b/src/splash-plugins/spinfinity/throbber-36.png
deleted file mode 100644 (file)
index 0ab43c5..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-# spinfinity_la-spinfinity.lo - a libtool object file
-# Generated by ltmain.sh - GNU libtool 1.5.24 (1.1220.2.456 2007/06/24 02:25:32)
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# Name of the PIC object.
-pic_object='.libs/spinfinity_la-spinfinity.o'
-
-# Name of the non-PIC object.
-non_pic_object='spinfinity_la-spinfinity.o'
-
diff --git a/src/splash-plugins/spinfinity/throbber-37.png b/src/splash-plugins/spinfinity/throbber-37.png
deleted file mode 100644 (file)
index d6812e2..0000000
Binary files a/src/splash-plugins/spinfinity/throbber-37.png and /dev/null differ
diff --git a/src/splash-plugins/spinfinity/throbber.c b/src/splash-plugins/spinfinity/throbber.c
new file mode 100644 (file)
index 0000000..a3a6413
--- /dev/null
@@ -0,0 +1,304 @@
+/* throbber.c - boot throbber
+ *
+ * Copyright (C) 2007, 2008 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by: Ray Strode <rstrode@redhat.com>
+ */
+#include "config.h"
+
+#include <assert.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <math.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <values.h>
+#include <unistd.h>
+#include <wchar.h>
+
+#include "throbber.h"
+#include "ply-event-loop.h"
+#include "ply-array.h"
+#include "ply-logger.h"
+#include "ply-frame-buffer.h"
+#include "ply-image.h"
+#include "ply-utils.h"
+#include "ply-window.h"
+
+#include <linux/kd.h>
+
+#ifndef FRAMES_PER_SECOND
+#define FRAMES_PER_SECOND 30
+#endif
+
+struct _throbber
+{
+  ply_array_t *frames;
+  ply_event_loop_t *loop;
+  char *frames_prefix;
+
+  ply_frame_buffer_t      *frame_buffer;
+  ply_frame_buffer_area_t  frame_area;
+
+  long x, y;
+  long width, height;
+  double start_time, now;
+};
+
+throbber_t *
+throbber_new (const char *frames_prefix)
+{
+  throbber_t *throbber;
+
+  assert (frames_prefix != NULL);
+
+  throbber = calloc (1, sizeof (throbber_t));
+
+  throbber->frames = ply_array_new ();
+  throbber->frames_prefix = strdup (frames_prefix);
+  throbber->width = 82;
+  throbber->height = 47;
+  throbber->frame_area.width = 0;
+  throbber->frame_area.height = 0;
+  throbber->frame_area.x = 700;
+  throbber->frame_area.y = 700;
+
+  return throbber;
+}
+
+static void
+throbber_remove_frames (throbber_t *throbber)
+{
+  int i;
+  ply_image_t **frames;
+
+  frames = (ply_image_t **) ply_array_steal_elements (throbber->frames);
+  for (i = 0; frames[i] != NULL; i++)
+    ply_image_free (frames[i]);
+  free (frames);
+}
+
+void
+throbber_free (throbber_t *throbber)
+{
+  if (throbber == NULL)
+    return;
+
+  throbber_remove_frames (throbber);
+  ply_array_free (throbber->frames);
+
+  free (throbber->frames_prefix);
+  free (throbber);
+}
+
+static void
+animate_at_time (throbber_t *throbber,
+                 double      time)
+{
+  int number_of_frames;
+  int frame_number;
+  ply_image_t * const * frames;
+  uint32_t *frame_data;
+
+  number_of_frames = ply_array_get_size (throbber->frames);
+  frame_number = (.5 * sin (time) + .5) * number_of_frames;
+
+  ply_frame_buffer_pause_updates (throbber->frame_buffer);
+  if (throbber->frame_area.width > 0)
+    ply_frame_buffer_fill_with_color (throbber->frame_buffer, &throbber->frame_area,
+                                      0.0, 0.43, .71, 1.0);
+
+  frames = (ply_image_t * const *) ply_array_get_elements (throbber->frames);
+
+  throbber->frame_area.x = throbber->x;
+  throbber->frame_area.y = throbber->y;
+  throbber->frame_area.width = ply_image_get_width (frames[frame_number]);
+  throbber->frame_area.height = ply_image_get_height (frames[frame_number]);
+  frame_data = ply_image_get_data (frames[frame_number]);
+
+  ply_frame_buffer_fill_with_argb32_data (throbber->frame_buffer,
+                                          &throbber->frame_area, 0, 0,
+                                          frame_data);
+  ply_frame_buffer_unpause_updates (throbber->frame_buffer);
+}
+
+static void
+on_timeout (throbber_t *throbber)
+{
+  double sleep_time;
+  throbber->now = ply_get_timestamp ();
+
+  animate_at_time (throbber,
+                   throbber->now - throbber->start_time);
+
+  sleep_time = 1.0 / FRAMES_PER_SECOND;
+  sleep_time = MAX (sleep_time - (ply_get_timestamp () - throbber->now),
+                    0.005);
+
+  ply_event_loop_watch_for_timeout (throbber->loop,
+                                    sleep_time,
+                                    (ply_event_loop_timeout_handler_t)
+                                    on_timeout, throbber);
+}
+
+static bool
+throbber_add_frame (throbber_t *throbber,
+                    const char *filename)
+{
+  ply_image_t *image;
+
+  image = ply_image_new (filename);
+
+  if (!ply_image_load (image))
+    {
+      ply_image_free (image);
+      return false;
+    }
+
+  ply_array_add_element (throbber->frames, image);
+
+  throbber->width = MAX (throbber->width, ply_image_get_width (image));
+  throbber->height = MAX (throbber->width, ply_image_get_height (image));
+
+  return true;
+}
+
+static bool
+throbber_add_frames (throbber_t *throbber)
+{
+  struct dirent **entries;
+  int number_of_entries;
+  int i;
+  bool load_finished;
+
+  entries = NULL;
+
+  number_of_entries = scandir (PLYMOUTH_IMAGE_DIR, &entries, NULL, versionsort);
+
+  if (number_of_entries < 0)
+    return false;
+
+  load_finished = false;
+  for (i = 0; i < number_of_entries; i++)
+    {
+      if (strncmp (entries[i]->d_name,
+                   throbber->frames_prefix,
+                   strlen (throbber->frames_prefix)) == 0
+          && (strlen (entries[i]->d_name) > 4)
+          && strcmp (entries[i]->d_name + strlen (entries[i]->d_name) - 4, ".png") == 0)
+        {
+          char *filename;
+
+          filename = NULL;
+          asprintf (&filename, PLYMOUTH_IMAGE_DIR "%s",
+                    entries[i]->d_name);
+
+          if (!throbber_add_frame (throbber, filename))
+            goto out;
+
+          free (filename);
+        }
+
+      free (entries[i]);
+      entries[i] = NULL;
+    }
+  load_finished = true;
+
+out:
+  if (!load_finished)
+    {
+      throbber_remove_frames (throbber);
+
+      while (entries[i] != NULL)
+        {
+          free (entries[i]);
+          i++;
+        }
+    }
+  free (entries);
+
+  return load_finished;
+}
+
+bool
+throbber_start (throbber_t         *throbber,
+                ply_event_loop_t   *loop,
+                ply_frame_buffer_t *frame_buffer,
+                long                x,
+                long                y)
+{
+  assert (throbber != NULL);
+  assert (throbber->loop == NULL);
+  assert (ply_array_get_size (throbber->frames) == 0);
+
+  if (!throbber_add_frames (throbber))
+    return false;
+
+  throbber->loop = loop;
+  throbber->frame_buffer = frame_buffer;
+
+  throbber->x = x;
+  throbber->y = y;
+
+  throbber->start_time = ply_get_timestamp ();
+
+  ply_event_loop_watch_for_timeout (throbber->loop,
+                                    1.0 / FRAMES_PER_SECOND,
+                                    (ply_event_loop_timeout_handler_t)
+                                    on_timeout, throbber);
+
+  return true;
+}
+
+void
+throbber_stop (throbber_t *throbber)
+{
+  if (throbber->frame_area.width > 0)
+    ply_frame_buffer_fill_with_color (throbber->frame_buffer, &throbber->frame_area,
+                                      0.0, 0.43, .71, 1.0);
+
+  if (throbber->loop != NULL)
+    {
+      ply_event_loop_stop_watching_for_timeout (throbber->loop,
+                                                (ply_event_loop_timeout_handler_t)
+                                                on_timeout, throbber);
+    }
+}
+
+long
+throbber_get_width (throbber_t *throbber)
+{
+  return throbber->width;
+}
+
+long
+throbber_get_height (throbber_t *throbber)
+{
+  return throbber->height;
+}
+
+/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
diff --git a/src/splash-plugins/spinfinity/throbber.h b/src/splash-plugins/spinfinity/throbber.h
new file mode 100644 (file)
index 0000000..2391275
--- /dev/null
@@ -0,0 +1,50 @@
+/* throbber.h - simple throbber animation
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written By: Ray Strode <rstrode@redhat.com>
+ */
+#ifndef THROBBER_H
+#define THROBBER_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "ply-event-loop.h"
+#include "ply-frame-buffer.h"
+
+typedef struct _throbber throbber_t;
+
+#ifndef PLY_HIDE_FUNCTION_DECLARATIONS
+throbber_t *throbber_new (const char *frames_prefix);
+void throbber_free (throbber_t *throbber);
+
+bool throbber_start (throbber_t         *throbber,
+                     ply_event_loop_t   *loop,
+                     ply_frame_buffer_t *frame_buffer,
+                     long                x,
+                     long                y);
+void throbber_stop (throbber_t *throbber);
+
+long throbber_get_width (throbber_t *throbber);
+long throbber_get_height (throbber_t *throbber);
+#endif
+
+#endif /* THROBBER_H */
+/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */