diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2009-07-14 13:03:17 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2009-07-14 13:03:17 +0000 |
commit | c72b23ad2e1b3a507a36b6223c0a35be9b746f0a (patch) | |
tree | 2cf43da7cca0ff2caf8544a1f3c48ac5d961701c /apps/plugins/pegbox.c | |
parent | e37f9f16915a1a05059aee931723c127a53a68e0 (diff) | |
download | rockbox-c72b23ad2e1b3a507a36b6223c0a35be9b746f0a.tar.gz rockbox-c72b23ad2e1b3a507a36b6223c0a35be9b746f0a.zip |
use lib display text to display help messages (FS#10099).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21861 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pegbox.c')
-rw-r--r-- | apps/plugins/pegbox.c | 176 |
1 files changed, 49 insertions, 127 deletions
diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c index d6f87cd46b..eb53eca8b5 100644 --- a/apps/plugins/pegbox.c +++ b/apps/plugins/pegbox.c | |||
@@ -19,6 +19,7 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "plugin.h" | 21 | #include "plugin.h" |
22 | #include "lib/display_text.h" | ||
22 | 23 | ||
23 | #include "pluginbitmaps/pegbox_header.h" | 24 | #include "pluginbitmaps/pegbox_header.h" |
24 | #include "pluginbitmaps/pegbox_pieces.h" | 25 | #include "pluginbitmaps/pegbox_pieces.h" |
@@ -720,111 +721,6 @@ char levels[NUM_LEVELS][ROWS][COLS] = { | |||
720 | 721 | ||
721 | 722 | ||
722 | /***************************************************************************** | 723 | /***************************************************************************** |
723 | * display_text() formats and outputs text. | ||
724 | ******************************************************************************/ | ||
725 | static void display_text(char *str, bool waitkey) | ||
726 | { | ||
727 | int chars_by_line; | ||
728 | int lines_by_screen; | ||
729 | int chars_for_line; | ||
730 | int current_line = 0; | ||
731 | int char_width, char_height; | ||
732 | int first_char_index = 0; | ||
733 | char *ptr_char; | ||
734 | char *ptr_line; | ||
735 | int i; | ||
736 | char line[255]; | ||
737 | int key; | ||
738 | bool go_on; | ||
739 | |||
740 | rb->lcd_clear_display(); | ||
741 | |||
742 | rb->lcd_getstringsize("a", &char_width, &char_height); | ||
743 | |||
744 | chars_by_line = LCD_WIDTH / char_width; | ||
745 | lines_by_screen = LCD_HEIGHT / char_height; | ||
746 | |||
747 | do | ||
748 | { | ||
749 | ptr_char = str + first_char_index; | ||
750 | chars_for_line = 0; | ||
751 | i = 0; | ||
752 | ptr_line = line; | ||
753 | while (i < chars_by_line) | ||
754 | { | ||
755 | switch (*ptr_char) | ||
756 | { | ||
757 | case '\t': | ||
758 | case ' ': | ||
759 | *(ptr_line++) = ' '; | ||
760 | case '\n': | ||
761 | case '\0': | ||
762 | chars_for_line = i; | ||
763 | break; | ||
764 | |||
765 | default: | ||
766 | *(ptr_line++) = *ptr_char; | ||
767 | } | ||
768 | if (*ptr_char == '\n' || *ptr_char == '\0') | ||
769 | break; | ||
770 | ptr_char++; | ||
771 | i++; | ||
772 | } | ||
773 | |||
774 | if (chars_for_line == 0) | ||
775 | chars_for_line = i; | ||
776 | |||
777 | line[chars_for_line] = '\0'; | ||
778 | |||
779 | /* test if we have cut a word. If it is the case we don't have to */ | ||
780 | /* skip the space */ | ||
781 | if (i == chars_by_line && chars_for_line == chars_by_line) | ||
782 | first_char_index += chars_for_line; | ||
783 | else | ||
784 | first_char_index += chars_for_line + 1; | ||
785 | |||
786 | /* print the line on the screen */ | ||
787 | rb->lcd_putsxy(0, current_line * char_height, line); | ||
788 | |||
789 | /* if the number of line showed on the screen is equals to the */ | ||
790 | /* maximum number of line we can show, we wait for a key pressed to */ | ||
791 | /* clear and show the remaining text. */ | ||
792 | current_line++; | ||
793 | if (current_line == lines_by_screen || *ptr_char == '\0') | ||
794 | { | ||
795 | current_line = 0; | ||
796 | rb->lcd_update(); | ||
797 | go_on = false; | ||
798 | while (waitkey && !go_on) | ||
799 | { | ||
800 | key = rb->button_get(true); | ||
801 | switch (key) | ||
802 | { | ||
803 | #ifdef HAVE_TOUCHSCREEN | ||
804 | case BUTTON_TOUCHSCREEN: | ||
805 | #endif | ||
806 | case PEGBOX_QUIT: | ||
807 | case PEGBOX_LEFT: | ||
808 | case PEGBOX_DOWN: | ||
809 | go_on = true; | ||
810 | break; | ||
811 | |||
812 | default: | ||
813 | /*if (rb->default_event_handler(key) == SYS_USB_CONNECTED) | ||
814 | { | ||
815 | usb_detected = true; | ||
816 | go_on = true; | ||
817 | break; | ||
818 | }*/ | ||
819 | break; | ||
820 | } | ||
821 | } | ||
822 | rb->lcd_clear_display(); | ||
823 | } | ||
824 | } while (*ptr_char != '\0'); | ||
825 | } | ||
826 | |||
827 | /***************************************************************************** | ||
828 | * draw_board() draws the game's current level. | 724 | * draw_board() draws the game's current level. |
829 | ******************************************************************************/ | 725 | ******************************************************************************/ |
830 | static void draw_board(struct game_context* pb) { | 726 | static void draw_board(struct game_context* pb) { |
@@ -1127,6 +1023,48 @@ static void pegbox_callback(void* param) { | |||
1127 | pegbox_savedata(pb); | 1023 | pegbox_savedata(pb); |
1128 | } | 1024 | } |
1129 | 1025 | ||
1026 | /*********************************************************************** | ||
1027 | * pegbox_help() display help text | ||
1028 | ************************************************************************/ | ||
1029 | static bool pegbox_help(void) | ||
1030 | { | ||
1031 | int button; | ||
1032 | #define WORDS (sizeof help_text / sizeof (char*)) | ||
1033 | static char* help_text[] = { | ||
1034 | "Pegbox", "", "Aim", "", | ||
1035 | "To", "beat", "each", "level,", "you", "must", "destroy", "all", "of", | ||
1036 | "the", "pegs.", "If", "two", "like", "pegs", "are", "pushed", "into", | ||
1037 | "each", "other,", "they", "disappear", "except", "for", "triangles", | ||
1038 | "which", "form", "a", "solid", "block", "and", "crosses", "which", | ||
1039 | "allow", "you", "to", "choose", "a", "replacement", "block.", "", "", | ||
1040 | "Controls", "", | ||
1041 | RESTART_TEXT, "to", "restart", "level", "", | ||
1042 | LVL_UP_TEXT, "to", "go", "up", "a", "level", "", | ||
1043 | LVL_DOWN_TEXT, "to", "go", "down", "a", "level", "", | ||
1044 | SAVE_TEXT, "to", "select/save", "", | ||
1045 | QUIT_TEXT, "to", "quit" | ||
1046 | }; | ||
1047 | static struct style_text formation[]={ | ||
1048 | { 0, TEXT_CENTER|TEXT_UNDERLINE }, | ||
1049 | { 2, C_RED }, | ||
1050 | { 46, C_RED }, | ||
1051 | { -1, 0 } | ||
1052 | }; | ||
1053 | |||
1054 | rb->lcd_setfont(FONT_UI); | ||
1055 | |||
1056 | if (display_text(WORDS, help_text, formation, NULL)) | ||
1057 | return true; | ||
1058 | do { | ||
1059 | button = rb->button_get(true); | ||
1060 | if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) | ||
1061 | return true; | ||
1062 | } while( ( button == BUTTON_NONE ) | ||
1063 | || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); | ||
1064 | rb->lcd_setfont(FONT_SYSFIXED); | ||
1065 | return false; | ||
1066 | } | ||
1067 | |||
1130 | /***************************************************************************** | 1068 | /***************************************************************************** |
1131 | * pegbox_menu() is the initial menu at the start of the game. | 1069 | * pegbox_menu() is the initial menu at the start of the game. |
1132 | ******************************************************************************/ | 1070 | ******************************************************************************/ |
@@ -1251,28 +1189,12 @@ static unsigned int pegbox_menu(struct game_context* pb) { | |||
1251 | pb->save_exist = false; | 1189 | pb->save_exist = false; |
1252 | } | 1190 | } |
1253 | breakout = true; | 1191 | breakout = true; |
1254 | } | 1192 | } |
1255 | else if (loc == 2) | 1193 | else if (loc == 2) |
1256 | display_text("How to Play\nTo beat each level, you must " | 1194 | { |
1257 | "destroy all of the pegs. If two like pegs are " | 1195 | if(pegbox_help()) |
1258 | "pushed into each other they disappear except " | 1196 | return PB_USB; |
1259 | "for triangles which form a solid block and " | 1197 | } |
1260 | "crosses which allow you to choose a " | ||
1261 | "replacement block.\n\n" | ||
1262 | "Controls\n" | ||
1263 | #if LCD_HEIGHT > 64 | ||
1264 | RESTART_TEXT " to restart level\n" | ||
1265 | LVL_UP_TEXT " to go up a level\n" | ||
1266 | LVL_DOWN_TEXT " to go down a level\n" | ||
1267 | SAVE_TEXT " to select/save\n" | ||
1268 | QUIT_TEXT " to quit\n",true); | ||
1269 | #else | ||
1270 | RESTART_TEXT ": restart\n" | ||
1271 | LVL_UP_TEXT ": level up\n" | ||
1272 | LVL_DOWN_TEXT " level down\n" | ||
1273 | SAVE_TEXT " select/save\n" | ||
1274 | QUIT_TEXT " quit\n",true); | ||
1275 | #endif | ||
1276 | else if (loc == 3) | 1198 | else if (loc == 3) |
1277 | return PB_QUIT; | 1199 | return PB_QUIT; |
1278 | break; | 1200 | break; |
@@ -1462,7 +1384,7 @@ enum plugin_status plugin_start(const void* parameter) { | |||
1462 | rb->lcd_setfont(FONT_SYSFIXED); | 1384 | rb->lcd_setfont(FONT_SYSFIXED); |
1463 | #if LCD_DEPTH > 1 | 1385 | #if LCD_DEPTH > 1 |
1464 | rb->lcd_set_backdrop(NULL); | 1386 | rb->lcd_set_backdrop(NULL); |
1465 | #endif | 1387 | #endif |
1466 | #ifdef HAVE_LCD_COLOR | 1388 | #ifdef HAVE_LCD_COLOR |
1467 | rb->lcd_set_foreground(LCD_WHITE); | 1389 | rb->lcd_set_foreground(LCD_WHITE); |
1468 | rb->lcd_set_background(BG_COLOR); | 1390 | rb->lcd_set_background(BG_COLOR); |