diff options
Diffstat (limited to 'apps/plugins/flipit.c')
-rw-r--r-- | apps/plugins/flipit.c | 127 |
1 files changed, 102 insertions, 25 deletions
diff --git a/apps/plugins/flipit.c b/apps/plugins/flipit.c index ed3448ed9b..909fbda06a 100644 --- a/apps/plugins/flipit.c +++ b/apps/plugins/flipit.c | |||
@@ -93,7 +93,25 @@ static int spots[20]; | |||
93 | static int toggle[20]; | 93 | static int toggle[20]; |
94 | static int cursor_pos, moves; | 94 | static int cursor_pos, moves; |
95 | static char s[5]; | 95 | static char s[5]; |
96 | |||
97 | #ifdef HAVE_LCD_COLOR | ||
98 | |||
99 | #if LCD_HEIGHT >= 200 | ||
100 | #define tksize 50 | ||
101 | #elif LCD_HEIGHT >=160 | ||
102 | #define tksize 40 | ||
103 | #else | ||
104 | #define tksize 30 | ||
105 | #endif | ||
106 | |||
107 | extern const fb_data flipit_tokens[]; | ||
108 | |||
109 | #else | ||
110 | |||
96 | static char *ptr; | 111 | static char *ptr; |
112 | |||
113 | #define tksize 16 | ||
114 | |||
97 | static unsigned char spot_pic[2][28] = { | 115 | static unsigned char spot_pic[2][28] = { |
98 | { 0xe0, 0xf8, 0xfc, 0xfe, 0xfe, 0xff, 0xff, | 116 | { 0xe0, 0xf8, 0xfc, 0xfe, 0xfe, 0xff, 0xff, |
99 | 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xf8, 0xe0, | 117 | 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xf8, 0xe0, |
@@ -109,18 +127,44 @@ static unsigned char cursor_pic[32] = { | |||
109 | 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xaa, | 127 | 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xaa, |
110 | 0x55, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, | 128 | 0x55, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, |
111 | 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa }; | 129 | 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa }; |
130 | #endif | ||
131 | |||
132 | #define INFO_WIDTH 32 | ||
133 | |||
134 | #if LCD_WIDTH - 5*tksize - INFO_WIDTH < 0 | ||
135 | # define INFO_UNDER | ||
136 | # undef INFO_WIDTH | ||
137 | # define INFO_WIDTH 60 | ||
138 | # define GRID_LEFT ((LCD_WIDTH-5*tksize)/2) | ||
139 | # define GRID_TOP 0 | ||
140 | #else | ||
141 | # define GRID_LEFT 0 | ||
142 | # define GRID_TOP ((LCD_HEIGHT-4*tksize)/2) | ||
143 | #endif | ||
112 | 144 | ||
113 | 145 | ||
114 | /* draw a spot at the coordinates (x,y), range of p is 0-19 */ | 146 | /* draw a spot at the coordinates (x,y), range of p is 0-19 */ |
115 | static void draw_spot(int p) { | 147 | static void draw_spot(int p) { |
148 | #if HAVE_LCD_COLOR | ||
149 | rb->lcd_bitmap_part( flipit_tokens, 0, spots[p]*tksize, tksize, | ||
150 | (p%5)*tksize+GRID_LEFT, (p/5)*tksize+GRID_TOP, | ||
151 | tksize, tksize ); | ||
152 | #else | ||
116 | ptr = spot_pic[spots[p]]; | 153 | ptr = spot_pic[spots[p]]; |
117 | rb->lcd_mono_bitmap (ptr, (p%5)*16+1, (p/5)*16+1, 14, 8); | 154 | rb->lcd_mono_bitmap (ptr, (p%5)*16+1, (p/5)*16+1, 14, 8); |
118 | ptr += 14; | 155 | ptr += 14; |
119 | rb->lcd_mono_bitmap (ptr, (p%5)*16+1, (p/5)*16+9, 14, 6); | 156 | rb->lcd_mono_bitmap (ptr, (p%5)*16+1, (p/5)*16+9, 14, 6); |
157 | #endif | ||
120 | } | 158 | } |
121 | 159 | ||
122 | /* draw the cursor at the current cursor position */ | 160 | /* draw the cursor at the current cursor position */ |
123 | static void draw_cursor(void) { | 161 | static void draw_cursor(void) { |
162 | #if HAVE_LCD_COLOR | ||
163 | rb->lcd_bitmap_transparent_part( flipit_tokens, 0, 2*tksize, tksize, | ||
164 | (cursor_pos%5)*tksize+GRID_LEFT, | ||
165 | (cursor_pos/5)*tksize+GRID_TOP, | ||
166 | tksize, tksize ); | ||
167 | #else | ||
124 | int i,j; | 168 | int i,j; |
125 | i = (cursor_pos%5)*16; | 169 | i = (cursor_pos%5)*16; |
126 | j = (cursor_pos/5)*16; | 170 | j = (cursor_pos/5)*16; |
@@ -130,10 +174,14 @@ static void draw_cursor(void) { | |||
130 | ptr += 16; | 174 | ptr += 16; |
131 | rb->lcd_mono_bitmap (ptr, i, j+8, 16, 8); | 175 | rb->lcd_mono_bitmap (ptr, i, j+8, 16, 8); |
132 | rb->lcd_set_drawmode(DRMODE_SOLID); | 176 | rb->lcd_set_drawmode(DRMODE_SOLID); |
177 | #endif | ||
133 | } | 178 | } |
134 | 179 | ||
135 | /* clear the cursor where it is */ | 180 | /* clear the cursor where it is */ |
136 | static void clear_cursor(void) { | 181 | static void clear_cursor(void) { |
182 | #if HAVE_LCD_COLOR | ||
183 | draw_spot( cursor_pos ); | ||
184 | #else | ||
137 | int i,j; | 185 | int i,j; |
138 | i = (cursor_pos%5)*16; | 186 | i = (cursor_pos%5)*16; |
139 | j = (cursor_pos/5)*16; | 187 | j = (cursor_pos/5)*16; |
@@ -143,6 +191,39 @@ static void clear_cursor(void) { | |||
143 | rb->lcd_drawline(i, j, i, j+15); | 191 | rb->lcd_drawline(i, j, i, j+15); |
144 | rb->lcd_drawline(i+15, j, i+15, j+15); | 192 | rb->lcd_drawline(i+15, j, i+15, j+15); |
145 | rb->lcd_set_drawmode(DRMODE_SOLID); | 193 | rb->lcd_set_drawmode(DRMODE_SOLID); |
194 | #endif | ||
195 | } | ||
196 | |||
197 | /* draw the info panel ... duh */ | ||
198 | static void draw_info_panel(void) | ||
199 | { | ||
200 | #ifdef INFO_UNDER | ||
201 | # define HEIGHT ( LCD_HEIGHT - 4*tksize ) | ||
202 | # define LEFT ( ( LCD_WIDTH - INFO_WIDTH ) / 2 ) | ||
203 | # define TOP ( LCD_HEIGHT - HEIGHT ) | ||
204 | #else | ||
205 | # define HEIGHT 64 | ||
206 | # define LEFT ( LCD_WIDTH - (LCD_WIDTH- 5*tksize-INFO_WIDTH)/2 - INFO_WIDTH ) | ||
207 | # define TOP ( ( LCD_HEIGHT - HEIGHT ) / 2 ) | ||
208 | #endif | ||
209 | rb->lcd_set_drawmode( DRMODE_SOLID|DRMODE_INVERSEVID ); | ||
210 | rb->lcd_fillrect( LEFT, TOP, INFO_WIDTH, HEIGHT ); | ||
211 | rb->lcd_set_drawmode( DRMODE_SOLID ); | ||
212 | rb->lcd_drawrect( LEFT, TOP, INFO_WIDTH, HEIGHT ); | ||
213 | #ifdef INFO_UNDER | ||
214 | rb->lcd_putsxy( LEFT+1, TOP+1, "Flips" ); | ||
215 | #else | ||
216 | rb->lcd_putsxy( LEFT+1, TOP+10, "Flips" ); | ||
217 | #endif | ||
218 | rb->snprintf( s, sizeof(s), "%d", moves ); | ||
219 | #ifdef INFO_UNDER | ||
220 | rb->lcd_putsxy( LEFT+32, TOP+1, s ); | ||
221 | #else | ||
222 | rb->lcd_putsxy( LEFT+1, TOP+20, s ); | ||
223 | #endif | ||
224 | # undef HEIGHT | ||
225 | # undef LEFT | ||
226 | # undef TOP | ||
146 | } | 227 | } |
147 | 228 | ||
148 | /* check if the puzzle is finished */ | 229 | /* check if the puzzle is finished */ |
@@ -177,8 +258,9 @@ static void flipit_toggle(void) { | |||
177 | draw_spot(cursor_pos+5); | 258 | draw_spot(cursor_pos+5); |
178 | } | 259 | } |
179 | moves++; | 260 | moves++; |
180 | rb->snprintf(s, sizeof(s), "%d", moves); | 261 | |
181 | rb->lcd_putsxy(85, 20, s); | 262 | draw_info_panel(); |
263 | |||
182 | if (flipit_finished()) | 264 | if (flipit_finished()) |
183 | clear_cursor(); | 265 | clear_cursor(); |
184 | } | 266 | } |
@@ -187,7 +269,8 @@ static void flipit_toggle(void) { | |||
187 | static void move_cursor(int x, int y) { | 269 | static void move_cursor(int x, int y) { |
188 | if (!(flipit_finished())) { | 270 | if (!(flipit_finished())) { |
189 | clear_cursor(); | 271 | clear_cursor(); |
190 | cursor_pos += (x+5*y); | 272 | cursor_pos = ( x + 5 + cursor_pos%5 )%5 |
273 | + ( ( y + 4 + cursor_pos/5 )%4 )*5; | ||
191 | draw_cursor(); | 274 | draw_cursor(); |
192 | } | 275 | } |
193 | rb->lcd_update(); | 276 | rb->lcd_update(); |
@@ -198,8 +281,6 @@ static void flipit_init(void) { | |||
198 | int i; | 281 | int i; |
199 | rb->lcd_clear_display(); | 282 | rb->lcd_clear_display(); |
200 | moves = 0; | 283 | moves = 0; |
201 | rb->lcd_drawrect(80, 0, 32, 64); | ||
202 | rb->lcd_putsxy(81, 10, "Flips"); | ||
203 | for (i=0; i<20; i++) { | 284 | for (i=0; i<20; i++) { |
204 | spots[i]=1; | 285 | spots[i]=1; |
205 | toggle[i]=1; | 286 | toggle[i]=1; |
@@ -214,13 +295,7 @@ static void flipit_init(void) { | |||
214 | cursor_pos = 0; | 295 | cursor_pos = 0; |
215 | draw_cursor(); | 296 | draw_cursor(); |
216 | moves = 0; | 297 | moves = 0; |
217 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | 298 | draw_info_panel(); |
218 | rb->lcd_fillrect(80, 0, 32, 64); | ||
219 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
220 | rb->lcd_drawrect(80, 0, 32, 64); | ||
221 | rb->lcd_putsxy(81, 10, "Flips"); | ||
222 | rb->snprintf(s, sizeof(s), "%d", moves); | ||
223 | rb->lcd_putsxy(85, 20, s); | ||
224 | rb->lcd_update(); | 299 | rb->lcd_update(); |
225 | } | 300 | } |
226 | 301 | ||
@@ -237,7 +312,7 @@ static bool flipit_loop(void) { | |||
237 | case FLIPIT_QUIT: | 312 | case FLIPIT_QUIT: |
238 | /* get out of here */ | 313 | /* get out of here */ |
239 | return PLUGIN_OK; | 314 | return PLUGIN_OK; |
240 | 315 | ||
241 | case FLIPIT_SHUFFLE: | 316 | case FLIPIT_SHUFFLE: |
242 | /* mix up the pieces */ | 317 | /* mix up the pieces */ |
243 | flipit_init(); | 318 | flipit_init(); |
@@ -250,8 +325,8 @@ static bool flipit_loop(void) { | |||
250 | if (!toggle[i]) { | 325 | if (!toggle[i]) { |
251 | clear_cursor(); | 326 | clear_cursor(); |
252 | cursor_pos = i; | 327 | cursor_pos = i; |
253 | draw_cursor(); | ||
254 | flipit_toggle(); | 328 | flipit_toggle(); |
329 | draw_cursor(); | ||
255 | rb->lcd_update(); | 330 | rb->lcd_update(); |
256 | rb->sleep(HZ*2/3); | 331 | rb->sleep(HZ*2/3); |
257 | } | 332 | } |
@@ -264,8 +339,8 @@ static bool flipit_loop(void) { | |||
264 | if (!toggle[i]) { | 339 | if (!toggle[i]) { |
265 | clear_cursor(); | 340 | clear_cursor(); |
266 | cursor_pos = i; | 341 | cursor_pos = i; |
267 | draw_cursor(); | ||
268 | flipit_toggle(); | 342 | flipit_toggle(); |
343 | draw_cursor(); | ||
269 | rb->lcd_update(); | 344 | rb->lcd_update(); |
270 | break; | 345 | break; |
271 | } | 346 | } |
@@ -280,28 +355,27 @@ static bool flipit_loop(void) { | |||
280 | /* toggle the pieces */ | 355 | /* toggle the pieces */ |
281 | if (!flipit_finished()) { | 356 | if (!flipit_finished()) { |
282 | flipit_toggle(); | 357 | flipit_toggle(); |
358 | #ifdef HAVE_LCD_COLOR | ||
359 | draw_cursor(); | ||
360 | #endif | ||
283 | rb->lcd_update(); | 361 | rb->lcd_update(); |
284 | } | 362 | } |
285 | break; | 363 | break; |
286 | 364 | ||
287 | case BUTTON_LEFT: | 365 | case BUTTON_LEFT: |
288 | if ((cursor_pos%5)>0) | 366 | move_cursor(-1, 0); |
289 | move_cursor(-1, 0); | ||
290 | break; | 367 | break; |
291 | 368 | ||
292 | case BUTTON_RIGHT: | 369 | case BUTTON_RIGHT: |
293 | if ((cursor_pos%5)<4) | 370 | move_cursor(1, 0); |
294 | move_cursor(1, 0); | ||
295 | break; | 371 | break; |
296 | 372 | ||
297 | case FLIPIT_UP: | 373 | case FLIPIT_UP: |
298 | if ((cursor_pos/5)>0) | 374 | move_cursor(0, -1); |
299 | move_cursor(0, -1); | ||
300 | break; | 375 | break; |
301 | 376 | ||
302 | case FLIPIT_DOWN: | 377 | case FLIPIT_DOWN: |
303 | if ((cursor_pos/5)<3) | 378 | move_cursor(0, 1); |
304 | move_cursor(0, 1); | ||
305 | break; | 379 | break; |
306 | 380 | ||
307 | default: | 381 | default: |
@@ -322,6 +396,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
322 | (void)parameter; | 396 | (void)parameter; |
323 | rb = api; | 397 | rb = api; |
324 | 398 | ||
399 | #ifdef HAVE_LCD_COLOR | ||
400 | rb->lcd_set_background(LCD_WHITE); | ||
401 | #endif | ||
402 | |||
325 | /* print title */ | 403 | /* print title */ |
326 | rb->lcd_getstringsize("FlipIt!", &w, &h); | 404 | rb->lcd_getstringsize("FlipIt!", &w, &h); |
327 | w = (w+1)/2; | 405 | w = (w+1)/2; |
@@ -364,8 +442,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
364 | rb->button_get_w_tmo(HZ*3); | 442 | rb->button_get_w_tmo(HZ*3); |
365 | 443 | ||
366 | rb->lcd_clear_display(); | 444 | rb->lcd_clear_display(); |
367 | rb->lcd_drawrect(80, 0, 32, 64); | 445 | draw_info_panel(); |
368 | rb->lcd_putsxy(81, 10, "Flips"); | ||
369 | for (i=0; i<20; i++) { | 446 | for (i=0; i<20; i++) { |
370 | spots[i]=1; | 447 | spots[i]=1; |
371 | draw_spot(i); | 448 | draw_spot(i); |