From af73ed3b8b766cecac78933bfea073d01acee925 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 29 Jul 2008 16:22:49 -0400 Subject: Add an entry control Right now we have some cut and paste code between the splash plugins for a password entry. This new file will move some of the repeated code into libplybootsplash. --- src/libplybootsplash/Makefile.am | 3 +- src/libplybootsplash/ply-entry.c | 246 +++++++++++++++++++++++++++++++++++++++ src/libplybootsplash/ply-entry.h | 56 +++++++++ 3 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 src/libplybootsplash/ply-entry.c create mode 100644 src/libplybootsplash/ply-entry.h diff --git a/src/libplybootsplash/Makefile.am b/src/libplybootsplash/Makefile.am index b609f9c..3a9793b 100644 --- a/src/libplybootsplash/Makefile.am +++ b/src/libplybootsplash/Makefile.am @@ -5,7 +5,7 @@ INCLUDES = -I$(top_srcdir) \ lib_LTLIBRARIES = libplybootsplash.la libplybootsplashdir = $(includedir)/plymouth-1/plybootsplash -libplybootsplash_HEADERS = ply-answer.h ply-text-pulser.h ply-throbber.h ply-window.h ply-boot-splash-plugin.h +libplybootsplash_HEADERS = ply-answer.h ply-entry.h ply-text-pulser.h ply-throbber.h ply-window.h ply-boot-splash-plugin.h libplybootsplash_la_CFLAGS = $(PLYMOUTH_CFLAGS) \ -DPLYMOUTH_BACKGROUND_COLOR=$(background_color) \ @@ -18,6 +18,7 @@ libplybootsplash_la_LDFLAGS = -export-symbols-regex '^[^_].*' \ libplybootsplash_la_SOURCES = \ $(libplybootsplash_HEADERS) \ ply-answer.c \ + ply-entry.c \ ply-throbber.c \ ply-text-pulser.c \ ply-window.c diff --git a/src/libplybootsplash/ply-entry.c b/src/libplybootsplash/ply-entry.c new file mode 100644 index 0000000..0145ab4 --- /dev/null +++ b/src/libplybootsplash/ply-entry.c @@ -0,0 +1,246 @@ +/* entry.c - boot entry + * + * 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 + */ +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ply-entry.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 + +#ifndef FRAMES_PER_SECOND +#define FRAMES_PER_SECOND 30 +#endif + +struct _ply_entry +{ + ply_event_loop_t *loop; + + ply_window_t *window; + ply_frame_buffer_t *frame_buffer; + ply_frame_buffer_area_t area; + ply_image_t *text_field_image; + ply_image_t *bullet_image; + + int number_of_bullets; + int max_number_of_visible_bullets; +}; + +ply_entry_t * +ply_entry_new (const char *image_dir) +{ + ply_entry_t *entry; + char *image_path; + + assert (image_dir != NULL); + + entry = calloc (1, sizeof (ply_entry_t)); + + image_path = NULL; + asprintf (&image_path, "%s/entry.png", image_dir); + entry->text_field_image = ply_image_new (image_path); + free (image_path); + + image_path = NULL; + asprintf (&image_path, "%s/bullet.png", image_dir); + entry->bullet_image = ply_image_new (image_path); + free (image_path); + + return entry; +} + +void +ply_entry_free (ply_entry_t *entry) +{ + if (entry == NULL) + return; + + free (entry); +} + +static int +get_max_number_of_visible_bullets (ply_entry_t *entry) +{ + long bullet_width, text_field_width; + + bullet_width = ply_image_get_width (entry->bullet_image); + text_field_width = ply_image_get_width (entry->text_field_image); + + return (int) (text_field_width / bullet_width); +} + +bool +ply_entry_load (ply_entry_t *entry) +{ + + if (!ply_image_load (entry->text_field_image)) + return false; + + if (!ply_image_load (entry->bullet_image)) + return false; + + entry->area.width = ply_image_get_width (entry->text_field_image); + entry->area.height = ply_image_get_height (entry->text_field_image); + + entry->max_number_of_visible_bullets = get_max_number_of_visible_bullets (entry); + + return true; +} + +static void +erase_entry_area (ply_entry_t *entry) +{ + ply_window_erase_area (entry->window, + entry->area.x, entry->area.y, + entry->area.width, entry->area.height); +} + +void +ply_entry_draw (ply_entry_t *entry) +{ + ply_frame_buffer_area_t bullet_area; + uint32_t *text_field_data, *bullet_data; + int i, number_of_visible_bullets; + + ply_frame_buffer_pause_updates (entry->frame_buffer); + + text_field_data = ply_image_get_data (entry->text_field_image); + + erase_entry_area (entry); + + ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, + &entry->area, 0, 0, + text_field_data); + + bullet_data = ply_image_get_data (entry->bullet_image); + bullet_area.width = ply_image_get_width (entry->bullet_image); + bullet_area.height = ply_image_get_height (entry->bullet_image); + + if (entry->number_of_bullets < entry->max_number_of_visible_bullets) + number_of_visible_bullets = entry->number_of_bullets; + else + { + number_of_visible_bullets = entry->max_number_of_visible_bullets; + + /* We've got more bullets than we can show in the available space, so + * draw a little half bullet to indicate some bullets are offscreen + */ + bullet_area.x = entry->area.x; + bullet_area.y = entry->area.y + entry->area.height / 2.0 - bullet_area.height / 2.0; + + ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, + &bullet_area, bullet_area.width / 2.0, 0, + bullet_data); + } + + for (i = 0; i < number_of_visible_bullets; i++) + { + bullet_area.x = entry->area.x + i * bullet_area.width + bullet_area.width / 2.0; + bullet_area.y = entry->area.y + entry->area.height / 2.0 - bullet_area.height / 2.0; + + ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, + &bullet_area, 0, 0, + bullet_data); + } + ply_frame_buffer_unpause_updates (entry->frame_buffer); +} + +void +ply_entry_add_bullet (ply_entry_t *entry) +{ + entry->number_of_bullets++; + ply_entry_draw (entry); +} + +void +ply_entry_remove_bullet (ply_entry_t *entry) +{ + entry->number_of_bullets--; + ply_entry_draw (entry); +} + +void +ply_entry_show (ply_entry_t *entry, + ply_event_loop_t *loop, + ply_window_t *window, + long x, + long y) +{ + assert (entry != NULL); + assert (entry->loop == NULL); + + entry->loop = loop; + entry->window = window; + entry->frame_buffer = ply_window_get_frame_buffer (window);; + + entry->area.x = x; + entry->area.y = y; + + ply_entry_draw (entry); +} + +void +ply_entry_hide (ply_entry_t *entry) +{ + erase_entry_area (entry); + + entry->frame_buffer = NULL; + entry->window = NULL; +} + +long +ply_entry_get_width (ply_entry_t *entry) +{ + return entry->area.width; +} + +long +ply_entry_get_height (ply_entry_t *entry) +{ + return entry->area.height; +} + +/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libplybootsplash/ply-entry.h b/src/libplybootsplash/ply-entry.h new file mode 100644 index 0000000..81dd23d --- /dev/null +++ b/src/libplybootsplash/ply-entry.h @@ -0,0 +1,56 @@ +/* ply-entry.h - simple text entry field + * + * 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 + */ +#ifndef PLY_ENTRY_H +#define PLY_ENTRY_H + +#include +#include +#include + +#include "ply-event-loop.h" +#include "ply-frame-buffer.h" +#include "ply-window.h" + +typedef struct _ply_entry ply_entry_t; + +#ifndef PLY_HIDE_FUNCTION_DECLARATIONS +ply_entry_t *ply_entry_new (const char *image_dir); +void ply_entry_free (ply_entry_t *entry); +bool ply_entry_load (ply_entry_t *entry); + +void ply_entry_show (ply_entry_t *entry, + ply_event_loop_t *loop, + ply_window_t *window, + long x, + long y); +void ply_entry_hide (ply_entry_t *entry); +void ply_entry_draw (ply_entry_t *entry); + +long ply_entry_get_width (ply_entry_t *entry); +long ply_entry_get_height (ply_entry_t *entry); + +void ply_entry_add_bullet (ply_entry_t *entry); +void ply_entry_remove_bullet (ply_entry_t *entry); +#endif + +#endif /* PLY_ENTRY_H */ +/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ -- cgit