From 942bc9449ea587fc3d50a468da56df32baf0748f Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Wed, 23 Apr 2003 11:26:25 +0000 Subject: Only redraw the status line when info actually changed. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3588 a1c6a512-1295-4272-9138-f99709370657 --- apps/menu.c | 4 +- apps/recorder/icons.c | 8 ---- apps/recorder/recording.c | 2 +- apps/screens.c | 7 ++-- apps/settings.c | 6 +-- apps/sleeptimer.c | 2 +- apps/sound_menu.c | 2 +- apps/status.c | 97 ++++++++++++++++++++++++++++++++--------------- apps/status.h | 2 +- apps/tree.c | 12 +++--- apps/wps-display.c | 4 +- apps/wps.c | 12 +++--- 12 files changed, 93 insertions(+), 65 deletions(-) (limited to 'apps') diff --git a/apps/menu.c b/apps/menu.c index 1c6be6f58a..023f6fbbfb 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -167,7 +167,7 @@ static void menu_draw(int m) LCD_HEIGHT - SCROLLBAR_Y, menus[m].itemcount, menus[m].top, menus[m].top + menu_lines, VERTICAL); #endif - status_draw(); + status_draw(true); lcd_update(); } @@ -332,7 +332,7 @@ int menu_show(int m) return MENU_ATTACHED_USB; } - status_draw(); + status_draw(false); } return MENU_SELECTED_EXIT; } diff --git a/apps/recorder/icons.c b/apps/recorder/icons.c index c8fe622d6a..af0352094f 100644 --- a/apps/recorder/icons.c +++ b/apps/recorder/icons.c @@ -138,14 +138,6 @@ unsigned char rockbox112x37[]={ }; -/* - * Wipe statusbar - */ -void statusbar_wipe(void) -{ - lcd_clearrect(0,0,LCD_WIDTH,8); -} - /* * Print battery icon to status bar */ diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index 14bd37d950..bff87735ff 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -416,7 +416,7 @@ bool recording_screen(void) global_settings.rec_quality); lcd_puts(0, 6, buf); - status_draw(); + status_draw(false); lcd_update(); } diff --git a/apps/screens.c b/apps/screens.c index 2e120de4ab..87a9869196 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -85,14 +85,14 @@ void usb_display_info(void) BMPWIDTH_usb_logo, 8, false); lcd_bitmap(usb_logo+BMPWIDTH_usb_logo*3, 6, 40, BMPWIDTH_usb_logo, 8, false); - status_draw(); + status_draw(true); lcd_update(); #else lcd_puts(0, 0, "[USB Mode]"); status_set_param(false); status_set_audio(false); status_set_usb(true); - status_draw(); + status_draw(false); #endif } @@ -101,9 +101,10 @@ void usb_screen(void) #ifndef SIMULATOR backlight_on(); usb_acknowledge(SYS_USB_CONNECTED_ACK); + usb_display_info(); while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) { if(usb_inserted()) { - usb_display_info(); + status_draw(false); } } #ifdef HAVE_LCD_CHARCELLS diff --git a/apps/settings.c b/apps/settings.c index f4949416cd..5646a43b01 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -1609,7 +1609,7 @@ bool set_int(char* string, snprintf(str,sizeof str,"%d %s ", *variable, unit); lcd_puts(0, 1, str); #ifdef HAVE_LCD_BITMAP - status_draw(); + status_draw(true); #endif lcd_update(); @@ -1699,7 +1699,7 @@ bool set_option(char* string, int* variable, char* options[], while ( !done ) { lcd_puts(0, 1, options[*variable]); #ifdef HAVE_LCD_BITMAP - status_draw(); + status_draw(true); #endif lcd_update(); @@ -1932,7 +1932,7 @@ bool set_time(char* string, int timedate[]) lcd_puts(0, 4, str(LANG_TIME_SET)); lcd_puts(0, 5, str(LANG_TIME_REVERT)); #ifdef HAVE_LCD_BITMAP - status_draw(); + status_draw(true); #endif lcd_update(); diff --git a/apps/sleeptimer.c b/apps/sleeptimer.c index bd9ccc359b..fb7630a241 100644 --- a/apps/sleeptimer.c +++ b/apps/sleeptimer.c @@ -147,7 +147,7 @@ bool sleeptimer_screen(void) lcd_puts(0, 1, str(LANG_OFF)); } - status_draw(); + status_draw(true); lcd_update(); } diff --git a/apps/sound_menu.c b/apps/sound_menu.c index 84d389a47a..26f37ea0e7 100644 --- a/apps/sound_menu.c +++ b/apps/sound_menu.c @@ -83,7 +83,7 @@ bool set_sound(char* string, } } lcd_puts(0,1,str); - status_draw(); + status_draw(true); lcd_update(); changed = false; diff --git a/apps/status.c b/apps/status.c index 5d4bba6aac..9773bc6356 100644 --- a/apps/status.c +++ b/apps/status.c @@ -16,6 +16,7 @@ * KIND, either express or implied. * ****************************************************************************/ +#include "string.h" #include "lcd.h" #include "debug.h" #include "kernel.h" @@ -44,6 +45,19 @@ static bool battery_state; #endif #endif +struct status_info { + int battlevel; + int volume; + int hour; + int minute; + int playmode; + int repeat; + bool inserted; + bool shuffle; + bool keylock; + bool battery_safe; +}; + void status_init(void) { status_set_playmode(STATUS_STOP); @@ -52,7 +66,7 @@ void status_init(void) void status_set_playmode(enum playmode mode) { current_mode = mode; - status_draw(); + status_draw(false); } #if defined(HAVE_LCD_CHARCELLS) @@ -83,36 +97,43 @@ void status_set_usb(bool b) #endif /* HAVE_LCD_CHARCELLS */ -void status_draw(void) +void status_draw(bool force_redraw) { - int battlevel = battery_level(); - int volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume); -#if defined(HAVE_LCD_BITMAP) && defined(HAVE_RTC) + struct status_info info; + +#ifdef HAVE_LCD_BITMAP + static struct status_info lastinfo; struct tm* tm; -#endif if ( !global_settings.statusbar ) return; +#else + (void)force_redraw; /* players always "redraw" */ +#endif + + info.battlevel = battery_level(); + info.volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume); + info.inserted = charger_inserted(); #if defined(HAVE_LCD_CHARCELLS) lcd_icon(ICON_VOLUME, true); - if(volume > 10) + if(info.volume > 10) lcd_icon(ICON_VOLUME_1, true); else lcd_icon(ICON_VOLUME_1, false); - if(volume > 30) + if(info.volume > 30) lcd_icon(ICON_VOLUME_2, true); else lcd_icon(ICON_VOLUME_2, false); - if(volume > 50) + if(info.volume > 50) lcd_icon(ICON_VOLUME_3, true); else lcd_icon(ICON_VOLUME_3, false); - if(volume > 70) + if(info.volume > 70) lcd_icon(ICON_VOLUME_4, true); else lcd_icon(ICON_VOLUME_4, false); - if(volume > 90) + if(info.volume > 90) lcd_icon(ICON_VOLUME_5, true); else lcd_icon(ICON_VOLUME_5, false); @@ -137,7 +158,7 @@ void status_draw(void) default: break; } - if(charger_inserted()) + if(info.inserted) { global_settings.runtime = 0; if(TIME_AFTER(current_tick, switch_tick)) @@ -174,15 +195,15 @@ void status_draw(void) } } else { lcd_icon(ICON_BATTERY, true); - if(battlevel > 25) + if(info.battlevel > 25) lcd_icon(ICON_BATTERY_1, true); else lcd_icon(ICON_BATTERY_1, false); - if(battlevel > 50) + if(info.battlevel > 50) lcd_icon(ICON_BATTERY_2, true); else lcd_icon(ICON_BATTERY_2, false); - if(battlevel > 75) + if(info.battlevel > 75) lcd_icon(ICON_BATTERY_3, true); else lcd_icon(ICON_BATTERY_3, false); @@ -198,17 +219,31 @@ void status_draw(void) #endif #ifdef HAVE_LCD_BITMAP - if (global_settings.statusbar) { - statusbar_wipe(); + + tm = get_time(); + info.hour = tm->tm_hour; + info.minute = tm->tm_min; + info.shuffle = global_settings.playlist_shuffle; + info.keylock = keys_locked; + info.battery_safe = battery_level_safe(); + info.repeat = global_settings.repeat_mode; + + if (force_redraw || + info.inserted || + !info.battery_safe || + memcmp(&info, &lastinfo, sizeof(struct status_info))) { + lcd_clearrect(0,0,LCD_WIDTH,8); + #ifdef HAVE_CHARGE_CTRL /* Recorder */ - if(charger_inserted()) { + if(info.inserted) { battery_state = true; plug_state = true; if (charge_state > 0) /* charge || top off || trickle */ global_settings.runtime = 0; if (charge_state == 1) { /* animate battery if charging */ - battlevel = battery_charge_step * 34; /* 34 for a better look */ - battlevel = battlevel > 100 ? 100 : battlevel; + info.battlevel = battery_charge_step * 34; /* 34 for a better look */ + if (info.battlevel > 100) + info.battlevel = 100; if(TIME_AFTER(current_tick, switch_tick)) { battery_charge_step=(battery_charge_step+1)%4; switch_tick = current_tick + HZ; @@ -217,7 +252,7 @@ void status_draw(void) } else { plug_state=false; - if(battery_level_safe()) + if(!info.battery_safe) battery_state = true; else /* blink battery if level is low */ if(TIME_AFTER(current_tick, switch_tick)) { @@ -226,18 +261,17 @@ void status_draw(void) } } - if (battery_state) - statusbar_icon_battery(battlevel, plug_state); + statusbar_icon_battery(info.battlevel, plug_state); #else #ifdef HAVE_FMADC /* FM */ - statusbar_icon_battery(battlevel, charger_inserted()); + statusbar_icon_battery(info.battlevel, charger_inserted()); #else /* Player */ - statusbar_icon_battery(battlevel, false); + statusbar_icon_battery(info.battlevel, false); #endif /* HAVE_FMADC */ #endif /* HAVE_CHARGE_CTRL */ - statusbar_icon_volume(volume); + statusbar_icon_volume(info.volume); statusbar_icon_play_state(current_mode + Icon_Play); - switch (global_settings.repeat_mode) { + switch (info.repeat) { case REPEAT_ONE: statusbar_icon_play_mode(Icon_RepeatOne); break; @@ -246,16 +280,17 @@ void status_draw(void) statusbar_icon_play_mode(Icon_Repeat); break; } - if(global_settings.playlist_shuffle) + if(info.shuffle) statusbar_icon_shuffle(); - if (keys_locked) + if (info.keylock) statusbar_icon_lock(); #ifdef HAVE_RTC - tm = get_time(); - statusbar_time(tm->tm_hour, tm->tm_min); + statusbar_time(info.hour, info.minute); #endif lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT); } + + lastinfo = info; #endif } diff --git a/apps/status.h b/apps/status.h index 34603656b6..203c7a80d7 100644 --- a/apps/status.h +++ b/apps/status.h @@ -35,7 +35,7 @@ void status_set_playmode(enum playmode mode); #ifdef HAVE_LCD_BITMAP bool statusbar(bool state); #endif -void status_draw(void); +void status_draw(bool force_redraw); #if defined(HAVE_LCD_CHARCELLS) void status_set_record(bool b); diff --git a/apps/tree.c b/apps/tree.c index 7abafe8f4a..1e10e51f80 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -494,7 +494,7 @@ static int showdir(char *path, int start) LCD_HEIGHT - SCROLLBAR_Y, filesindir, start, start + tree_max_on_screen, VERTICAL); #endif - status_draw(); + status_draw(false); return filesindir; } @@ -511,7 +511,7 @@ bool ask_resume(void) lcd_clear_display(); lcd_puts(0,0,str(LANG_RESUME_ASK)); #ifdef HAVE_LCD_CHARCELLS - status_draw(); + status_draw(false); lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER)); #else lcd_puts(0,1,str(LANG_RESUME_CONFIRM_RECORDER)); @@ -621,7 +621,7 @@ void start_resume(void) } status_set_playmode(STATUS_PLAY); - status_draw(); + status_draw(true); wps_show(); } } @@ -839,7 +839,7 @@ bool dirbrowse(char *root) case BUTTON_OFF: mpeg_stop(); status_set_playmode(STATUS_STOP); - status_draw(); + status_draw(false); restore = true; break; @@ -996,7 +996,7 @@ bool dirbrowse(char *root) } status_set_playmode(STATUS_PLAY); - status_draw(); + status_draw(false); lcd_stop_scroll(); if ( wps_show() == SYS_USB_CONNECTED ) { reload_root = true; @@ -1136,7 +1136,7 @@ bool dirbrowse(char *root) break; case BUTTON_NONE: - status_draw(); + status_draw(false); break; } diff --git a/apps/wps-display.c b/apps/wps-display.c index e6cf65a260..c35ba8675c 100644 --- a/apps/wps-display.c +++ b/apps/wps-display.c @@ -801,7 +801,7 @@ bool wps_display(struct mp3entry* id3) #endif global_settings.resume_index = -1; status_set_playmode(STATUS_STOP); - status_draw(); + status_draw(true); sleep(HZ); return true; } @@ -827,7 +827,7 @@ bool wps_display(struct mp3entry* id3) } yield(); wps_refresh(id3, 0, WPS_REFRESH_ALL); - status_draw(); + status_draw(true); lcd_update(); return false; } diff --git a/apps/wps.c b/apps/wps.c index edc876e506..187f244775 100644 --- a/apps/wps.c +++ b/apps/wps.c @@ -103,7 +103,7 @@ void player_change_volume(int button) if (!exit) button = button_get(true); } - status_draw(); + status_draw(false); wps_refresh(id3,0, WPS_REFRESH_ALL); } #endif @@ -443,7 +443,7 @@ static bool update(void) if (id3) wps_refresh(id3, 0, WPS_REFRESH_NON_STATIC); - status_draw(); + status_draw(false); /* save resume data */ if ( id3 && @@ -488,7 +488,7 @@ static bool keylock(void) #endif return false; } - status_draw(); + status_draw(false); while (button_get(false)); /* clear button queue */ while (!exit) { @@ -560,7 +560,7 @@ static bool menu(void) #ifdef HAVE_LCD_CHARCELLS status_set_param(true); - status_draw(); + status_draw(false); #endif while (!exit) { @@ -896,7 +896,7 @@ int wps_show(void) if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME)) global_settings.volume = mpeg_sound_max(SOUND_VOLUME); mpeg_sound_set(SOUND_VOLUME, global_settings.volume); - status_draw(); + status_draw(false); settings_save(); break; @@ -910,7 +910,7 @@ int wps_show(void) if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME)) global_settings.volume = mpeg_sound_min(SOUND_VOLUME); mpeg_sound_set(SOUND_VOLUME, global_settings.volume); - status_draw(); + status_draw(false); settings_save(); break; -- cgit v1.2.3