Add platform file for Ipod 1G / 2G. Now only the front image is missing for building...
[Rockbox.git] / apps / gui / splash.c
blob72279a371d92090171ff5798c17cfef0616db1fc
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) Daniel Stenberg (2002)
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "stdarg.h"
20 #include "string.h"
21 #include "rbunicode.h"
22 #include "stdio.h"
23 #include "kernel.h"
24 #include "screen_access.h"
26 #ifndef MAX
27 #define MAX(a, b) (((a)>(b))?(a):(b))
28 #endif
30 #ifdef HAVE_LCD_BITMAP
32 #define MAXLINES (LCD_HEIGHT/6)
33 #define MAXBUFFER 512
35 #else /* HAVE_LCD_CHARCELLS */
37 #define MAXLINES 2
38 #define MAXBUFFER 64
40 #endif
42 static void splash(struct screen * screen, const char *fmt, va_list ap)
44 char splash_buf[MAXBUFFER];
45 short widths[MAXLINES];
46 char *lines[MAXLINES];
48 char *next;
49 char *lastbreak = NULL;
50 char *store = NULL;
51 int line = 0;
52 int x = 0;
53 int y, i;
54 int space_w, w, h;
55 #ifdef HAVE_LCD_BITMAP
56 int maxw = 0;
57 #if LCD_DEPTH > 1
58 unsigned prevfg = 0;
59 #endif
61 screen->getstringsize(" ", &space_w, &h);
62 #else /* HAVE_LCD_CHARCELLS */
64 space_w = h = 1;
65 screen->double_height (false);
66 #endif
67 y = h;
69 vsnprintf(splash_buf, sizeof(splash_buf), fmt, ap);
70 va_end(ap);
72 /* break splash string into display lines, doing proper word wrap */
74 next = strtok_r(splash_buf, " ", &store);
75 if (!next)
76 return; /* nothing to display */
78 lines[0] = next;
79 while (true)
81 #ifdef HAVE_LCD_BITMAP
82 screen->getstringsize(next, &w, NULL);
83 #else
84 w = utf8length(next);
85 #endif
86 if (lastbreak)
88 if (x + (next - lastbreak) * space_w + w > screen->width)
89 { /* too wide, wrap */
90 widths[line] = x;
91 #ifdef HAVE_LCD_BITMAP
92 if (x > maxw)
93 maxw = x;
94 #endif
95 if ((y + h > screen->height) || (line >= (MAXLINES-1)))
96 break; /* screen full or out of lines */
97 x = 0;
98 y += h;
99 lines[++line] = next;
101 else
103 /* restore & calculate spacing */
104 *lastbreak = ' ';
105 x += (next - lastbreak) * space_w;
108 x += w;
109 lastbreak = next + strlen(next);
110 next = strtok_r(NULL, " ", &store);
111 if (!next)
112 { /* no more words */
113 widths[line] = x;
114 #ifdef HAVE_LCD_BITMAP
115 if (x > maxw)
116 maxw = x;
117 #endif
118 break;
122 /* prepare screen */
124 screen->stop_scroll();
126 #ifdef HAVE_LCD_BITMAP
127 /* If we center the display, then just clear the box we need and put
128 a nice little frame and put the text in there! */
129 y = (screen->height - y) / 2; /* height => y start position */
130 x = (screen->width - maxw) / 2 - 2;
132 #if LCD_DEPTH > 1
133 if (screen->depth > 1)
135 prevfg = screen->get_foreground();
136 screen->set_drawmode(DRMODE_FG);
137 screen->set_foreground(
138 SCREEN_COLOR_TO_NATIVE(screen, LCD_LIGHTGRAY));
140 else
141 #endif
142 screen->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
144 screen->fillrect(x, y-2, maxw+4, screen->height-y*2+4);
146 #if LCD_DEPTH > 1
147 if (screen->depth > 1)
148 screen->set_foreground(SCREEN_COLOR_TO_NATIVE(screen, LCD_BLACK));
149 else
150 #endif
151 screen->set_drawmode(DRMODE_SOLID);
153 screen->drawrect(x, y-2, maxw+4, screen->height-y*2+4);
154 #else /* HAVE_LCD_CHARCELLS */
155 y = 0; /* vertical centering on 2 lines would be silly */
156 x = 0;
157 screen->clear_display();
158 #endif
160 /* print the message to screen */
162 for (i = 0; i <= line; i++)
164 x = MAX((screen->width - widths[i]) / 2, 0);
166 #ifdef HAVE_LCD_BITMAP
167 screen->putsxy(x, y, lines[i]);
168 #else
169 screen->puts(x, y, lines[i]);
170 #endif
171 y += h;
174 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH > 1)
175 if (screen->depth > 1)
177 screen->set_foreground(prevfg);
178 screen->set_drawmode(DRMODE_SOLID);
180 #endif
181 screen->update();
184 void gui_splash(struct screen * screen, int ticks,
185 const unsigned char *fmt, ...)
187 va_list ap;
188 va_start( ap, fmt );
189 splash(screen, fmt, ap);
190 va_end( ap );
192 if(ticks)
193 sleep(ticks);
196 void gui_syncsplash(int ticks, const unsigned char *fmt, ...)
198 va_list ap;
199 int i;
200 va_start( ap, fmt );
201 FOR_NB_SCREENS(i)
202 splash(&(screens[i]), fmt, ap);
203 va_end( ap );
205 if(ticks)
206 sleep(ticks);