Index: apps/plugins/lib/text.c =================================================================== --- apps/plugins/lib/text.c (Revision 0) +++ apps/plugins/lib/text.c (Revision 0) @@ -0,0 +1,151 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: highscore.c 19776 2009-01-16 10:34:40Z unhelpful $ + * + * Copyright (C) 2009 Johannes Schwarz + * based on Will Robertson code in superdom + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "plugin.h" +#include "text.h" + +int display_text(short words, char** text, struct style_text* style, struct viewport* vp_text) +{ + int space_w, width, height; + int tmp_drawmode; + unsigned short xmargin = 5, ymargin = 5; + unsigned short x , y; + unsigned short text_width = LCD_WIDTH; + unsigned short text_height = LCD_HEIGHT; + unsigned standard_fcolor; + int button; + short i=0; + /* no viewport available */ + if (vp_text==NULL) { +#if LCD_DEPTH > 1 + rb->lcd_set_background(LCD_BLACK); + rb->lcd_set_foreground(LCD_WHITE); + standard_fcolor = LCD_WHITE; +#endif +#ifdef HAVE_LCD_BITMAP + tmp_drawmode = rb->lcd_get_drawmode(); + rb->lcd_set_drawmode(DRMODE_SOLID); +#endif + rb->lcd_clear_display(); + } else { + xmargin = xmargin + (*vp_text).x; + ymargin = ymargin + (*vp_text).y; + text_width = (*vp_text).width; + text_height = (*vp_text).height; + standard_fcolor=(*vp_text).fg_pattern; +#if LCD_DEPTH > 1 + rb->lcd_set_foreground((*vp_text).fg_pattern); + rb->lcd_set_background((*vp_text).bg_pattern); + standard_fcolor = (*vp_text).fg_pattern; +#endif +#ifdef HAVE_LCD_BITMAP + tmp_drawmode = (*vp_text).drawmode; + (*vp_text).drawmode = DRMODE_SOLID; +#endif + } + x = xmargin, y = xmargin; + rb->button_clear_queue(); + 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 > text_width - xmargin) { + x = xmargin; + y = y + height; + } + /* .. or if the word is the empty string */ + if (rb->strcmp(text[i], "")==0) { + x = xmargin; + y = y + height; + continue; + } + /* display the remaining text by button click or exit */ + if (y + height > text_height - ymargin) { + y = ymargin; + if (vp_text==NULL) { + rb->lcd_update(); + } else { + rb->screens[SCREEN_MAIN]->update_viewport(); + } + rb->yield(); + do { + button = rb->button_get(true); + if (button == SYS_USB_CONNECTED) { + return PLUGIN_USB_CONNECTED; + } + } while( ( button == BUTTON_NONE ) + || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); + if (vp_text==NULL) { + rb->lcd_clear_display(); + } else { + rb->screens[SCREEN_MAIN]->clear_viewport(); + } + } + /* no text formations available */ + if (style==NULL) { + rb->lcd_putsxy(x, y, text[i]); + } else { + /* set align */ + if (style[i].center==1) { + x=(LCD_WIDTH/2)-(width/2); + } + /* set font color */ +#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; + case C_ORANGE: + rb->lcd_set_foreground(LCD_RGBPACK(255,192,0)); + break; + case STANDARD: + rb->lcd_set_foreground(standard_fcolor); + break; + } +#endif + rb->lcd_putsxy(x, y, text[i]); +#ifdef HAVE_LCD_BITMAP + if (style[i].underline==1) { + rb->lcd_hline(x, x+width, y+height-1); + } +#endif + } + x += width + space_w; + } + rb->lcd_update(); +#ifdef HAVE_LCD_BITMAP + if (vp_text==NULL) { + rb->lcd_set_drawmode(tmp_drawmode); + } else { + (*vp_text).drawmode = tmp_drawmode; + } +#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,41 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: highscore.c 19776 2009-01-16 10:34:40Z unhelpful $ + * + * Copyright (C) 2009 Johannes Schwarz + * based on Will Robertson code in superdom + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "plugin.h" +/* + * basis usage: + * #define WORDS (sizeof help_text / sizeof (char*)) + * char *text[] = {word, word}; + * struct style_text formation[WORDS]={}; + * formation[0].center=1; + * formation[1].underline=1; + * formation[1].color=C_RED; + * if (display_text(WORDS, help_text, formation, NULL)==PLUGIN_USB_CONNECTED) + * return PLUGIN_USB_CONNECTED; +*/ + +struct style_text { + enum EColor { STANDARD, C_YELLOW, C_RED, C_BLUE, C_GREEN , C_ORANGE } color; + short center; + short underline; +}; + +int display_text(short words, char** text, struct style_text* style, struct viewport* vp_text);