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
This commit is contained in:
Peter D'Hoye 2008-09-07 20:09:11 +00:00
parent e682143af5
commit 3c1e9ca558
9 changed files with 124 additions and 86 deletions

View file

@ -53,11 +53,11 @@ void list_draw(struct screen *display, struct viewport *parent,
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];

View file

@ -158,8 +158,9 @@ 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 */
display->getheight() >=
MARGIN_TOP +
display->getcharheight()*4 + /* Title + 3 sliders */
TITLE_MARGIN_BOTTOM +
SELECTOR_TB_MARGIN*6 + /* 2 margins/slider */
MARGIN_BOTTOM;
@ -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 */
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->char_height)
if (y < MARGIN_TOP+display->getcharheight())
{
if (button == BUTTON_REL)
return ACTION_STD_CANCEL;

View file

@ -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... */
{

View file

@ -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);

View file

@ -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();
@ -410,7 +409,6 @@ static void init(void)
#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)

View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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