summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-25 21:22:00 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-25 21:22:00 +0000
commit2fb63ae6a8c32ffff751b1745e746dab015d1704 (patch)
tree84a09a5730e5552011ef3d053a34e7c39996d27f
parentc5082f58c614516c22b9eb11a97f5fbf2ef13492 (diff)
downloadrockbox-2fb63ae6a8c32ffff751b1745e746dab015d1704.tar.gz
rockbox-2fb63ae6a8c32ffff751b1745e746dab015d1704.zip
Add in-grid graphical markers for scratchpad values to sudoku (FS#8364 by Henri Valta with adjustments by me).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18880 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/sudoku/sudoku.c114
1 files changed, 109 insertions, 5 deletions
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c
index 3910e14011..b709002880 100644
--- a/apps/plugins/sudoku/sudoku.c
+++ b/apps/plugins/sudoku/sudoku.c
@@ -109,6 +109,9 @@ static const char default_game[9][9] =
109#define CELL_WIDTH 8 109#define CELL_WIDTH 8
110#define CELL_HEIGHT 6 110#define CELL_HEIGHT 6
111#define SMALL_BOARD 111#define SMALL_BOARD
112#define MARK_OFFS 1 /* Pixels between border and mark */
113#define MARK_SPACE 1 /* Pixels between two marks */
114#define MARK_SIZE 1 /* Mark width and height */
112 115
113#elif ((LCD_HEIGHT==80) && (LCD_WIDTH==132)) 116#elif ((LCD_HEIGHT==80) && (LCD_WIDTH==132))
114/* C200, 9 cells @ 8x8 with 8 border lines */ 117/* C200, 9 cells @ 8x8 with 8 border lines */
@@ -117,6 +120,9 @@ static const char default_game[9][9] =
117#define CELL_WIDTH 8 120#define CELL_WIDTH 8
118#define CELL_HEIGHT 8 121#define CELL_HEIGHT 8
119#define SMALL_BOARD 122#define SMALL_BOARD
123#define MARK_OFFS 1 /* Pixels between border and mark */
124#define MARK_SPACE 1 /* Pixels between two marks */
125#define MARK_SIZE 1 /* Mark width and height */
120 126
121#elif ((LCD_HEIGHT==96) && (LCD_WIDTH==128)) 127#elif ((LCD_HEIGHT==96) && (LCD_WIDTH==128))
122/* iAudio M3, 9 cells @ 9x9 with 14 border lines */ 128/* iAudio M3, 9 cells @ 9x9 with 14 border lines */
@@ -124,6 +130,9 @@ static const char default_game[9][9] =
124/* Internal dimensions of a cell */ 130/* Internal dimensions of a cell */
125#define CELL_WIDTH 9 131#define CELL_WIDTH 9
126#define CELL_HEIGHT 9 132#define CELL_HEIGHT 9
133#define MARK_OFFS 1 /* Pixels between border and mark */
134#define MARK_SPACE 2 /* Pixels between two marks */
135#define MARK_SIZE 1 /* Mark width and height */
127 136
128#elif (LCD_HEIGHT==110) && (LCD_WIDTH==138) \ 137#elif (LCD_HEIGHT==110) && (LCD_WIDTH==138) \
129 || (LCD_HEIGHT==128) && (LCD_WIDTH==128) 138 || (LCD_HEIGHT==128) && (LCD_WIDTH==128)
@@ -133,6 +142,9 @@ static const char default_game[9][9] =
133/* Internal dimensions of a cell */ 142/* Internal dimensions of a cell */
134#define CELL_WIDTH 10 143#define CELL_WIDTH 10
135#define CELL_HEIGHT 10 144#define CELL_HEIGHT 10
145#define MARK_OFFS 1 /* Pixels between border and mark */
146#define MARK_SPACE 1 /* Pixels between two marks */
147#define MARK_SIZE 2 /* Mark width and height */
136 148
137#elif ((LCD_HEIGHT==128) && (LCD_WIDTH==160)) \ 149#elif ((LCD_HEIGHT==128) && (LCD_WIDTH==160)) \
138 || ((LCD_HEIGHT==132) && (LCD_WIDTH==176)) 150 || ((LCD_HEIGHT==132) && (LCD_WIDTH==176))
@@ -142,6 +154,9 @@ static const char default_game[9][9] =
142/* Internal dimensions of a cell */ 154/* Internal dimensions of a cell */
143#define CELL_WIDTH 12 155#define CELL_WIDTH 12
144#define CELL_HEIGHT 12 156#define CELL_HEIGHT 12
157#define MARK_OFFS 1 /* Pixels between border and mark */
158#define MARK_SPACE 2 /* Pixels between two marks */
159#define MARK_SIZE 2 /* Mark width and height */
145 160
146#elif ((LCD_HEIGHT==176) && (LCD_WIDTH==220)) 161#elif ((LCD_HEIGHT==176) && (LCD_WIDTH==220))
147/* Iriver h300, iPod Color/Photo - 220x176, 9 cells @ 16x16 with 14 border lines */ 162/* Iriver h300, iPod Color/Photo - 220x176, 9 cells @ 16x16 with 14 border lines */
@@ -149,6 +164,9 @@ static const char default_game[9][9] =
149/* Internal dimensions of a cell */ 164/* Internal dimensions of a cell */
150#define CELL_WIDTH 16 165#define CELL_WIDTH 16
151#define CELL_HEIGHT 16 166#define CELL_HEIGHT 16
167#define MARK_OFFS 1 /* Pixels between border and mark */
168#define MARK_SPACE 1 /* Pixels between two marks */
169#define MARK_SIZE 4 /* Mark width and height */
152 170
153#elif (LCD_HEIGHT>=240) && (LCD_WIDTH>=320) 171#elif (LCD_HEIGHT>=240) && (LCD_WIDTH>=320)
154/* iPod Video - 320x240, 9 cells @ 24x24 with 14 border lines */ 172/* iPod Video - 320x240, 9 cells @ 24x24 with 14 border lines */
@@ -156,6 +174,9 @@ static const char default_game[9][9] =
156/* Internal dimensions of a cell */ 174/* Internal dimensions of a cell */
157#define CELL_WIDTH 24 175#define CELL_WIDTH 24
158#define CELL_HEIGHT 24 176#define CELL_HEIGHT 24
177#define MARK_OFFS 1 /* Pixels between border and mark */
178#define MARK_SPACE 2 /* Pixels between two marks */
179#define MARK_SIZE 6 /* Mark width and height */
159 180
160#else 181#else
161 #error SUDOKU: Unsupported LCD size 182 #error SUDOKU: Unsupported LCD size
@@ -170,6 +191,9 @@ static const char default_game[9][9] =
170/* Internal dimensions of a cell */ 191/* Internal dimensions of a cell */
171#define CELL_WIDTH 16 192#define CELL_WIDTH 16
172#define CELL_HEIGHT 16 193#define CELL_HEIGHT 16
194#define MARK_OFFS 1 /* Pixels between border and mark */
195#define MARK_SPACE 1 /* Pixels between two marks */
196#define MARK_SIZE 4 /* Mark width and height */
173 197
174#elif (LCD_HEIGHT>=320) && (LCD_WIDTH>=240) 198#elif (LCD_HEIGHT>=320) && (LCD_WIDTH>=240)
175/* Gigabeat - 240x320, 9 cells @ 24x24 with 14 border lines */ 199/* Gigabeat - 240x320, 9 cells @ 24x24 with 14 border lines */
@@ -177,6 +201,9 @@ static const char default_game[9][9] =
177/* Internal dimensions of a cell */ 201/* Internal dimensions of a cell */
178#define CELL_WIDTH 24 202#define CELL_WIDTH 24
179#define CELL_HEIGHT 24 203#define CELL_HEIGHT 24
204#define MARK_OFFS 1 /* Pixels between border and mark */
205#define MARK_SPACE 2 /* Pixels between two marks */
206#define MARK_SIZE 6 /* Mark width and height */
180 207
181#else 208#else
182 #error SUDOKU: Unsupported LCD size 209 #error SUDOKU: Unsupported LCD size
@@ -187,20 +214,45 @@ static const char default_game[9][9] =
187#define CFGFILE_VERSION 0 /* Current config file version */ 214#define CFGFILE_VERSION 0 /* Current config file version */
188#define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */ 215#define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */
189 216
190#ifdef HAVE_LCD_COLOR 217#if defined(HAVE_LCD_COLOR) || defined(SUDOKU_BUTTON_POSSIBLE)
191/* settings */ 218/* settings */
192struct sudoku_config { 219struct sudoku_config {
220#ifdef HAVE_LCD_COLOR
193 int number_display; 221 int number_display;
222#endif
223#ifdef SUDOKU_BUTTON_POSSIBLE
224 int show_markings;
225#endif
226};
227
228struct sudoku_config sudcfg_disk = {
229#ifdef HAVE_LCD_COLOR
230 0,
231#endif
232#ifdef SUDOKU_BUTTON_POSSIBLE
233 1,
234#endif
194}; 235};
195struct sudoku_config sudcfg_disk = { 0 };
196struct sudoku_config sudcfg; 236struct sudoku_config sudcfg;
197 237
198static const char cfg_filename[] = "sudoku.cfg"; 238static const char cfg_filename[] = "sudoku.cfg";
239#ifdef HAVE_LCD_COLOR
199static char *number_str[2] = { "black", "coloured" }; 240static char *number_str[2] = { "black", "coloured" };
241#endif
242#ifdef SUDOKU_BUTTON_POSSIBLE
243static char *mark_str[2] = { "hide", "show" };
244#endif
200 245
201struct configdata disk_config[] = { 246struct configdata disk_config[] = {
247#ifdef HAVE_LCD_COLOR
202 { TYPE_ENUM, 0, 2, &sudcfg_disk.number_display, "numbers", number_str, NULL }, 248 { TYPE_ENUM, 0, 2, &sudcfg_disk.number_display, "numbers", number_str, NULL },
249#endif
250#ifdef SUDOKU_BUTTON_POSSIBLE
251 { TYPE_ENUM, 0, 2, &sudcfg_disk.show_markings, "markings", mark_str, NULL },
252#endif
203}; 253};
254#endif
255#ifdef HAVE_LCD_COLOR
204#define NUMBER_TYPE (sudcfg.number_display*CELL_WIDTH) 256#define NUMBER_TYPE (sudcfg.number_display*CELL_WIDTH)
205#else 257#else
206#define NUMBER_TYPE 0 258#define NUMBER_TYPE 0
@@ -830,6 +882,9 @@ void update_cell(struct sudoku_state_t* state, int r, int c)
830void display_board(struct sudoku_state_t* state) 882void display_board(struct sudoku_state_t* state)
831{ 883{
832 int r,c; 884 int r,c;
885#ifdef SUDOKU_BUTTON_POSSIBLE
886 int i;
887#endif
833 888
834 /* Clear the display buffer */ 889 /* Clear the display buffer */
835 rb->lcd_clear_display(); 890 rb->lcd_clear_display();
@@ -961,7 +1016,7 @@ void display_board(struct sudoku_state_t* state)
961 2) Starting number 1016 2) Starting number
962 3) Cursor in cell 1017 3) Cursor in cell
963 */ 1018 */
964 1019
965 if ((r==state->y) && (c==state->x)) { 1020 if ((r==state->y) && (c==state->x)) {
966 rb->lcd_bitmap_part(sudoku_inverse,NUMBER_TYPE, 1021 rb->lcd_bitmap_part(sudoku_inverse,NUMBER_TYPE,
967 BITMAP_HEIGHT*(state->currentboard[r][c]- 1022 BITMAP_HEIGHT*(state->currentboard[r][c]-
@@ -985,6 +1040,30 @@ void display_board(struct sudoku_state_t* state)
985 XOFS+cellxpos[c],YOFS+cellypos[r], 1040 XOFS+cellxpos[c],YOFS+cellypos[r],
986 CELL_WIDTH,CELL_HEIGHT); 1041 CELL_WIDTH,CELL_HEIGHT);
987 } 1042 }
1043
1044#ifdef SUDOKU_BUTTON_POSSIBLE
1045 /* Draw the possible number markings on the board */
1046 if(sudcfg.show_markings && state->startboard[r][c]=='0'
1047 && state->currentboard[r][c]=='0') {
1048 for(i=0;i<9;i++) {
1049 if(state->possiblevals[r][c]&(2<<i)) {
1050#if LCD_DEPTH > 1
1051 /* draw markings in dark grey */
1052 rb->lcd_set_foreground(LCD_DARKGRAY);
1053#endif
1054 rb->lcd_fillrect(XOFS+cellxpos[c]+MARK_OFFS
1055 +(i%3)*(MARK_SIZE+MARK_SPACE),
1056 YOFS+cellypos[r]+MARK_OFFS
1057 +(i/3)*(MARK_SIZE+MARK_SPACE),
1058 MARK_SIZE,
1059 MARK_SIZE);
1060#if LCD_DEPTH > 1
1061 rb->lcd_set_foreground(LCD_BLACK);
1062#endif
1063 }
1064 }
1065 }
1066#endif /* SUDOKU_BUTTON_POSSIBLE */
988 } 1067 }
989 } 1068 }
990 } 1069 }
@@ -1040,11 +1119,27 @@ static bool numdisplay_setting(void)
1040} 1119}
1041#endif 1120#endif
1042 1121
1122#ifdef SUDOKU_BUTTON_POSSIBLE
1123static bool showmarkings_setting(void)
1124{
1125 static const struct opt_items names[] = {
1126 {"Hide", -1},
1127 {"Show", -1},
1128 };
1129
1130 return rb->set_option("Show Markings", &sudcfg.show_markings, INT, names,
1131 sizeof(names) / sizeof(names[0]), NULL);
1132}
1133#endif
1134
1043enum { 1135enum {
1044 SM_AUDIO_PLAYBACK = 0, 1136 SM_AUDIO_PLAYBACK = 0,
1045#ifdef HAVE_LCD_COLOR 1137#ifdef HAVE_LCD_COLOR
1046 SM_NUMBER_DISPLAY, 1138 SM_NUMBER_DISPLAY,
1047#endif 1139#endif
1140#ifdef SUDOKU_BUTTON_POSSIBLE
1141 SM_SHOW_MARKINGS,
1142#endif
1048 SM_SAVE, 1143 SM_SAVE,
1049 SM_RELOAD, 1144 SM_RELOAD,
1050 SM_CLEAR, 1145 SM_CLEAR,
@@ -1064,6 +1159,9 @@ bool sudoku_menu(struct sudoku_state_t* state)
1064#ifdef HAVE_LCD_COLOR 1159#ifdef HAVE_LCD_COLOR
1065 [SM_NUMBER_DISPLAY] = { "Number Display", NULL }, 1160 [SM_NUMBER_DISPLAY] = { "Number Display", NULL },
1066#endif 1161#endif
1162#ifdef SUDOKU_BUTTON_POSSIBLE
1163 [SM_SHOW_MARKINGS] = { "Show Markings", NULL },
1164#endif
1067 [SM_SAVE] = { "Save", NULL }, 1165 [SM_SAVE] = { "Save", NULL },
1068 [SM_RELOAD] = { "Reload", NULL }, 1166 [SM_RELOAD] = { "Reload", NULL },
1069 [SM_CLEAR] = { "Clear", NULL }, 1167 [SM_CLEAR] = { "Clear", NULL },
@@ -1088,6 +1186,12 @@ bool sudoku_menu(struct sudoku_state_t* state)
1088 numdisplay_setting(); 1186 numdisplay_setting();
1089 break; 1187 break;
1090#endif 1188#endif
1189
1190#ifdef SUDOKU_BUTTON_POSSIBLE
1191 case SM_SHOW_MARKINGS:
1192 showmarkings_setting();
1193 break;
1194#endif
1091 case SM_SAVE: 1195 case SM_SAVE:
1092 save_sudoku(state); 1196 save_sudoku(state);
1093 break; 1197 break;
@@ -1204,7 +1308,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame
1204 rb = api; 1308 rb = api;
1205 /* end of plugin init */ 1309 /* end of plugin init */
1206 1310
1207#ifdef HAVE_LCD_COLOR 1311#if defined(HAVE_LCD_COLOR) || defined(SUDOKU_BUTTON_POSSIBLE)
1208 configfile_init(rb); 1312 configfile_init(rb);
1209 configfile_load(cfg_filename, disk_config, 1313 configfile_load(cfg_filename, disk_config,
1210 sizeof(disk_config) / sizeof(disk_config[0]), 1314 sizeof(disk_config) / sizeof(disk_config[0]),
@@ -1438,7 +1542,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame
1438 1542
1439 display_board(&state); 1543 display_board(&state);
1440 } 1544 }
1441#ifdef HAVE_LCD_COLOR 1545#if defined(HAVE_LCD_COLOR) || defined(SUDOKU_BUTTON_POSSIBLE)
1442 if (rb->memcmp(&sudcfg, &sudcfg_disk, sizeof(sudcfg))) /* save settings if changed */ 1546 if (rb->memcmp(&sudcfg, &sudcfg_disk, sizeof(sudcfg))) /* save settings if changed */
1443 { 1547 {
1444 rb->memcpy(&sudcfg_disk, &sudcfg, sizeof(sudcfg)); 1548 rb->memcpy(&sudcfg_disk, &sudcfg, sizeof(sudcfg));