calculate the string width for numerical volume display and time display in
[kugel-rb.git] / apps / recorder / icons.c
blobbac719e0f18252911fc1e59c15f2220e6a3a718f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Robert E. Hak
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 <lcd.h>
20 #include <string.h>
21 #include "kernel.h"
22 #include "sprintf.h"
23 #include "rtc.h"
25 #include "icons.h"
27 unsigned char slider_bar[] =
29 0x38, 0x28, 0x28, 0x28, 0x28,
30 0x7c, 0x28, 0x28, 0x28, 0x28,
31 0x7c, 0x28, 0x28, 0x28, 0x28,
32 0x7c, 0x28, 0x28, 0x28, 0x28,
33 0x7c, 0x28, 0x28, 0x28, 0x28,
34 0x7c, 0x28, 0x28, 0x28, 0x28,
35 0x7c, 0x28, 0x28, 0x28, 0x28,
36 0x7c, 0x28, 0x28, 0x28, 0x28, 0x38
39 static unsigned char bitmap_icon_5x8[][5] =
41 /* Lock */
42 {0x78,0x7f,0x49,0x7f,0x78}
45 unsigned char bitmap_icons_6x8[LastIcon][6] =
47 /* Box_Filled */
48 { 0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f },
49 /* Box_Empty */
50 { 0x00, 0x7f, 0x41, 0x41, 0x41, 0x7f },
51 /* Slider_Horizontal */
52 { 0x00, 0x3e, 0x7f, 0x63, 0x7f, 0x3e },
53 /* File */
54 { 0x60, 0x7f, 0x03, 0x63, 0x7f, 0x00 },
55 /* Folder */
56 { 0x7e, 0x41, 0x41, 0x42, 0x7e, 0x00 },
57 /* Directory */
58 { 0x3e, 0x26, 0x26, 0x24, 0x3c, 0x00 },
59 /* Playlist */
60 { 0x55, 0x00, 0x55, 0x55, 0x55, 0x00 },
61 /* Repeat */
62 { 0x39, 0x43, 0x47, 0x71, 0x61, 0x4e },
63 /* Selected */
64 { 0x00, 0x1c, 0x3e, 0x3e, 0x3e, 0x1c },
65 /* Cursor / Marker */
66 { 0x3e, 0x1c, 0x08, 0x00, 0x00, 0x00 },
69 static unsigned char bitmap_icon_7x8[][7] =
71 /* Power plug */
72 {0x08,0x1c,0x3e,0x3e,0x3e,0x14,0x14},
73 /* Speaker */
74 {0x00,0x1c,0x1c,0x3e,0x7f,0x00,0x00},
75 /* Speaker mute */
76 {0x01,0x1e,0x1c,0x3e,0x7f,0x20,0x40},
77 /* Play */
78 {0x00,0x7f,0x7f,0x3e,0x1c,0x08,0x00},
79 /* Stop */
80 {0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f},
81 /* Pause */
82 {0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00},
83 /* Fast forward */
84 {0x7f,0x3e,0x1c,0x7f,0x3e,0x1c,0x08},
85 /* Fast backward */
86 {0x08,0x1c,0x3e,0x7f,0x1c,0x3e,0x7f},
87 /* Record */
88 {0x1c,0x3e,0x7f,0x7f,0x7f,0x3e,0x1c},
89 /* Record pause */
90 {0x1c,0x3e,0x7f,0x00,0x7f,0x3e,0x1c},
91 /* Normal playmode */
92 {0x08,0x08,0x08,0x08,0x3e,0x1c,0x08},
93 /* Repeat playmode */
94 {0x38,0x44,0x44,0x4e,0x5f,0x44,0x38},
95 /* Shuffle playmode (dice) */
96 {0x3e,0x41,0x51,0x41,0x45,0x41,0x3e}
99 unsigned char rockbox112x37[]={
100 0x00, 0x00, 0x02, 0xff, 0x02, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
101 0xf8, 0xf8, 0xf0, 0xe0, 0x80, 0x00, 0x00, 0x80, 0xe0, 0xf0, 0xf8, 0xf8, 0xfc,
102 0x7c, 0x7d, 0xfd, 0xfa, 0xfa, 0xf4, 0xe8, 0x90, 0x60, 0x80, 0xe0, 0x10, 0xc8,
103 0xe4, 0xf2, 0xfa, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfa, 0xfa, 0xf4, 0x02, 0xfa,
104 0xfa, 0xfa, 0xfa, 0x02, 0xff, 0x02, 0x00, 0x80, 0xe2, 0xfa, 0xfa, 0xfa, 0xfa,
105 0x3a, 0x0e, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110 0x60, 0x90, 0x20, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x05, 0x05, 0xf9,
111 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x0f, 0x01, 0x00,
112 0xff, 0x01, 0x0e, 0xf1, 0x0f, 0xff, 0xff, 0xff, 0xfc, 0x03, 0xf8, 0xff, 0xff,
113 0xff, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0f, 0x00, 0xff,
114 0xff, 0xff, 0xff, 0x80, 0xff, 0xf8, 0xfe, 0xff, 0xff, 0xff, 0x07, 0x07, 0x04,
115 0x04, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
118 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 0xc0, 0x38, 0x07, 0x9d, 0x60, 0xbf, 0xbf, 0xff, 0xff, 0xfc, 0xff, 0xfd, 0xfe,
121 0xff, 0xff, 0x9f, 0x0f, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x08, 0x08,
122 0x3f, 0x08, 0x08, 0xff, 0x08, 0xff, 0xff, 0xff, 0xff, 0x08, 0xff, 0xff, 0xff,
123 0xff, 0x08, 0x08, 0x08, 0x08, 0xfe, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0xff,
124 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xf3, 0xc0, 0xff, 0x00, 0x00, 0x00,
125 0x00, 0x03, 0x82, 0x41, 0x41, 0xa1, 0xa1, 0x41, 0x41, 0x81, 0x02, 0x02, 0x04,
126 0x08, 0x30, 0x08, 0x04, 0x02, 0x02, 0x81, 0x41, 0x41, 0xa1, 0xa1, 0x41, 0x41,
127 0x81, 0x01, 0x03, 0x05, 0x01, 0x01, 0x01, 0x01, 0x02, 0x0c, 0x12, 0x0d, 0x02,
128 0x01, 0x01, 0xc1, 0x31, 0xc9, 0x35, 0x0b, 0x04,
130 0x01, 0x07, 0x0c, 0x09, 0x18, 0xe3, 0x1b, 0xfc, 0xff, 0x00, 0xff, 0x03, 0x1f,
131 0x7f, 0xff, 0xff, 0xfc, 0xf0, 0x80, 0x0f, 0x7f, 0xff, 0xff, 0xfc, 0xe0, 0xc0,
132 0xa0, 0xa0, 0xdc, 0xe3, 0xfc, 0xff, 0xff, 0x7f, 0x0f, 0x00, 0x07, 0x3f, 0xff,
133 0xff, 0xfc, 0xf0, 0xe0, 0xc0, 0xff, 0xc0, 0xc0, 0xe0, 0xf0, 0xfc, 0x00, 0xff,
134 0xff, 0xff, 0xff, 0x06, 0x19, 0x67, 0x9f, 0x7f, 0xff, 0xff, 0xfc, 0xf0, 0xc0,
135 0x00, 0x06, 0x19, 0x20, 0x20, 0x50, 0x50, 0x29, 0x26, 0x19, 0x06, 0x00, 0x00,
136 0x00, 0xc0, 0x00, 0x00, 0x00, 0x06, 0x19, 0x20, 0x20, 0x50, 0x50, 0x29, 0x26,
137 0x19, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x06, 0x00, 0x00, 0x80, 0x00, 0x00,
138 0x06, 0x09, 0x36, 0xc9, 0x30, 0xc0, 0x00, 0x00,
140 0x20, 0xa0, 0x00, 0x40, 0x83, 0xec, 0x0c, 0x0f, 0x0f, 0xe8, 0xff, 0xa8, 0x08,
141 0x00, 0x01, 0x0f, 0x0f, 0x0f, 0x0f, 0x0e, 0x58, 0xc9, 0x03, 0x47, 0x07, 0xef,
142 0xef, 0xaf, 0x0f, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x08, 0x48, 0xe8, 0xe8,
143 0xa9, 0x4b, 0xef, 0xef, 0xaf, 0xaf, 0xaf, 0x07, 0x47, 0x27, 0xc3, 0x00, 0x4f,
144 0x8f, 0xef, 0x0f, 0x00, 0x00, 0xe8, 0xe9, 0xae, 0x19, 0x0f, 0x0f, 0x0f, 0x0f,
145 0x0f, 0x0c, 0x04, 0x48, 0xc8, 0x08, 0x48, 0x68, 0x48, 0x08, 0x04, 0x24, 0xe2,
146 0xe1, 0xa0, 0x61, 0x42, 0x04, 0x04, 0x88, 0x28, 0x08, 0x08, 0x28, 0xe8, 0xe8,
147 0xa8, 0xc8, 0xec, 0xea, 0xa8, 0x28, 0xa8, 0x08, 0x44, 0xeb, 0x24, 0x03, 0x04,
148 0x08, 0xe8, 0xe8, 0xa8, 0x09, 0x0a, 0x0d, 0x02,
153 * Wipe statusbar
155 void statusbar_wipe(void)
157 int x;
159 for (x = 0; x < LCD_WIDTH; x++)
160 lcd_framebuffer[x][STATUSBAR_Y_POS / 8] = 0;
164 * Print battery icon to status bar
166 void statusbar_icon_battery(int percent, bool charging)
168 int i,j;
169 int fill;
171 /* draw battery */
172 for (i=0; i < 17; i++) {
173 DRAW_PIXEL(ICON_BATTERY_X_POS + i, STATUSBAR_Y_POS);
174 DRAW_PIXEL(ICON_BATTERY_X_POS + i, STATUSBAR_Y_POS + 6);
177 for (i=1; i < 6; i++) {
178 DRAW_PIXEL(ICON_BATTERY_X_POS, STATUSBAR_Y_POS + i);
179 DRAW_PIXEL(ICON_BATTERY_X_POS + 16, STATUSBAR_Y_POS + i);
182 for (i=2; i < 5; i++)
183 DRAW_PIXEL(ICON_BATTERY_X_POS + 17, STATUSBAR_Y_POS + i);
185 /* fill battery */
186 fill=percent;
187 if (fill < 0)
188 fill = 0;
189 if (fill > 100)
190 fill = 100;
192 fill = fill * 15 / 100;
194 for (i=1; i <= fill; i++)
195 for (j=1; j < 6; j++)
196 DRAW_PIXEL(ICON_BATTERY_X_POS + i, STATUSBAR_Y_POS + j);
198 if (charging)
199 lcd_bitmap(bitmap_icon_7x8[Icon_Plug], ICON_PLUG_X_POS,
200 STATUSBAR_Y_POS, ICON_PLUG_WIDTH, STATUSBAR_HEIGHT, false);
204 * Print volume gauge to status bar
206 void statusbar_icon_volume(int percent)
208 int i,j;
209 int volume;
210 int step=0;
211 char buffer[4];
212 unsigned int width, height;
213 #if defined(LOADABLE_FONTS)
214 unsigned char *font;
215 #endif
216 static long switch_tick;
217 static int last_volume;
219 volume = percent;
220 if (volume < 0)
221 volume = 0;
222 if (volume > 100)
223 volume = 100;
225 if (volume==0) {
226 lcd_bitmap(bitmap_icon_7x8[Icon_Mute],
227 ICON_VOLUME_X_POS + ICON_VOLUME_WIDTH / 2 - 4,
228 STATUSBAR_Y_POS, 7, STATUSBAR_HEIGHT, false);
230 else {
231 if (last_volume != volume) {
232 switch_tick = current_tick + HZ;
233 last_volume = volume;
235 /* display volume lever numerical? */
236 if (TIME_BEFORE(current_tick,switch_tick)) {
237 snprintf(buffer, sizeof(buffer), "%2d", percent);
238 #if defined(LCD_PROPFONTS)
239 lcd_getstringsize(buffer, 0, &width, &height);
240 width += strlen(buffer) - 1;
241 #elif defined(LOADABLE_FONTS)
242 font = lcd_getcurrentldfont();
243 lcd_getstringsize(buffer, font, &width, &height);
244 #else
245 width = 6*strlen(buffer);
246 height = 8;
247 #endif
248 if (height <= STATUSBAR_HEIGHT)
249 lcd_putsxy(ICON_VOLUME_X_POS + ICON_VOLUME_WIDTH / 2 -
250 width/2, STATUSBAR_Y_POS, buffer, 0);
252 else { /* display volume bar */
253 volume = volume * 14 / 100;
254 for(i=0; i < volume; i++) {
255 if(i%2 == 0)
256 step++;
257 for(j=1; j <= step; j++)
258 DRAW_PIXEL(ICON_VOLUME_X_POS + i, STATUSBAR_Y_POS + 7 - j);
265 * Print play state to status bar
267 void statusbar_icon_play_state(int state)
269 lcd_bitmap(bitmap_icon_7x8[state], ICON_PLAY_STATE_X_POS, STATUSBAR_Y_POS,
270 ICON_PLAY_STATE_WIDTH, STATUSBAR_HEIGHT, false);
274 * Print play mode to status bar
276 void statusbar_icon_play_mode(int mode)
278 lcd_bitmap(bitmap_icon_7x8[mode], ICON_PLAY_MODE_X_POS, STATUSBAR_Y_POS,
279 ICON_PLAY_MODE_WIDTH, STATUSBAR_HEIGHT, false);
283 * Print shuffle mode to status bar
285 void statusbar_icon_shuffle(void)
287 lcd_bitmap(bitmap_icon_7x8[Icon_Shuffle], ICON_SHUFFLE_X_POS,
288 STATUSBAR_Y_POS, ICON_SHUFFLE_WIDTH, STATUSBAR_HEIGHT, false);
292 * Print lock when keys are locked
294 void statusbar_icon_lock(void)
296 lcd_bitmap(bitmap_icon_5x8[Icon_Lock], LOCK_X_POS,
297 STATUSBAR_Y_POS, 5, 8, false);
300 #ifdef HAVE_RTC
302 * Print time to status bar
304 void statusbar_time(void)
306 int hour,minute;
307 unsigned char buffer[6];
308 unsigned int width, height;
309 #if defined(LOADABLE_FONTS)
310 unsigned char *font;
311 #endif
313 hour = rtc_read(0x03);
314 minute = rtc_read(0x02);
316 snprintf(buffer, sizeof(buffer), "%d%d:%d%d",
317 (hour & 0x30) >> 4,
318 hour & 0x0f,
319 (minute & 0xf0) >> 4,
320 minute & 0x0f);
321 #if defined(LCD_PROPFONTS)
322 lcd_getstringsize(buffer, 0, &width, &height);
323 width += strlen(buffer) - 1;
324 #elif defined(LOADABLE_FONTS)
325 font = lcd_getcurrentldfont();
326 lcd_getstringsize(buffer, font, &width, &height);
327 #else
328 width = 6*strlen(buffer);
329 height = 8;
330 #endif
331 if (height <= STATUSBAR_HEIGHT)
332 lcd_putsxy(TIME_X_END - width, STATUSBAR_Y_POS, buffer, 0);
334 #endif