Fix a few problems with RTL, statusbar and custom ui viewport.
[kugel-rb.git] / apps / gui / statusbar.c
blob8edc824e2ebab2882b9cee449bc1de47aa33a8db
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) Robert E. Hak (2002), Linus Nielsen Feltzing (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 ****************************************************************************/
22 #include "config.h"
23 #include "font.h"
24 #include "kernel.h"
25 #include "string.h" /* for memcmp oO*/
26 #include "sprintf.h"
27 #include "sound.h"
28 #include "settings.h"
29 #include "viewport.h"
30 #if CONFIG_CODEC == SWCODEC
31 #include "metadata.h"
32 #endif
33 #include "icons.h"
34 #include "powermgmt.h"
35 #include "usb.h"
36 #include "led.h"
37 #include "screen_access.h"
39 #include "status.h" /* needed for battery_state global var */
40 #include "action.h" /* for keys_locked */
41 #include "statusbar.h"
42 #ifdef HAVE_RECORDING
43 #include "audio.h"
44 #include "recording.h"
45 #include "pcm_record.h"
46 #endif
47 #include "appevents.h"
48 #include "timefuncs.h"
50 /* FIXME: should be removed from icon.h to avoid redefinition,
51 but still needed for compatibility with old system */
52 #define ICONS_SPACING 2
53 #define STATUSBAR_BATTERY_X_POS 0*ICONS_SPACING
54 #define STATUSBAR_BATTERY_WIDTH 18
55 #define STATUSBAR_PLUG_X_POS STATUSBAR_X_POS + \
56 STATUSBAR_BATTERY_WIDTH + \
57 ICONS_SPACING
58 #define STATUSBAR_PLUG_WIDTH 7
59 #define STATUSBAR_VOLUME_X_POS STATUSBAR_X_POS + \
60 STATUSBAR_BATTERY_WIDTH + \
61 STATUSBAR_PLUG_WIDTH + \
62 2*ICONS_SPACING
63 #define STATUSBAR_VOLUME_WIDTH 16
64 #define STATUSBAR_ENCODER_X_POS STATUSBAR_X_POS + \
65 STATUSBAR_BATTERY_WIDTH + \
66 STATUSBAR_PLUG_WIDTH + \
67 2*ICONS_SPACING - 1
68 #define STATUSBAR_ENCODER_WIDTH 18
69 #define STATUSBAR_PLAY_STATE_X_POS STATUSBAR_X_POS + \
70 STATUSBAR_BATTERY_WIDTH + \
71 STATUSBAR_PLUG_WIDTH + \
72 STATUSBAR_VOLUME_WIDTH + \
73 3*ICONS_SPACING
74 #define STATUSBAR_PLAY_STATE_WIDTH 7
75 #define STATUSBAR_PLAY_MODE_X_POS STATUSBAR_X_POS + \
76 STATUSBAR_BATTERY_WIDTH + \
77 STATUSBAR_PLUG_WIDTH + \
78 STATUSBAR_VOLUME_WIDTH + \
79 STATUSBAR_PLAY_STATE_WIDTH + \
80 4*ICONS_SPACING
81 #define STATUSBAR_PLAY_MODE_WIDTH 7
82 #define STATUSBAR_RECFREQ_X_POS STATUSBAR_X_POS + \
83 STATUSBAR_BATTERY_WIDTH + \
84 STATUSBAR_PLUG_WIDTH + \
85 STATUSBAR_VOLUME_WIDTH + \
86 STATUSBAR_PLAY_STATE_WIDTH + \
87 3*ICONS_SPACING
88 #define STATUSBAR_RECFREQ_WIDTH 12
89 #define STATUSBAR_RECCHANNELS_X_POS STATUSBAR_X_POS + \
90 STATUSBAR_BATTERY_WIDTH + \
91 STATUSBAR_PLUG_WIDTH + \
92 STATUSBAR_VOLUME_WIDTH + \
93 STATUSBAR_PLAY_STATE_WIDTH + \
94 STATUSBAR_RECFREQ_WIDTH + \
95 4*ICONS_SPACING
96 #define STATUSBAR_RECCHANNELS_WIDTH 5
97 #define STATUSBAR_SHUFFLE_X_POS STATUSBAR_X_POS + \
98 STATUSBAR_BATTERY_WIDTH + \
99 STATUSBAR_PLUG_WIDTH + \
100 STATUSBAR_VOLUME_WIDTH + \
101 STATUSBAR_PLAY_STATE_WIDTH + \
102 STATUSBAR_PLAY_MODE_WIDTH + \
103 5*ICONS_SPACING
104 #define STATUSBAR_SHUFFLE_WIDTH 7
105 #define STATUSBAR_LOCKM_X_POS STATUSBAR_X_POS + \
106 STATUSBAR_BATTERY_WIDTH + \
107 STATUSBAR_PLUG_WIDTH + \
108 STATUSBAR_VOLUME_WIDTH + \
109 STATUSBAR_PLAY_STATE_WIDTH + \
110 STATUSBAR_PLAY_MODE_WIDTH + \
111 STATUSBAR_SHUFFLE_WIDTH + \
112 6*ICONS_SPACING
113 #define STATUSBAR_LOCKM_WIDTH 5
114 #define STATUSBAR_LOCKR_X_POS STATUSBAR_X_POS + \
115 STATUSBAR_BATTERY_WIDTH + \
116 STATUSBAR_PLUG_WIDTH + \
117 STATUSBAR_VOLUME_WIDTH + \
118 STATUSBAR_PLAY_STATE_WIDTH + \
119 STATUSBAR_PLAY_MODE_WIDTH + \
120 STATUSBAR_SHUFFLE_WIDTH + \
121 STATUSBAR_LOCKM_WIDTH + \
122 7*ICONS_SPACING
123 #define STATUSBAR_LOCKR_WIDTH 5
125 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
126 #define STATUSBAR_DISK_WIDTH 12
127 #define STATUSBAR_DISK_X_POS(statusbar_width) statusbar_width - \
128 STATUSBAR_DISK_WIDTH
129 #else
130 #define STATUSBAR_DISK_WIDTH 0
131 #endif
132 #define STATUSBAR_TIME_X_END(statusbar_width) statusbar_width - 1 - \
133 STATUSBAR_DISK_WIDTH
134 struct gui_syncstatusbar statusbars;
136 /* Prototypes */
137 #ifdef HAVE_LCD_BITMAP
138 static void gui_statusbar_icon_battery(struct screen * display, int percent,
139 int batt_charge_step);
140 static bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
141 static void gui_statusbar_icon_play_state(struct screen * display, int state);
142 static void gui_statusbar_icon_play_mode(struct screen * display, int mode);
143 static void gui_statusbar_icon_shuffle(struct screen * display);
144 static void gui_statusbar_icon_lock(struct screen * display);
145 #ifdef HAS_REMOTE_BUTTON_HOLD
146 static void gui_statusbar_icon_lock_remote(struct screen * display);
147 #endif
148 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
149 static void gui_statusbar_led(struct screen * display);
150 #endif
151 #ifdef HAVE_RECORDING
152 static void gui_statusbar_icon_recording_info(struct screen * display);
153 #endif
154 #if CONFIG_RTC
155 static void gui_statusbar_time(struct screen * display, struct tm *time);
156 #endif
157 #endif
159 /* End prototypes */
163 * Initializes a status bar
164 * - bar : the bar to initialize
166 static void gui_statusbar_init(struct gui_statusbar * bar)
168 bar->redraw_volume = true;
169 bar->volume_icon_switch_tick = bar->battery_icon_switch_tick = current_tick;
170 memset((void*)&(bar->lastinfo), 0, sizeof(struct status_info));
171 #if CONFIG_RTC
172 bar->last_tm_min = 0;
173 #endif
176 #define GET_RECT(vp, vals,display) do { \
177 viewport_set_fullscreen(&(vp), (display)->screen_type); \
178 (vp).flags &= ~VP_FLAG_IS_RTL; \
179 (vp).height = STATUSBAR_HEIGHT; \
180 (vp).x = STATUSBAR_X_POS; \
181 if ((vals) != STATUSBAR_BOTTOM) \
182 (vp).y = 0; \
183 else \
184 (vp).y = (display)->lcdheight - STATUSBAR_HEIGHT; \
185 } while(0)
187 void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
189 struct screen * display = bar->display;
191 #ifdef HAVE_LCD_CHARCELLS
192 int val;
193 (void)force_redraw; /* The Player always has "redraw" */
194 #endif /* HAVE_LCD_CHARCELLS */
196 bar->info.battlevel = battery_level();
197 #ifdef HAVE_USB_POWER
198 bar->info.usb_inserted = usb_inserted();
199 #endif
200 #if CONFIG_CHARGING
201 bar->info.inserted = (charger_input_state == CHARGER);
202 if (bar->info.inserted)
204 bar->info.battery_state = true;
206 #if CONFIG_CHARGING >= CHARGING_MONITOR
208 /* zero battery run time if charging */
209 if (charge_state > DISCHARGING)
210 lasttime = current_tick;
212 /* animate battery if charging */
213 if ((charge_state == DISCHARGING) || (charge_state == TRICKLE))
215 bar->info.batt_charge_step = -1;
217 else
219 #else /* CONFIG_CHARGING < CHARGING_MONITOR */
220 lasttime = current_tick;
222 #endif /* CONFIG_CHARGING < CHARGING_MONITOR */
223 /* animate in (max.) 4 steps, starting near the current charge level */
224 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick))
226 if (++bar->info.batt_charge_step > 3)
227 bar->info.batt_charge_step = bar->info.battlevel / 34;
228 bar->battery_icon_switch_tick = current_tick + HZ;
232 else
233 #endif /* CONFIG_CHARGING */
235 bar->info.batt_charge_step = -1;
236 if (battery_level_safe())
237 bar->info.battery_state = true;
238 else
239 /* blink battery if level is low */
240 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
241 (bar->info.battlevel > -1))
243 bar->info.battery_state = !bar->info.battery_state;
244 bar->battery_icon_switch_tick = current_tick + HZ;
248 bar->info.volume = global_settings.volume;
249 #ifdef HAVE_LCD_BITMAP
250 bar->info.shuffle = global_settings.playlist_shuffle;
251 #ifdef HAS_BUTTON_HOLD
252 bar->info.keylock = button_hold();
253 #else
254 bar->info.keylock = is_keys_locked();
255 #endif /* HAS_BUTTON_HOLD */
256 #ifdef HAS_REMOTE_BUTTON_HOLD
257 bar->info.keylockremote = remote_button_hold();
258 #endif
259 bar->info.repeat = global_settings.repeat_mode;
260 bar->info.playmode = current_playmode();
262 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
263 if(!display->has_disk_led)
264 bar->info.led = led_read(HZ/2); /* delay should match polling interval */
265 #endif
266 #if CONFIG_RTC
267 bar->time = get_time();
268 #endif /* CONFIG_RTC */
270 /* only redraw if forced to, or info has changed */
271 if (force_redraw || bar->redraw_volume ||
272 #if CONFIG_RTC
273 (bar->time->tm_min != bar->last_tm_min) ||
274 #endif
275 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
277 struct viewport vp;
279 GET_RECT(vp,statusbar_position(display->screen_type),display);
280 display->set_viewport(&vp);
281 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
282 display->fillrect(0, 0, display->getwidth(), STATUSBAR_HEIGHT);
283 display->set_drawmode(DRMODE_SOLID);
285 if (bar->info.battery_state)
286 gui_statusbar_icon_battery(display, bar->info.battlevel,
287 bar->info.batt_charge_step);
288 #ifdef HAVE_USB_POWER
289 if (bar->info.usb_inserted)
290 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
291 STATUSBAR_PLUG_X_POS,
292 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
293 STATUSBAR_HEIGHT);
294 #endif /* HAVE_USB_POWER */
295 #if CONFIG_CHARGING
296 #ifdef HAVE_USB_POWER
297 else
298 #endif
299 /* draw power plug if charging */
300 if (bar->info.inserted)
301 display->mono_bitmap(bitmap_icons_7x8[Icon_Plug],
302 STATUSBAR_PLUG_X_POS,
303 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
304 STATUSBAR_HEIGHT);
305 #endif /* CONFIG_CHARGING */
306 #ifdef HAVE_RECORDING
307 /* turn off volume display in recording screen */
308 bool recscreen_on = in_recording_screen();
309 if (!recscreen_on)
310 #endif
311 bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume);
312 gui_statusbar_icon_play_state(display, current_playmode() + Icon_Play);
314 #ifdef HAVE_RECORDING
315 /* If in recording screen, replace repeat mode, volume
316 and shuffle icons with recording info */
317 if (recscreen_on)
318 gui_statusbar_icon_recording_info(display);
319 else
320 #endif
322 switch (bar->info.repeat) {
323 #ifdef AB_REPEAT_ENABLE
324 case REPEAT_AB:
325 gui_statusbar_icon_play_mode(display, Icon_RepeatAB);
326 break;
327 #endif /* AB_REPEAT_ENABLE == 1 */
329 case REPEAT_ONE:
330 gui_statusbar_icon_play_mode(display, Icon_RepeatOne);
331 break;
333 case REPEAT_ALL:
334 case REPEAT_SHUFFLE:
335 gui_statusbar_icon_play_mode(display, Icon_Repeat);
336 break;
338 if (bar->info.shuffle)
339 gui_statusbar_icon_shuffle(display);
341 if (bar->info.keylock)
342 gui_statusbar_icon_lock(display);
343 #ifdef HAS_REMOTE_BUTTON_HOLD
344 if (bar->info.keylockremote)
345 gui_statusbar_icon_lock_remote(display);
346 #endif
347 #if CONFIG_RTC
348 gui_statusbar_time(display, bar->time);
349 bar->last_tm_min = bar->time->tm_min;
350 #endif /* CONFIG_RTC */
351 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
352 if(!display->has_disk_led && bar->info.led)
353 gui_statusbar_led(display);
354 #endif
355 display->update_viewport();
356 display->set_viewport(NULL);
357 bar->lastinfo = bar->info;
359 #endif /* HAVE_LCD_BITMAP */
362 #ifdef HAVE_LCD_CHARCELLS
363 display->icon(ICON_BATTERY, bar->info.battery_state);
365 if (bar->info.batt_charge_step > -1)
366 val = bar->info.batt_charge_step;
367 else
368 val = (bar->info.battlevel * 3 + 50) / 100;
369 display->icon(ICON_BATTERY_1, val >= 1);
370 display->icon(ICON_BATTERY_2, val >= 2);
371 display->icon(ICON_BATTERY_3, val >= 3);
373 val = 10 * (bar->info.volume - sound_min(SOUND_VOLUME))
374 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
375 display->icon(ICON_VOLUME, true);
376 display->icon(ICON_VOLUME_1, val >= 1);
377 display->icon(ICON_VOLUME_2, val >= 3);
378 display->icon(ICON_VOLUME_3, val >= 5);
379 display->icon(ICON_VOLUME_4, val >= 7);
380 display->icon(ICON_VOLUME_5, val >= 9);
382 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
383 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
385 display->icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
386 display->icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
388 display->icon(ICON_RECORD, record);
389 display->icon(ICON_AUDIO, audio);
390 display->icon(ICON_PARAM, param);
391 display->icon(ICON_USB, usb);
392 #endif /* HAVE_LCD_CHARCELLS */
395 #ifdef HAVE_LCD_BITMAP
396 /* from icon.c */
398 * Print battery icon to status bar
400 static void gui_statusbar_icon_battery(struct screen * display, int percent,
401 int batt_charge_step)
403 int fill, endfill;
404 char buffer[5];
405 unsigned int width, height;
406 #if LCD_DEPTH > 1
407 unsigned int prevfg = 0;
408 #endif
410 #if CONFIG_CHARGING
411 if (batt_charge_step >= 0)
413 fill = percent * (STATUSBAR_BATTERY_WIDTH-3) / 100;
414 endfill = 34 * batt_charge_step * (STATUSBAR_BATTERY_WIDTH-3) / 100;
416 else
417 #else
418 (void)batt_charge_step;
419 #endif
421 fill = endfill = (percent * (STATUSBAR_BATTERY_WIDTH-3) + 50) / 100;
424 #if CONFIG_CHARGING == CHARGING_MONITOR && !defined(SIMULATOR)
425 /* Certain charge controlled targets */
426 /* show graphical animation when charging instead of numbers */
427 if ((global_settings.battery_display) &&
428 (charge_state != CHARGING) &&
429 (percent > -1)) {
430 #else /* all others */
431 if (global_settings.battery_display && (percent > -1)) {
432 #endif
433 /* Numeric display */
434 display->setfont(FONT_SYSFIXED);
435 snprintf(buffer, sizeof(buffer), "%3d", percent);
436 display->getstringsize(buffer, &width, &height);
437 if (height <= STATUSBAR_HEIGHT)
438 display->putsxy(STATUSBAR_BATTERY_X_POS
439 + STATUSBAR_BATTERY_WIDTH / 2
440 - width/2, STATUSBAR_Y_POS, buffer);
441 display->setfont(FONT_UI);
444 else {
445 /* draw battery */
446 display->drawrect(STATUSBAR_BATTERY_X_POS, STATUSBAR_Y_POS, 17, 7);
447 display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2,
448 STATUSBAR_Y_POS + 4);
450 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
451 fill, 5);
452 #if LCD_DEPTH > 1
453 if (display->depth > 1)
455 prevfg = display->get_foreground();
456 display->set_foreground(LCD_DARKGRAY);
458 #endif
459 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
460 STATUSBAR_Y_POS + 1, endfill - fill, 5);
461 #if LCD_DEPTH > 1
462 if (display->depth > 1)
463 display->set_foreground(prevfg);
464 #endif
467 if (percent == -1) {
468 display->setfont(FONT_SYSFIXED);
469 display->putsxy(STATUSBAR_BATTERY_X_POS + STATUSBAR_BATTERY_WIDTH / 2
470 - 4, STATUSBAR_Y_POS, "?");
471 display->setfont(FONT_UI);
476 * Print volume gauge to status bar
478 static bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume)
480 int i;
481 int vol;
482 char buffer[4];
483 unsigned int width, height;
484 bool needs_redraw = false;
485 int type = global_settings.volume_type;
486 struct screen * display=bar->display;
487 const int minvol = sound_min(SOUND_VOLUME);
488 const int maxvol = sound_max(SOUND_VOLUME);
490 if (volume < minvol)
491 volume = minvol;
492 if (volume > maxvol)
493 volume = maxvol;
495 if (volume == minvol) {
496 display->mono_bitmap(bitmap_icons_7x8[Icon_Mute],
497 STATUSBAR_VOLUME_X_POS + STATUSBAR_VOLUME_WIDTH / 2 - 4,
498 STATUSBAR_Y_POS, 7, STATUSBAR_HEIGHT);
500 else {
501 /* We want to redraw the icon later on */
502 if (bar->last_volume != volume && bar->last_volume >= minvol) {
503 bar->volume_icon_switch_tick = current_tick + HZ;
506 /* If the timeout hasn't yet been reached, we show it numerically
507 and tell the caller that we want to be called again */
508 if (TIME_BEFORE(current_tick,bar->volume_icon_switch_tick)) {
509 type = 1;
510 needs_redraw = true;
513 /* display volume level numerical? */
514 if (type)
516 display->setfont(FONT_SYSFIXED);
517 snprintf(buffer, sizeof(buffer), "%2d", volume);
518 display->getstringsize(buffer, &width, &height);
519 if (height <= STATUSBAR_HEIGHT)
521 display->putsxy(STATUSBAR_VOLUME_X_POS
522 + STATUSBAR_VOLUME_WIDTH / 2
523 - width/2, STATUSBAR_Y_POS, buffer);
525 display->setfont(FONT_UI);
526 } else {
527 /* display volume bar */
528 vol = (volume - minvol) * 14 / (maxvol - minvol);
529 for(i=0; i < vol; i++) {
530 display->vline(STATUSBAR_VOLUME_X_POS + i,
531 STATUSBAR_Y_POS + 6 - i / 2,
532 STATUSBAR_Y_POS + 6);
536 bar->last_volume = volume;
538 return needs_redraw;
542 * Print play state to status bar
544 static void gui_statusbar_icon_play_state(struct screen * display, int state)
546 display->mono_bitmap(bitmap_icons_7x8[state], STATUSBAR_PLAY_STATE_X_POS,
547 STATUSBAR_Y_POS, STATUSBAR_PLAY_STATE_WIDTH,
548 STATUSBAR_HEIGHT);
552 * Print play mode to status bar
554 static void gui_statusbar_icon_play_mode(struct screen * display, int mode)
556 display->mono_bitmap(bitmap_icons_7x8[mode], STATUSBAR_PLAY_MODE_X_POS,
557 STATUSBAR_Y_POS, STATUSBAR_PLAY_MODE_WIDTH,
558 STATUSBAR_HEIGHT);
562 * Print shuffle mode to status bar
564 static void gui_statusbar_icon_shuffle(struct screen * display)
566 display->mono_bitmap(bitmap_icons_7x8[Icon_Shuffle],
567 STATUSBAR_SHUFFLE_X_POS, STATUSBAR_Y_POS,
568 STATUSBAR_SHUFFLE_WIDTH, STATUSBAR_HEIGHT);
572 * Print lock when keys are locked
574 static void gui_statusbar_icon_lock(struct screen * display)
576 display->mono_bitmap(bitmap_icons_5x8[Icon_Lock_Main],
577 STATUSBAR_LOCKM_X_POS, STATUSBAR_Y_POS,
578 STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT);
581 #ifdef HAS_REMOTE_BUTTON_HOLD
583 * Print remote lock when remote hold is enabled
585 static void gui_statusbar_icon_lock_remote(struct screen * display)
587 display->mono_bitmap(bitmap_icons_5x8[Icon_Lock_Remote],
588 STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS,
589 STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT);
591 #endif
593 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
595 * no real LED: disk activity in status bar
597 static void gui_statusbar_led(struct screen * display)
599 display->mono_bitmap(bitmap_icon_disk,
600 STATUSBAR_DISK_X_POS(display->getwidth()),
601 STATUSBAR_Y_POS, STATUSBAR_DISK_WIDTH,
602 STATUSBAR_HEIGHT);
604 #endif
606 #if CONFIG_RTC
608 * Print time to status bar
610 static void gui_statusbar_time(struct screen * display, struct tm *time)
612 unsigned char buffer[6];
613 unsigned int width, height;
614 int hour, minute;
615 if ( valid_time(time) ) {
616 hour = time->tm_hour;
617 minute = time->tm_min;
618 if ( global_settings.timeformat ) { /* 12 hour clock */
619 hour %= 12;
620 if ( hour == 0 ) {
621 hour += 12;
624 snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute);
626 else {
627 strlcpy(buffer, "--:--", sizeof(buffer));
629 display->setfont(FONT_SYSFIXED);
630 display->getstringsize(buffer, &width, &height);
631 if (height <= STATUSBAR_HEIGHT) {
632 display->putsxy(STATUSBAR_TIME_X_END(display->getwidth()) - width,
633 STATUSBAR_Y_POS, buffer);
635 display->setfont(FONT_UI);
637 #endif
639 #ifdef HAVE_RECORDING
640 #if CONFIG_CODEC == SWCODEC
642 * Write a number to the display using bitmaps and return new position
644 static int write_bitmap_number(struct screen * display, int value,
645 int x, int y)
647 char buf[12], *ptr;
648 snprintf(buf, sizeof(buf), "%d", value);
650 for (ptr = buf; *ptr != '\0'; ptr++, x += BM_GLYPH_WIDTH)
651 display->mono_bitmap(bitmap_glyphs_4x8[*ptr - '0'], x, y,
652 BM_GLYPH_WIDTH, STATUSBAR_HEIGHT);
653 return x;
657 * Write format info bitmaps - right justified
659 static void gui_statusbar_write_format_info(struct screen * display)
661 /* Can't fit info for sw codec targets in statusbar using FONT_SYSFIXED
662 so must use icons */
663 int rec_format = global_settings.rec_format;
664 unsigned bitrk = 0; /* compiler warns about unitialized use !! */
665 int xpos = STATUSBAR_ENCODER_X_POS;
666 int width = STATUSBAR_ENCODER_WIDTH;
667 const unsigned char *bm = bitmap_formats_18x8[rec_format];
669 if (rec_format == REC_FORMAT_MPA_L3)
671 /* Special handling for mp3 */
672 bitrk = global_settings.mp3_enc_config.bitrate;
673 bitrk = mp3_enc_bitr[bitrk];
675 width = BM_MPA_L3_M_WIDTH;
677 /* Slide 'M' to right if fewer than three digits used */
678 if (bitrk > 999)
679 bitrk = 999; /* neurotic safety check if corrupted */
680 else
682 if (bitrk < 100)
683 xpos += BM_GLYPH_WIDTH;
684 if (bitrk < 10)
685 xpos += BM_GLYPH_WIDTH;
690 /* Show bitmap - clipping right edge if needed */
691 display->mono_bitmap_part(bm, 0, 0, STATUSBAR_ENCODER_WIDTH,
692 xpos, STATUSBAR_Y_POS, width, STATUSBAR_HEIGHT);
694 if (rec_format == REC_FORMAT_MPA_L3)
696 xpos += BM_MPA_L3_M_WIDTH; /* to right of 'M' */
697 write_bitmap_number(display, bitrk, xpos, STATUSBAR_Y_POS);
702 * Write sample rate using bitmaps - left justified
704 static void gui_statusbar_write_samplerate_info(struct screen * display)
706 unsigned long samprk;
707 int xpos;
709 #ifdef SIMULATOR
710 samprk = 44100;
711 #else
712 #ifdef HAVE_SPDIF_REC
713 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
714 /* Use rate in use, not current measured rate if it changed */
715 samprk = pcm_rec_sample_rate();
716 else
717 #endif
718 samprk = rec_freq_sampr[global_settings.rec_frequency];
719 #endif /* SIMULATOR */
721 samprk /= 1000;
722 if (samprk > 99)
723 samprk = 99; /* Limit to 3 glyphs */
725 xpos = write_bitmap_number(display, (unsigned)samprk,
726 STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS);
728 /* write the 'k' */
729 display->mono_bitmap(bitmap_glyphs_4x8[Glyph_4x8_k], xpos,
730 STATUSBAR_Y_POS, BM_GLYPH_WIDTH,
731 STATUSBAR_HEIGHT);
733 #endif /* CONFIG_CODEC == SWCODEC */
735 static void gui_statusbar_icon_recording_info(struct screen * display)
737 #if CONFIG_CODEC != SWCODEC
738 char buffer[3];
739 int width, height;
740 display->setfont(FONT_SYSFIXED);
741 #endif /* CONFIG_CODEC != SWCODEC */
743 /* Display Codec info in statusbar */
744 #if CONFIG_CODEC == SWCODEC
745 gui_statusbar_write_format_info(display);
746 #else /* !SWCODEC */
747 display->mono_bitmap(bitmap_icons_5x8[Icon_q],
748 STATUSBAR_ENCODER_X_POS + 8, STATUSBAR_Y_POS,
749 5, STATUSBAR_HEIGHT);
751 snprintf(buffer, sizeof(buffer), "%d", global_settings.rec_quality);
752 display->getstringsize(buffer, &width, &height);
753 if (height <= STATUSBAR_HEIGHT)
754 display->putsxy(STATUSBAR_ENCODER_X_POS + 13, STATUSBAR_Y_POS, buffer);
755 #endif /* CONFIG_CODEC == SWCODEC */
757 /* Display Samplerate info in statusbar */
758 #if CONFIG_CODEC == SWCODEC
759 /* SWCODEC targets use bitmaps for glyphs */
760 gui_statusbar_write_samplerate_info(display);
761 #else /* !SWCODEC */
762 /* hwcodec targets have sysfont characters */
763 #ifdef HAVE_SPDIF_REC
764 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
766 /* Can't measure S/PDIF sample rate on Archos/Sim yet */
767 strlcpy(buffer, "--", sizeof(buffer));
769 else
770 #endif /* HAVE_SPDIF_IN */
772 static char const * const freq_strings[12] =
773 { "44", "48", "32", "22", "24", "16" };
774 strlcpy(buffer, freq_strings[global_settings.rec_frequency],
775 sizeof(buffer));
778 display->getstringsize(buffer, &width, &height);
780 if (height <= STATUSBAR_HEIGHT)
781 display->putsxy(STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS, buffer);
783 display->setfont(FONT_UI);
784 #endif /* CONFIG_CODEC == SWCODEC */
786 /* Display Channel status in status bar */
787 if(global_settings.rec_channels)
789 display->mono_bitmap(bitmap_icons_5x8[Icon_Mono],
790 STATUSBAR_RECCHANNELS_X_POS , STATUSBAR_Y_POS,
791 STATUSBAR_RECCHANNELS_WIDTH, STATUSBAR_HEIGHT);
793 else
795 display->mono_bitmap(bitmap_icons_5x8[Icon_Stereo],
796 STATUSBAR_RECCHANNELS_X_POS, STATUSBAR_Y_POS,
797 STATUSBAR_RECCHANNELS_WIDTH, STATUSBAR_HEIGHT);
800 #endif /* HAVE_RECORDING */
802 #endif /* HAVE_LCD_BITMAP */
804 void gui_syncstatusbar_init(struct gui_syncstatusbar * bars)
806 int i;
807 FOR_NB_SCREENS(i) {
808 gui_statusbar_init( &(bars->statusbars[i]) );
809 gui_statusbar_set_screen( &(bars->statusbars[i]), &(screens[i]) );
813 void gui_syncstatusbar_draw(struct gui_syncstatusbar * bars,
814 bool force_redraw)
816 #ifdef HAVE_LCD_BITMAP
817 if(!global_settings.statusbar)
818 return;
819 #endif /* HAVE_LCD_BITMAP */
820 int i;
821 FOR_NB_SCREENS(i) {
822 gui_statusbar_draw( &(bars->statusbars[i]), force_redraw );
826 #ifdef HAVE_LCD_BITMAP
827 void gui_statusbar_changed( enum screen_type screen,
828 enum statusbar_values old)
830 /* clear and update the statusbar area to remove old parts */
831 enum statusbar_values bar = statusbar_position(screen);
833 struct screen *display = &screens[screen];
834 struct viewport vp;
836 if (old != STATUSBAR_OFF && old != bar)
838 GET_RECT(vp, old, display);
839 display->set_viewport(&vp);
840 display->clear_viewport();
841 display->update_viewport();
842 display->set_viewport(NULL);
845 #endif
847 #ifdef HAVE_REMOTE_LCD
848 enum statusbar_values statusbar_position(int screen)
850 if (screen == SCREEN_REMOTE)
851 return global_settings.remote_statusbar;
852 return global_settings.statusbar;
854 #endif