#ifdef HAVE_LCD_BITMAP /* Bubbles */ #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64) bubbles_emblem.112x64x1.bmp #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110) bubbles_emblem.138x110x2.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && !defined(HAVE_LCD_COLOR) bubbles_emblem.160x128x2.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && defined(HAVE_LCD_COLOR) bubbles_emblem.160x128x16.bmp bubbles_left.160x128x16.bmp bubbles_right.160x128x16.bmp #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) bubbles_emblem.160x128x16.bmp bubbles_left.176x132x16.bmp bubbles_right.176x132x16.bmp #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176) bubbles_emblem.220x176x16.bmp bubbles_left.220x176x16.bmp bubbles_right.220x176x16.bmp #elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320) bubbles_emblem.220x176x16.bmp bubbles_left.240x320x16.bmp bubbles_right.240x320x16.bmp #elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240) bubbles_emblem.320x240x16.bmp bubbles_left.320x240x16.bmp bubbles_right.320x240x16.bmp #endif /* ChessBox */ #if (LCD_WIDTH >= 240) && (LCD_HEIGHT >= 240) & (LCD_DEPTH >= 16) chessbox_pieces.240x240x16.bmp #elif (LCD_WIDTH >= 176) && (LCD_HEIGHT >= 176) & (LCD_DEPTH >= 16) chessbox_pieces.176x176x16.bmp #elif (LCD_WIDTH >= 128) && (LCD_HEIGHT >= 128) & (LCD_DEPTH > 1) chessbox_pieces.128x128x2.bmp #elif (LCD_WIDTH >= 128) && (LCD_HEIGHT >= 128) chessbox_pieces.128x128x1.bmp #elif (LCD_WIDTH >= 104) && (LCD_HEIGHT >= 104) & (LCD_DEPTH > 1) chessbox_pieces.104x104x2.bmp #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64) & (LCD_DEPTH == 1) chessbox_pieces.80x64x1.bmp #elif (LCD_WIDTH >= 64) && (LCD_HEIGHT >= 64) chessbox_pieces.64x64x1.bmp #endif /* Jewels */ #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64) jewels.112x64x1.bmp #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64) jewels.112x64x1.bmp #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110) jewels.138x110x1.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && !defined(HAVE_LCD_COLOR) jewels.160x128x1.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && defined(HAVE_LCD_COLOR) jewels.160x128x16.bmp #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) jewels.160x128x16.bmp #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176) jewels.220x176x16.bmp #elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320) jewels.220x176x16.bmp #elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240) jewels.320x240x16.bmp #endif /* Snake2 */ #if (LCD_WIDTH >= 320) && (LCD_HEIGHT >= 240) && (LCD_DEPTH >= 16) snake2_header1.320x240x16.bmp snake2_header2.320x240x16.bmp snake2_left.320x240x16.bmp snake2_right.320x240x16.bmp snake2_bottom.320x240x16.bmp #elif (LCD_WIDTH >= 240) && (LCD_HEIGHT >= 192) && (LCD_DEPTH >= 16) snake2_header1.240x320x16.bmp snake2_header2.240x320x16.bmp snake2_left.240x320x16.bmp snake2_right.240x320x16.bmp snake2_bottom.240x320x16.bmp #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH >= 16) snake2_header1.220x176x16.bmp snake2_header2.220x176x16.bmp snake2_left.220x176x16.bmp snake2_right.220x176x16.bmp snake2_bottom.220x176x16.bmp #elif (LCD_WIDTH >= 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH >= 16) snake2_header1.176x132x16.bmp snake2_header2.176x132x16.bmp snake2_left.176x132x16.bmp snake2_right.176x132x16.bmp snake2_bottom.176x132x16.bmp #elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >= 16) snake2_header1.160x128x16.bmp snake2_header2.160x128x16.bmp snake2_left.160x128x16.bmp snake2_right.160x128x16.bmp snake2_bottom.160x128x16.bmp #elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >= 1) snake2_header1.160x128x2.bmp snake2_header2.160x128x2.bmp snake2_left.160x128x2.bmp snake2_right.160x128x2.bmp snake2_bottom.160x128x2.bmp #endif /* Sokoban*/ #ifdef HAVE_LCD_COLOR #if LCD_HEIGHT >= 240 sokoban_tiles.14x14.bmp #elif LCD_HEIGHT >= 176 sokoban_tiles.9x9.bmp #else /* LCD_HEIGHT >= 128 */ sokoban_tiles.6x6.bmp #endif #elif LCD_DEPTH >= 2 sokoban_tiles.6x6x2.bmp #endif /* Flip it */ #ifdef HAVE_LCD_COLOR #if LCD_HEIGHT >= 200 flipit_tokens.50x50.bmp #elif LCD_HEIGHT >= 160 flipit_tokens.40x40.bmp #else flipit_tokens.30x30.bmp #endif #elif LCD_DEPTH >= 2 #if LCD_WIDTH >= 150 flipit_tokens.30x30x2.bmp #else flipit_tokens.20x20x2.bmp #endif #endif /* Star */ #if defined( HAVE_LCD_COLOR ) #if LCD_WIDTH >= 320 star_tiles.20x20.bmp #elif LCD_WIDTH >= 220 star_tiles.13x13.bmp #else star_tiles.10x10.bmp #endif #elif LCD_DEPTH > 1 star_tiles.10x10.grey.bmp #endif /* Solitaire */ #ifdef HAVE_LCD_COLOR #if (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) solitaire_cardback.220x176x16.bmp #else solitaire_cardback.176x132x16.bmp #endif #endif /* Sudoku */ #if LCD_WIDTH >= LCD_HEIGHT #if (LCD_WIDTH == 112) && (LCD_HEIGHT==64) && (LCD_DEPTH == 1) sudoku_start.112x64x1.bmp sudoku_normal.112x64x1.bmp sudoku_inverse.112x64x1.bmp #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110) && (LCD_DEPTH >= 2) sudoku_start.138x110x2.bmp sudoku_normal.138x110x2.bmp sudoku_inverse.138x110x2.bmp #elif ((LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && (LCD_DEPTH == 16)) || \ ((LCD_WIDTH == 176) && (LCD_HEIGHT == 132) && (LCD_DEPTH == 16)) sudoku_start.160x128x16.bmp sudoku_normal.160x128x16.bmp sudoku_inverse.160x128x16.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && (LCD_DEPTH >= 2) sudoku_start.160x128x2.bmp sudoku_normal.160x128x2.bmp sudoku_inverse.160x128x2.bmp #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176) && (LCD_DEPTH == 16) sudoku_start.220x176x16.bmp sudoku_normal.220x176x16.bmp sudoku_inverse.220x176x16.bmp #elif (LCD_WIDTH >= 320) && (LCD_HEIGHT >= 240) && (LCD_DEPTH == 16) sudoku_start.320x240x16.bmp sudoku_normal.320x240x16.bmp sudoku_inverse.320x240x16.bmp #endif #else #if (LCD_WIDTH >= 240) && (LCD_HEIGHT >= 320) && (LCD_DEPTH == 16) sudoku_start.320x240x16.bmp sudoku_normal.320x240x16.bmp sudoku_inverse.320x240x16.bmp #endif #endif /* Brickmania */ #if (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16) #if (LCD_WIDTH == 320) brickmania_menu_bg.320x240x16.bmp #else brickmania_menu_bg.220x176x16.bmp #endif brickmania_menu_items.220x176x16.bmp brickmania_ball.220x176x16.bmp brickmania_bricks.220x176x16.bmp brickmania_gameover.220x176x16.bmp brickmania_pads.220x176x16.bmp brickmania_powerups.220x176x16.bmp brickmania_break.220x176x16.bmp #elif (((LCD_WIDTH == 160) && (LCD_HEIGHT == 128)) || \ ((LCD_WIDTH == 138) && (LCD_HEIGHT == 110))) && (LCD_DEPTH == 2) brickmania_menu_items.160x128x2.bmp brickmania_ball.160x128x2.bmp #if (LCD_WIDTH == 160) brickmania_bricks.160x128x2.bmp #else brickmania_bricks.138x110x2.bmp #endif brickmania_gameover.160x128x2.bmp brickmania_menu_bg.160x128x2.bmp brickmania_pads.160x128x2.bmp brickmania_powerups.160x128x2.bmp brickmania_break.160x128x2.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && (LCD_DEPTH == 16) brickmania_menu_items.160x128x16.bmp brickmania_ball.160x128x16.bmp brickmania_bricks.160x128x16.bmp brickmania_gameover.160x128x16.bmp brickmania_menu_bg.160x128x16.bmp brickmania_pads.160x128x16.bmp brickmania_powerups.160x128x16.bmp brickmania_break.160x128x16.bmp #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) && (LCD_DEPTH == 16) brickmania_menu_items.176x132x16.bmp brickmania_ball.176x132x16.bmp brickmania_bricks.176x132x16.bmp brickmania_gameover.176x132x16.bmp brickmania_menu_bg.176x132x16.bmp brickmania_pads.176x132x16.bmp brickmania_powerups.176x132x16.bmp brickmania_break.176x132x16.bmp #endif /* Tetrox */ #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240) && (LCD_DEPTH == 16) tetrox_background.320x240x16.bmp #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16) tetrox_background.220x176x16.bmp #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) && (LCD_DEPTH == 16) tetrox_background.176x132x16.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && (LCD_DEPTH >= 16) tetrox_background.160x128x16.bmp #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128) && (LCD_DEPTH == 16) tetrox_background.128x128x16.bmp #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128) && (LCD_DEPTH == 2) tetrox_background.160x128x2.bmp #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110) && (LCD_DEPTH == 2) tetrox_background.138x110x2.bmp #endif #ifdef HAVE_LCD_COLOR /* Rockpaint */ rockpaint.bmp rockpaint_hsvrgb.bmp #endif #if defined( HAVE_LCD_COLOR ) #if ( LCD_HEIGHT * LCD_WIDTH ) / ( 16 * 16 ) >= 130 minesweeper_tiles.16x16x24.bmp #else minesweeper_tiles.12x12x24.bmp #endif #elif LCD_DEPTH > 1 minesweeper_tiles.12x12x2.bmp #else minesweeper_tiles.8x8x1.bmp #endif #endif /* HAVE_LCD_BITMAP */ ref='#n169'>169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id: flipit.c,v 1.0 2003/01/18 23:51:47
*
* Copyright (C) 2002 Vicentini Martin
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#ifdef HAVE_LCD_BITMAP
PLUGIN_HEADER
/* variable button definitions */
#if CONFIG_KEYPAD == RECORDER_PAD
#define FLIPIT_UP BUTTON_UP
#define FLIPIT_DOWN BUTTON_DOWN
#define FLIPIT_QUIT BUTTON_OFF
#define FLIPIT_SHUFFLE BUTTON_F1
#define FLIPIT_SOLVE BUTTON_F2
#define FLIPIT_STEP_BY_STEP BUTTON_F3
#define FLIPIT_TOGGLE BUTTON_PLAY
#elif CONFIG_KEYPAD == ONDIO_PAD
#define FLIPIT_UP BUTTON_UP
#define FLIPIT_DOWN BUTTON_DOWN
#define FLIPIT_QUIT BUTTON_OFF
#define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT)
#define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP)
#define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT)
#define FLIPIT_TOGGLE_PRE BUTTON_MENU
#define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL)
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
(CONFIG_KEYPAD == IRIVER_H300_PAD)
#define FLIPIT_UP BUTTON_UP
#define FLIPIT_DOWN BUTTON_DOWN
#define FLIPIT_QUIT BUTTON_OFF
#define FLIPIT_SHUFFLE BUTTON_MODE
#define FLIPIT_SOLVE BUTTON_ON
#define FLIPIT_STEP_BY_STEP BUTTON_REC
#define FLIPIT_TOGGLE_PRE BUTTON_SELECT
#define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
#define FLIPIT_RC_QUIT BUTTON_RC_STOP
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
(CONFIG_KEYPAD == IPOD_3G_PAD)
#define FLIPIT_UP BUTTON_MENU
#define FLIPIT_DOWN BUTTON_PLAY
#define FLIPIT_QUIT (BUTTON_SELECT | BUTTON_MENU)
#define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
#define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_PLAY)
#define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_RIGHT)
#define FLIPIT_TOGGLE_PRE BUTTON_SELECT
#define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
#define FLIPIT_UP BUTTON_UP
#define FLIPIT_DOWN BUTTON_DOWN
#define FLIPIT_QUIT BUTTON_POWER
#define FLIPIT_SHUFFLE (BUTTON_PLAY | BUTTON_LEFT)
#define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_RIGHT)
#define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_UP)
#define FLIPIT_TOGGLE_PRE BUTTON_SELECT
#define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
#define FLIPIT_UP BUTTON_UP
#define FLIPIT_DOWN BUTTON_DOWN
#define FLIPIT_QUIT BUTTON_A
#define FLIPIT_SHUFFLE (BUTTON_POWER | BUTTON_LEFT)
#define FLIPIT_SOLVE (BUTTON_POWER | BUTTON_RIGHT)
#define FLIPIT_STEP_BY_STEP (BUTTON_POWER | BUTTON_UP)
#define FLIPIT_TOGGLE_PRE BUTTON_MENU
#define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL)
#endif
static struct plugin_api* rb;
static int spots[20];
static int toggle[20];
static int cursor_pos, moves;
static char s[5];
#if LCD_DEPTH >= 2
#ifdef HAVE_LCD_COLOR
#if LCD_HEIGHT >= 200
#define tksize 50
#elif LCD_HEIGHT >=160
#define tksize 40
#else
#define tksize 30
#endif
#else
#if LCD_WIDTH >= 150
#define tksize 30
#else
#define tksize 20
#endif
#endif
extern const fb_data flipit_tokens[];
#else
static char *ptr;
#define tksize 16
static unsigned char spot_pic[2][28] = {
{ 0xe0, 0xf8, 0xfc, 0xfe, 0xfe, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xf8, 0xe0,
0x01, 0x07, 0x0f, 0x1f, 0x1f, 0x3f, 0x3f,
0x3f, 0x3f, 0x1f, 0x1f, 0x0f, 0x07, 0x01 },
{ 0xe0, 0x18, 0x04, 0x02, 0x02, 0x01, 0x01,
0x01, 0x01, 0x02, 0x02, 0x04, 0x18, 0xe0,
0x01, 0x06, 0x08, 0x10, 0x10, 0x20, 0x20,
0x20, 0x20, 0x10, 0x10, 0x08, 0x06, 0x01 }
};
static unsigned char cursor_pic[32] = {
0x55, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xaa,
0x55, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa };
#endif
#define INFO_WIDTH 32
#if LCD_WIDTH - 5*tksize - INFO_WIDTH < 0
# define INFO_UNDER
# undef INFO_WIDTH
# define INFO_WIDTH 60
# define GRID_LEFT ((LCD_WIDTH-5*tksize)/2)
# define GRID_TOP 0
#else
# define GRID_LEFT 0
# define GRID_TOP ((LCD_HEIGHT-4*tksize)/2)
#endif
/* draw a spot at the coordinates (x,y), range of p is 0-19 */
static void draw_spot(int p) {
#if LCD_DEPTH >= 2
rb->lcd_bitmap_part( flipit_tokens, 0, spots[p]*tksize, tksize,
(p%5)*tksize+GRID_LEFT, (p/5)*tksize+GRID_TOP,
tksize, tksize );
#else
ptr = spot_pic[spots[p]];
rb->lcd_mono_bitmap (ptr, (p%5)*16+1, (p/5)*16+1, 14, 8);
ptr += 14;
rb->lcd_mono_bitmap (ptr, (p%5)*16+1, (p/5)*16+9, 14, 6);
#endif
}
/* draw the cursor at the current cursor position */
static void draw_cursor(void) {
#ifdef HAVE_LCD_COLOR
rb->lcd_bitmap_transparent_part( flipit_tokens, 0, 2*tksize, tksize,
(cursor_pos%5)*tksize+GRID_LEFT,
(cursor_pos/5)*tksize+GRID_TOP,
tksize, tksize );
#elif LCD_DEPTH >= 2
/* grayscale doesn't have transparent bitmap ... */
int i,j;
i = ( cursor_pos%5 )*tksize;
j = ( cursor_pos/5 )*tksize;
rb->lcd_set_drawmode( DRMODE_SOLID );
rb->lcd_drawline( i+GRID_LEFT, j+GRID_TOP,
i+tksize-1+GRID_LEFT, j+GRID_TOP );
rb->lcd_drawline( i+GRID_LEFT, j+tksize-1+GRID_TOP,
i+tksize-1+GRID_LEFT, j+tksize-1+GRID_TOP );
rb->lcd_drawline( i+GRID_LEFT, j+GRID_TOP,
i+GRID_LEFT, j+tksize-1+GRID_TOP );
rb->lcd_drawline( i+tksize-1+GRID_LEFT, j+GRID_TOP,
i+tksize-1+GRID_LEFT, j+tksize-1+GRID_TOP );
#else
int i,j;
i = (cursor_pos%5)*16;
j = (cursor_pos/5)*16;
rb->lcd_set_drawmode(DRMODE_FG);
ptr = cursor_pic;
rb->lcd_mono_bitmap (ptr, i, j, 16, 8);
ptr += 16;
rb->lcd_mono_bitmap (ptr, i, j+8, 16, 8);
rb->lcd_set_drawmode(DRMODE_SOLID);
#endif
}
/* clear the cursor where it is */
static void clear_cursor(void) {
#if LCD_DEPTH >= 2
draw_spot( cursor_pos );
#else
int i,j;
i = (cursor_pos%5)*16;
j = (cursor_pos/5)*16;
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_drawline(i, j, i+15, j);
rb->lcd_drawline(i, j+15, i+15, j+15);
rb->lcd_drawline(i, j, i, j+15);
rb->lcd_drawline(i+15, j, i+15, j+15);
rb->lcd_set_drawmode(DRMODE_SOLID);
#endif
}
/* draw the info panel ... duh */
static void draw_info_panel(void)
{
#ifdef INFO_UNDER
# define HEIGHT ( LCD_HEIGHT - 4*tksize )
# define LEFT ( ( LCD_WIDTH - INFO_WIDTH ) / 2 )
# define TOP ( LCD_HEIGHT - HEIGHT )
#else
# define HEIGHT 64
# define LEFT ( LCD_WIDTH - (LCD_WIDTH- 5*tksize-INFO_WIDTH)/2 - INFO_WIDTH )
# define TOP ( ( LCD_HEIGHT - HEIGHT ) / 2 )
#endif
rb->lcd_set_drawmode( DRMODE_SOLID|DRMODE_INVERSEVID );
rb->lcd_fillrect( LEFT, TOP, INFO_WIDTH, HEIGHT );
rb->lcd_set_drawmode( DRMODE_SOLID );
rb->lcd_drawrect( LEFT, TOP, INFO_WIDTH, HEIGHT );
#ifdef INFO_UNDER
rb->lcd_putsxy( LEFT+1, TOP+1, "Flips" );
#else
rb->lcd_putsxy( LEFT+1, TOP+10, "Flips" );
#endif
rb->snprintf( s, sizeof(s), "%d", moves );
#ifdef INFO_UNDER
rb->lcd_putsxy( LEFT+32, TOP+1, s );
#else
rb->lcd_putsxy( LEFT+1, TOP+20, s );
#endif
# undef HEIGHT
# undef LEFT
# undef TOP
}
/* check if the puzzle is finished */
static bool flipit_finished(void) {
int i;
for (i=0; i<20; i++)
if (!spots[i])
return false;
clear_cursor();
return true;
}
/* draws the toggled spots */
static void flipit_toggle(void) {
spots[cursor_pos] = 1-spots[cursor_pos];
toggle[cursor_pos] = 1-toggle[cursor_pos];
draw_spot(cursor_pos);
if (cursor_pos%5 > 0) {
spots[cursor_pos-1] = 1-spots[cursor_pos-1];
draw_spot(cursor_pos-1);
}
if (cursor_pos%5 < 4) {
spots[cursor_pos+1] = 1-spots[cursor_pos+1];
draw_spot(cursor_pos+1);
}
if (cursor_pos/5 > 0) {
spots[cursor_pos-5] = 1-spots[cursor_pos-5];
draw_spot(cursor_pos-5);
}
if (cursor_pos/5 < 3) {
spots[cursor_pos+5] = 1-spots[cursor_pos+5];
draw_spot(cursor_pos+5);
}
moves++;
draw_info_panel();
if (flipit_finished())
clear_cursor();
}
/* move the cursor in any direction */
static void move_cursor(int x, int y) {
if (!(flipit_finished())) {
clear_cursor();
cursor_pos = ( x + 5 + cursor_pos%5 )%5
+ ( ( y + 4 + cursor_pos/5 )%4 )*5;
draw_cursor();
}
rb->lcd_update();
}
/* initialize the board */
static void flipit_init(void) {
int i;
rb->lcd_clear_display();
moves = 0;
for (i=0; i<20; i++) {
spots[i]=1;
toggle[i]=1;
draw_spot(i);
}
rb->lcd_update();
for (i=0; i<20; i++) {
cursor_pos = (rb->rand() % 20);
flipit_toggle();
}
cursor_pos = 0;
draw_cursor();
moves = 0;
draw_info_panel();
rb->lcd_update();
}
/* the main game loop */
static bool flipit_loop(void) {
int i;
int button;
int lastbutton = BUTTON_NONE;
flipit_init();
while(true) {
button = rb->button_get(true);
switch (button) {
#ifdef FLIPIT_RC_QUIT
case FLIPIT_RC_QUIT:
#endif
case FLIPIT_QUIT:
/* get out of here */
return PLUGIN_OK;
case FLIPIT_SHUFFLE:
/* mix up the pieces */
flipit_init();
break;
case FLIPIT_SOLVE:
/* solve the puzzle */
if (!flipit_finished()) {
for (i=0; i<20; i++)
if (!toggle[i]) {
clear_cursor();
cursor_pos = i;
flipit_toggle();
draw_cursor();
rb->lcd_update();
rb->sleep(HZ*2/3);
}
}
break;
case FLIPIT_STEP_BY_STEP:
if (!flipit_finished()) {
for (i=0; i<20; i++)
if (!toggle[i]) {
clear_cursor();
cursor_pos = i;
flipit_toggle();
draw_cursor();
rb->lcd_update();
break;
}
}
break;
case FLIPIT_TOGGLE:
#ifdef FLIPIT_TOGGLE_PRE
if (lastbutton != FLIPIT_TOGGLE_PRE)
break;
#endif
/* toggle the pieces */
if (!flipit_finished()) {
flipit_toggle();
#if LCD_DEPTH >= 2
draw_cursor();
#endif
rb->lcd_update();
}
break;
case BUTTON_LEFT:
move_cursor(-1, 0);
break;
case BUTTON_RIGHT:
move_cursor(1, 0);
break;
case FLIPIT_UP:
move_cursor(0, -1);
break;
case FLIPIT_DOWN:
move_cursor(0, 1);
break;
default:
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
return PLUGIN_USB_CONNECTED;
break;
}
if (button != BUTTON_NONE)
lastbutton = button;
}
}
/* called function from outside */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
int w, h, i;
(void)parameter;
rb = api;
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_WHITE);
#endif
/* print title */
rb->lcd_getstringsize("FlipIt!", &w, &h);
w = (w+1)/2;
h = (h+1)/2;
rb->lcd_clear_display();
rb->lcd_putsxy(LCD_WIDTH/2-w, (LCD_HEIGHT/2)-h, "FlipIt!");
rb->lcd_update();
rb->sleep(HZ);
/* print instructions */
rb->lcd_clear_display();
rb->lcd_setfont(FONT_SYSFIXED);
#if CONFIG_KEYPAD == RECORDER_PAD
rb->lcd_putsxy(2, 8, "[OFF] to stop");
rb->lcd_putsxy(2, 18, "[PLAY] toggle");
rb->lcd_putsxy(2, 28, "[F1] shuffle");
rb->lcd_putsxy(2, 38, "[F2] solution");
rb->lcd_putsxy(2, 48, "[F3] step by step");
#elif CONFIG_KEYPAD == ONDIO_PAD
rb->lcd_putsxy(2, 8, "[OFF] to stop");
rb->lcd_putsxy(2, 18, "[MODE] toggle");
rb->lcd_putsxy(2, 28, "[M-LEFT] shuffle");
rb->lcd_putsxy(2, 38, "[M-UP] solution");
rb->lcd_putsxy(2, 48, "[M-RIGHT] step by step");
#elif CONFIG_KEYPAD == IRIVER_H100_PAD
rb->lcd_putsxy(2, 8, "[STOP] to stop");
rb->lcd_putsxy(2, 18, "[SELECT] toggle");
rb->lcd_putsxy(2, 28, "[MODE] shuffle");
rb->lcd_putsxy(2, 38, "[PLAY] solution");
rb->lcd_putsxy(2, 48, "[REC] step by step");
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
(CONFIG_KEYPAD == IPOD_4G_PAD)
rb->lcd_putsxy(2, 8, "[S-MENU] to stop");
rb->lcd_putsxy(2, 18, "[SELECT] toggle");
rb->lcd_putsxy(2, 28, "[S-LEFT] shuffle");
rb->lcd_putsxy(2, 38, "[S-PLAY] solution");
rb->lcd_putsxy(2, 48, "[S-RIGHT] step by step");
#endif
rb->lcd_update();
rb->button_get_w_tmo(HZ*3);
rb->lcd_clear_display();
draw_info_panel();
for (i=0; i<20; i++) {
spots[i]=1;
draw_spot(i);
}
rb->lcd_update();
rb->sleep(HZ*3/2);
rb->srand(*rb->current_tick);
return flipit_loop();
}
#endif