rbutil: store the voice language in the correct setting.
[kugel-rb.git] / apps / gui / splash.c
blob4ddd22aba23f2ef843a3427e68f34c315c916349
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) Daniel Stenberg (2002)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "stdarg.h"
22 #include "string.h"
23 #include "rbunicode.h"
24 #include "stdio.h"
25 #include "kernel.h"
26 #include "screen_access.h"
27 #include "lang.h"
28 #include "settings.h"
29 #include "talk.h"
30 #include "splash.h"
31 #include "viewport.h"
33 #ifdef HAVE_LCD_BITMAP
35 #define MAXLINES (LCD_HEIGHT/6)
36 #define MAXBUFFER 512
37 #define RECT_SPACING 2
39 #else /* HAVE_LCD_CHARCELLS */
41 #define MAXLINES 2
42 #define MAXBUFFER 64
43 #define RECT_SPACING 0
45 #endif
48 static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
50 char splash_buf[MAXBUFFER];
51 char *lines[MAXLINES];
53 char *next;
54 char *lastbreak = NULL;
55 char *store = NULL;
56 int line = 0;
57 int x = 0;
58 int y, i;
59 int space_w, w, h;
60 #ifdef HAVE_LCD_BITMAP
61 struct viewport vp;
62 int maxw = 0;
64 viewport_set_defaults(&vp, screen->screen_type);
65 screen->set_viewport(&vp);
67 screen->getstringsize(" ", &space_w, &h);
68 #else /* HAVE_LCD_CHARCELLS */
70 space_w = h = 1;
71 screen->double_height (false);
72 #endif
73 y = h;
75 vsnprintf(splash_buf, sizeof(splash_buf), fmt, ap);
76 va_end(ap);
78 /* break splash string into display lines, doing proper word wrap */
80 next = strtok_r(splash_buf, " ", &store);
81 if (!next)
82 goto end; /* nothing to display */
84 lines[0] = next;
85 while (true)
87 #ifdef HAVE_LCD_BITMAP
88 screen->getstringsize(next, &w, NULL);
89 #else
90 w = utf8length(next);
91 #endif
92 if (lastbreak)
94 if (x + (next - lastbreak) * space_w + w
95 > screen->lcdwidth - RECT_SPACING*2)
96 { /* too wide, wrap */
97 #ifdef HAVE_LCD_BITMAP
98 if (x > maxw)
99 maxw = x;
100 #endif
101 if ((y + h > screen->lcdheight) || (line >= (MAXLINES-1)))
102 break; /* screen full or out of lines */
103 x = 0;
104 y += h;
105 lines[++line] = next;
107 else
109 /* restore & calculate spacing */
110 *lastbreak = ' ';
111 x += (next - lastbreak) * space_w;
114 x += w;
115 lastbreak = next + strlen(next);
116 next = strtok_r(NULL, " ", &store);
117 if (!next)
118 { /* no more words */
119 #ifdef HAVE_LCD_BITMAP
120 if (x > maxw)
121 maxw = x;
122 #endif
123 break;
127 /* prepare viewport
128 * First boundaries, then the grey filling, then the black border and finally
129 * the text*/
131 screen->stop_scroll();
133 #ifdef HAVE_LCD_BITMAP
134 /* If we center the display, then just clear the box we need and put
135 a nice little frame and put the text in there! */
136 vp.y = (screen->lcdheight - y) / 2 - RECT_SPACING; /* height => y start position */
137 vp.x = (screen->lcdwidth - maxw) / 2 - RECT_SPACING;
138 vp.width = maxw + 2*RECT_SPACING;
139 vp.height = screen->lcdheight - (vp.y*2) + RECT_SPACING;
141 if (vp.y < 0)
142 vp.y = 0;
143 if (vp.x < 0)
144 vp.x = 0;
145 if (vp.width > screen->lcdwidth)
146 vp.width = screen->lcdwidth;
147 if (vp.height > screen->lcdheight)
148 vp.height = screen->lcdheight;
150 vp.flags |= VP_FLAG_ALIGN_CENTER;
151 #if LCD_DEPTH > 1
152 if (screen->depth > 1)
154 vp.drawmode = DRMODE_FG;
155 /* can't do vp.fg_pattern here, since set_foreground does a bit more on
156 * greyscale */
157 screen->set_foreground(SCREEN_COLOR_TO_NATIVE(screen, LCD_LIGHTGRAY));
159 else
160 #endif
161 vp.drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
163 screen->fillrect(0, 0, vp.width, vp.height);
165 #if LCD_DEPTH > 1
166 if (screen->depth > 1)
167 /* can't do vp.fg_pattern here, since set_foreground does a bit more on
168 * greyscale */
169 screen->set_foreground(SCREEN_COLOR_TO_NATIVE(screen, LCD_BLACK));
170 else
171 #endif
172 vp.drawmode = DRMODE_SOLID;
174 screen->drawrect(0, 0, vp.width, vp.height);
176 /* prepare putting the text */
177 y = RECT_SPACING;
178 #else /* HAVE_LCD_CHARCELLS */
179 y = 0; /* vertical centering on 2 lines would be silly */
180 screen->clear_display();
181 #endif
183 /* print the message to screen */
184 for (i = 0; i <= line; i++, y+=h)
186 #ifdef HAVE_LCD_BITMAP
187 screen->putsxy(0, y, lines[i]);
188 #else
189 screen->puts(0, y, lines[i]);
190 #endif
192 screen->update_viewport();
193 end:
194 screen->set_viewport(NULL);
197 void splashf(int ticks, const char *fmt, ...)
199 va_list ap;
200 int i;
202 /* If fmt is a lang ID then get the corresponding string (which
203 still might contain % place holders). */
204 fmt = P2STR((unsigned char *)fmt);
205 FOR_NB_SCREENS(i)
207 va_start(ap, fmt);
208 splash_internal(&(screens[i]), fmt, ap);
209 va_end(ap);
211 if (ticks)
212 sleep(ticks);
215 void splash(int ticks, const char *str)
217 #if !defined(SIMULATOR) || CONFIG_CODEC == SWCODEC
218 long id;
219 /* fmt may be a so called virtual pointer. See settings.h. */
220 if((id = P2ID((const unsigned char*)str)) >= 0)
221 /* If fmt specifies a voicefont ID, and voice menus are
222 enabled, then speak it. */
223 cond_talk_ids_fq(id);
224 #endif
225 splashf(ticks, "%s", P2STR((const unsigned char*)str));