Fix yellow.
[kugel-rb.git] / apps / plugins / flipit.c
bloba837b1a64e8c535f16f15f5b5593cd1f2ed09355
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Vicentini Martin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "plugin.h"
25 /* variable button definitions */
26 #if CONFIG_KEYPAD == RECORDER_PAD
27 #define FLIPIT_LEFT BUTTON_LEFT
28 #define FLIPIT_RIGHT BUTTON_RIGHT
29 #define FLIPIT_UP BUTTON_UP
30 #define FLIPIT_DOWN BUTTON_DOWN
31 #define FLIPIT_QUIT BUTTON_OFF
32 #define FLIPIT_SHUFFLE BUTTON_F1
33 #define FLIPIT_SOLVE BUTTON_F2
34 #define FLIPIT_STEP_BY_STEP BUTTON_F3
35 #define FLIPIT_TOGGLE BUTTON_PLAY
37 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
38 #define FLIPIT_LEFT BUTTON_LEFT
39 #define FLIPIT_RIGHT BUTTON_RIGHT
40 #define FLIPIT_UP BUTTON_UP
41 #define FLIPIT_DOWN BUTTON_DOWN
42 #define FLIPIT_QUIT BUTTON_OFF
43 #define FLIPIT_SHUFFLE BUTTON_F1
44 #define FLIPIT_SOLVE BUTTON_F2
45 #define FLIPIT_STEP_BY_STEP BUTTON_F3
46 #define FLIPIT_TOGGLE BUTTON_SELECT
48 #elif CONFIG_KEYPAD == PLAYER_PAD
49 #define FLIPIT_LEFT BUTTON_LEFT
50 #define FLIPIT_RIGHT BUTTON_RIGHT
51 #define FLIPIT_UP_PRE BUTTON_ON
52 #define FLIPIT_UP (BUTTON_ON | BUTTON_REL)
53 #define FLIPIT_DOWN BUTTON_MENU
54 #define FLIPIT_QUIT BUTTON_STOP
55 #define FLIPIT_SHUFFLE (BUTTON_ON | BUTTON_LEFT)
56 #define FLIPIT_SOLVE (BUTTON_ON | BUTTON_RIGHT)
57 #define FLIPIT_STEP_BY_STEP (BUTTON_ON | BUTTON_PLAY)
58 #define FLIPIT_TOGGLE BUTTON_PLAY
60 #elif CONFIG_KEYPAD == ONDIO_PAD
61 #define FLIPIT_LEFT BUTTON_LEFT
62 #define FLIPIT_RIGHT BUTTON_RIGHT
63 #define FLIPIT_UP BUTTON_UP
64 #define FLIPIT_DOWN BUTTON_DOWN
65 #define FLIPIT_QUIT BUTTON_OFF
66 #define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT)
67 #define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP)
68 #define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT)
69 #define FLIPIT_TOGGLE_PRE BUTTON_MENU
70 #define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL)
72 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
73 (CONFIG_KEYPAD == IRIVER_H300_PAD)
74 #define FLIPIT_LEFT BUTTON_LEFT
75 #define FLIPIT_RIGHT BUTTON_RIGHT
76 #define FLIPIT_UP BUTTON_UP
77 #define FLIPIT_DOWN BUTTON_DOWN
78 #define FLIPIT_QUIT BUTTON_OFF
79 #define FLIPIT_SHUFFLE BUTTON_MODE
80 #define FLIPIT_SOLVE BUTTON_ON
81 #define FLIPIT_STEP_BY_STEP BUTTON_REC
82 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
83 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
85 #define FLIPIT_RC_QUIT BUTTON_RC_STOP
87 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
88 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
89 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
91 #define FLIPIT_SCROLLWHEEL
92 #define FLIPIT_LEFT BUTTON_LEFT
93 #define FLIPIT_RIGHT BUTTON_RIGHT
94 #define FLIPIT_UP BUTTON_MENU
95 #define FLIPIT_DOWN BUTTON_PLAY
96 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
97 #define FLIPIT_PREV BUTTON_SCROLL_BACK
98 #define FLIPIT_QUIT (BUTTON_SELECT | BUTTON_MENU)
99 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
100 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_PLAY)
101 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_RIGHT)
102 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
103 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
105 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
107 #define FLIPIT_LEFT BUTTON_LEFT
108 #define FLIPIT_RIGHT BUTTON_RIGHT
109 #define FLIPIT_UP BUTTON_UP
110 #define FLIPIT_DOWN BUTTON_DOWN
111 #define FLIPIT_QUIT BUTTON_POWER
112 #define FLIPIT_SHUFFLE BUTTON_REC
113 #define FLIPIT_SOLVE_PRE BUTTON_PLAY
114 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_REPEAT)
115 #define FLIPIT_STEP_PRE BUTTON_PLAY
116 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_REL)
117 #define FLIPIT_TOGGLE BUTTON_SELECT
119 #elif CONFIG_KEYPAD == GIGABEAT_PAD
121 #define FLIPIT_LEFT BUTTON_LEFT
122 #define FLIPIT_RIGHT BUTTON_RIGHT
123 #define FLIPIT_UP BUTTON_UP
124 #define FLIPIT_DOWN BUTTON_DOWN
125 #define FLIPIT_QUIT BUTTON_POWER
126 #define FLIPIT_SHUFFLE BUTTON_MENU
127 #define FLIPIT_SOLVE BUTTON_VOL_UP
128 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
129 #define FLIPIT_TOGGLE BUTTON_SELECT
131 #elif CONFIG_KEYPAD == SANSA_E200_PAD
133 #define FLIPIT_SCROLLWHEEL
134 #define FLIPIT_LEFT BUTTON_LEFT
135 #define FLIPIT_RIGHT BUTTON_RIGHT
136 #define FLIPIT_UP BUTTON_UP
137 #define FLIPIT_DOWN BUTTON_DOWN
138 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
139 #define FLIPIT_PREV BUTTON_SCROLL_BACK
140 #define FLIPIT_QUIT BUTTON_POWER
141 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
142 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
143 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
144 #define FLIPIT_TOGGLE BUTTON_SELECT
146 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
148 #define FLIPIT_SCROLLWHEEL
149 #define FLIPIT_LEFT BUTTON_LEFT
150 #define FLIPIT_RIGHT BUTTON_RIGHT
151 #define FLIPIT_UP BUTTON_UP
152 #define FLIPIT_DOWN BUTTON_DOWN
153 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
154 #define FLIPIT_PREV BUTTON_SCROLL_BACK
155 #define FLIPIT_QUIT (BUTTON_HOME|BUTTON_REPEAT)
156 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
157 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_DOWN)
158 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_RIGHT)
159 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
160 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
162 #elif CONFIG_KEYPAD == SANSA_C200_PAD
164 #define FLIPIT_LEFT BUTTON_LEFT
165 #define FLIPIT_RIGHT BUTTON_RIGHT
166 #define FLIPIT_UP BUTTON_UP
167 #define FLIPIT_DOWN BUTTON_DOWN
168 #define FLIPIT_QUIT BUTTON_POWER
169 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
170 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
171 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
172 #define FLIPIT_TOGGLE BUTTON_SELECT
174 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
176 #define FLIPIT_LEFT BUTTON_LEFT
177 #define FLIPIT_RIGHT BUTTON_RIGHT
178 #define FLIPIT_UP BUTTON_UP
179 #define FLIPIT_DOWN BUTTON_DOWN
180 #define FLIPIT_QUIT BUTTON_POWER
181 #define FLIPIT_SHUFFLE (BUTTON_HOME | BUTTON_LEFT)
182 #define FLIPIT_SOLVE (BUTTON_HOME | BUTTON_RIGHT)
183 #define FLIPIT_STEP_BY_STEP (BUTTON_HOME | BUTTON_SELECT)
184 #define FLIPIT_TOGGLE BUTTON_SELECT
186 #elif CONFIG_KEYPAD == SANSA_M200_PAD
188 #define FLIPIT_LEFT BUTTON_LEFT
189 #define FLIPIT_RIGHT BUTTON_RIGHT
190 #define FLIPIT_UP BUTTON_UP
191 #define FLIPIT_DOWN BUTTON_DOWN
192 #define FLIPIT_QUIT BUTTON_POWER
193 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
194 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_RIGHT)
195 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_UP)
196 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
198 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
200 #define FLIPIT_LEFT BUTTON_LEFT
201 #define FLIPIT_RIGHT BUTTON_RIGHT
202 #define FLIPIT_UP BUTTON_SCROLL_UP
203 #define FLIPIT_DOWN BUTTON_SCROLL_DOWN
204 #define FLIPIT_QUIT BUTTON_POWER
205 #define FLIPIT_SHUFFLE (BUTTON_PLAY | BUTTON_LEFT)
206 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_RIGHT)
207 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_SCROLL_UP)
208 #define FLIPIT_TOGGLE_PRE BUTTON_REW
209 #define FLIPIT_TOGGLE (BUTTON_REW | BUTTON_REL)
211 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
213 #define FLIPIT_LEFT BUTTON_LEFT
214 #define FLIPIT_RIGHT BUTTON_RIGHT
215 #define FLIPIT_UP BUTTON_UP
216 #define FLIPIT_DOWN BUTTON_DOWN
217 #define FLIPIT_QUIT BUTTON_BACK
218 #define FLIPIT_SHUFFLE BUTTON_MENU
219 #define FLIPIT_SOLVE BUTTON_VOL_UP
220 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
221 #define FLIPIT_TOGGLE BUTTON_SELECT
223 #elif CONFIG_KEYPAD == MROBE100_PAD
225 #define FLIPIT_LEFT BUTTON_LEFT
226 #define FLIPIT_RIGHT BUTTON_RIGHT
227 #define FLIPIT_UP BUTTON_UP
228 #define FLIPIT_DOWN BUTTON_DOWN
229 #define FLIPIT_QUIT BUTTON_POWER
230 #define FLIPIT_SHUFFLE BUTTON_MENU
231 #define FLIPIT_SOLVE BUTTON_PLAY
232 #define FLIPIT_STEP_BY_STEP BUTTON_DISPLAY
233 #define FLIPIT_TOGGLE BUTTON_SELECT
235 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
237 #define FLIPIT_LEFT BUTTON_RC_REW
238 #define FLIPIT_RIGHT BUTTON_RC_FF
239 #define FLIPIT_UP BUTTON_RC_VOL_UP
240 #define FLIPIT_DOWN BUTTON_RC_VOL_DOWN
241 #define FLIPIT_QUIT BUTTON_RC_REC
242 #define FLIPIT_SHUFFLE BUTTON_RC_MODE
243 #define FLIPIT_SOLVE_PRE BUTTON_RC_MENU
244 #define FLIPIT_SOLVE (BUTTON_RC_MENU|BUTTON_REPEAT)
245 #define FLIPIT_STEP_PRE BUTTON_RC_MENU
246 #define FLIPIT_STEP_BY_STEP (BUTTON_RC_MENU|BUTTON_REL)
247 #define FLIPIT_TOGGLE BUTTON_RC_PLAY
249 #define FLIPIT_RC_QUIT BUTTON_REC
251 #elif CONFIG_KEYPAD == COWON_D2_PAD
253 #define FLIPIT_QUIT BUTTON_POWER
255 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
257 #define FLIPIT_LEFT BUTTON_LEFT
258 #define FLIPIT_RIGHT BUTTON_RIGHT
259 #define FLIPIT_UP BUTTON_UP
260 #define FLIPIT_DOWN BUTTON_DOWN
261 #define FLIPIT_QUIT BUTTON_BACK
262 #define FLIPIT_SHUFFLE BUTTON_CUSTOM
263 #define FLIPIT_SOLVE BUTTON_PLAY
264 #define FLIPIT_STEP_BY_STEP BUTTON_MENU
265 #define FLIPIT_TOGGLE BUTTON_SELECT
267 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
269 #define FLIPIT_LEFT BUTTON_LEFT
270 #define FLIPIT_RIGHT BUTTON_RIGHT
271 #define FLIPIT_UP BUTTON_UP
272 #define FLIPIT_DOWN BUTTON_DOWN
273 #define FLIPIT_QUIT BUTTON_POWER
274 #define FLIPIT_SHUFFLE BUTTON_MENU
275 #define FLIPIT_SOLVE BUTTON_VIEW
276 #define FLIPIT_STEP_BY_STEP BUTTON_PLAYLIST
277 #define FLIPIT_TOGGLE BUTTON_SELECT
279 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
281 #define FLIPIT_LEFT BUTTON_LEFT
282 #define FLIPIT_RIGHT BUTTON_RIGHT
283 #define FLIPIT_UP BUTTON_UP
284 #define FLIPIT_DOWN BUTTON_DOWN
285 #define FLIPIT_QUIT BUTTON_POWER
286 #define FLIPIT_SHUFFLE BUTTON_MENU
287 #define FLIPIT_SOLVE BUTTON_VIEW
288 #define FLIPIT_STEP_BY_STEP BUTTON_NEXT
289 #define FLIPIT_TOGGLE BUTTON_PLAY
291 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
293 #define FLIPIT_LEFT BUTTON_PREV
294 #define FLIPIT_RIGHT BUTTON_NEXT
295 #define FLIPIT_UP BUTTON_UP
296 #define FLIPIT_DOWN BUTTON_DOWN
297 #define FLIPIT_QUIT BUTTON_POWER
298 #define FLIPIT_SHUFFLE BUTTON_MENU
299 #define FLIPIT_SOLVE BUTTON_RIGHT
300 #define FLIPIT_STEP_BY_STEP BUTTON_LEFT
301 #define FLIPIT_TOGGLE BUTTON_PLAY
303 #elif CONFIG_KEYPAD == ONDAVX747_PAD || CONFIG_KEYPAD == MROBE500_PAD
305 #define FLIPIT_QUIT BUTTON_POWER
307 #elif CONFIG_KEYPAD == ONDAVX777_PAD
309 #define FLIPIT_QUIT BUTTON_POWER
311 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
313 #define FLIPIT_LEFT BUTTON_LEFT
314 #define FLIPIT_RIGHT BUTTON_RIGHT
315 #define FLIPIT_UP BUTTON_UP
316 #define FLIPIT_DOWN BUTTON_DOWN
317 #define FLIPIT_QUIT BUTTON_REC
318 #define FLIPIT_SHUFFLE BUTTON_PLAY
319 #define FLIPIT_SOLVE BUTTON_FFWD
320 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY|BUTTON_UP)
321 #define FLIPIT_TOGGLE (BUTTON_PLAY|BUTTON_DOWN)
323 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
325 #define FLIPIT_LEFT BUTTON_PREV
326 #define FLIPIT_RIGHT BUTTON_NEXT
327 #define FLIPIT_UP BUTTON_UP
328 #define FLIPIT_DOWN BUTTON_DOWN
329 #define FLIPIT_QUIT BUTTON_REC
330 #define FLIPIT_SHUFFLE BUTTON_PLAY
331 #define FLIPIT_SOLVE BUTTON_MENU
332 #define FLIPIT_STEP_BY_STEP BUTTON_CANCEL
333 #define FLIPIT_TOGGLE BUTTON_OK
335 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
337 #define FLIPIT_LEFT BUTTON_VOL_DOWN
338 #define FLIPIT_RIGHT BUTTON_VOL_UP
339 #define FLIPIT_UP BUTTON_REW
340 #define FLIPIT_DOWN BUTTON_FF
341 #define FLIPIT_QUIT (BUTTON_REC|BUTTON_PLAY)
342 #define FLIPIT_SHUFFLE BUTTON_FUNC
343 #define FLIPIT_SOLVE BUTTON_REC
344 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY|BUTTON_REW)
345 #define FLIPIT_TOGGLE (BUTTON_PLAY|BUTTON_FF)
347 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
349 #define FLIPIT_LEFT BUTTON_REW
350 #define FLIPIT_RIGHT BUTTON_FF
351 #define FLIPIT_UP BUTTON_UP
352 #define FLIPIT_DOWN BUTTON_DOWN
353 #define FLIPIT_QUIT (BUTTON_REC|BUTTON_REPEAT)
354 #define FLIPIT_SHUFFLE BUTTON_PLAY
355 #define FLIPIT_SOLVE BUTTON_MENU
356 #define FLIPIT_STEP_BY_STEP BUTTON_REC
357 #define FLIPIT_TOGGLE BUTTON_ENTER
359 #else
360 #error No keymap defined!
361 #endif
363 #ifdef HAVE_TOUCHSCREEN
364 #ifndef FLIPIT_LEFT
365 #define FLIPIT_LEFT BUTTON_MIDLEFT
366 #endif
367 #ifndef FLIPIT_RIGHT
368 #define FLIPIT_RIGHT BUTTON_MIDRIGHT
369 #endif
370 #ifndef FLIPIT_UP
371 #define FLIPIT_UP BUTTON_TOPMIDDLE
372 #endif
373 #ifndef FLIPIT_DOWN
374 #define FLIPIT_DOWN BUTTON_BOTTOMMIDDLE
375 #endif
376 #ifndef FLIPIT_QUIT
377 #define FLIPIT_QUIT BUTTON_TOPLEFT
378 #endif
379 #ifndef FLIPIT_SHUFFLE
380 #define FLIPIT_SHUFFLE BUTTON_TOPRIGHT
381 #endif
382 #ifndef FLIPIT_SOLVE
383 #define FLIPIT_SOLVE BUTTON_BOTTOMLEFT
384 #endif
385 #ifndef FLIPIT_STEP_BY_STEP
386 #define FLIPIT_STEP_BY_STEP BUTTON_BOTTOMRIGHT
387 #endif
388 #ifndef FLIPIT_TOGGLE
389 #define FLIPIT_TOGGLE BUTTON_CENTER
390 #endif
391 #endif
393 static int spots[20];
394 static int toggle[20];
395 static int cursor_pos, moves;
397 #ifdef HAVE_LCD_BITMAP
399 #include "pluginbitmaps/flipit_cursor.h"
400 #include "pluginbitmaps/flipit_tokens.h"
402 #define PANEL_HEIGHT 12
403 #define TK_WIDTH BMPWIDTH_flipit_cursor
404 #define TK_HEIGHT BMPHEIGHT_flipit_cursor
405 #define TK_SPACE MAX(0, MIN((LCD_WIDTH - 5*TK_WIDTH)/4, \
406 (LCD_HEIGHT - PANEL_HEIGHT - 4*TK_HEIGHT)/4))
407 #define GRID_WIDTH (5*TK_WIDTH + 4*TK_SPACE)
408 #define GRID_LEFT ((LCD_WIDTH - GRID_WIDTH)/2)
409 #define GRID_HEIGHT (4*TK_HEIGHT + 4*TK_SPACE) /* includes grid-panel space */
410 #define GRID_TOP MAX(0, ((LCD_HEIGHT - PANEL_HEIGHT - GRID_HEIGHT)/2))
412 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
413 static void draw_spot(int p)
415 rb->lcd_bitmap_part( flipit_tokens, 0, spots[p] * TK_HEIGHT,
416 STRIDE(SCREEN_MAIN, BMPWIDTH_flipit_tokens,
417 BMPHEIGHT_flipit_tokens),
418 GRID_LEFT + (p%5) * (TK_WIDTH+TK_SPACE),
419 GRID_TOP + (p/5) * (TK_HEIGHT+TK_SPACE),
420 TK_WIDTH, TK_HEIGHT );
423 /* draw the cursor at the current cursor position */
424 static void draw_cursor(void)
426 #ifdef HAVE_LCD_COLOR
427 rb->lcd_bitmap_transparent( flipit_cursor,
428 GRID_LEFT + (cursor_pos%5) * (TK_WIDTH+TK_SPACE),
429 GRID_TOP + (cursor_pos/5) * (TK_HEIGHT+TK_SPACE),
430 TK_WIDTH, TK_HEIGHT );
431 #else
432 rb->lcd_set_drawmode(DRMODE_FG);
433 rb->lcd_mono_bitmap( flipit_cursor,
434 GRID_LEFT + (cursor_pos%5) * (TK_WIDTH+TK_SPACE),
435 GRID_TOP + (cursor_pos/5) * (TK_HEIGHT+TK_SPACE),
436 TK_WIDTH, TK_HEIGHT );
437 rb->lcd_set_drawmode(DRMODE_SOLID);
438 #endif
441 /* draw the info panel ... duh */
442 static void draw_info_panel(void)
444 char s[32];
446 rb->lcd_set_drawmode( DRMODE_SOLID|DRMODE_INVERSEVID );
447 rb->lcd_fillrect( GRID_LEFT, GRID_TOP + 4*(TK_HEIGHT+TK_SPACE),
448 GRID_WIDTH, PANEL_HEIGHT );
449 rb->lcd_set_drawmode( DRMODE_SOLID );
450 rb->lcd_drawrect( GRID_LEFT, GRID_TOP + 4*(TK_HEIGHT+TK_SPACE),
451 GRID_WIDTH, PANEL_HEIGHT );
453 rb->snprintf( s, sizeof(s), "Flips: %d", moves );
454 rb->lcd_putsxy( (LCD_WIDTH - rb->lcd_getstringsize(s, NULL, NULL)) / 2,
455 GRID_TOP + 4*(TK_HEIGHT+TK_SPACE) + 2, s );
458 #else /* HAVE_LCD_CHARCELLS */
460 static const unsigned char tk_pat[4][7] = {
461 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* white - white */
462 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x1f, 0x0e }, /* white - black */
463 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* black - white */
464 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x1f, 0x0e } /* black - black */
467 static unsigned char cur_pat[7];
468 static unsigned long gfx_chars[5];
470 static void release_gfx(void)
472 int i;
474 for (i = 0; i < 5; i++)
475 if (gfx_chars[i])
476 rb->lcd_unlock_pattern(gfx_chars[i]);
479 static bool init_gfx(void)
481 int i;
483 for (i = 0; i < 5; i++) {
484 if ((gfx_chars[i] = rb->lcd_get_locked_pattern()) == 0) {
485 release_gfx();
486 return false;
489 for (i = 0; i < 4; i++)
490 rb->lcd_define_pattern(gfx_chars[i], tk_pat[i]);
491 return true;
494 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
495 static void draw_spot(int p)
497 if ((p/5) & 1)
498 p -= 5;
500 rb->lcd_putc (p%5, p/10, gfx_chars[2*spots[p]+spots[p+5]]);
503 /* draw the cursor at the current cursor position */
504 static void draw_cursor(void)
506 if ((cursor_pos/5) & 1) {
507 rb->memcpy( cur_pat, tk_pat[2*spots[cursor_pos-5]+spots[cursor_pos]], 7 );
508 cur_pat[4] ^= 0x15;
509 cur_pat[6] ^= 0x11;
511 else {
512 rb->memcpy( cur_pat, tk_pat[2*spots[cursor_pos]+spots[cursor_pos+5]], 7 );
513 cur_pat[0] ^= 0x15;
514 cur_pat[2] ^= 0x11;
516 rb->lcd_define_pattern(gfx_chars[4], cur_pat);
517 rb->lcd_putc( cursor_pos%5, cursor_pos/10, gfx_chars[4] );
520 /* draw the info panel ... duh */
521 static void draw_info_panel(void)
523 rb->lcd_puts( 6, 0, "Flips" );
524 rb->lcd_putsf( 6, 1, "%d", moves );
527 #endif /* LCD */
529 /* clear the cursor where it is */
530 static inline void clear_cursor(void)
532 draw_spot( cursor_pos );
535 /* check if the puzzle is finished */
536 static bool flipit_finished(void)
538 int i;
539 for (i=0; i<20; i++)
540 if (!spots[i])
541 return false;
542 clear_cursor();
543 return true;
546 /* draws the toggled spots */
547 static void flipit_toggle(void)
549 spots[cursor_pos] = 1-spots[cursor_pos];
550 toggle[cursor_pos] = 1-toggle[cursor_pos];
551 draw_spot(cursor_pos);
552 if (cursor_pos%5 > 0) {
553 spots[cursor_pos-1] = 1-spots[cursor_pos-1];
554 draw_spot(cursor_pos-1);
556 if (cursor_pos%5 < 4) {
557 spots[cursor_pos+1] = 1-spots[cursor_pos+1];
558 draw_spot(cursor_pos+1);
560 if (cursor_pos/5 > 0) {
561 spots[cursor_pos-5] = 1-spots[cursor_pos-5];
562 draw_spot(cursor_pos-5);
564 if (cursor_pos/5 < 3) {
565 spots[cursor_pos+5] = 1-spots[cursor_pos+5];
566 draw_spot(cursor_pos+5);
568 moves++;
570 draw_info_panel();
572 if (flipit_finished())
573 clear_cursor();
576 /* move the cursor in any direction */
577 static void move_cursor(int x, int y)
579 if (!(flipit_finished())) {
580 clear_cursor();
581 cursor_pos = ( x + 5 + cursor_pos%5 )%5
582 + ( ( y + 4 + cursor_pos/5 )%4 )*5;
583 draw_cursor();
585 rb->lcd_update();
588 /* initialize the board */
589 static void flipit_init(void)
591 int i;
593 rb->lcd_clear_display();
594 for (i=0; i<20; i++) {
595 spots[i]=1;
596 toggle[i]=1;
597 draw_spot(i);
599 rb->lcd_update();
601 for (i=0; i<20; i++) {
602 cursor_pos = (rb->rand() % 20);
603 flipit_toggle();
606 cursor_pos = 0;
607 draw_cursor();
608 moves = 0;
609 draw_info_panel();
610 rb->lcd_update();
613 /* the main game loop */
614 static bool flipit_loop(void)
616 int i;
617 int button;
618 int lastbutton = BUTTON_NONE;
620 flipit_init();
621 while(true) {
622 button = rb->button_get(true);
623 switch (button) {
624 #ifdef FLIPIT_RC_QUIT
625 case FLIPIT_RC_QUIT:
626 #endif
627 case FLIPIT_QUIT:
628 /* get out of here */
629 return PLUGIN_OK;
631 case FLIPIT_SHUFFLE:
632 /* mix up the pieces */
633 flipit_init();
634 break;
636 case FLIPIT_SOLVE:
637 #ifdef FLIPIT_SOLVE_PRE
638 if (lastbutton != FLIPIT_SOLVE_PRE)
639 break;
640 #endif
641 /* solve the puzzle */
642 if (!flipit_finished()) {
643 for (i=0; i<20; i++)
644 if (!toggle[i]) {
645 clear_cursor();
646 cursor_pos = i;
647 flipit_toggle();
648 draw_cursor();
649 rb->lcd_update();
650 rb->sleep(HZ*2/3);
653 break;
655 case FLIPIT_STEP_BY_STEP:
656 #ifdef FLIPIT_STEP_PRE
657 if (lastbutton != FLIPIT_STEP_PRE)
658 break;
659 #endif
660 if (!flipit_finished()) {
661 for (i=0; i<20; i++)
662 if (!toggle[i]) {
663 clear_cursor();
664 cursor_pos = i;
665 flipit_toggle();
666 draw_cursor();
667 rb->lcd_update();
668 break;
671 break;
673 case FLIPIT_TOGGLE:
674 #ifdef FLIPIT_TOGGLE_PRE
675 if (lastbutton != FLIPIT_TOGGLE_PRE)
676 break;
677 #endif
678 /* toggle the pieces */
679 if (!flipit_finished()) {
680 flipit_toggle();
681 draw_cursor();
682 rb->lcd_update();
684 break;
686 case FLIPIT_LEFT:
687 move_cursor(-1, 0);
688 break;
690 case FLIPIT_RIGHT:
691 move_cursor(1, 0);
692 break;
693 /*move cursor though the entire field*/
694 #ifdef FLIPIT_SCROLLWHEEL
695 case FLIPIT_PREV:
696 case FLIPIT_PREV|BUTTON_REPEAT:
697 if ((cursor_pos)%5 == 0) {
698 move_cursor(-1, -1);
700 else {
701 move_cursor(-1, 0);
703 break;
705 case FLIPIT_NEXT:
706 case FLIPIT_NEXT|BUTTON_REPEAT:
707 if ((cursor_pos+1)%5 == 0) {
708 move_cursor(1, 1);
710 else {
711 move_cursor(1, 0);
713 break;
714 #endif
715 case FLIPIT_UP:
716 #ifdef FLIPIT_UP_PRE
717 if (lastbutton != FLIPIT_UP_PRE)
718 break;
719 #endif
720 move_cursor(0, -1);
721 break;
723 case FLIPIT_DOWN:
724 move_cursor(0, 1);
725 break;
727 default:
728 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
729 return PLUGIN_USB_CONNECTED;
730 break;
732 if (button != BUTTON_NONE)
733 lastbutton = button;
737 /* called function from outside */
738 enum plugin_status plugin_start(const void* parameter)
740 int i, rc;
742 (void)parameter;
744 #ifdef HAVE_LCD_COLOR
745 rb->lcd_set_background(LCD_WHITE);
746 rb->lcd_set_foreground(LCD_BLACK);
747 #endif
749 #if LCD_DEPTH > 1
750 rb->lcd_set_backdrop(NULL);
751 #endif
753 rb->splash(HZ, "FlipIt!");
755 #ifdef HAVE_LCD_BITMAP
756 /* print instructions */
757 rb->lcd_clear_display();
758 rb->lcd_setfont(FONT_SYSFIXED);
759 #if CONFIG_KEYPAD == RECORDER_PAD
760 rb->lcd_putsxy(2, 8, "[OFF] to stop");
761 rb->lcd_putsxy(2, 18, "[PLAY] toggle");
762 rb->lcd_putsxy(2, 28, "[F1] shuffle");
763 rb->lcd_putsxy(2, 38, "[F2] solution");
764 rb->lcd_putsxy(2, 48, "[F3] step by step");
765 #elif CONFIG_KEYPAD == ONDIO_PAD
766 rb->lcd_putsxy(2, 8, "[OFF] to stop");
767 rb->lcd_putsxy(2, 18, "[MODE] toggle");
768 rb->lcd_putsxy(2, 28, "[M-LEFT] shuffle");
769 rb->lcd_putsxy(2, 38, "[M-UP] solution");
770 rb->lcd_putsxy(2, 48, "[M-RIGHT] step by step");
771 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
772 (CONFIG_KEYPAD == IRIVER_H300_PAD)
773 rb->lcd_putsxy(2, 8, "[STOP] to stop");
774 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
775 rb->lcd_putsxy(2, 28, "[MODE] shuffle");
776 rb->lcd_putsxy(2, 38, "[PLAY] solution");
777 rb->lcd_putsxy(2, 48, "[REC] step by step");
778 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
779 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
780 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
781 rb->lcd_putsxy(2, 8, "[S-MENU] to stop");
782 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
783 rb->lcd_putsxy(2, 28, "[S-LEFT] shuffle");
784 rb->lcd_putsxy(2, 38, "[S-PLAY] solution");
785 rb->lcd_putsxy(2, 48, "[S-RIGHT] step by step");
786 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
787 rb->lcd_putsxy(2, 8, "[POWER] to stop");
788 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
789 rb->lcd_putsxy(2, 28, "[REC] shuffle");
790 rb->lcd_putsxy(2, 38, "[PLAY..] solution");
791 rb->lcd_putsxy(2, 48, "[PLAY] step by step");
792 #elif CONFIG_KEYPAD == GIGABEAT_PAD
793 rb->lcd_putsxy(2, 8, "[POWER] to stop");
794 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
795 rb->lcd_putsxy(2, 28, "[MENU] shuffle");
796 rb->lcd_putsxy(2, 38, "[VOL+] solution");
797 rb->lcd_putsxy(2, 48, "[VOL-] step by step");
798 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
799 rb->lcd_putsxy(2, 8, "[POWER] to stop");
800 rb->lcd_putsxy(2, 18, "[REW] toggle");
801 rb->lcd_putsxy(2, 28, "[PL-LEFT] shuffle");
802 rb->lcd_putsxy(2, 38, "[PL-RIGHT] solution");
803 rb->lcd_putsxy(2, 48, "[PL-UP] step by step");
804 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
805 rb->lcd_putsxy(2, 8, "[BACK] to stop");
806 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
807 rb->lcd_putsxy(2, 28, "[MENU] shuffle");
808 rb->lcd_putsxy(2, 38, "[VOL+] solution");
809 rb->lcd_putsxy(2, 48, "[VOL-] step by step");
810 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
811 (CONFIG_KEYPAD == SANSA_C200_PAD)
812 rb->lcd_putsxy(2, 8, "[POWER] to stop");
813 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
814 rb->lcd_putsxy(2, 28, "[REC-LEFT] shuffle");
815 rb->lcd_putsxy(2, 38, "[REC-RIGHT] solution");
816 rb->lcd_putsxy(2, 48, "[REC-SEL] step by step");
817 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
818 rb->lcd_putsxy(2, 8, "[REC] to stop");
819 rb->lcd_putsxy(2, 18, "[PLAY] toggle");
820 rb->lcd_putsxy(2, 28, "[MODE] shuffle");
821 rb->lcd_putsxy(2, 38, "[MENU..] solution");
822 rb->lcd_putsxy(2, 48, "[MENU] step by step");
823 #endif
825 #ifdef HAVE_TOUCHSCREEN
826 rb->lcd_putsxy(2, 8, "[BOTTOMLEFT] to stop");
827 rb->lcd_putsxy(2, 18, "[CENTRE] toggle");
828 rb->lcd_putsxy(2, 28, "[TOPRIGHT] shuffle");
829 rb->lcd_putsxy(2, 38, "[BOTTOMLEFT] solution");
830 rb->lcd_putsxy(2, 48, "[BOTTOMRIGHT] step by step");
831 #endif
833 rb->lcd_update();
834 #else /* HAVE_LCD_CHARCELLS */
835 if (!init_gfx())
836 return PLUGIN_ERROR;
837 #endif
838 rb->button_get_w_tmo(HZ*3);
840 rb->lcd_clear_display();
841 draw_info_panel();
842 for (i=0; i<20; i++) {
843 spots[i]=1;
844 draw_spot(i);
846 rb->lcd_update();
847 rb->sleep(HZ*3/2);
848 rb->srand(*rb->current_tick);
850 rc = flipit_loop();
851 #ifdef HAVE_LCD_CHARCELLS
852 release_gfx();
853 #endif
854 return rc;