Index: apps/plugins/lib/SOURCES =================================================================== --- apps/plugins/lib/SOURCES (Revision 20626) +++ apps/plugins/lib/SOURCES (Arbeitskopie) @@ -5,6 +5,7 @@ playback_control.c rgb_hsv.c buflib.c +text.c #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) /* The scaler is not provided in core on mono targets, but is built in Index: apps/plugins/lib/text.c =================================================================== --- apps/plugins/lib/text.c (Revision 0) +++ apps/plugins/lib/text.c (Revision 0) @@ -0,0 +1,83 @@ +#include "plugin.h" +#include "text.h" + +#define MARGIN 5 + +int display_text(short words, char** text, struct style_text style[]) +{ +#ifdef HAVE_LCD_COLOR + rb->lcd_set_background(LCD_BLACK); + rb->lcd_set_foreground(LCD_WHITE); +#endif +#ifdef HAVE_LCD_BITMAP + rb->lcd_setfont(FONT_UI); +#endif + int y = MARGIN; + int space_w, width, height; + unsigned short x = MARGIN, i = 0; + int button; + rb->lcd_clear_display(); + rb->lcd_getstringsize(" ", &space_w, &height); + for (i = 0; i < words; i++) { + rb->lcd_getstringsize(text[i], &width, NULL); + /* Skip to next line if the current one can't fit the word */ + if (x + width > LCD_WIDTH - MARGIN) { + x = MARGIN; + y += height; + } + /* .. or if the word is the empty string */ + if (strcmp(text[i], "") == 0) { + x = MARGIN; + y += height; + continue; + } + /* We filled the screen */ + if (y + height > LCD_HEIGHT - MARGIN) { + y = MARGIN; + rb->lcd_update(); + do { + button = rb->button_get(true); + if (button == SYS_USB_CONNECTED) { + return PLUGIN_USB_CONNECTED; + } + } while( ( button == BUTTON_NONE ) + || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); + rb->lcd_clear_display(); + } + /* set align */ + if (style[i].center) { + x=(LCD_WIDTH/2)-(width/x); + } + /* set colour */ +#ifdef HAVE_LCD_COLOR + switch (style[i].color) { + case C_RED: + rb->lcd_set_foreground(LCD_RGBPACK(255,0,0)); + break; + case C_YELLOW: + rb->lcd_set_foreground(LCD_RGBPACK(255,255,0)); + break; + case C_GREEN: + rb->lcd_set_foreground(LCD_RGBPACK(0,192,0)); + break; + case C_BLUE: + rb->lcd_set_foreground(LCD_RGBPACK(0,0,255)); + break; + } +#endif + rb->lcd_putsxy(x, y, text[i]); + rb->lcd_set_foreground(LCD_WHITE); +#ifdef HAVE_LCD_CHARCELLS + if (style[i].underline) { + rb->lcd_set_drawmode(DRMODE_SOLID); + rb->lcd_hline(x, x+width, y+height); + } +#endif + x += width + space_w; + } + rb->lcd_update(); +#ifdef HAVE_LCD_BITMAP + rb->lcd_setfont(FONT_SYSFIXED); +#endif + return 0; +} Index: apps/plugins/lib/text.h =================================================================== --- apps/plugins/lib/text.h (Revision 0) +++ apps/plugins/lib/text.h (Revision 0) @@ -0,0 +1,33 @@ +#include "plugin.h" +/************************************ + * Usage: + * #define WORDS (sizeof instructions / sizeof (char*)) + * char* instructions[] = {"word","word","word","word",}; + * struct style_text formations[WORDS]={NORMAL, false, false}; occurs a warning + * formations[0].color=C_RED; + * formations[0].center=true; + * formations[2].underline=true; + * formations[0].underline=true; + * formations[3].color=C_BLUE; + * formations[2].center=false; + * if (display_text(WORDS, instructions, formations)==PLUGIN_USB_CONNECTED) { + * return PLUGIN_USB_CONNECTED; + * } +*****************************************/ + +enum { + NORMAL, + C_YELLOW, + C_RED, + C_BLUE, + C_GREEN, +}; + +struct style_text { + short color; + bool center; + bool underline; +}; +/* it would be better to use also a pointer on the struct */ +/* the struct should be optional */ +int display_text(short words, char** text, struct style_text style[]);