1
0
Fork 0
forked from len0rd/rockbox

some changes to use of display_text.

* add parameter, wait_key to display_text().
 - set this true to wait button press after all words is displayed.
* use ARRAYLEN macro instead of #define WORDS
* add macro to indicate end of style array.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24846 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2010-02-22 07:17:15 +00:00
parent 04067fd7a0
commit 56d29e8977
13 changed files with 91 additions and 166 deletions

View file

@ -28,8 +28,20 @@
#define MARGIN 5
#endif
bool display_text(short words, char** text, struct style_text* style,
struct viewport* vp_text)
static bool wait_key_press(void)
{
int button;
do {
button = rb->button_get(true);
if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
return true;
} while( ( button == BUTTON_NONE )
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
return false;
}
bool display_text(unsigned short words, char** text, struct style_text* style,
struct viewport* vp_text, bool wait_key)
{
#ifdef HAVE_LCD_BITMAP
int prev_drawmode;
@ -41,7 +53,6 @@ bool display_text(short words, char** text, struct style_text* style,
unsigned short x , y;
unsigned short vp_width = LCD_WIDTH;
unsigned short vp_height = LCD_HEIGHT;
int button;
unsigned short i = 0, style_index = 0;
if (vp_text != NULL) {
vp_width = vp_text->width;
@ -76,12 +87,8 @@ bool display_text(short words, char** text, struct style_text* style,
if (y + height > vp_height - MARGIN) {
y = MARGIN;
rb->screens[SCREEN_MAIN]->update_viewport();
do {
button = rb->button_get(true);
if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
return true;
} while( ( button == BUTTON_NONE )
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
if (wait_key_press())
return true;
rb->screens[SCREEN_MAIN]->clear_viewport();
}
/* no text formatting available */
@ -134,5 +141,10 @@ bool display_text(short words, char** text, struct style_text* style,
#ifdef HAVE_LCD_BITMAP
rb->lcd_set_drawmode(prev_drawmode);
#endif
if (wait_key)
{
if (wait_key_press())
return true;
}
return false;
}

View file

@ -19,16 +19,20 @@
* KIND, either express or implied.
*
****************************************************************************/
#ifndef _DISPLAY_TEXT_H
#define _DISPLAY_TEXT_H
#include "plugin.h"
/*
* basic usage:
* #define WORDS (sizeof text / sizeof (char*))
* char *text[] = {"normal", "centering", "red,underline"};
* struct style_text formation[]={
* { 1, TEXT_CENTER },
* { 2, C_RED|TEXT_UNDERLINE },
* LAST_STYLE_ITEM
* };
* if (display_text(WORDS, text, formation, NULL))
* if (display_text(ARRAYLEN(text), text, formation, NULL, true))
* return PLUGIN_USB_CONNECTED;
*/
@ -36,13 +40,23 @@ enum ecolor { STANDARD, C_YELLOW, C_RED, C_BLUE, C_GREEN , C_ORANGE };
#define TEXT_COLOR_MASK 0x00ff
#define TEXT_CENTER 0x0100
#define TEXT_UNDERLINE 0x0200
#define LAST_STYLE_ITEM { -1, 0 }
struct style_text {
unsigned short index;
unsigned short flags;
};
/* style and vp_text are optional.
* return true if usb is connected. */
bool display_text(short words, char** text, struct style_text* style,
struct viewport* vp_text);
/*
* display text.
* - words : number of words in text.
* - text : array of word to be displayed. use empty string for newline.
* - style : (optional) set style of each word. must be sorted by index.
* - vp_text : (optional) viewport to display text.
* - wait_key : set true to wait button press after all words is displayed.
* return true if usb is connected, false otherwise.
*/
bool display_text(unsigned short words, char** text, struct style_text* style,
struct viewport* vp_text, bool wait_key);
#endif /* _DISPLAY_TEXT_H */