changeset 101:0bc32f70d67c

label: add more customization
author David Demelier <markand@malikania.fr>
date Tue, 31 Mar 2020 20:05:00 +0200
parents ef9135c34505
children 26fef20fd89d
files src/core/label.h src/core/message.c src/core/theme.c
diffstat 3 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/label.h	Tue Mar 31 10:57:14 2020 +0200
+++ b/src/core/label.h	Tue Mar 31 20:05:00 2020 +0200
@@ -27,6 +27,14 @@
 struct theme;
 
 /**
+ * \brief Label flags.
+ */
+enum label_flags {
+	LABEL_NONE,             /*!< No flags. */
+	LABEL_NO_SHADOW         /*!< Disable shadow. */
+};
+
+/**
  * \brief GUI label.
  */
 struct label {
@@ -35,6 +43,8 @@
 	unsigned int w;         /*!< (RW) Width. */
 	unsigned int h;         /*!< (RW) Height. */
 	const char *text;       /*!< (RW, ref) Text to show. */
+	enum label_flags flags; /*!< (RW) Optional flags. */
+	unsigned long color;    /*!< (RW) Color to use (0 = use theme). */
 	struct theme *theme;    /*!< (RW, ref, optional) Theme to use. */
 };
 
--- a/src/core/message.c	Tue Mar 31 10:57:14 2020 +0200
+++ b/src/core/message.c	Tue Mar 31 20:05:00 2020 +0200
@@ -201,9 +201,7 @@
 		 * THEME_FONT_INTERFACE so update its color if needed.
 		 */
 		if (msg->flags & MESSAGE_QUESTION && msg->index == i)
-			font->color = THEME(msg)->colors[THEME_COLOR_SELECTED];
-		else
-			font->color = THEME(msg)->colors[THEME_COLOR_NORMAL];
+			label.color = THEME(msg)->colors[THEME_COLOR_SELECTED];
 
 		label_draw(&label);
 	}
--- a/src/core/theme.c	Tue Mar 31 10:57:14 2020 +0200
+++ b/src/core/theme.c	Tue Mar 31 20:05:00 2020 +0200
@@ -2999,6 +2999,22 @@
 {
 	struct texture tex;
 
+	/* Shadow text, only if enabled. */
+	if (!(label->flags & LABEL_NO_SHADOW)) {
+		t->fonts[THEME_FONT_INTERFACE]->color = t->colors[THEME_COLOR_SHADOW];
+
+		if (!font_render(t->fonts[THEME_FONT_INTERFACE], &tex, label->text))
+			panic();
+
+		texture_draw(&tex, label->x + 1, label->y + 1);
+		texture_finish(&tex);
+	}
+
+	/* Normal text. */
+	t->fonts[THEME_FONT_INTERFACE]->color = label->color
+		? label->color
+		: t->colors[THEME_COLOR_NORMAL];
+
 	if (!font_render(t->fonts[THEME_FONT_INTERFACE], &tex, label->text))
 		panic();