Index: apps/plugins/sudoku/sudoku.c =================================================================== --- apps/plugins/sudoku/sudoku.c (revision 15968) +++ apps/plugins/sudoku/sudoku.c (working copy) @@ -107,6 +107,9 @@ #define CELL_WIDTH 8 #define CELL_HEIGHT 6 #define SMALL_BOARD +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 1 /* Pixels between two marks */ +#define MARK_SIZE 1 /* Mark width and height */ #elif ((LCD_HEIGHT==80) && (LCD_WIDTH==132)) /* C200, 9 cells @ 8x8 with 8 border lines */ @@ -115,6 +118,9 @@ #define CELL_WIDTH 8 #define CELL_HEIGHT 8 #define SMALL_BOARD +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 1 /* Pixels between two marks */ +#define MARK_SIZE 1 /* Mark width and height */ #elif (LCD_HEIGHT==110) && (LCD_WIDTH==138) /* iPod Mini - 138x110, 9 cells @ 10x10 with 14 border lines */ @@ -122,6 +128,9 @@ /* Internal dimensions of a cell */ #define CELL_WIDTH 10 #define CELL_HEIGHT 10 +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 1 /* Pixels between two marks */ +#define MARK_SIZE 2 /* Mark width and height */ #elif (LCD_HEIGHT==128) && (LCD_WIDTH==128) /* iriver H10 5-6GB - 128x128, 9 cells @ 10x10 with 14 border lines */ @@ -129,6 +138,9 @@ /* Internal dimensions of a cell */ #define CELL_WIDTH 10 #define CELL_HEIGHT 10 +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 1 /* Pixels between two marks */ +#define MARK_SIZE 2 /* Mark width and height */ #elif ((LCD_HEIGHT==128) && (LCD_WIDTH==160)) || \ ((LCD_HEIGHT==132) && (LCD_WIDTH==176)) @@ -138,6 +150,9 @@ /* Internal dimensions of a cell */ #define CELL_WIDTH 12 #define CELL_HEIGHT 12 +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 2 /* Pixels between two marks */ +#define MARK_SIZE 2 /* Mark width and height */ #elif ((LCD_HEIGHT==176) && (LCD_WIDTH==220)) /* Iriver h300, iPod Color/Photo - 220x176, 9 cells @ 16x16 with 14 border lines */ @@ -145,6 +160,9 @@ /* Internal dimensions of a cell */ #define CELL_WIDTH 16 #define CELL_HEIGHT 16 +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 1 /* Pixels between two marks */ +#define MARK_SIZE 4 /* Mark width and height */ #elif (LCD_HEIGHT>=240) && (LCD_WIDTH>=320) /* iPod Video - 320x240, 9 cells @ 24x24 with 14 border lines */ @@ -152,6 +170,9 @@ /* Internal dimensions of a cell */ #define CELL_WIDTH 24 #define CELL_HEIGHT 24 +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 2 /* Pixels between two marks */ +#define MARK_SIZE 6 /* Mark width and height */ #else #error SUDOKU: Unsupported LCD size @@ -166,6 +187,9 @@ /* Internal dimensions of a cell */ #define CELL_WIDTH 16 #define CELL_HEIGHT 16 +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 1 /* Pixels between two marks */ +#define MARK_SIZE 4 /* Mark width and height */ #elif (LCD_HEIGHT>=320) && (LCD_WIDTH>=240) /* Gigabeat - 240x320, 9 cells @ 24x24 with 14 border lines */ @@ -173,6 +197,9 @@ /* Internal dimensions of a cell */ #define CELL_WIDTH 24 #define CELL_HEIGHT 24 +#define MARK_OFFS 1 /* Pixels between border and mark */ +#define MARK_SPACE 2 /* Pixels between two marks */ +#define MARK_SIZE 6 /* Mark width and height */ #else #error SUDOKU: Unsupported LCD size @@ -183,20 +210,23 @@ #define CFGFILE_VERSION 0 /* Current config file version */ #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */ -#ifdef HAVE_LCD_COLOR /* settings */ struct sudoku_config { int number_display; + int show_markings; }; -struct sudoku_config sudcfg_disk = { 0 }; +struct sudoku_config sudcfg_disk = { 0, 1 }; struct sudoku_config sudcfg; static const char cfg_filename[] = "sudoku.cfg"; static char *number_str[2] = { "black", "coloured" }; +static char *mark_str[2] = { "hide", "show" }; struct configdata disk_config[] = { { TYPE_ENUM, 0, 2, &sudcfg_disk.number_display, "numbers", number_str, NULL }, + { TYPE_ENUM, 0, 2, &sudcfg_disk.show_markings, "markings", mark_str, NULL }, }; +#ifdef HAVE_LCD_COLOR #define NUMBER_TYPE (sudcfg.number_display*CELL_WIDTH) #else #define NUMBER_TYPE 0 @@ -825,7 +855,7 @@ void display_board(struct sudoku_state_t* state) { - int r,c; + int r,c,i; /* Clear the display buffer */ rb->lcd_clear_display(); @@ -981,6 +1011,20 @@ XOFS+cellxpos[c],YOFS+cellypos[r], CELL_WIDTH,CELL_HEIGHT); } + +#ifdef SUDOKU_BUTTON_POSSIBLE + /* Draw the possible number markings on the board */ + if(sudcfg.show_markings && state->startboard[r][c]=='0' && state->currentboard[r][c]=='0') { + for(i=0;i<9;i++) { + if(state->possiblevals[r][c]&(2<lcd_fillrect(XOFS+cellxpos[c]+MARK_OFFS+(i%3)*(MARK_SIZE+MARK_SPACE), + YOFS+cellypos[r]+MARK_OFFS+(i/3)*(MARK_SIZE+MARK_SPACE), + MARK_SIZE, + MARK_SIZE); + } + } + } +#endif /* SUDOKU_BUTTON_POSSIBLE */ } } } @@ -1036,11 +1080,27 @@ } #endif +#ifdef SUDOKU_BUTTON_POSSIBLE +static bool showmarkings_setting(void) +{ + static const struct opt_items names[] = { + {"Hide", -1}, + {"Show", -1}, + }; + + return rb->set_option("Show Markings", &sudcfg.show_markings, INT, names, + sizeof(names) / sizeof(names[0]), NULL); +} +#endif + enum { SM_AUDIO_PLAYBACK = 0, #ifdef HAVE_LCD_COLOR SM_NUMBER_DISPLAY, #endif +#ifdef SUDOKU_BUTTON_POSSIBLE + SM_SHOW_MARKINGS, +#endif SM_SAVE, SM_RELOAD, SM_CLEAR, @@ -1060,6 +1120,9 @@ #ifdef HAVE_LCD_COLOR [SM_NUMBER_DISPLAY] = { "Number Display", NULL }, #endif +#ifdef SUDOKU_BUTTON_POSSIBLE + [SM_SHOW_MARKINGS] = { "Show Markings", NULL }, +#endif [SM_SAVE] = { "Save", NULL }, [SM_RELOAD] = { "Reload", NULL }, [SM_CLEAR] = { "Clear", NULL }, @@ -1084,6 +1147,12 @@ numdisplay_setting(); break; #endif + +#ifdef SUDOKU_BUTTON_POSSIBLE + case SM_SHOW_MARKINGS: + showmarkings_setting(); + break; +#endif case SM_SAVE: save_sudoku(state); break; @@ -1200,13 +1269,11 @@ rb = api; /* end of plugin init */ -#ifdef HAVE_LCD_COLOR configfile_init(rb); configfile_load(cfg_filename, disk_config, sizeof(disk_config) / sizeof(disk_config[0]), CFGFILE_MINVERSION); rb->memcpy(&sudcfg, &sudcfg_disk, sizeof(sudcfg)); /* copy to running config */ -#endif #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); @@ -1434,7 +1501,7 @@ display_board(&state); } -#ifdef HAVE_LCD_COLOR + if (rb->memcmp(&sudcfg, &sudcfg_disk, sizeof(sudcfg))) /* save settings if changed */ { rb->memcpy(&sudcfg_disk, &sudcfg, sizeof(sudcfg)); @@ -1442,7 +1509,7 @@ sizeof(disk_config) / sizeof(disk_config[0]), CFGFILE_VERSION); } -#endif + return rc; }