diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2010-02-22 07:17:15 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2010-02-22 07:17:15 +0000 |
commit | 56d29e89778f30e87a20bb1e67fd6854fe19684c (patch) | |
tree | 588064022421b1094aebdc6f627a1a0f5ed4d4df /apps/plugins | |
parent | 04067fd7a0570692b0a25f578aaeeb5ab1cbff46 (diff) | |
download | rockbox-56d29e89778f30e87a20bb1e67fd6854fe19684c.tar.gz rockbox-56d29e89778f30e87a20bb1e67fd6854fe19684c.zip |
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
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/blackjack.c | 15 | ||||
-rw-r--r-- | apps/plugins/brickmania.c | 15 | ||||
-rw-r--r-- | apps/plugins/clix.c | 19 | ||||
-rw-r--r-- | apps/plugins/jewels.c | 20 | ||||
-rw-r--r-- | apps/plugins/lib/display_text.c | 30 | ||||
-rw-r--r-- | apps/plugins/lib/display_text.h | 26 | ||||
-rw-r--r-- | apps/plugins/pegbox.c | 14 | ||||
-rw-r--r-- | apps/plugins/robotfindskitten.c | 3 | ||||
-rw-r--r-- | apps/plugins/rockblox.c | 27 | ||||
-rw-r--r-- | apps/plugins/solitaire.c | 25 | ||||
-rw-r--r-- | apps/plugins/spacerocks.c | 25 | ||||
-rw-r--r-- | apps/plugins/star.c | 28 | ||||
-rw-r--r-- | apps/plugins/superdom.c | 10 |
13 files changed, 91 insertions, 166 deletions
diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c index 897a40bd19..9a9c91cb0a 100644 --- a/apps/plugins/blackjack.c +++ b/apps/plugins/blackjack.c @@ -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; } diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c index 25eb7e9ef7..d0f45ff6f0 100644 --- a/apps/plugins/brickmania.c +++ b/apps/plugins/brickmania.c @@ -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; } diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c index 34c62e954f..a048246196 100644 --- a/apps/plugins/clix.c +++ b/apps/plugins/clix.c @@ -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; diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c index 711a65591e..8a0ba94a41 100644 --- a/apps/plugins/jewels.c +++ b/apps/plugins/jewels.c @@ -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; diff --git a/apps/plugins/lib/display_text.c b/apps/plugins/lib/display_text.c index c69661030e..5d13fc678d 100644 --- a/apps/plugins/lib/display_text.c +++ b/apps/plugins/lib/display_text.c @@ -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; } diff --git a/apps/plugins/lib/display_text.h b/apps/plugins/lib/display_text.h index 39b5f76a14..33a8ff53af 100644 --- a/apps/plugins/lib/display_text.h +++ b/apps/plugins/lib/display_text.h @@ -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 */ diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c index feaf543ae6..f80b163c3f 100644 --- a/apps/plugins/pegbox.c +++ b/apps/plugins/pegbox.c @@ -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; } diff --git a/apps/plugins/robotfindskitten.c b/apps/plugins/robotfindskitten.c index 5cd0e465f8..99fc327085 100644 --- a/apps/plugins/robotfindskitten.c +++ b/apps/plugins/robotfindskitten.c @@ -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(); } diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c index a3d644e583..6bff1ea5a2 100644 --- a/apps/plugins/rockblox.c +++ b/apps/plugins/rockblox.c @@ -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; } diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index f40c761024..8737275627 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c @@ -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; } diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c index 361caa1b99..055bd78229 100644 --- a/apps/plugins/spacerocks.c +++ b/apps/plugins/spacerocks.c @@ -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; diff --git a/apps/plugins/star.c b/apps/plugins/star.c index c714601542..1e8eb868a9 100644 --- a/apps/plugins/star.c +++ b/apps/plugins/star.c @@ -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 ); -#endif +#if LCD_DEPTH > 1 && !defined(HAVE_LCD_COLOR) + rb->lcd_set_background(LCD_WHITE); + rb->lcd_set_foreground(LCD_BLACK); #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; } diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index 0018b9c91f..d26e98803e 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c @@ -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; } |