1
0
Fork 0
forked from len0rd/rockbox

reduce size of the instance of struct style_text in lib/display.h (thanks to Teruaki Kawashima)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21614 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Johannes Schwarz 2009-07-02 17:02:47 +00:00
parent 278f1f69bb
commit bff790d692
2 changed files with 17 additions and 11 deletions

View file

@ -35,14 +35,14 @@ bool display_text(short words, char** text, struct style_text* style,
int prev_drawmode; int prev_drawmode;
#endif #endif
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
unsigned standard_fgcolor; int standard_fgcolor;
#endif #endif
int space_w, width, height; int space_w, width, height;
unsigned short x , y; unsigned short x , y;
unsigned short vp_width = LCD_WIDTH; unsigned short vp_width = LCD_WIDTH;
unsigned short vp_height = LCD_HEIGHT; unsigned short vp_height = LCD_HEIGHT;
int button; int button;
short i=0; unsigned short i = 0, style_index = 0;
if (vp_text != NULL) { if (vp_text != NULL) {
vp_width = vp_text->width; vp_width = vp_text->width;
vp_height = vp_text->height; vp_height = vp_text->height;
@ -85,17 +85,17 @@ bool display_text(short words, char** text, struct style_text* style,
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
rb->screens[SCREEN_MAIN]->clear_viewport(); rb->screens[SCREEN_MAIN]->clear_viewport();
} }
/* no text formations available */ /* no text formatting available */
if (style==NULL) { if (style==NULL || style[style_index].index != i) {
rb->lcd_putsxy(x, y, text[i]); rb->lcd_putsxy(x, y, text[i]);
} else { } else {
/* set align */ /* set align */
if (style[i].flags&TEXT_CENTER) { if (style[style_index].flags&TEXT_CENTER) {
x = (vp_width-width)/2; x = (vp_width-width)/2;
} }
/* set font color */ /* set font color */
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
switch (style[i].flags&TEXT_COLOR_MASK) { switch (style[style_index].flags&TEXT_COLOR_MASK) {
case C_RED: case C_RED:
rb->lcd_set_foreground(LCD_RGBPACK(255,0,0)); rb->lcd_set_foreground(LCD_RGBPACK(255,0,0));
break; break;
@ -118,11 +118,16 @@ bool display_text(short words, char** text, struct style_text* style,
} }
#endif #endif
rb->lcd_putsxy(x, y, text[i]); rb->lcd_putsxy(x, y, text[i]);
/* underline the word */
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
if (style[i].flags&TEXT_UNDERLINE) { if (style[style_index].flags&TEXT_UNDERLINE) {
rb->lcd_hline(x, x+width, y+height-1); rb->lcd_hline(x, x+width, y+height-1);
} }
#endif #endif
#ifdef HAVE_LCD_COLOR
rb->lcd_set_foreground(standard_fgcolor);
#endif
style_index++;
} }
x += width + space_w; x += width + space_w;
} }

View file

@ -24,9 +24,9 @@
* basic usage: * basic usage:
* #define WORDS (sizeof text / sizeof (char*)) * #define WORDS (sizeof text / sizeof (char*))
* char *text[] = {"normal", "centering", "red,underline"}; * char *text[] = {"normal", "centering", "red,underline"};
* struct style_text formation[WORDS]={ * struct style_text formation[]={
* [1] = { TEXT_CENTER }, * { 1, TEXT_CENTER },
* [2] = { C_RED|TEXT_UNDERLINE }, * { 2, C_RED|TEXT_UNDERLINE },
* }; * };
* if (display_text(WORDS, text, formation, NULL)) * if (display_text(WORDS, text, formation, NULL))
* return PLUGIN_USB_CONNECTED; * return PLUGIN_USB_CONNECTED;
@ -38,10 +38,11 @@ enum ecolor { STANDARD, C_YELLOW, C_RED, C_BLUE, C_GREEN , C_ORANGE };
#define TEXT_UNDERLINE 0x0200 #define TEXT_UNDERLINE 0x0200
struct style_text { struct style_text {
unsigned short index;
unsigned short flags; unsigned short flags;
}; };
/* style and vp_text is optional. /* style and vp_text are optional.
* return true if usb is connected. */ * return true if usb is connected. */
bool display_text(short words, char** text, struct style_text* style, bool display_text(short words, char** text, struct style_text* style,
struct viewport* vp_text); struct viewport* vp_text);