[Splashy-devel] Translucent Text Area Patch.
Pat Suwalski
pats at xandros.com
Fri Mar 17 20:29:35 UTC 2006
Hello,
I'm attaching a patch I wrote last week. It's undergone a lot of testing
now.
This patch adds a translucent text box at the designated coordinates and
prints messages there that are put in via the command "print foo bar" to
the pipe.
Technical details:
- It uses a subsurface, so that if the text is too big, it's simply
cut off.
- I pulled out the code to determine the divider factor based on
pixels or percent to a function that can be used anywhere in video.c.
- It is cool. :)
The goal of this is not to print console output. The goal is to provide
little hints about what is starting in the background. Possible "print"s
are "Detecting hardware" and "Starting Services". No more than four or
five during startup.
I'm sorry the patch is against 0.16 and it builds upon the previous
patch for pixel-preciseness. I realize it's a pain getting a patch like
that, but due to release cycles we're sticking with that version and I
simply don't have time to rewrite the patch for newer upstream.
Here is a sample stanza from the config.xml file:
<textbox>
<enable>yes</enable>
<x>265</x>
<y>422</y>
<width>487</width>
<height>32</height>
<background>
<red>0</red>
<green>0</green>
<blue>0</blue>
<alpha>64</alpha>
</background>
<text>
<font>/pathto/Vera.ttf</font>
<fontsize>14</fontsize>
<red>255</red>
<green>255</green>
<blue>255</blue>
</text>
</textbox>
This config block assumes that the <width> and <height> tags are set to
1024 and 768 in the <background> section. Otherwise percentages will be
used and you will not see anything with these numbers.
Enjoy. Happy St. Pat's Day.
--Pat
-------------- next part --------------
diff -uNr src.orig/splashy-0.1.6/src/functions.c src/splashy-0.1.6/src/functions.c
--- splashy-0.1.6/src/functions.c 2006-03-06 14:28:48.000000000 -0500
+++ splashy-0.1.6/src/functions.c 2006-03-07 11:22:26.000000000 -0500
@@ -212,6 +212,20 @@
}
gint
+cmd_print (void **args)
+{
+ video_printline (&video, args[0]);
+ return 0;
+}
+
+ gint
+cmd_print_clear (void **args)
+{
+ video_printline (&video, "");
+ return 0;
+}
+
+ gint
cmd_chvt (void **args)
{
/*
@@ -255,6 +269,11 @@
.cmd = "progress",.handler = cmd_progress,.args = 1,.specs =
"d"},
{
+ .cmd = "print",.handler = cmd_print,.args = 1,.specs =
+ "s"},
+ {
+ .cmd = "clrprint",.handler = cmd_print_clear,.args = 0,.specs = NULL,},
+ {
.cmd = "chvt",.handler = cmd_chvt,.args = 1,.specs = "d",},
{
.cmd = "allowchvt",.handler = cmd_allow_chvt,.args =
@@ -741,6 +760,9 @@
video_draw_progressbar (&video, &progressbar);
}
+ /* Initialize optional text area */
+ video_start_text_area (&video);
+
/*
* setup our main input: keyboard
*/
diff -uNr src.orig/splashy-0.1.6/src/Makefile.am src/splashy-0.1.6/src/Makefile.am
--- splashy-0.1.6/src/Makefile.am 2006-03-06 14:28:48.000000000 -0500
+++ splashy-0.1.6/src/Makefile.am 2006-03-06 14:56:34.000000000 -0500
@@ -1,6 +1,6 @@
DFB_PREFIX = $(shell ../directfb-config --prefix)
DFB_VERSION = $(shell ../directfb-config --version)
-DFB = $(shell ../directfb-config --cflags --libs --graphics=all --imageprovider=png,jpeg --input=keyboard --font=default)
+DFB = $(shell ../directfb-config --cflags --libs --graphics=all --imageprovider=png,jpeg --input=keyboard --font=default,ft2)
sbin_PROGRAMS = splashy
splashy_SOURCES = main.c functions.c xml_parser.c xml_config.c video.c
diff -uNr src.orig/splashy-0.1.6/src/Makefile.in src/splashy-0.1.6/src/Makefile.in
--- splashy-0.1.6/src/Makefile.in 2006-03-06 14:28:48.000000000 -0500
+++ splashy-0.1.6/src/Makefile.in 2006-03-06 14:56:43.000000000 -0500
@@ -186,7 +186,7 @@
target_alias = @target_alias@
DFB_PREFIX = $(shell ../directfb-config --prefix)
DFB_VERSION = $(shell ../directfb-config --version)
-DFB = $(shell ../directfb-config --cflags --libs --graphics=all --imageprovider=png,jpeg --input=keyboard --font=default)
+DFB = $(shell ../directfb-config --cflags --libs --graphics=all --imageprovider=png,jpeg --input=keyboard --font=default,ft2)
splashy_SOURCES = main.c functions.c xml_parser.c xml_config.c video.c
# set the include path found by configure
--- splashy-0.1.6/src/video.c 2006-03-06 14:28:48.000000000 -0500
+++ splashy-0.1.6/src/video.c 2006-03-07 13:33:33.000000000 -0500
@@ -144,15 +144,10 @@
DirectFBSetOption ("force-windowed", NULL);
}
- gint
-video_draw_progressbar (splashy_video_t * video, DFBRectangle * progressbar)
+ void
+video_get_divider (splashy_video_t *video, gint *dividerW, gint *dividerH)
{
- gint screen_width, screen_height;
-
- /* Source image width and height */
- gint sourceWidth, sourceHeight, dividerW, dividerH;
-
- guint rectangle_red, rectangle_green, rectangle_blue, rectangle_alpha;
+ gint sourceWidth, sourceHeight;
/* If a source image width and height is specified, assume
* pixel-precise placement of progress bar rather than percentage. */
@@ -162,14 +157,27 @@
if (sourceWidth > 0 && sourceHeight > 0)
{
/* The value is based on specified units */
- dividerW = sourceWidth;
- dividerH = sourceHeight;
+ *dividerW = sourceWidth;
+ *dividerH = sourceHeight;
}
else
{
/* The value is based on percentage */
- dividerW = dividerH = 100;
+ *dividerW = *dividerH = 100;
}
+}
+
+ gint
+video_draw_progressbar (splashy_video_t * video, DFBRectangle * progressbar)
+{
+ gint screen_width, screen_height;
+
+ /* Source image divider (image dimension or percentage) */
+ gint dividerW, dividerH;
+
+ guint rectangle_red, rectangle_green, rectangle_blue, rectangle_alpha;
+
+ video_get_divider (video, ÷rW, ÷rH);
video->surface->GetSize (video->surface, &screen_width, &screen_height);
@@ -542,6 +550,126 @@
}
/**
+ * Initialize and draw an alpha-transparent text box.
+ *
+ * @return
+ */
+ void
+video_start_text_area(splashy_video_t *video)
+{
+ gint dividerW, dividerH;
+ gint screen_width, screen_height;
+ gint red, green, blue, alpha;
+ gint temp;
+ const gchar *fontface;
+
+ /* Check if there will be a text area. */
+ const gchar *enable = xml_parser_get_text ("/splashy/textbox/enable");
+
+ if (g_ascii_strncasecmp (enable, "yes", 3) != 0)
+ return;
+
+ video->surface->GetSize (video->surface, &screen_width, &screen_height);
+ video_get_divider(video, ÷rW, ÷rH);
+
+ video->textbox = g_new0 (splashy_textbox_t, 1);
+
+ /* Set some defaults so that there are no divide by zeroes if the
+ * checks below fail */
+ video->textbox->area.x = video->textbox->area.w = dividerW / 4;
+ video->textbox->area.y = video->textbox->area.h = dividerH / 4;
+
+ /* Read in the text box dimensions */
+ temp = xml_parser_get_int ("/splashy/textbox/x", 10);
+ if (temp >= 0 && temp < dividerW)
+ video->textbox->area.x = temp * screen_width / dividerW;
+
+ temp = xml_parser_get_int ("/splashy/textbox/y", 10);
+ if (temp >= 0 && temp < dividerH)
+ video->textbox->area.y = temp * screen_height / dividerH;
+
+ temp = xml_parser_get_int ("/splashy/textbox/width", 10);
+ if (temp > 0 && temp <= dividerW)
+ video->textbox->area.w = temp * screen_width / dividerW;
+
+ temp = xml_parser_get_int ("/splashy/textbox/height", 10);
+ if (temp > 0 && temp <= dividerH)
+ video->textbox->area.h = temp * screen_height / dividerH;
+
+ video->textbox->desc.width = video->textbox->area.w;
+ video->textbox->desc.height = video->textbox->area.h;
+ video->textbox->desc.caps = DSCAPS_SYSTEMONLY; // Only in system memory
+ video->textbox->desc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT;
+
+ /* Grab the textbox area to a seperate surface */
+ video->dfb->CreateSurface (video->dfb, &video->textbox->desc, &video->textbox->offscreen);
+ video->textbox->offscreen->Blit (video->textbox->offscreen, video->surface, &video->textbox->area, 0, 0);
+
+ /* Get the tinting colour */
+ red = xml_parser_get_int ("/splashy/textbox/background/red", 10);
+ green = xml_parser_get_int ("/splashy/textbox/background/green", 10);
+ blue = xml_parser_get_int ("/splashy/textbox/background/blue", 10);
+ alpha = xml_parser_get_int ("/splashy/textbox/background/alpha", 10);
+ if (red < 0 || red > 255) red = 128;
+ if (green < 0 || green > 255) green = 128;
+ if (blue < 0 || blue > 255) blue = 128;
+ if (alpha < 0 || alpha > 255) alpha = 255;
+
+ /* Tint the box in the off-screen surface */
+ video->textbox->offscreen->SetDrawingFlags(video->textbox->offscreen, DSDRAW_BLEND);
+ video->textbox->offscreen->SetColor(video->textbox->offscreen, red, green, blue, alpha);
+ video->textbox->offscreen->FillRectangle (video->textbox->offscreen, 0, 0,
+ video->textbox->area.w,
+ video->textbox->area.h);
+
+ /* Get the text colour (no alpha) */
+ red = xml_parser_get_int ("/splashy/textbox/text/red", 10);
+ green = xml_parser_get_int ("/splashy/textbox/text/green", 10);
+ blue = xml_parser_get_int ("/splashy/textbox/text/blue", 10);
+ if (red < 0 || red > 255) red = 128;
+ if (green < 0 || green > 255) green = 128;
+ if (blue < 0 || blue > 255) blue = 128;
+
+ /* Establish the subsurface to which we print */
+ video->surface->GetSubSurface(video->surface, &video->textbox->area, &video->textbox->surface);
+ video->textbox->surface->SetColor(video->textbox->surface, red, green, blue, 255);
+
+ /* Initialize the font */
+ video->textbox->fontdesc.flags = DFDESC_HEIGHT;
+ fontface = xml_parser_get_text("/splashy/textbox/text/font");
+ temp = xml_parser_get_int("/splashy/textbox/text/fontsize", 10);
+ video->textbox->fontdesc.height = temp * screen_height / dividerH;
+ video->dfb->CreateFont (video->dfb, fontface, &video->textbox->fontdesc, &font);
+ if (font == NULL)
+ video->dfb->CreateFont (video->dfb, NULL, NULL, &font);
+ video->textbox->surface->SetFont (video->textbox->surface, font);
+
+ /* Draw a single blank string to draw the box */
+ video_printline (video, "");
+}
+
+/**
+ * Print a line of text in the textbox.
+ *
+ * @return
+ */
+ void
+video_printline (splashy_video_t *video, gchar *string)
+{
+ if (video->textbox == NULL)
+ return;
+
+ /* Copy the textbox background from off-screen surface */
+ video->surface->Blit (video->textbox->surface, video->textbox->offscreen, NULL, 0, 0);
+
+ /* Draw string to the clipped surface */
+ video->textbox->surface->DrawString (video->textbox->surface, string, -1,
+ video->textbox->area.w / 2,
+ (video->textbox->area.h / 2) + (video->textbox->fontdesc.height / 2),
+ DSTF_CENTER | DSTF_BOTTOM);
+}
+
+/**
* FIXME work in progress ...
* When pressing F2, we show the scrolling UNIX text, in a smaller window
*
diff -uNr src.orig/splashy-0.1.6/src/video.h src/splashy-0.1.6/src/video.h
--- splashy-0.1.6/src/video.h 2006-03-06 14:28:48.000000000 -0500
+++ splashy-0.1.6/src/video.h 2006-03-07 10:48:28.000000000 -0500
@@ -15,6 +15,15 @@
} spl_videomode_t;
typedef struct {
+ gboolean enabled;
+ IDirectFBSurface *offscreen; /** off-screen storage */
+ IDirectFBSurface *surface; /* Subsurface to draw text on */
+ DFBSurfaceDescription desc;
+ DFBRectangle area;
+ DFBFontDescription fontdesc;
+} splashy_textbox_t;
+
+typedef struct {
IDirectFB *dfb; /** our directfb object */
IDirectFBImageProvider *provider; /** foo */
IDirectFBSurface *surface; /** our image holder */
@@ -22,6 +31,7 @@
IDirectFBEventBuffer *ev_buffer; /** our events listener */
DFBSurfaceDescription desc; /** bar */
spl_videomode_t *mode; /** video mode supported by surface */
+ splashy_textbox_t *textbox; /** text box parameters */
} splashy_video_t;
/* public functions */
@@ -29,8 +39,10 @@
gint video_update_progressbar(splashy_video_t *video, DFBRectangle *progressbar, gint perc);
void video_start_splash(splashy_video_t *video, const gchar *background);
void video_change_splash(splashy_video_t *video, const gchar *newimage);
+void video_start_text_area(splashy_video_t *video);
void video_set_mode(splashy_video_t *video);
void video_allow_vt_switching();
+void video_printline(splashy_video_t *video, gchar *string);
void video_verbose_text(splashy_video_t * video);
#endif
More information about the Splashy-devel
mailing list