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

@ -1135,7 +1135,6 @@ static unsigned int play_again(void) {
* blackjack_help() displays help text.
******************************************************************************/
static bool blackjack_help(void) {
#define WORDS (sizeof help_text / sizeof (char*))
static char *help_text[] = {
"Blackjack", "", "Aim", "",
"Try", "to", "get", "as", "close", "to", "21", "without", "going",
@ -1151,26 +1150,18 @@ static bool blackjack_help(void) {
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ 26, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
int button;
rb->lcd_setfont(FONT_UI);
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
if (display_text(WORDS, help_text, formation, NULL))
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
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) ) );
rb->lcd_setfont(FONT_SYSFIXED);
return false;
}

View file

@ -1138,7 +1138,6 @@ static void brickmania_sleep(int secs)
static int brickmania_help(void)
{
#define WORDS (sizeof help_text / sizeof (char*))
static char *help_text[] = {
"Brickmania", "", "Aim", "",
"Destroy", "all", "the", "bricks", "by", "bouncing",
@ -1205,26 +1204,18 @@ static int brickmania_help(void)
{ 67, C_GREEN },
{ 74, C_YELLOW },
{ 80, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
int button;
rb->lcd_setfont(FONT_UI);
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
if (display_text(WORDS, help_text, formation, NULL))
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return 1;
do {
button = rb->button_get(true);
if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
return 1;
}
} while( ( button == BUTTON_NONE )
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
rb->lcd_setfont(FONT_SYSFIXED);
return 0;
}

View file

@ -435,6 +435,7 @@ static void clix_draw(struct clix_game_state_t* state)
}
rb->lcd_update();
rb->lcd_set_foreground(LCD_WHITE);
}
static void clix_move_cursor(struct clix_game_state_t* state, const bool left)
@ -467,7 +468,6 @@ static void clix_move_cursor(struct clix_game_state_t* state, const bool left)
}
}
} while ( y != state->y);
}
/* returns the color of the given position, if out of bounds return CC_BLACK */
@ -581,7 +581,6 @@ static int clix_clear_selected(struct clix_game_state_t* state)
static bool clix_help(void)
{
#define WORDS (sizeof help_text / sizeof (char*))
static char *help_text[] = {
"Clix", "", "Aim", "",
"Remove", "all", "blocks", "from", "the", "board", "to", "achieve",
@ -593,22 +592,16 @@ static bool clix_help(void)
static struct style_text formation[]={
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
int button;
rb->lcd_setfont(FONT_UI);
rb->lcd_set_foreground(LCD_WHITE);
if (display_text(WORDS, help_text, formation, NULL))
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
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) ) );
rb->lcd_setfont(FONT_SYSFIXED);
return 0;
return false;
}
static bool _ingame;

View file

@ -1300,8 +1300,6 @@ static void jewels_nextlevel(struct game_context* bj) {
static bool jewels_help(void)
{
rb->lcd_setfont(FONT_UI);
#define WORDS (sizeof help_text / sizeof (char*))
static char *help_text[] = {
"Jewels", "", "Aim", "",
"Swap", "pairs", "of", "jewels", "to", "form", "connected",
@ -1323,22 +1321,12 @@ static bool jewels_help(void)
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ 42, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
int button;
if (display_text(WORDS, help_text, formation, NULL))
rb->lcd_setfont(FONT_UI);
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
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) ) );
rb->lcd_setfont(FONT_SYSFIXED);
return false;

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 */

View file

@ -970,8 +970,6 @@ static void pegbox_move_player(struct game_context* pb, signed int x_dir,
************************************************************************/
static bool pegbox_help(void)
{
int button;
#define WORDS (sizeof help_text / sizeof (char*))
static char* help_text[] = {
"Pegbox", "", "Aim", "",
"To", "beat", "each", "level,", "you", "must", "destroy", "all", "of",
@ -990,20 +988,14 @@ static bool pegbox_help(void)
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ 46, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
rb->lcd_setfont(FONT_UI);
if (display_text(WORDS, help_text, formation, NULL))
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
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) ) );
rb->lcd_setfont(FONT_SYSFIXED);
return false;
}

View file

@ -863,7 +863,6 @@ static void play_animation(int input)
static void instructions()
{
#define WORDS (sizeof help_text / sizeof (char*))
static char* help_text[] = {
#if 0
/* Not sure if we want to include this? */
@ -879,7 +878,7 @@ static void instructions()
"The", "game", "ends", "when", "robotfindskitten.", "", "",
"Press", "any", "key", "to", "start",
};
display_text(WORDS, help_text, NULL, NULL);
display_text(ARRAYLEN(help_text), help_text, NULL, NULL, false);
pause();
}

View file

@ -1218,20 +1218,20 @@ static void move_down (void)
static bool rockblox_help(void)
{
int button;
#define WORDS (sizeof help_text / sizeof (char*))
char *help_text[] = {
"Rockblox", "", "Aim", "", "Make", "the", "falling", "blocks", "of", "different",
"shapes", "form", "full", "rows.", "Whenever", "a", "row", "is", "completed,", "it",
"will", "be", "cleared", "away", "and", "you", "gain", "points."
static char *help_text[] = {
"Rockblox", "", "Aim", "",
"Make", "the", "falling", "blocks", "of",
"different", "shapes", "form", "full", "rows.",
"Whenever", "a", "row", "is", "completed,",
"it", "will", "be", "cleared", "away",
"and", "you", "gain", "points."
};
static struct style_text formation[]={
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
#ifdef HAVE_LCD_BITMAP
rb->lcd_setfont(FONT_UI);
#endif
@ -1239,17 +1239,12 @@ static bool rockblox_help(void)
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
if (display_text(WORDS, help_text, formation, NULL))
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
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) ) );
#ifdef HAVE_LCD_BITMAP
rb->lcd_setfont(FONT_SYSFIXED);
#endif
return false;
}

View file

@ -686,8 +686,6 @@ static void draw_empty_stack( int s, int x, int y, bool cursor )
/* Help */
static bool solitaire_help( void )
{
#define WORDS (sizeof help_text / sizeof (char*))
static char* help_text[] = {
"Solitaire", "", "Controls", "",
HK_LR ":", "Move", "the", "cursor", "to", "the",
@ -711,29 +709,10 @@ static bool solitaire_help( void )
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ 48, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
#if LCD_DEPTH > 1
fb_data* backdrop = rb->lcd_get_backdrop();
rb->lcd_set_backdrop(NULL);
#endif
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
int button;
if (display_text(WORDS, help_text, formation, NULL))
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
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 LCD_DEPTH > 1
rb->lcd_set_backdrop(backdrop);
#endif
return false;
}

View file

@ -1745,31 +1745,22 @@ static void initialise_game(void)
static bool spacerocks_help(void)
{
static char *help_text[] = {
"Spacerocks", "", "Aim", "", "The", "goal", "of", "the", "game", "is",
"to", "blow", "up", "the", "asteroids", "and", "avoid", "being", "hit", "by",
"them.", "Also", "you'd", "better", "watch", "out", "for", "the", "UFOs!"
"Spacerocks", "", "Aim", "",
"The", "goal", "of", "the", "game", "is", "to", "blow", "up",
"the", "asteroids", "and", "avoid", "being", "hit", "by", "them.",
"Also", "you'd", "better", "watch", "out", "for", "the", "UFOs!"
};
static struct style_text formation[]={
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
int button;
rb->lcd_setfont(FONT_UI);
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL)
== PLUGIN_USB_CONNECTED)
SET_BG(LCD_BLACK);
SET_FG(LCD_WHITE);
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
do {
button = rb->button_get(true);
if (button == SYS_USB_CONNECTED)
return true;
} while( ( button == BUTTON_NONE )
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
rb->lcd_setfont(FONT_SYSFIXED);
return false;

View file

@ -1051,8 +1051,6 @@ static int star_run_game(int current_level)
*/
static bool star_help(void)
{
int button;
#define WORDS (sizeof help_text / sizeof (char*))
static char* help_text[] = {
"Star", "", "Aim", "",
"Take", "all", "the", "stars", "to", "go", "to", "the", "next", "level.",
@ -1070,27 +1068,17 @@ static bool star_help(void)
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ 35, C_RED },
{ -1, 0 }
LAST_STYLE_ITEM
};
#if LCD_DEPTH > 1
#ifndef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_WHITE );
rb->lcd_set_foreground(LCD_BLACK );
#if LCD_DEPTH > 1 && !defined(HAVE_LCD_COLOR)
rb->lcd_set_background(LCD_WHITE);
rb->lcd_set_foreground(LCD_BLACK);
#endif
#endif
if (display_text(WORDS, help_text, formation, NULL))
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
return true;
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 LCD_DEPTH > 1
#ifndef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_BLACK );
rb->lcd_set_foreground(LCD_WHITE );
#endif
#if LCD_DEPTH > 1 && !defined(HAVE_LCD_COLOR)
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
return false;
}

View file

@ -566,7 +566,6 @@ int settings_menu(void) {
}
static int superdom_help(void) {
int button;
static char* help_text[] = {
"Super", "domination", "is", "a", "turn", "based", "strategy", "game,",
"where", "the", "aim", "is", "to", "overpower", "the", "computer",
@ -580,15 +579,8 @@ static int superdom_help(void) {
"and", "number", "of", "troops", "on", "them.",
};
if (display_text(ARRAYLEN(help_text), help_text, NULL, NULL))
if (display_text(ARRAYLEN(help_text), help_text, NULL, NULL, true))
return RET_VAL_USB;
do {
button = rb->button_get(true);
if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
return RET_VAL_USB;
} while( ( button == BUTTON_NONE )
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
return RET_VAL_OK;
}