From: Hans de Goede Date: Fri, 8 Feb 2019 13:06:28 +0000 (+0100) Subject: ply-progress-bar: Allow choosing fore- and back-ground color X-Git-Tag: 0.9.5~74^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78bb39da5cc9b95d582665f42d2a1d6fb7bc0c15;p=thirdparty%2Fplymouth.git ply-progress-bar: Allow choosing fore- and back-ground color 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 --- diff --git a/src/libply-splash-graphics/ply-progress-bar.c b/src/libply-splash-graphics/ply-progress-bar.c index 2ba3bf40..e5697b46 100644 --- a/src/libply-splash-graphics/ply-progress-bar.c +++ b/src/libply-splash-graphics/ply-progress-bar.c @@ -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 * Will Woods + * Hans de Goede */ #include "config.h" @@ -50,10 +51,6 @@ #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: */ diff --git a/src/libply-splash-graphics/ply-progress-bar.h b/src/libply-splash-graphics/ply-progress-bar.h index 2fd80e0b..1eab64c5 100644 --- a/src/libply-splash-graphics/ply-progress-bar.h +++ b/src/libply-splash-graphics/ply-progress-bar.h @@ -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 */