From 3c1e9ca55892ae342c9efb396cd9f49f3d403a5a Mon Sep 17 00:00:00 2001 From: Peter D'Hoye Date: Sun, 7 Sep 2008 20:09:11 +0000 Subject: [PATCH] Change screens memebers char_width, char_height and nb_lines to functions returning a calculated value. Fixes FS #9361 because the values were calculated based on sysfont, not the user selected font. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18441 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/charcell/list.c | 8 +-- apps/gui/color_picker.c | 52 ++++++++++---------- apps/gui/pitchscreen.c | 14 +++--- apps/gui/quickscreen.c | 2 +- apps/main.c | 10 ++-- apps/onplay.c | 5 +- apps/playlist_viewer.c | 6 +-- apps/screen_access.c | 102 ++++++++++++++++++++++++++++----------- apps/screen_access.h | 11 ++--- 9 files changed, 124 insertions(+), 86 deletions(-) diff --git a/apps/gui/charcell/list.c b/apps/gui/charcell/list.c index 2df030f8b6..b1d0adcdd6 100644 --- a/apps/gui/charcell/list.c +++ b/apps/gui/charcell/list.c @@ -51,13 +51,13 @@ void list_draw(struct screen *display, struct viewport *parent, int i; int lines; int start, end; - + display->set_viewport(NULL); - lines = display->nb_lines; - + lines = display->getnblines(); + display->clear_display(); start = 0; - end = display->nb_lines; + end = display->getnblines(); gui_list->last_displayed_start_item[display->screen_type] = gui_list->start_item[display->screen_type]; diff --git a/apps/gui/color_picker.c b/apps/gui/color_picker.c index d1ac2a9103..eb4490035d 100644 --- a/apps/gui/color_picker.c +++ b/apps/gui/color_picker.c @@ -158,11 +158,12 @@ static void draw_screen(struct screen *display, char *title, enough to display the selected slider - calculate total height of display with three sliders present */ display_three_rows = - display->getheight() >= MARGIN_TOP + - display->char_height*4 + /* Title + 3 sliders */ - TITLE_MARGIN_BOTTOM + - SELECTOR_TB_MARGIN*6 + /* 2 margins/slider */ - MARGIN_BOTTOM; + display->getheight() >= + MARGIN_TOP + + display->getcharheight()*4 + /* Title + 3 sliders */ + TITLE_MARGIN_BOTTOM + + SELECTOR_TB_MARGIN*6 + /* 2 margins/slider */ + MARGIN_BOTTOM; /* Figure out widest label character in case they vary - this function assumes labels are one character */ @@ -185,8 +186,8 @@ static void draw_screen(struct screen *display, char *title, slider_left = MARGIN_LEFT + SELECTOR_WIDTH + SELECTOR_LR_MARGIN + max_label_width + SLIDER_MARGIN_LEFT; slider_width = display->getwidth() - slider_left - SLIDER_MARGIN_RIGHT - - display->char_width*2 - SELECTOR_LR_MARGIN - SELECTOR_WIDTH - - MARGIN_RIGHT; + display->getcharwidth()*2 - SELECTOR_LR_MARGIN - + SELECTOR_WIDTH - MARGIN_RIGHT; for (i = 0; i < 3; i++) { @@ -209,7 +210,7 @@ static void draw_screen(struct screen *display, char *title, display->fillrect(0, text_top - SELECTOR_TB_MARGIN, display->getwidth(), - display->char_height + + display->getcharheight() + SELECTOR_TB_MARGIN*2); if (display->depth < 16) @@ -221,7 +222,7 @@ static void draw_screen(struct screen *display, char *title, else if (display_three_rows) { /* Draw "> <" around sliders */ - int top = text_top + (display->char_height - + int top = text_top + (display->getcharheight() - SELECTOR_HEIGHT) / 2; screen_put_iconxy(display, MARGIN_LEFT, top, Icon_Cursor); screen_put_iconxy(display, @@ -244,7 +245,7 @@ static void draw_screen(struct screen *display, char *title, /* Draw label */ buf[0] = str(LANG_COLOR_RGB_LABELS)[i]; buf[1] = '\0'; - display->putsxy(slider_left - display->char_width - + display->putsxy(slider_left - display->getcharwidth() - SLIDER_MARGIN_LEFT, text_top, buf); /* Draw color value */ @@ -255,24 +256,21 @@ static void draw_screen(struct screen *display, char *title, /* Draw scrollbar */ gui_scrollbar_draw(display, slider_left, - text_top + display->char_height / 4, + text_top + display->getcharheight() / 4, slider_width, - display->char_height / 2, + display->getcharheight() / 2, rgb_max[i], 0, rgb->rgb_val[i], sb_flags); /* Advance to next line */ - text_top += display->char_height + 2*SELECTOR_TB_MARGIN; + text_top += display->getcharheight() + 2*SELECTOR_TB_MARGIN; if (!display_three_rows) break; } /* end for */ - /* Draw color value in system font */ - display->setfont(FONT_SYSFIXED); - /* Format RGB: #rrggbb */ snprintf(buf, sizeof(buf), str(LANG_COLOR_RGB_VALUE), rgb->red, rgb->green, rgb->blue); @@ -287,7 +285,7 @@ static void draw_screen(struct screen *display, char *title, int height = display->getheight() - top - MARGIN_BOTTOM; /* Only draw if room */ - if (height >= display->char_height + 2) + if (height >= display->getcharheight() + 2) { display->set_foreground(rgb->color); display->fillrect(left, top, width, height); @@ -357,19 +355,21 @@ static int touchscreen_slider(struct rgb_pick *rgb, int *selected_slider) max_label_width = x1; } /* Get slider positions and top starting position */ - text_top = MARGIN_TOP + display->char_height + TITLE_MARGIN_BOTTOM + SELECTOR_TB_MARGIN; + text_top = MARGIN_TOP + display->getcharheight() + TITLE_MARGIN_BOTTOM + + SELECTOR_TB_MARGIN; slider_left = MARGIN_LEFT + SELECTOR_WIDTH + SELECTOR_LR_MARGIN + max_label_width + SLIDER_MARGIN_LEFT; slider_width = display->getwidth() - slider_left - SLIDER_MARGIN_RIGHT - - display->char_width*2 - SELECTOR_LR_MARGIN - SELECTOR_WIDTH - - MARGIN_RIGHT; + display->getcharwidth()*2 - SELECTOR_LR_MARGIN - + SELECTOR_WIDTH - MARGIN_RIGHT; display_three_rows = - display->getheight() >= MARGIN_TOP + - display->char_height*4 + /* Title + 3 sliders */ - TITLE_MARGIN_BOTTOM + - SELECTOR_TB_MARGIN*6 + /* 2 margins/slider */ - MARGIN_BOTTOM; - if (y < MARGIN_TOP+display->char_height) + display->getheight() >= + MARGIN_TOP + + display->getcharheight()*4 + /* Title + 3 sliders */ + TITLE_MARGIN_BOTTOM + + SELECTOR_TB_MARGIN*6 + /* 2 margins/slider */ + MARGIN_BOTTOM; + if (y < MARGIN_TOP+display->getcharheight()) { if (button == BUTTON_REL) return ACTION_STD_CANCEL; diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c index 2a568afc0a..c4f78f4baa 100644 --- a/apps/gui/pitchscreen.c +++ b/apps/gui/pitchscreen.c @@ -60,12 +60,12 @@ static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode) display->clear_display(); - if (display->nb_lines < 4) /* very small screen, just show the pitch value */ + if (display->getnblines() < 4) /* very small screen, just show pitch value*/ { w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_PITCH), pitch / 10, pitch % 10 ); - display->putsxy((display->lcdwidth-(w*display->char_width))/2, - display->nb_lines/2,buf); + display->putsxy((display->lcdwidth-(w*display->getcharwidth()))/2, + display->getnblines()/2,buf); } else /* bigger screen, show everything... */ { @@ -242,7 +242,7 @@ bool pitch_screen(void) nudged = (new_pitch != pitch); pitch = new_pitch; break; - + case ACTION_PS_NUDGE_LEFTOFF: if (nudged) { pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false); @@ -268,7 +268,7 @@ bool pitch_screen(void) return 1; break; } - + if(delta) { if (pitch_mode == PITCH_MODE_ABSOLUTE) { @@ -276,10 +276,10 @@ bool pitch_screen(void) } else { pitch = pitch_increase_semitone(pitch, delta > 0 ? true:false); } - + delta = 0; } - + } #if CONFIG_CODEC == SWCODEC pcmbuf_set_low_latency(false); diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index 4e55dfed7d..9c850b74ca 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c @@ -207,7 +207,7 @@ static void gui_quickscreen_draw(struct gui_quickscreen *qs, value = option_get_valuestring((struct settings_list*)qs->items[i], buf, MAX_PATH, temp); - if (vps[screen][i].height < display->char_height*2) + if (vps[screen][i].height < display->getcharheight()*2) { char text[MAX_PATH]; snprintf(text, MAX_PATH, "%s: %s", title, value); diff --git a/apps/main.c b/apps/main.c index d59d17a5f1..bacaa51e01 100644 --- a/apps/main.c +++ b/apps/main.c @@ -288,7 +288,6 @@ static void init(void) debug_init(); #endif /* Must be done before any code uses the multi-screen APi */ - screen_access_init(); gui_syncstatusbar_init(&statusbars); ata_init(); settings_reset(); @@ -404,13 +403,12 @@ static void init(void) button_init(); powermgmt_init(); - + #if CONFIG_TUNER radio_init(); #endif /* Must be done before any code uses the multi-screen APi */ - screen_access_init(); gui_syncstatusbar_init(&statusbars); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) @@ -448,11 +446,11 @@ static void init(void) #ifdef HAVE_EEPROM_SETTINGS eeprom_settings_init(); #endif - + usb_start_monitoring(); #ifndef HAVE_USBSTACK while (usb_detect() == USB_INSERTED) - { + { #ifdef HAVE_EEPROM_SETTINGS firmware_settings.disk_clean = false; #endif @@ -517,7 +515,7 @@ static void init(void) remove(TAGCACHE_STATEFILE); #endif } - + gui_sync_wps_init(); settings_apply(true); init_dircache(false); diff --git a/apps/onplay.c b/apps/onplay.c index 9ca0c6743e..cfe1985eb9 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -674,8 +674,9 @@ static void draw_slider(void) int i; FOR_NB_SCREENS(i) { - show_busy_slider(&screens[i], 1, LCD_HEIGHT-2*screens[i].char_height, - LCD_WIDTH-2, 2*screens[i].char_height-1); + show_busy_slider(&screens[i], 1, + LCD_HEIGHT-2*screens[i].getcharheight(), + LCD_WIDTH-2, 2*screens[i].getcharheight()-1); screens[i].update(); } } diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index 62e755a53a..3b74406d37 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c @@ -58,7 +58,7 @@ /* The number of items between the selected one and the end/start of * the buffer under which the buffer must reload */ -#define MIN_BUFFER_MARGIN (screens[0].nb_lines+1) +#define MIN_BUFFER_MARGIN (screens[0].getnblines()+1) /* Information about a specific track */ struct playlist_entry { @@ -182,7 +182,7 @@ static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb, { if(direction==FORWARD) { - int min_start=viewer.selected_track-2*screens[0].nb_lines; + int min_start=viewer.selected_track-2*screens[0].getnblines(); while(min_start<0) min_start+=viewer.num_tracks; min_start %= viewer.num_tracks; @@ -190,7 +190,7 @@ static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb, } else { - int max_start=viewer.selected_track+2*screens[0].nb_lines; + int max_start=viewer.selected_track+2*screens[0].getnblines(); max_start%=viewer.num_tracks; playlist_buffer_load_entries(pb, max_start, BACKWARD); } diff --git a/apps/screen_access.c b/apps/screen_access.c index de59537770..2f928b7360 100644 --- a/apps/screen_access.c +++ b/apps/screen_access.c @@ -32,6 +32,73 @@ #include "screen_access.h" +/* some helper functions to calculate metrics on the fly */ +static int screen_helper_getcharwidth(void) +{ +#ifdef HAVE_LCD_BITMAP + return font_get(lcd_getfont())->maxwidth; +#else + return 1; +#endif +} + +static int screen_helper_getcharheight(void) +{ +#ifdef HAVE_LCD_BITMAP + return font_get(lcd_getfont())->height; +#else + return 1; +#endif +} + +static int screen_helper_getnblines(void) +{ + int height=screens[0].lcdheight; +#ifdef HAVE_LCD_BITMAP + if(global_settings.statusbar) + height -= STATUSBAR_HEIGHT; +#ifdef HAVE_BUTTONBAR + if(global_settings.buttonbar && screens[0].has_buttonbar) + height -= BUTTONBAR_HEIGHT; +#endif +#endif + return height / screens[0].getcharheight(); +} + +#if NB_SCREENS == 2 +static int screen_helper_remote_getcharwidth(void) +{ +#ifdef HAVE_LCD_BITMAP + return font_get(lcd_remote_getfont())->maxwidth; +#else + return 1; +#endif +} + +static int screen_helper_remote_getcharheight(void) +{ +#ifdef HAVE_LCD_BITMAP + return font_get(lcd_remote_getfont())->height; +#else + return 1; +#endif +} + +static int screen_helper_remote_getnblines(void) +{ + int height=screens[1].lcdheight; +#ifdef HAVE_LCD_BITMAP + if(global_settings.statusbar) + height -= STATUSBAR_HEIGHT; +#ifdef HAVE_BUTTONBAR + if(global_settings.buttonbar && screens[0].has_buttonbar) + height -= BUTTONBAR_HEIGHT; +#endif +#endif + return height / screens[1].getcharheight(); +} +#endif + struct screen screens[NB_SCREENS] = { { @@ -39,6 +106,7 @@ struct screen screens[NB_SCREENS] = .lcdwidth=LCD_WIDTH, .lcdheight=LCD_HEIGHT, .depth=LCD_DEPTH, + .getnblines=&screen_helper_getnblines, #if defined(HAVE_LCD_COLOR) .is_color=true, #else @@ -47,6 +115,8 @@ struct screen screens[NB_SCREENS] = #ifdef HAVE_LCD_BITMAP .pixel_format=LCD_PIXELFORMAT, #endif + .getcharwidth=screen_helper_getcharwidth, + .getcharheight=screen_helper_getcharheight, #if (CONFIG_LED == LED_VIRTUAL) .has_disk_led=false, #elif defined(HAVE_REMOTE_LCD) @@ -137,8 +207,11 @@ struct screen screens[NB_SCREENS] = .lcdwidth=LCD_REMOTE_WIDTH, .lcdheight=LCD_REMOTE_HEIGHT, .depth=LCD_REMOTE_DEPTH, + .getnblines=&screen_helper_remote_getnblines, .is_color=false,/* No color remotes yet */ .pixel_format=LCD_REMOTE_PIXELFORMAT, + .getcharwidth=screen_helper_remote_getcharwidth, + .getcharheight=screen_helper_remote_getcharheight, .has_disk_led=false, .set_viewport=&lcd_remote_set_viewport, .getwidth=&lcd_remote_getwidth, @@ -219,32 +292,3 @@ void screen_clear_area(struct screen * display, int xstart, int ystart, display->set_drawmode(DRMODE_SOLID); } #endif - -void screen_access_init(void) -{ - int i; - struct screen *display; - FOR_NB_SCREENS(i) - { - display = &screens[i]; -#ifdef HAVE_LCD_BITMAP - ((struct screen*)&screens[i])->setfont(FONT_UI); -#endif - - int height=display->lcdheight; -#ifdef HAVE_LCD_BITMAP - if(global_settings.statusbar) - height -= STATUSBAR_HEIGHT; -#ifdef HAVE_BUTTONBAR - if(global_settings.buttonbar && display->has_buttonbar) - height -= BUTTONBAR_HEIGHT; -#endif - display->getstringsize((unsigned char *)"A", &display->char_width, - &display->char_height); -#else - display->char_width = 1; - display->char_height = 1; -#endif - display->nb_lines = height / display->char_height; - } -} diff --git a/apps/screen_access.h b/apps/screen_access.h index d800c31489..c76d2b1c86 100644 --- a/apps/screen_access.h +++ b/apps/screen_access.h @@ -60,12 +60,12 @@ struct screen enum screen_type screen_type; int lcdwidth, lcdheight; int depth; - int nb_lines; + int (*getnblines)(void); #ifdef HAVE_LCD_BITMAP int pixel_format; #endif - int char_width; - int char_height; + int (*getcharwidth)(void); + int (*getcharheight)(void); bool is_color; #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) bool has_disk_led; @@ -165,11 +165,6 @@ void screen_clear_area(struct screen * display, int xstart, int ystart, int width, int height); #endif -/* - * Initializes the whole screen_access api - */ -extern void screen_access_init(void); - /* * exported screens array that should be used * by each app that wants to write to access display