A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

Small cleanup statusbar

move some things around and split out a few things to their own functions

Change-Id: I76ce216776ca939f030cb0b2caefc09b56fe66df

authored by

William Wilgus and committed by
William Wilgus
e5690803 ca2e195a

+74 -71
+68 -66
apps/gui/statusbar.c
··· 160 160 * Initializes a status bar 161 161 * - bar : the bar to initialize 162 162 */ 163 - static void gui_statusbar_init(struct gui_statusbar * bar) 163 + static void gui_statusbar_init(struct screen * display, struct gui_statusbar * bar) 164 164 { 165 + bar->display = display; 165 166 bar->redraw_volume = true; 166 167 bar->volume_icon_switch_tick = bar->battery_icon_switch_tick = current_tick; 167 168 memset((void*)&(bar->lastinfo), 0, sizeof(struct status_info)); ··· 170 171 #endif 171 172 } 172 173 173 - #define GET_RECT(vp, vals,display) do { \ 174 - viewport_set_fullscreen(&(vp), (display)->screen_type); \ 175 - (vp).flags &= ~VP_FLAG_ALIGN_RIGHT; \ 176 - (vp).height = STATUSBAR_HEIGHT; \ 177 - (vp).x = STATUSBAR_X_POS; \ 178 - if ((vals) != STATUSBAR_BOTTOM) \ 179 - (vp).y = 0; \ 180 - else \ 181 - (vp).y = (display)->lcdheight - STATUSBAR_HEIGHT; \ 182 - } while(0) 183 - 184 - void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw, struct viewport *vp) 174 + static struct screen * sb_fill_bar_info(struct gui_statusbar * bar) 185 175 { 186 - struct screen * display = bar->display; 187 - struct viewport *last_vp = NULL; 176 + struct screen *display = bar->display; 188 177 189 178 if (!display) 190 - return; 179 + return display; 191 180 192 181 bar->info.battlevel = battery_level(); 193 182 #ifdef HAVE_USB_POWER ··· 213 202 else 214 203 { 215 204 #else /* CONFIG_CHARGING < CHARGING_MONITOR */ 216 - lasttime = current_tick; 205 + lasttime = current_tick; 217 206 { 218 207 #endif /* CONFIG_CHARGING < CHARGING_MONITOR */ 219 208 /* animate in (max.) 4 steps, starting near the current charge level */ ··· 240 229 bar->battery_icon_switch_tick = current_tick + HZ; 241 230 } 242 231 } 243 - 244 232 bar->info.volume = global_settings.volume; 245 233 bar->info.shuffle = global_settings.playlist_shuffle; 246 234 #ifdef HAS_BUTTON_HOLD ··· 253 241 #endif 254 242 bar->info.repeat = global_settings.repeat_mode; 255 243 bar->info.playmode = current_playmode(); 256 - 244 + #if CONFIG_RTC 245 + bar->time = get_time(); 246 + #endif /* CONFIG_RTC */ 257 247 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) 258 248 if(!display->has_disk_led) 259 249 bar->info.led = led_read(HZ/2); /* delay should match polling interval */ 260 250 #endif 261 - #if CONFIG_RTC 262 - bar->time = get_time(); 263 - #endif /* CONFIG_RTC */ 251 + 252 + return display; 253 + } 254 + 255 + void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw, struct viewport *vp) 256 + { 257 + struct viewport *last_vp = NULL; 258 + struct screen * display = sb_fill_bar_info(bar); 259 + if (!display) 260 + return; 264 261 265 262 /* only redraw if forced to, or info has changed */ 266 263 if (force_redraw || bar->redraw_volume || ··· 273 270 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 274 271 display->fill_viewport(); 275 272 display->set_drawmode(DRMODE_SOLID); 273 + display->setfont(FONT_SYSFIXED); 276 274 277 275 if (bar->info.battery_state) 278 276 gui_statusbar_icon_battery(display, bar->info.battlevel, ··· 311 309 else 312 310 #endif 313 311 { 314 - switch (bar->info.repeat) { 315 - #ifdef AB_REPEAT_ENABLE 316 - case REPEAT_AB: 317 - gui_statusbar_icon_play_mode(display, Icon_RepeatAB); 318 - break; 319 - #endif /* AB_REPEAT_ENABLE */ 312 + gui_statusbar_icon_play_mode(display, bar->info.repeat); 320 313 321 - case REPEAT_ONE: 322 - gui_statusbar_icon_play_mode(display, Icon_RepeatOne); 323 - break; 324 - 325 - case REPEAT_ALL: 326 - case REPEAT_SHUFFLE: 327 - gui_statusbar_icon_play_mode(display, Icon_Repeat); 328 - break; 329 - } 330 314 if (bar->info.shuffle) 331 315 gui_statusbar_icon_shuffle(display); 332 316 } ··· 342 326 #endif /* CONFIG_RTC */ 343 327 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) 344 328 if(!display->has_disk_led && bar->info.led) 329 + { 345 330 gui_statusbar_led(display); 331 + } 346 332 #endif 333 + display->setfont(FONT_UI); 347 334 display->update_viewport(); 348 335 display->set_viewport(last_vp); 349 336 bar->lastinfo = bar->info; ··· 389 376 if (global_settings.battery_display && (percent > -1) && (percent <= 100)) { 390 377 #endif 391 378 /* Numeric display */ 392 - display->setfont(FONT_SYSFIXED); 393 379 snprintf(buffer, sizeof(buffer), "%3d", percent); 394 - display->getstringsize(buffer, &width, &height); 395 - if (height <= STATUSBAR_HEIGHT) 396 - display->putsxy(STATUSBAR_BATTERY_X_POS 380 + font_getstringsize(buffer, &width, &height, FONT_SYSFIXED); 381 + if (height <= STATUSBAR_HEIGHT) { 382 + display->putsxy(STATUSBAR_BATTERY_X_POS 397 383 + STATUSBAR_BATTERY_WIDTH / 2 398 384 - width/2, STATUSBAR_Y_POS, buffer); 399 - display->setfont(FONT_UI); 385 + } 400 386 401 387 } 402 388 else { ··· 424 410 } 425 411 426 412 if (percent == -1 || percent > 100) { 427 - display->setfont(FONT_SYSFIXED); 428 413 display->putsxy(STATUSBAR_BATTERY_X_POS + STATUSBAR_BATTERY_WIDTH / 2 429 - - 4, STATUSBAR_Y_POS, "?"); 430 - display->setfont(FONT_UI); 414 + - 4, STATUSBAR_Y_POS, "?"); 431 415 } 432 416 } 433 417 ··· 444 428 int type = global_settings.volume_type; 445 429 struct screen * display=bar->display; 446 430 const int minvol = sound_min(SOUND_VOLUME); 447 - const int maxvol = sound_max(SOUND_VOLUME); 448 - const int num_decimals = sound_numdecimals(SOUND_VOLUME); 449 431 450 432 if (volume < minvol) 451 433 volume = minvol; 452 - if (volume > maxvol) 453 - volume = maxvol; 454 434 455 435 if (volume == minvol) { 456 436 display->mono_bitmap(bitmap_icons_7x8[Icon_Mute], ··· 458 438 STATUSBAR_Y_POS, 7, SB_ICON_HEIGHT); 459 439 } 460 440 else { 441 + const int maxvol = sound_max(SOUND_VOLUME); 442 + 443 + if (volume > maxvol) 444 + volume = maxvol; 461 445 /* We want to redraw the icon later on */ 462 446 if (bar->last_volume != volume && bar->last_volume >= minvol) { 463 447 bar->volume_icon_switch_tick = current_tick + HZ; ··· 473 457 /* display volume level numerical? */ 474 458 if (type) 475 459 { 460 + const int num_decimals = sound_numdecimals(SOUND_VOLUME); 476 461 if (num_decimals) 477 462 volume /= 10 * num_decimals; 478 - display->setfont(FONT_SYSFIXED); 463 + 479 464 snprintf(buffer, sizeof(buffer), "%2d", volume); 480 - display->getstringsize(buffer, &width, &height); 481 - if (height <= STATUSBAR_HEIGHT) 482 - { 465 + font_getstringsize(buffer, &width, &height, FONT_SYSFIXED); 466 + if (height <= STATUSBAR_HEIGHT) { 483 467 display->putsxy(STATUSBAR_VOLUME_X_POS 484 - + STATUSBAR_VOLUME_WIDTH / 2 485 - - width/2, STATUSBAR_Y_POS, buffer); 468 + + STATUSBAR_VOLUME_WIDTH / 2 469 + - width/2, STATUSBAR_Y_POS, buffer); 486 470 } 487 - display->setfont(FONT_UI); 488 471 } else { 489 472 /* display volume bar */ 490 473 vol = (volume - minvol) * 14 / (maxvol - minvol); ··· 515 498 */ 516 499 static void gui_statusbar_icon_play_mode(struct screen * display, int mode) 517 500 { 518 - display->mono_bitmap(bitmap_icons_7x8[mode], STATUSBAR_PLAY_MODE_X_POS, 519 - STATUSBAR_Y_POS, STATUSBAR_PLAY_MODE_WIDTH, 520 - SB_ICON_HEIGHT); 501 + switch (mode) { 502 + #ifdef AB_REPEAT_ENABLE 503 + case REPEAT_AB: 504 + display->mono_bitmap(bitmap_icons_7x8[Icon_RepeatAB], 505 + STATUSBAR_PLAY_MODE_X_POS, 506 + STATUSBAR_Y_POS, STATUSBAR_PLAY_MODE_WIDTH, 507 + SB_ICON_HEIGHT); 508 + break; 509 + #endif /* AB_REPEAT_ENABLE */ 510 + 511 + case REPEAT_ONE: 512 + display->mono_bitmap(bitmap_icons_7x8[Icon_RepeatOne], 513 + STATUSBAR_PLAY_MODE_X_POS, 514 + STATUSBAR_Y_POS, STATUSBAR_PLAY_MODE_WIDTH, 515 + SB_ICON_HEIGHT); 516 + break; 517 + 518 + case REPEAT_ALL: 519 + case REPEAT_SHUFFLE: 520 + display->mono_bitmap(bitmap_icons_7x8[Icon_Repeat], 521 + STATUSBAR_PLAY_MODE_X_POS, 522 + STATUSBAR_Y_POS, STATUSBAR_PLAY_MODE_WIDTH, 523 + SB_ICON_HEIGHT); 524 + break; 525 + } 521 526 } 522 - 523 527 /* 524 528 * Print shuffle mode to status bar 525 529 */ ··· 589 593 else { 590 594 p = "--:--"; 591 595 } 592 - display->setfont(FONT_SYSFIXED); 593 - display->getstringsize(p, &width, &height); 596 + 597 + font_getstringsize(p, &width, &height, FONT_SYSFIXED); 594 598 if (height <= STATUSBAR_HEIGHT) { 595 599 display->putsxy(STATUSBAR_TIME_X_END(display->getwidth()) - width, 596 600 STATUSBAR_Y_POS, p); 597 601 } 598 - display->setfont(FONT_UI); 602 + 599 603 } 600 604 #endif 601 605 ··· 647 651 xpos += BM_GLYPH_WIDTH; 648 652 } 649 653 } 650 - 651 654 652 655 /* Show bitmap - clipping right edge if needed */ 653 656 display->mono_bitmap_part(bm, 0, 0, STATUSBAR_ENCODER_WIDTH, ··· 720 723 void gui_syncstatusbar_init(struct gui_syncstatusbar * bars) 721 724 { 722 725 FOR_NB_SCREENS(i) { 723 - gui_statusbar_init( &(bars->statusbars[i]) ); 724 - gui_statusbar_set_screen( &(bars->statusbars[i]), &(screens[i]) ); 726 + gui_statusbar_init(&(screens[i]), &(bars->statusbars[i])); 725 727 } 726 728 } 727 729
+6 -5
apps/gui/statusbar.h
··· 57 57 58 58 struct gui_statusbar 59 59 { 60 - long battery_icon_switch_tick; 60 + struct status_info info; 61 + struct status_info lastinfo; 61 62 63 + bool redraw_volume; /* true if the volume gauge needs updating */ 64 + int last_volume; 62 65 long volume_icon_switch_tick; 63 - int last_volume; 64 - bool redraw_volume; /* true if the volume gauge needs updating */ 66 + 67 + long battery_icon_switch_tick; 65 68 66 - struct status_info info; 67 - struct status_info lastinfo; 68 69 #if CONFIG_RTC 69 70 struct tm *time; 70 71 int last_tm_min;