fix red.
[kugel-rb/myfork.git] / apps / plugins / cube.c
blobb90bbee481dee604892c1ad70ee553c6a840cb7f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Damien Teney
11 * modified to use int instead of float math by Andreas Zwirtes
12 * heavily extended by Jens Arnold
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ***************************************************************************/
23 #include "plugin.h"
24 #include "lib/grey.h"
25 #include "lib/playergfx.h"
26 #include "lib/xlcd.h"
27 #include "lib/fixedpoint.h"
29 PLUGIN_HEADER
31 /* Loops that the values are displayed */
32 #define DISP_TIME 30
34 /* variable button definitions */
35 #if CONFIG_KEYPAD == RECORDER_PAD
36 #define CUBE_QUIT BUTTON_OFF
37 #define CUBE_NEXT BUTTON_RIGHT
38 #define CUBE_PREV BUTTON_LEFT
39 #define CUBE_INC BUTTON_UP
40 #define CUBE_DEC BUTTON_DOWN
41 #define CUBE_MODE BUTTON_F1
42 #define CUBE_PAUSE BUTTON_PLAY
43 #define CUBE_HIGHSPEED BUTTON_ON
45 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
46 #define CUBE_QUIT BUTTON_OFF
47 #define CUBE_NEXT BUTTON_RIGHT
48 #define CUBE_PREV BUTTON_LEFT
49 #define CUBE_INC BUTTON_UP
50 #define CUBE_DEC BUTTON_DOWN
51 #define CUBE_MODE BUTTON_F1
52 #define CUBE_PAUSE BUTTON_SELECT
53 #define CUBE_HIGHSPEED BUTTON_ON
55 #elif CONFIG_KEYPAD == PLAYER_PAD
56 #define CUBE_QUIT BUTTON_STOP
57 #define CUBE_INC BUTTON_RIGHT
58 #define CUBE_DEC BUTTON_LEFT
59 #define CUBE_NEXT (BUTTON_ON | BUTTON_RIGHT)
60 #define CUBE_PREV (BUTTON_ON | BUTTON_LEFT)
61 #define CUBE_MODE BUTTON_MENU
62 #define CUBE_PAUSE BUTTON_PLAY
63 #define CUBE_HIGHSPEED_PRE BUTTON_ON
64 #define CUBE_HIGHSPEED (BUTTON_ON | BUTTON_REL)
66 #elif CONFIG_KEYPAD == ONDIO_PAD
67 #define CUBE_QUIT BUTTON_OFF
68 #define CUBE_NEXT BUTTON_RIGHT
69 #define CUBE_PREV BUTTON_LEFT
70 #define CUBE_INC BUTTON_UP
71 #define CUBE_DEC BUTTON_DOWN
72 #define CUBE_MODE_PRE BUTTON_MENU
73 #define CUBE_MODE (BUTTON_MENU | BUTTON_REL)
74 #define CUBE_PAUSE (BUTTON_MENU | BUTTON_LEFT)
75 #define CUBE_HIGHSPEED (BUTTON_MENU | BUTTON_RIGHT)
77 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
78 (CONFIG_KEYPAD == IRIVER_H300_PAD)
79 #define CUBE_QUIT BUTTON_OFF
80 #define CUBE_NEXT BUTTON_RIGHT
81 #define CUBE_PREV BUTTON_LEFT
82 #define CUBE_INC BUTTON_UP
83 #define CUBE_DEC BUTTON_DOWN
84 #define CUBE_MODE BUTTON_MODE
85 #define CUBE_PAUSE BUTTON_ON
86 #define CUBE_HIGHSPEED BUTTON_SELECT
88 #define CUBE_RC_QUIT BUTTON_RC_STOP
90 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
91 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
92 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
93 #define CUBE_QUIT (BUTTON_SELECT | BUTTON_MENU)
94 #define CUBE_NEXT BUTTON_RIGHT
95 #define CUBE_PREV BUTTON_LEFT
96 #define CUBE_INC BUTTON_SCROLL_FWD
97 #define CUBE_DEC BUTTON_SCROLL_BACK
98 #define CUBE_MODE BUTTON_MENU
99 #define CUBE_PAUSE BUTTON_PLAY
100 #define CUBE_HIGHSPEED_PRE BUTTON_SELECT
101 #define CUBE_HIGHSPEED (BUTTON_SELECT | BUTTON_REL)
103 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
104 #define CUBE_QUIT BUTTON_PLAY
105 #define CUBE_NEXT BUTTON_RIGHT
106 #define CUBE_PREV BUTTON_LEFT
107 #define CUBE_INC BUTTON_UP
108 #define CUBE_DEC BUTTON_DOWN
109 #define CUBE_MODE BUTTON_MODE
110 #define CUBE_PAUSE BUTTON_SELECT
111 #define CUBE_HIGHSPEED BUTTON_EQ
113 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
114 #define CUBE_QUIT BUTTON_POWER
115 #define CUBE_NEXT BUTTON_RIGHT
116 #define CUBE_PREV BUTTON_LEFT
117 #define CUBE_INC BUTTON_UP
118 #define CUBE_DEC BUTTON_DOWN
119 #define CUBE_MODE BUTTON_REC
120 #define CUBE_PAUSE BUTTON_PLAY
121 #define CUBE_HIGHSPEED BUTTON_SELECT
123 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
124 #define CUBE_QUIT BUTTON_POWER
125 #define CUBE_NEXT BUTTON_RIGHT
126 #define CUBE_PREV BUTTON_LEFT
127 #define CUBE_INC BUTTON_UP
128 #define CUBE_DEC BUTTON_DOWN
129 #define CUBE_MODE BUTTON_MENU
130 #define CUBE_PAUSE BUTTON_SELECT
131 #define CUBE_HIGHSPEED BUTTON_A
133 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
134 #define CUBE_QUIT BUTTON_POWER
135 #define CUBE_NEXT BUTTON_RIGHT
136 #define CUBE_PREV BUTTON_LEFT
137 #define CUBE_INC BUTTON_SCROLL_FWD
138 #define CUBE_DEC BUTTON_SCROLL_BACK
139 #define CUBE_MODE BUTTON_DOWN
140 #define CUBE_PAUSE BUTTON_UP
141 #define CUBE_HIGHSPEED BUTTON_SELECT
143 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
144 #define CUBE_QUIT (BUTTON_HOME|BUTTON_REPEAT)
145 #define CUBE_NEXT BUTTON_RIGHT
146 #define CUBE_PREV BUTTON_LEFT
147 #define CUBE_INC BUTTON_SCROLL_FWD
148 #define CUBE_DEC BUTTON_SCROLL_BACK
149 #define CUBE_MODE BUTTON_DOWN
150 #define CUBE_PAUSE BUTTON_UP
151 #define CUBE_HIGHSPEED BUTTON_SELECT
153 #elif (CONFIG_KEYPAD == SANSA_C200_PAD) || \
154 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
155 (CONFIG_KEYPAD == SANSA_M200_PAD)
156 #define CUBE_QUIT BUTTON_POWER
157 #define CUBE_NEXT BUTTON_RIGHT
158 #define CUBE_PREV BUTTON_LEFT
159 #define CUBE_INC BUTTON_VOL_UP
160 #define CUBE_DEC BUTTON_VOL_DOWN
161 #define CUBE_MODE BUTTON_DOWN
162 #define CUBE_PAUSE BUTTON_UP
163 #define CUBE_HIGHSPEED BUTTON_SELECT
166 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
167 #define CUBE_QUIT BUTTON_POWER
168 #define CUBE_NEXT BUTTON_RIGHT
169 #define CUBE_PREV BUTTON_LEFT
170 #define CUBE_INC BUTTON_SCROLL_UP
171 #define CUBE_DEC BUTTON_SCROLL_DOWN
172 #define CUBE_MODE BUTTON_REW
173 #define CUBE_PAUSE BUTTON_PLAY
174 #define CUBE_HIGHSPEED BUTTON_FF
176 #elif CONFIG_KEYPAD == MROBE500_PAD
177 #define CUBE_QUIT BUTTON_POWER
179 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
180 #define CUBE_QUIT BUTTON_BACK
181 #define CUBE_NEXT BUTTON_RIGHT
182 #define CUBE_PREV BUTTON_LEFT
183 #define CUBE_INC BUTTON_UP
184 #define CUBE_DEC BUTTON_DOWN
185 #define CUBE_MODE BUTTON_MENU
186 #define CUBE_PAUSE BUTTON_PLAY
187 #define CUBE_HIGHSPEED BUTTON_SELECT
189 #elif (CONFIG_KEYPAD == MROBE100_PAD)
190 #define CUBE_QUIT BUTTON_POWER
191 #define CUBE_NEXT BUTTON_RIGHT
192 #define CUBE_PREV BUTTON_LEFT
193 #define CUBE_INC BUTTON_UP
194 #define CUBE_DEC BUTTON_DOWN
195 #define CUBE_MODE BUTTON_MENU
196 #define CUBE_PAUSE BUTTON_PLAY
197 #define CUBE_HIGHSPEED BUTTON_SELECT
199 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
200 #define CUBE_QUIT BUTTON_RC_REC
201 #define CUBE_NEXT BUTTON_RC_FF
202 #define CUBE_PREV BUTTON_RC_REW
203 #define CUBE_INC BUTTON_RC_VOL_UP
204 #define CUBE_DEC BUTTON_RC_VOL_DOWN
205 #define CUBE_MODE BUTTON_RC_MODE
206 #define CUBE_PAUSE BUTTON_RC_PLAY
207 #define CUBE_HIGHSPEED BUTTON_RC_MENU
209 #elif CONFIG_KEYPAD == COWOND2_PAD
210 #define CUBE_QUIT BUTTON_POWER
212 #elif (CONFIG_KEYPAD == IAUDIO67_PAD)
213 #define CUBE_QUIT BUTTON_POWER
214 #define CUBE_NEXT BUTTON_RIGHT
215 #define CUBE_PREV BUTTON_LEFT
216 #define CUBE_INC BUTTON_VOLUP
217 #define CUBE_DEC BUTTON_VOLDOWN
218 #define CUBE_MODE BUTTON_MENU
219 #define CUBE_PAUSE BUTTON_PLAY
220 #define CUBE_HIGHSPEED BUTTON_STOP
222 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
223 #define CUBE_QUIT BUTTON_BACK
224 #define CUBE_NEXT BUTTON_RIGHT
225 #define CUBE_PREV BUTTON_LEFT
226 #define CUBE_INC BUTTON_UP
227 #define CUBE_DEC BUTTON_DOWN
228 #define CUBE_MODE BUTTON_MENU
229 #define CUBE_PAUSE BUTTON_PLAY
230 #define CUBE_HIGHSPEED BUTTON_SELECT
232 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
233 #define CUBE_QUIT BUTTON_POWER
234 #define CUBE_NEXT BUTTON_RIGHT
235 #define CUBE_PREV BUTTON_LEFT
236 #define CUBE_INC BUTTON_UP
237 #define CUBE_DEC BUTTON_DOWN
238 #define CUBE_MODE BUTTON_MENU
239 #define CUBE_PAUSE BUTTON_SELECT
240 #define CUBE_HIGHSPEED BUTTON_VIEW
242 #elif CONFIG_KEYPAD == ONDAVX747_PAD
243 #define CUBE_QUIT BUTTON_POWER
245 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
246 #define CUBE_QUIT BUTTON_REC
247 #define CUBE_NEXT BUTTON_RIGHT
248 #define CUBE_PREV BUTTON_LEFT
249 #define CUBE_INC BUTTON_UP
250 #define CUBE_DEC BUTTON_DOWN
251 #define CUBE_MODE BUTTON_REW
252 #define CUBE_PAUSE BUTTON_PLAY
253 #define CUBE_HIGHSPEED BUTTON_FFWD
256 #else
257 #error No keymap defined!
258 #endif
260 #ifdef HAVE_TOUCHSCREEN
261 #ifndef CUBE_QUIT
262 #define CUBE_QUIT BUTTON_TOPLEFT
263 #endif
264 #ifndef CUBE_NEXT
265 #define CUBE_NEXT BUTTON_MIDRIGHT
266 #endif
267 #ifndef CUBE_PREV
268 #define CUBE_PREV BUTTON_MIDLEFT
269 #endif
270 #ifndef CUBE_INC
271 #define CUBE_INC BUTTON_TOPMIDDLE
272 #endif
273 #ifndef CUBE_DEC
274 #define CUBE_DEC BUTTON_BOTTOMMIDDLE
275 #endif
276 #ifndef CUBE_MODE
277 #define CUBE_MODE BUTTON_TOPRIGHT
278 #endif
279 #ifndef CUBE_PAUSE
280 #define CUBE_PAUSE BUTTON_CENTER
281 #endif
282 #ifndef CUBE_HIGHSPEED
283 #define CUBE_HIGHSPEED BUTTON_BOTTOMRIGHT
284 #endif
285 #endif
288 #ifdef HAVE_LCD_BITMAP
290 #define DIST (10 * MIN(LCD_HEIGHT, LCD_WIDTH) / 16)
291 static int x_off = LCD_WIDTH/2;
292 static int y_off = LCD_HEIGHT/2;
294 #if LCD_DEPTH == 1
295 #define USE_GSLIB
296 GREY_INFO_STRUCT
297 struct my_lcd {
298 void (*update)(void);
299 void (*clear_display)(void);
300 void (*drawline)(int x1, int y1, int x2, int y2);
301 void (*putsxy)(int x, int y, const unsigned char *string);
304 static struct my_lcd greyfuncs = {
305 grey_update, grey_clear_display, grey_drawline, grey_putsxy
307 static struct my_lcd lcdfuncs; /* initialised at runtime */
308 static struct my_lcd *mylcd = &greyfuncs;
310 #define MYLCD(fn) mylcd->fn
311 #define MY_FILLTRIANGLE(x1, y1, x2, y2, x3, y3) grey_filltriangle(x1, y1, x2, y2, x3, y3)
312 #define MY_SET_FOREGROUND(fg) grey_set_foreground(fg)
313 #define MY_GET_FOREGROUND() grey_get_foreground()
315 #else
316 #define MYLCD(fn) rb->lcd_ ## fn
317 #define MY_FILLTRIANGLE(x1, y1, x2, y2, x3, y3) xlcd_filltriangle(x1, y1, x2, y2, x3, y3)
318 #define MY_SET_FOREGROUND(fg) rb->lcd_set_foreground(fg)
319 #define MY_GET_FOREGROUND() rb->lcd_get_foreground()
320 #endif
322 #if CONFIG_LCD == LCD_SSD1815
323 #define ASPECT 320 /* = 1.25 (fixed point 24.8) */
324 #else
325 #define ASPECT 256 /* = 1.00 */
326 #endif
328 #else /* !LCD_BITMAP */
330 #define MYLCD(fn) pgfx_ ## fn
331 #define DIST 9
332 static int x_off = 10;
333 static int y_off = 7;
334 #define ASPECT 300 /* = 1.175 */
336 #endif /* !LCD_BITMAP */
338 struct point_3D {
339 long x, y, z;
342 struct point_2D {
343 long x, y;
346 struct line {
347 int start, end;
350 struct face {
351 int corner[4];
352 int line[4];
355 /* initial, unrotated cube corners */
356 static const struct point_3D sommet[8] =
358 {-DIST, -DIST, -DIST},
359 { DIST, -DIST, -DIST},
360 { DIST, DIST, -DIST},
361 {-DIST, DIST, -DIST},
362 {-DIST, -DIST, DIST},
363 { DIST, -DIST, DIST},
364 { DIST, DIST, DIST},
365 {-DIST, DIST, DIST}
368 /* The 12 lines forming the edges */
369 static const struct line lines[12] =
371 {0, 1}, {1, 2}, {2, 3}, {3, 0},
372 {4, 7}, {7, 6}, {6, 5}, {5, 4},
373 {0, 4}, {1, 5}, {2, 6}, {3, 7}
376 static bool lines_drawn[12];
378 /* The 6 faces of the cube; points are in clockwise order when viewed
379 from the outside */
380 static const struct face faces[6] =
382 {{0, 1, 2, 3}, {0, 1, 2, 3}},
383 {{4, 7, 6, 5}, {4, 5, 6, 7}},
384 {{0, 4, 5, 1}, {8, 7, 9, 0}},
385 {{2, 6, 7, 3}, {10, 5, 11, 2}},
386 {{0, 3, 7, 4}, {3, 11, 4, 8}},
387 {{1, 5, 6, 2}, {9, 6, 10, 1}}
390 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
391 static const unsigned face_colors[6] =
393 #ifdef HAVE_LCD_COLOR
394 LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(0, 255, 0),
395 LCD_RGBPACK(0, 255, 0), LCD_RGBPACK(0, 0, 255), LCD_RGBPACK(0, 0, 255)
396 #elif defined(USE_GSLIB)
397 #ifdef MROBE_100
398 GREY_LIGHTGRAY, GREY_LIGHTGRAY, GREY_DARKGRAY,
399 GREY_DARKGRAY, GREY_WHITE, GREY_WHITE
400 #else
401 GREY_LIGHTGRAY, GREY_LIGHTGRAY, GREY_DARKGRAY,
402 GREY_DARKGRAY, GREY_BLACK, GREY_BLACK
403 #endif
404 #else
405 LCD_LIGHTGRAY, LCD_LIGHTGRAY, LCD_DARKGRAY,
406 LCD_DARKGRAY, LCD_BLACK, LCD_BLACK
407 #endif
409 #endif
411 enum {
412 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
413 SOLID,
414 #endif
415 HIDDEN_LINES,
416 WIREFRAME,
417 NUM_MODES
420 static int mode = 0;
422 struct counter {
423 const char *label;
424 short speed;
425 short angle;
428 static struct counter axes[] = {
429 {"x-axis", 1, 0},
430 {"y-axis", 3, 0},
431 {"z-axis", 2, 0}
434 static struct point_3D point3D[8];
435 static struct point_2D point2D[8];
436 static long matrice[3][3];
438 static const int nb_points = 8;
439 static long z_off = 600;
441 static void cube_rotate(int xa, int ya, int za)
443 int i;
444 /* Just to prevent unnecessary lookups */
445 long sxa, cxa, sya, cya, sza, cza;
447 sxa = fp14_sin(xa);
448 cxa = fp14_cos(xa);
449 sya = fp14_sin(ya);
450 cya = fp14_cos(ya);
451 sza = fp14_sin(za);
452 cza = fp14_cos(za);
454 /* calculate overall translation matrix */
455 matrice[0][0] = (cza * cya) >> 14;
456 matrice[1][0] = (sza * cya) >> 14;
457 matrice[2][0] = -sya;
459 matrice[0][1] = (((cza * sya) >> 14) * sxa - sza * cxa) >> 14;
460 matrice[1][1] = (((sza * sya) >> 14) * sxa + cxa * cza) >> 14;
461 matrice[2][1] = (sxa * cya) >> 14;
463 matrice[0][2] = (((cza * sya) >> 14) * cxa + sza * sxa) >> 14;
464 matrice[1][2] = (((sza * sya) >> 14) * cxa - cza * sxa) >> 14;
465 matrice[2][2] = (cxa * cya) >> 14;
467 /* apply translation matrix to all points */
468 for (i = 0; i < nb_points; i++)
470 point3D[i].x = matrice[0][0] * sommet[i].x + matrice[1][0] * sommet[i].y
471 + matrice[2][0] * sommet[i].z;
473 point3D[i].y = matrice[0][1] * sommet[i].x + matrice[1][1] * sommet[i].y
474 + matrice[2][1] * sommet[i].z;
476 point3D[i].z = matrice[0][2] * sommet[i].x + matrice[1][2] * sommet[i].y
477 + matrice[2][2] * sommet[i].z;
481 static void cube_viewport(void)
483 int i;
485 /* Do viewport transformation for all points */
486 for (i = 0; i < nb_points; i++)
488 #if ASPECT != 256
489 point2D[i].x = (point3D[i].x * ASPECT) / (point3D[i].z + (z_off << 14))
490 + x_off;
491 #else
492 point2D[i].x = (point3D[i].x << 8) / (point3D[i].z + (z_off << 14))
493 + x_off;
494 #endif
495 point2D[i].y = (point3D[i].y << 8) / (point3D[i].z + (z_off << 14))
496 + y_off;
500 static void cube_draw(void)
502 int i, j, line;
503 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
504 unsigned old_foreground;
505 #endif
507 switch (mode)
509 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
510 case SOLID:
512 old_foreground = MY_GET_FOREGROUND();
513 for (i = 0; i < 6; i++)
515 /* backface culling; if the shape winds counter-clockwise, we are
516 * looking at the backface, and the (simplified) cross product
517 * is < 0. Do not draw it. */
518 if (0 >= (point2D[faces[i].corner[1]].x - point2D[faces[i].corner[0]].x)
519 * (point2D[faces[i].corner[2]].y - point2D[faces[i].corner[1]].y)
520 - (point2D[faces[i].corner[1]].y - point2D[faces[i].corner[0]].y)
521 * (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x))
522 continue;
524 MY_SET_FOREGROUND(face_colors[i]);
525 MY_FILLTRIANGLE(point2D[faces[i].corner[0]].x,
526 point2D[faces[i].corner[0]].y,
527 point2D[faces[i].corner[1]].x,
528 point2D[faces[i].corner[1]].y,
529 point2D[faces[i].corner[2]].x,
530 point2D[faces[i].corner[2]].y);
531 MY_FILLTRIANGLE(point2D[faces[i].corner[0]].x,
532 point2D[faces[i].corner[0]].y,
533 point2D[faces[i].corner[2]].x,
534 point2D[faces[i].corner[2]].y,
535 point2D[faces[i].corner[3]].x,
536 point2D[faces[i].corner[3]].y);
539 MY_SET_FOREGROUND(old_foreground);
540 break;
541 #endif /* (LCD_DEPTH > 1) || GSLIB */
543 case HIDDEN_LINES:
545 rb->memset(lines_drawn, 0, sizeof(lines_drawn));
546 for (i = 0; i < 6; i++)
548 /* backface culling; if the shape winds counter-clockwise, we are
549 * looking at the backface, and the (simplified) cross product
550 * is < 0. Do not draw it. */
551 if (0 >= (point2D[faces[i].corner[1]].x - point2D[faces[i].corner[0]].x)
552 * (point2D[faces[i].corner[2]].y - point2D[faces[i].corner[1]].y)
553 - (point2D[faces[i].corner[1]].y - point2D[faces[i].corner[0]].y)
554 * (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x))
555 continue;
557 for (j = 0; j < 4; j++)
559 line = faces[i].line[j];
560 if (!lines_drawn[line])
562 lines_drawn[line] = true;
563 MYLCD(drawline)(point2D[lines[line].start].x,
564 point2D[lines[line].start].y,
565 point2D[lines[line].end].x,
566 point2D[lines[line].end].y);
570 break;
572 case WIREFRAME:
574 for (i = 0; i < 12; i++)
575 MYLCD(drawline)(point2D[lines[i].start].x,
576 point2D[lines[i].start].y,
577 point2D[lines[i].end].x,
578 point2D[lines[i].end].y);
579 break;
583 void cleanup(void *parameter)
585 (void)parameter;
587 #ifdef USE_GSLIB
588 grey_release();
589 #elif defined HAVE_LCD_CHARCELLS
590 pgfx_release();
591 #endif
594 enum plugin_status plugin_start(const void* parameter)
596 char buffer[30];
597 int t_disp = 0;
598 #ifdef USE_GSLIB
599 unsigned char *gbuf;
600 size_t gbuf_size = 0;
601 bool mode_switch = true;
602 #endif
604 int button;
605 int lastbutton = BUTTON_NONE;
606 int curr = 0;
607 bool highspeed = false;
608 bool paused = false;
609 bool redraw = true;
610 bool exit = false;
612 (void)(parameter);
614 #ifdef HAVE_LCD_BITMAP
615 #if defined(USE_GSLIB)
616 gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size);
617 if (!grey_init(gbuf, gbuf_size, GREY_BUFFERED,
618 LCD_WIDTH, LCD_HEIGHT, NULL))
620 rb->splash(HZ, "Couldn't init greyscale display");
621 return PLUGIN_ERROR;
623 /* init lcd_ function pointers */
624 lcdfuncs.update = rb->lcd_update;
625 lcdfuncs.clear_display = rb->lcd_clear_display;
626 lcdfuncs.drawline = rb->lcd_drawline;
627 lcdfuncs.putsxy = rb->lcd_putsxy;
629 #ifdef MROBE_100
630 grey_set_background(GREY_BLACK);
631 #endif
633 grey_setfont(FONT_SYSFIXED);
634 #endif
635 rb->lcd_setfont(FONT_SYSFIXED);
636 #else /* LCD_CHARCELLS */
637 if (!pgfx_init(4, 2))
639 rb->splash(HZ*2, "Old LCD :(");
640 return PLUGIN_OK;
642 pgfx_display(0, 0);
643 #endif
645 while(!exit)
647 if (redraw)
649 MYLCD(clear_display)();
650 cube_rotate(axes[0].angle, axes[1].angle, axes[2].angle);
651 cube_viewport();
652 cube_draw();
653 redraw = false;
656 #ifdef HAVE_LCD_BITMAP
657 if (t_disp > 0)
659 t_disp--;
660 rb->snprintf(buffer, sizeof(buffer), "%s: %d %s",
661 axes[curr].label,
662 paused ? axes[curr].angle : axes[curr].speed,
663 highspeed ? "(hs)" : "");
664 MYLCD(putsxy)(0, LCD_HEIGHT-8, buffer);
665 if (t_disp == 0)
666 redraw = true;
668 #else
669 if (t_disp > 0)
671 if (t_disp == DISP_TIME)
673 rb->lcd_puts(5, 0, axes[curr].label);
674 rb->snprintf(buffer, sizeof(buffer), "%d %c",
675 paused ? axes[curr].angle : axes[curr].speed,
676 highspeed ? 'H' : ' ');
677 rb->lcd_puts(5, 1, buffer);
679 t_disp--;
680 if (t_disp == 0)
682 rb->lcd_clear_display();
683 pgfx_display(0, 0);
686 #endif
687 #ifdef USE_GSLIB
688 if (mode_switch)
690 grey_show(mode == SOLID);
691 mode_switch = false;
693 #endif
694 MYLCD(update)();
696 if (!paused)
698 int i;
700 for (i = 0; i < 3; i++)
702 axes[i].angle += axes[i].speed;
703 if (axes[i].angle > 359)
704 axes[i].angle -= 360;
705 else if (axes[i].angle < 0)
706 axes[i].angle += 360;
708 redraw = true;
710 if (highspeed)
711 rb->yield();
712 else
713 rb->sleep(HZ/25);
714 button = rb->button_get(false);
716 else
718 button = rb->button_get_w_tmo(HZ/25);
721 switch (button)
723 case CUBE_INC:
724 case CUBE_INC|BUTTON_REPEAT:
725 if (!paused)
727 if (axes[curr].speed < 10)
728 axes[curr].speed++;
730 else
732 if (++axes[curr].angle > 359)
733 axes[curr].angle -= 360;
735 t_disp = DISP_TIME;
736 redraw = true;
737 break;
739 case CUBE_DEC:
740 case CUBE_DEC|BUTTON_REPEAT:
741 if (!paused)
743 if (axes[curr].speed > -10)
744 axes[curr].speed--;
746 else
748 if (--axes[curr].angle < 0)
749 axes[curr].angle += 360;
751 t_disp = DISP_TIME;
752 redraw = true;
753 break;
755 case CUBE_NEXT:
756 if (++curr > 2)
757 curr = 0;
758 t_disp = DISP_TIME;
759 break;
761 case CUBE_PREV:
762 if (--curr < 0)
763 curr = 2;
764 t_disp = DISP_TIME;
765 break;
767 case CUBE_MODE:
768 #ifdef CUBE_MODE_PRE
769 if (lastbutton != CUBE_MODE_PRE)
770 break;
771 #endif
772 if (++mode >= NUM_MODES)
773 mode = 0;
774 #ifdef USE_GSLIB
775 mylcd = (mode == SOLID) ? &greyfuncs : &lcdfuncs;
776 mode_switch = true;
777 #endif
778 redraw = true;
779 break;
781 case CUBE_PAUSE:
782 #ifdef CUBE_PAUSE_PRE
783 if (lastbutton != CUBE_PAUSE_PRE)
784 break;
785 #endif
786 paused = !paused;
787 break;
789 case CUBE_HIGHSPEED:
790 #ifdef CUBE_HIGHSPEED_PRE
791 if (lastbutton != CUBE_HIGHSPEED_PRE)
792 break;
793 #endif
794 highspeed = !highspeed;
795 t_disp = DISP_TIME;
796 break;
798 #ifdef CUBE_RC_QUIT
799 case CUBE_RC_QUIT:
800 #endif
801 case CUBE_QUIT:
802 exit = true;
803 break;
805 default:
806 if (rb->default_event_handler_ex(button, cleanup, NULL)
807 == SYS_USB_CONNECTED)
808 return PLUGIN_USB_CONNECTED;
809 break;
811 if (button != BUTTON_NONE)
812 lastbutton = button;
815 #ifdef USE_GSLIB
816 grey_release();
817 #elif defined(HAVE_LCD_CHARCELLS)
818 pgfx_release();
819 #endif
820 return PLUGIN_OK;