]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-progress-bar: Allow choosing fore- and back-ground color
authorHans de Goede <hdegoede@redhat.com>
Fri, 8 Feb 2019 13:06:28 +0000 (14:06 +0100)
committerHans de Goede <hdegoede@redhat.com>
Sat, 23 Feb 2019 13:56:54 +0000 (14:56 +0100)
Allow choosing a fore- and back-ground color instead of hardcoding
the foreground to white and the background to transparent.

This commit does not change behavior for existing users (tested with the
spinfinity theme).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
src/libply-splash-graphics/ply-progress-bar.c
src/libply-splash-graphics/ply-progress-bar.h

index 2ba3bf4048e085aa790d174a57f52397e86c3a03..e5697b4660d03add058f9759b4553a02ee2a9655 100644 (file)
@@ -1,6 +1,6 @@
 /* progress_bar.c - boot progress_bar
  *
- * Copyright (C) 2008 Red Hat, Inc.
+ * Copyright (C) 2008, 2019 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
@@ -19,6 +19,7 @@
  *
  * Written by: Ray Strode <rstrode@redhat.com>
  *             Will Woods <wwoods@redhat.com>
+ *             Hans de Goede <hdegoede@redhat.com>
  */
 #include "config.h"
 
 #include "ply-image.h"
 #include "ply-utils.h"
 
-#ifndef FRAMES_PER_SECOND
-#define FRAMES_PER_SECOND 30
-#endif
-
 #ifndef BAR_HEIGHT
 #define BAR_HEIGHT 16
 #endif
@@ -63,6 +60,8 @@ struct _ply_progress_bar
         ply_pixel_display_t *display;
         ply_rectangle_t      area;
 
+        uint32_t             fg_color;
+        uint32_t             bg_color;
         double               percent_done;
 
         uint32_t             is_hidden : 1;
@@ -76,11 +75,9 @@ ply_progress_bar_new (void)
         progress_bar = calloc (1, sizeof(ply_progress_bar_t));
 
         progress_bar->is_hidden = true;
+        progress_bar->fg_color = 0xffffffff; /* Solid white */
+        progress_bar->bg_color = 0x01000000; /* Transparent */
         progress_bar->percent_done = 0.0;
-        progress_bar->area.x = 0;
-        progress_bar->area.y = 0;
-        progress_bar->area.width = 0;
-        progress_bar->area.height = BAR_HEIGHT;
 
         return progress_bar;
 }
@@ -93,21 +90,6 @@ ply_progress_bar_free (ply_progress_bar_t *progress_bar)
         free (progress_bar);
 }
 
-static void
-ply_progress_bar_update_area (ply_progress_bar_t *progress_bar,
-                              long                x,
-                              long                y)
-{
-        unsigned long display_width;
-
-        progress_bar->area.x = x;
-        progress_bar->area.y = y;
-        progress_bar->area.height = BAR_HEIGHT;
-
-        display_width = ply_pixel_display_get_width (progress_bar->display);
-        progress_bar->area.width = (long) (display_width * progress_bar->percent_done);
-}
-
 void
 ply_progress_bar_draw_area (ply_progress_bar_t *progress_bar,
                             ply_pixel_buffer_t *buffer,
@@ -116,20 +98,23 @@ ply_progress_bar_draw_area (ply_progress_bar_t *progress_bar,
                             unsigned long       width,
                             unsigned long       height)
 {
-        ply_rectangle_t paint_area;
+        ply_rectangle_t fill_area;
 
         if (progress_bar->is_hidden)
                 return;
 
-        paint_area.x = x;
-        paint_area.y = y;
-        paint_area.width = width;
-        paint_area.height = height;
+        /* Note we ignore the passed in area / rectangle to update,
+         * since ply_pixel_display_draw_area() already pushes it to
+         * the buffer's clip_area list.
+         */
 
-        ply_rectangle_intersect (&progress_bar->area, &paint_area, &paint_area);
-        ply_pixel_buffer_fill_with_hex_color (buffer,
-                                              &paint_area,
-                                              0xffffff); /* white */
+        fill_area = progress_bar->area;
+        fill_area.width = progress_bar->area.width * progress_bar->percent_done;
+        ply_pixel_buffer_fill_with_hex_color (buffer, &fill_area, progress_bar->fg_color);
+
+        fill_area.x = fill_area.x + fill_area.width;
+        fill_area.width = progress_bar->area.width - fill_area.width;
+        ply_pixel_buffer_fill_with_hex_color (buffer, &fill_area, progress_bar->bg_color);
 }
 
 void
@@ -138,7 +123,6 @@ ply_progress_bar_draw (ply_progress_bar_t *progress_bar)
         if (progress_bar->is_hidden)
                 return;
 
-        ply_progress_bar_update_area (progress_bar, progress_bar->area.x, progress_bar->area.y);
         ply_pixel_display_draw_area (progress_bar->display,
                                      progress_bar->area.x,
                                      progress_bar->area.y,
@@ -155,8 +139,10 @@ ply_progress_bar_show (ply_progress_bar_t  *progress_bar,
         assert (progress_bar != NULL);
 
         progress_bar->display = display;
-
-        ply_progress_bar_update_area (progress_bar, x, y);
+        progress_bar->area.x = x;
+        progress_bar->area.y = y;
+        progress_bar->area.height = BAR_HEIGHT;
+        progress_bar->area.width = ply_pixel_display_get_width (display);
 
         progress_bar->is_hidden = false;
         ply_progress_bar_draw (progress_bar);
@@ -208,4 +194,14 @@ ply_progress_bar_get_percent_done (ply_progress_bar_t *progress_bar)
         return progress_bar->percent_done;
 }
 
+void
+ply_progress_bar_set_colors (ply_progress_bar_t *progress_bar,
+                             uint32_t            fg_color,
+                             uint32_t            bg_color)
+{
+        progress_bar->fg_color = fg_color;
+        progress_bar->bg_color = bg_color;
+        ply_progress_bar_draw (progress_bar);
+}
+
 /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
index 2fd80e0b5a8c83a8e2424acbf5cc4215debccce4..1eab64c5e197d9d0ec7e45a058564494606b083a 100644 (file)
@@ -57,6 +57,10 @@ long ply_progress_bar_get_height (ply_progress_bar_t *bar);
 void ply_progress_bar_set_percent_done (ply_progress_bar_t *bar,
                                         double              percent_done);
 double ply_progress_bar_get_percent_done (ply_progress_bar_t *bar);
+
+void ply_progress_bar_set_colors (ply_progress_bar_t *bar,
+                                  uint32_t            fg_color,
+                                  uint32_t            bg_color);
 #endif
 
 #endif /* PLY_PROGRESS_BAR_H */