Move Info tab content to a separate widget.
[maemo-rb.git] / apps / gui / statusbar.c
blob84de16987ff89f0581fdf4a22eb13641d9776018
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 <stdio.h>
23 #include "config.h"
24 #include "font.h"
25 #include "kernel.h"
26 #include "string.h" /* for memcmp oO*/
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_ALIGN_RIGHT; \
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, struct viewport *vp)
189 struct screen * display = bar->display;
191 if (!display)
192 return;
194 #ifdef HAVE_LCD_CHARCELLS
195 int val;
196 (void)force_redraw; /* The Player always has "redraw" */
197 (void)vp;
198 #endif /* HAVE_LCD_CHARCELLS */
200 bar->info.battlevel = battery_level();
201 #ifdef HAVE_USB_POWER
202 bar->info.usb_inserted = usb_inserted();
203 #endif
204 #if CONFIG_CHARGING
205 bar->info.inserted = (charger_input_state == CHARGER);
206 if (bar->info.inserted)
208 bar->info.battery_state = true;
210 #if CONFIG_CHARGING >= CHARGING_MONITOR
212 /* zero battery run time if charging */
213 if (charge_state > DISCHARGING)
214 lasttime = current_tick;
216 /* animate battery if charging */
217 if ((charge_state == DISCHARGING) || (charge_state == TRICKLE))
219 bar->info.batt_charge_step = -1;
221 else
223 #else /* CONFIG_CHARGING < CHARGING_MONITOR */
224 lasttime = current_tick;
226 #endif /* CONFIG_CHARGING < CHARGING_MONITOR */
227 /* animate in (max.) 4 steps, starting near the current charge level */
228 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick))
230 if (++bar->info.batt_charge_step > 3)
231 bar->info.batt_charge_step = bar->info.battlevel / 34;
232 bar->battery_icon_switch_tick = current_tick + HZ;
236 else
237 #endif /* CONFIG_CHARGING */
239 bar->info.batt_charge_step = -1;
240 if (battery_level_safe())
241 bar->info.battery_state = true;
242 else
243 /* blink battery if level is low */
244 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
245 (bar->info.battlevel > -1))
247 bar->info.battery_state = !bar->info.battery_state;
248 bar->battery_icon_switch_tick = current_tick + HZ;
252 bar->info.volume = global_settings.volume;
253 #ifdef HAVE_LCD_BITMAP
254 bar->info.shuffle = global_settings.playlist_shuffle;
255 #ifdef HAS_BUTTON_HOLD
256 bar->info.keylock = button_hold();
257 #else
258 bar->info.keylock = is_keys_locked();
259 #endif /* HAS_BUTTON_HOLD */
260 #ifdef HAS_REMOTE_BUTTON_HOLD
261 bar->info.keylockremote = remote_button_hold();
262 #endif
263 bar->info.repeat = global_settings.repeat_mode;
264 bar->info.playmode = current_playmode();
266 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
267 if(!display->has_disk_led)
268 bar->info.led = led_read(HZ/2); /* delay should match polling interval */
269 #endif
270 #if CONFIG_RTC
271 bar->time = get_time();
272 #endif /* CONFIG_RTC */
274 /* only redraw if forced to, or info has changed */
275 if (force_redraw || bar->redraw_volume ||
276 #if CONFIG_RTC
277 (bar->time->tm_min != bar->last_tm_min) ||
278 #endif
279 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
281 display->set_viewport(vp);
282 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
283 display->fill_viewport();
284 display->set_drawmode(DRMODE_SOLID);
286 if (bar->info.battery_state)
287 gui_statusbar_icon_battery(display, bar->info.battlevel,
288 bar->info.batt_charge_step);
289 #ifdef HAVE_USB_POWER
290 if (bar->info.usb_inserted)
291 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
292 STATUSBAR_PLUG_X_POS,
293 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
294 STATUSBAR_HEIGHT);
295 #endif /* HAVE_USB_POWER */
296 #if CONFIG_CHARGING
297 #ifdef HAVE_USB_POWER
298 else
299 #endif
300 /* draw power plug if charging */
301 if (bar->info.inserted)
302 display->mono_bitmap(bitmap_icons_7x8[Icon_Plug],
303 STATUSBAR_PLUG_X_POS,
304 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
305 STATUSBAR_HEIGHT);
306 #endif /* CONFIG_CHARGING */
307 #ifdef HAVE_RECORDING
308 /* turn off volume display in recording screen */
309 bool recscreen_on = in_recording_screen();
310 if (!recscreen_on)
311 #endif
312 bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume);
313 gui_statusbar_icon_play_state(display, current_playmode() + Icon_Play);
315 #ifdef HAVE_RECORDING
316 /* If in recording screen, replace repeat mode, volume
317 and shuffle icons with recording info */
318 if (recscreen_on)
319 gui_statusbar_icon_recording_info(display);
320 else
321 #endif
323 switch (bar->info.repeat) {
324 #ifdef AB_REPEAT_ENABLE
325 case REPEAT_AB:
326 gui_statusbar_icon_play_mode(display, Icon_RepeatAB);
327 break;
328 #endif /* AB_REPEAT_ENABLE */
330 case REPEAT_ONE:
331 gui_statusbar_icon_play_mode(display, Icon_RepeatOne);
332 break;
334 case REPEAT_ALL:
335 case REPEAT_SHUFFLE:
336 gui_statusbar_icon_play_mode(display, Icon_Repeat);
337 break;
339 if (bar->info.shuffle)
340 gui_statusbar_icon_shuffle(display);
342 if (bar->info.keylock)
343 gui_statusbar_icon_lock(display);
344 #ifdef HAS_REMOTE_BUTTON_HOLD
345 if (bar->info.keylockremote)
346 gui_statusbar_icon_lock_remote(display);
347 #endif
348 #if CONFIG_RTC
349 gui_statusbar_time(display, bar->time);
350 bar->last_tm_min = bar->time->tm_min;
351 #endif /* CONFIG_RTC */
352 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
353 if(!display->has_disk_led && bar->info.led)
354 gui_statusbar_led(display);
355 #endif
356 display->update_viewport();
357 display->set_viewport(NULL);
358 bar->lastinfo = bar->info;
360 #endif /* HAVE_LCD_BITMAP */
363 #ifdef HAVE_LCD_CHARCELLS
364 display->icon(ICON_BATTERY, bar->info.battery_state);
366 if (bar->info.batt_charge_step > -1)
367 val = bar->info.batt_charge_step;
368 else
369 val = (bar->info.battlevel * 3 + 50) / 100;
370 display->icon(ICON_BATTERY_1, val >= 1);
371 display->icon(ICON_BATTERY_2, val >= 2);
372 display->icon(ICON_BATTERY_3, val >= 3);
374 val = 10 * (bar->info.volume - sound_min(SOUND_VOLUME))
375 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
376 display->icon(ICON_VOLUME, true);
377 display->icon(ICON_VOLUME_1, val >= 1);
378 display->icon(ICON_VOLUME_2, val >= 3);
379 display->icon(ICON_VOLUME_3, val >= 5);
380 display->icon(ICON_VOLUME_4, val >= 7);
381 display->icon(ICON_VOLUME_5, val >= 9);
383 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
384 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
386 display->icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
387 display->icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
389 display->icon(ICON_RECORD, record);
390 display->icon(ICON_AUDIO, audio);
391 display->icon(ICON_PARAM, param);
392 display->icon(ICON_USB, usb);
393 #endif /* HAVE_LCD_CHARCELLS */
396 #ifdef HAVE_LCD_BITMAP
397 /* from icon.c */
399 * Print battery icon to status bar
401 static void gui_statusbar_icon_battery(struct screen * display, int percent,
402 int batt_charge_step)
404 int fill, endfill;
405 char buffer[5];
406 unsigned int width, height;
407 #if LCD_DEPTH > 1
408 unsigned int prevfg = 0;
409 #endif
411 #if CONFIG_CHARGING
412 if (batt_charge_step >= 0)
414 fill = percent * (STATUSBAR_BATTERY_WIDTH-3) / 100;
415 endfill = 34 * batt_charge_step * (STATUSBAR_BATTERY_WIDTH-3) / 100;
417 else
418 #else
419 (void)batt_charge_step;
420 #endif
422 fill = endfill = (percent * (STATUSBAR_BATTERY_WIDTH-3) + 50) / 100;
425 #if CONFIG_CHARGING == CHARGING_MONITOR && !defined(SIMULATOR)
426 /* Certain charge controlled targets */
427 /* show graphical animation when charging instead of numbers */
428 if ((global_settings.battery_display) &&
429 (charge_state != CHARGING) &&
430 (percent > -1)) {
431 #else /* all others */
432 if (global_settings.battery_display && (percent > -1)) {
433 #endif
434 /* Numeric display */
435 display->setfont(FONT_SYSFIXED);
436 snprintf(buffer, sizeof(buffer), "%3d", percent);
437 display->getstringsize(buffer, &width, &height);
438 if (height <= STATUSBAR_HEIGHT)
439 display->putsxy(STATUSBAR_BATTERY_X_POS
440 + STATUSBAR_BATTERY_WIDTH / 2
441 - width/2, STATUSBAR_Y_POS, buffer);
442 display->setfont(FONT_UI);
445 else {
446 /* draw battery */
447 display->drawrect(STATUSBAR_BATTERY_X_POS, STATUSBAR_Y_POS, 17, 7);
448 display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2,
449 STATUSBAR_Y_POS + 4);
451 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
452 fill, 5);
453 #if LCD_DEPTH > 1
454 if (display->depth > 1)
456 prevfg = display->get_foreground();
457 display->set_foreground(LCD_DARKGRAY);
459 #endif
460 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
461 STATUSBAR_Y_POS + 1, endfill - fill, 5);
462 #if LCD_DEPTH > 1
463 if (display->depth > 1)
464 display->set_foreground(prevfg);
465 #endif
468 if (percent == -1) {
469 display->setfont(FONT_SYSFIXED);
470 display->putsxy(STATUSBAR_BATTERY_X_POS + STATUSBAR_BATTERY_WIDTH / 2
471 - 4, STATUSBAR_Y_POS, "?");
472 display->setfont(FONT_UI);
477 * Print volume gauge to status bar
479 static bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume)
481 int i;
482 int vol;
483 char buffer[4];
484 unsigned int width, height;
485 bool needs_redraw = false;
486 int type = global_settings.volume_type;
487 struct screen * display=bar->display;
488 const int minvol = sound_min(SOUND_VOLUME);
489 const int maxvol = sound_max(SOUND_VOLUME);
491 if (volume < minvol)
492 volume = minvol;
493 if (volume > maxvol)
494 volume = maxvol;
496 if (volume == minvol) {
497 display->mono_bitmap(bitmap_icons_7x8[Icon_Mute],
498 STATUSBAR_VOLUME_X_POS + STATUSBAR_VOLUME_WIDTH / 2 - 4,
499 STATUSBAR_Y_POS, 7, STATUSBAR_HEIGHT);
501 else {
502 /* We want to redraw the icon later on */
503 if (bar->last_volume != volume && bar->last_volume >= minvol) {
504 bar->volume_icon_switch_tick = current_tick + HZ;
507 /* If the timeout hasn't yet been reached, we show it numerically
508 and tell the caller that we want to be called again */
509 if (TIME_BEFORE(current_tick,bar->volume_icon_switch_tick)) {
510 type = 1;
511 needs_redraw = true;
514 /* display volume level numerical? */
515 if (type)
517 display->setfont(FONT_SYSFIXED);
518 snprintf(buffer, sizeof(buffer), "%2d", volume);
519 display->getstringsize(buffer, &width, &height);
520 if (height <= STATUSBAR_HEIGHT)
522 display->putsxy(STATUSBAR_VOLUME_X_POS
523 + STATUSBAR_VOLUME_WIDTH / 2
524 - width/2, STATUSBAR_Y_POS, buffer);
526 display->setfont(FONT_UI);
527 } else {
528 /* display volume bar */
529 vol = (volume - minvol) * 14 / (maxvol - minvol);
530 for(i=0; i < vol; i++) {
531 display->vline(STATUSBAR_VOLUME_X_POS + i,
532 STATUSBAR_Y_POS + 6 - i / 2,
533 STATUSBAR_Y_POS + 6);
537 bar->last_volume = volume;
539 return needs_redraw;
543 * Print play state to status bar
545 static void gui_statusbar_icon_play_state(struct screen * display, int state)
547 display->mono_bitmap(bitmap_icons_7x8[state], STATUSBAR_PLAY_STATE_X_POS,
548 STATUSBAR_Y_POS, STATUSBAR_PLAY_STATE_WIDTH,
549 STATUSBAR_HEIGHT);
553 * Print play mode to status bar
555 static void gui_statusbar_icon_play_mode(struct screen * display, int mode)
557 display->mono_bitmap(bitmap_icons_7x8[mode], STATUSBAR_PLAY_MODE_X_POS,
558 STATUSBAR_Y_POS, STATUSBAR_PLAY_MODE_WIDTH,
559 STATUSBAR_HEIGHT);
563 * Print shuffle mode to status bar
565 static void gui_statusbar_icon_shuffle(struct screen * display)
567 display->mono_bitmap(bitmap_icons_7x8[Icon_Shuffle],
568 STATUSBAR_SHUFFLE_X_POS, STATUSBAR_Y_POS,
569 STATUSBAR_SHUFFLE_WIDTH, STATUSBAR_HEIGHT);
573 * Print lock when keys are locked
575 static void gui_statusbar_icon_lock(struct screen * display)
577 display->mono_bitmap(bitmap_icons_5x8[Icon_Lock_Main],
578 STATUSBAR_LOCKM_X_POS, STATUSBAR_Y_POS,
579 STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT);
582 #ifdef HAS_REMOTE_BUTTON_HOLD
584 * Print remote lock when remote hold is enabled
586 static void gui_statusbar_icon_lock_remote(struct screen * display)
588 display->mono_bitmap(bitmap_icons_5x8[Icon_Lock_Remote],
589 STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS,
590 STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT);
592 #endif
594 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
596 * no real LED: disk activity in status bar
598 static void gui_statusbar_led(struct screen * display)
600 display->mono_bitmap(bitmap_icon_disk,
601 STATUSBAR_DISK_X_POS(display->getwidth()),
602 STATUSBAR_Y_POS, STATUSBAR_DISK_WIDTH,
603 STATUSBAR_HEIGHT);
605 #endif
607 #if CONFIG_RTC
609 * Print time to status bar
611 static void gui_statusbar_time(struct screen * display, struct tm *time)
613 unsigned char buffer[6];
614 const unsigned char *p = buffer;
615 unsigned int width, height;
616 int hour, minute;
617 if ( valid_time(time) ) {
618 hour = time->tm_hour;
619 minute = time->tm_min;
620 if ( global_settings.timeformat ) { /* 12 hour clock */
621 hour %= 12;
622 if ( hour == 0 ) {
623 hour += 12;
626 snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute);
628 else {
629 p = "--:--";
631 display->setfont(FONT_SYSFIXED);
632 display->getstringsize(p, &width, &height);
633 if (height <= STATUSBAR_HEIGHT) {
634 display->putsxy(STATUSBAR_TIME_X_END(display->getwidth()) - width,
635 STATUSBAR_Y_POS, p);
637 display->setfont(FONT_UI);
639 #endif
641 #ifdef HAVE_RECORDING
642 #if CONFIG_CODEC == SWCODEC
644 * Write a number to the display using bitmaps and return new position
646 static int write_bitmap_number(struct screen * display, int value,
647 int x, int y)
649 char buf[12], *ptr;
650 snprintf(buf, sizeof(buf), "%d", value);
652 for (ptr = buf; *ptr != '\0'; ptr++, x += BM_GLYPH_WIDTH)
653 display->mono_bitmap(bitmap_glyphs_4x8[*ptr - '0'], x, y,
654 BM_GLYPH_WIDTH, STATUSBAR_HEIGHT);
655 return x;
659 * Write format info bitmaps - right justified
661 static void gui_statusbar_write_format_info(struct screen * display)
663 /* Can't fit info for sw codec targets in statusbar using FONT_SYSFIXED
664 so must use icons */
665 int rec_format = global_settings.rec_format;
666 unsigned bitrk = 0; /* compiler warns about unitialized use !! */
667 int xpos = STATUSBAR_ENCODER_X_POS;
668 int width = STATUSBAR_ENCODER_WIDTH;
669 const unsigned char *bm = bitmap_formats_18x8[rec_format];
671 if (rec_format == REC_FORMAT_MPA_L3)
673 /* Special handling for mp3 */
674 bitrk = global_settings.mp3_enc_config.bitrate;
675 bitrk = mp3_enc_bitr[bitrk];
677 width = BM_MPA_L3_M_WIDTH;
679 /* Slide 'M' to right if fewer than three digits used */
680 if (bitrk > 999)
681 bitrk = 999; /* neurotic safety check if corrupted */
682 else
684 if (bitrk < 100)
685 xpos += BM_GLYPH_WIDTH;
686 if (bitrk < 10)
687 xpos += BM_GLYPH_WIDTH;
692 /* Show bitmap - clipping right edge if needed */
693 display->mono_bitmap_part(bm, 0, 0, STATUSBAR_ENCODER_WIDTH,
694 xpos, STATUSBAR_Y_POS, width, STATUSBAR_HEIGHT);
696 if (rec_format == REC_FORMAT_MPA_L3)
698 xpos += BM_MPA_L3_M_WIDTH; /* to right of 'M' */
699 write_bitmap_number(display, bitrk, xpos, STATUSBAR_Y_POS);
704 * Write sample rate using bitmaps - left justified
706 static void gui_statusbar_write_samplerate_info(struct screen * display)
708 unsigned long samprk;
709 int xpos;
711 #ifdef SIMULATOR
712 samprk = 44100;
713 #else
714 #ifdef HAVE_SPDIF_REC
715 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
716 /* Use rate in use, not current measured rate if it changed */
717 samprk = pcm_rec_sample_rate();
718 else
719 #endif
720 samprk = rec_freq_sampr[global_settings.rec_frequency];
721 #endif /* SIMULATOR */
723 samprk /= 1000;
724 if (samprk > 99)
725 samprk = 99; /* Limit to 3 glyphs */
727 xpos = write_bitmap_number(display, (unsigned)samprk,
728 STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS);
730 /* write the 'k' */
731 display->mono_bitmap(bitmap_glyphs_4x8[Glyph_4x8_k], xpos,
732 STATUSBAR_Y_POS, BM_GLYPH_WIDTH,
733 STATUSBAR_HEIGHT);
735 #endif /* CONFIG_CODEC == SWCODEC */
737 static void gui_statusbar_icon_recording_info(struct screen * display)
739 #if CONFIG_CODEC != SWCODEC
740 char buffer[3];
741 const char *p = buffer;
742 int width, height;
743 display->setfont(FONT_SYSFIXED);
744 #endif /* CONFIG_CODEC != SWCODEC */
746 /* Display Codec info in statusbar */
747 #if CONFIG_CODEC == SWCODEC
748 gui_statusbar_write_format_info(display);
749 #else /* !SWCODEC */
750 display->mono_bitmap(bitmap_icons_5x8[Icon_q],
751 STATUSBAR_ENCODER_X_POS + 8, STATUSBAR_Y_POS,
752 5, STATUSBAR_HEIGHT);
754 snprintf(buffer, sizeof(buffer), "%d", global_settings.rec_quality);
755 display->getstringsize(buffer, &width, &height);
756 if (height <= STATUSBAR_HEIGHT)
757 display->putsxy(STATUSBAR_ENCODER_X_POS + 13, STATUSBAR_Y_POS, buffer);
758 #endif /* CONFIG_CODEC == SWCODEC */
760 /* Display Samplerate info in statusbar */
761 #if CONFIG_CODEC == SWCODEC
762 /* SWCODEC targets use bitmaps for glyphs */
763 gui_statusbar_write_samplerate_info(display);
764 #else /* !SWCODEC */
765 /* hwcodec targets have sysfont characters */
766 #ifdef HAVE_SPDIF_REC
767 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
769 /* Can't measure S/PDIF sample rate on Archos/Sim yet */
770 p = "--";
772 else
773 #endif /* HAVE_SPDIF_IN */
775 static const char * const freq_strings[] =
776 {"44", "48", "32", "22", "24", "16"};
777 p = freq_strings[global_settings.rec_frequency];
780 display->getstringsize(p, &width, &height);
782 if (height <= STATUSBAR_HEIGHT)
783 display->putsxy(STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS, p);
785 display->setfont(FONT_UI);
786 #endif /* CONFIG_CODEC == SWCODEC */
788 /* Display Channel status in status bar */
789 if(global_settings.rec_channels)
791 display->mono_bitmap(bitmap_icons_5x8[Icon_Mono],
792 STATUSBAR_RECCHANNELS_X_POS , STATUSBAR_Y_POS,
793 STATUSBAR_RECCHANNELS_WIDTH, STATUSBAR_HEIGHT);
795 else
797 display->mono_bitmap(bitmap_icons_5x8[Icon_Stereo],
798 STATUSBAR_RECCHANNELS_X_POS, STATUSBAR_Y_POS,
799 STATUSBAR_RECCHANNELS_WIDTH, STATUSBAR_HEIGHT);
802 #endif /* HAVE_RECORDING */
804 #endif /* HAVE_LCD_BITMAP */
806 void gui_syncstatusbar_init(struct gui_syncstatusbar * bars)
808 FOR_NB_SCREENS(i) {
809 gui_statusbar_init( &(bars->statusbars[i]) );
810 gui_statusbar_set_screen( &(bars->statusbars[i]), &(screens[i]) );
814 void gui_syncstatusbar_draw(struct gui_syncstatusbar * bars,
815 bool force_redraw)
817 #ifdef HAVE_LCD_BITMAP
818 if(!global_settings.statusbar)
819 return;
820 struct viewport viewport;
821 FOR_NB_SCREENS(i) {
822 GET_RECT(viewport,statusbar_position(i),&screens[i]);
823 gui_statusbar_draw( &(bars->statusbars[i]), force_redraw, &viewport );
825 #else
826 gui_statusbar_draw( &(bars->statusbars[0]), force_redraw, NULL );
827 #endif /* HAVE_LCD_BITMAP */
831 #ifdef HAVE_REMOTE_LCD
832 enum statusbar_values statusbar_position(int screen)
834 if (screen == SCREEN_REMOTE)
835 return global_settings.remote_statusbar;
836 return global_settings.statusbar;
838 #endif