Restore translated strings removed by accident in the previous revision.
[kugel-rb.git] / apps / plugins / fireworks.c
blob1954f19cac17ede011cf1a5f265573eec0d0b5eb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Zakk Roberts
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"
22 #include "lib/helper.h"
23 #include "lib/playback_control.h"
27 /***
28 * FIREWORKS.C by ZAKK ROBERTS
29 * Rockbox plugin simulating a fireworks display.
30 * Supports all bitmap LCDs, fully scalable.
31 * Currently disabled for Archos Recorder - runs too slow.
32 ***/
34 /* All sorts of keymappings.. */
35 #if (CONFIG_KEYPAD == IRIVER_H300_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD)
36 #define BTN_MENU BUTTON_OFF
37 #define BTN_FIRE BUTTON_SELECT
39 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
40 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
41 #define BTN_MENU BUTTON_MENU
42 #define BTN_FIRE BUTTON_SELECT
44 #elif (CONFIG_KEYPAD == RECORDER_PAD)
45 #define BTN_MENU BUTTON_OFF
46 #define BTN_FIRE BUTTON_PLAY
48 #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
49 #define BTN_MENU BUTTON_OFF
50 #define BTN_FIRE BUTTON_SELECT
52 #elif (CONFIG_KEYPAD == ONDIO_PAD)
53 #define BTN_MENU BUTTON_MENU
54 #define BTN_FIRE BUTTON_UP
56 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
57 #define BTN_MENU BUTTON_POWER
58 #define BTN_FIRE BUTTON_SELECT
60 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
61 #define BTN_MENU BUTTON_MODE
62 #define BTN_FIRE BUTTON_SELECT
64 #elif (CONFIG_KEYPAD == GIGABEAT_PAD) || \
65 (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
66 (CONFIG_KEYPAD == MROBE100_PAD)
67 #define BTN_MENU BUTTON_MENU
68 #define BTN_FIRE BUTTON_SELECT
70 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
71 (CONFIG_KEYPAD == SANSA_C200_PAD)
72 #define BTN_MENU BUTTON_POWER
73 #define BTN_FIRE BUTTON_SELECT
75 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
76 #define BTN_MENU (BUTTON_HOME|BUTTON_REPEAT)
77 #define BTN_FIRE BUTTON_SELECT
79 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
80 #define BTN_MENU BUTTON_POWER
81 #define BTN_FIRE BUTTON_PLAY
83 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
84 #define BTN_MENU BUTTON_RC_REC
85 #define BTN_FIRE BUTTON_RC_PLAY
87 #elif (CONFIG_KEYPAD == COWON_D2_PAD)
88 #define BTN_MENU (BUTTON_MENU|BUTTON_REL)
90 #elif CONFIG_KEYPAD == IAUDIO67_PAD
91 #define BTN_MENU BUTTON_MENU
92 #define BTN_FIRE BUTTON_PLAY
94 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
95 #define BTN_MENU BUTTON_MENU
96 #define BTN_FIRE BUTTON_SELECT
98 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
99 #define BTN_MENU BUTTON_MENU
100 #define BTN_FIRE BUTTON_SELECT
102 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
103 #define BTN_MENU BUTTON_MENU
104 #define BTN_FIRE BUTTON_PLAY
106 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
107 #define BTN_MENU (BUTTON_MENU|BUTTON_REL)
109 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
110 #define BTN_MENU BUTTON_LEFT
111 #define BTN_FIRE BUTTON_PLAY
113 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
114 #define BTN_MENU BUTTON_MENU
115 #define BTN_FIRE BUTTON_OK
117 #elif (CONFIG_KEYPAD == MPIO_HD200_PAD)
118 #define BTN_MENU BUTTON_REC
119 #define BTN_FIRE BUTTON_SELECT
121 #elif defined(HAVE_TOUCHSCREEN)
122 /* This is a touchscreen target */
123 #else
124 #error No keymap defined!
125 #endif
127 #ifdef HAVE_TOUCHSCREEN
128 #ifndef BTN_MENU
129 #define BTN_MENU (BUTTON_TOPLEFT|BUTTON_REL)
130 #endif
131 #ifndef BTN_FIRE
132 #define BTN_FIRE BUTTON_CENTER
133 #endif
134 #endif
136 /* The lowdown on source terminology:
137 * a ROCKET is launched from the LCD bottom.
138 * FIREWORKs are ejected from the rocket when it explodes. */
140 #define MAX_ROCKETS 40
141 #define ROCKET_LIFE (LCD_HEIGHT/2)
142 #define ROCKET_LIFE_VAR (LCD_HEIGHT/4)
143 #define ROCKET_SIZE 2
144 #define ROCKET_MOVEMENT_RANGE 4
145 #define ROCKET_TRAIL_PARTICLES 50
147 #define MAX_FIREWORKS 40
148 #define FIREWORK_MOVEMENT_RANGE 6
149 #define FIREWORK_SIZE 2
151 /* position, speed, "phase" (age), color of all fireworks */
152 int firework_xpoints[MAX_ROCKETS][MAX_FIREWORKS];
153 int firework_ypoints[MAX_ROCKETS][MAX_FIREWORKS];
154 int firework_xspeed[MAX_ROCKETS][MAX_FIREWORKS];
155 int firework_yspeed[MAX_ROCKETS][MAX_FIREWORKS];
156 int firework_phase[MAX_ROCKETS];
157 #ifdef HAVE_LCD_COLOR
158 int firework_color[MAX_ROCKETS][MAX_FIREWORKS];
159 #endif
161 /* position, speed, "phase" (age) of all rockets */
162 int rocket_xpos[MAX_ROCKETS];
163 int rocket_ypos[MAX_ROCKETS];
164 int rocket_xspeed[MAX_ROCKETS];
165 int rocket_yspeed[MAX_ROCKETS];
166 int rocket_phase[MAX_ROCKETS];
167 int rocket_targetphase[MAX_ROCKETS];
169 /* settings values. these should eventually be saved to
170 * disk. maybe a preset loading/saving system? */
171 int autofire_delay = 0;
172 int particles_per_firework = 2;
173 int particle_life = 1;
174 int gravity = 1;
175 int show_rockets = 1;
176 int frames_per_second = 4;
177 bool quit_plugin = false;
179 /* firework colors:
180 * firework_colors = brightest firework color, used most of the time.
181 * DARK colors = fireworks are nearly burnt out.
182 * DARKER colors = fireworks are several frames away from burning out.
183 * DARKEST colors = fireworks are a couple frames from burning out. */
184 #ifdef HAVE_LCD_COLOR
185 static const unsigned firework_colors[] = {
186 LCD_RGBPACK(0,255,64), LCD_RGBPACK(61,255,249), LCD_RGBPACK(255,200,61),
187 LCD_RGBPACK(217,22,217), LCD_RGBPACK(22,217,132), LCD_RGBPACK(67,95,254),
188 LCD_RGBPACK(151,84,213) };
190 static const unsigned firework_dark_colors[] = {
191 LCD_RGBPACK(0,128,32), LCD_RGBPACK(30,128,128), LCD_RGBPACK(128,100,30),
192 LCD_RGBPACK(109,11,109), LCD_RGBPACK(11,109,66), LCD_RGBPACK(33,47,128),
193 LCD_RGBPACK(75,42,105) };
195 static const unsigned firework_darker_colors[] = {
196 LCD_RGBPACK(0,64,16), LCD_RGBPACK(15,64,64), LCD_RGBPACK(64,50,15),
197 LCD_RGBPACK(55,5,55), LCD_RGBPACK(5,55,33), LCD_RGBPACK(16,24,64),
198 LCD_RGBPACK(38,21,52) };
200 static const unsigned firework_darkest_colors[] = {
201 LCD_RGBPACK(0,32,8), LCD_RGBPACK(7,32,32), LCD_RGBPACK(32,25,7),
202 LCD_RGBPACK(27,2,27), LCD_RGBPACK(2,27,16), LCD_RGBPACK(8,12,32),
203 LCD_RGBPACK(19,10,26) };
205 #define EXPLOSION_COLOR LCD_RGBPACK(255,240,0)
207 #endif
209 static const struct opt_items autofire_delay_settings[15] = {
210 { "Off", -1 },
211 { "50ms", -1 },
212 { "100ms", -1 },
213 { "200ms", -1 },
214 { "300ms", -1 },
215 { "400ms", -1 },
216 { "500ms", -1 },
217 { "600ms", -1 },
218 { "700ms", -1 },
219 { "800ms", -1 },
220 { "900ms", -1 },
221 { "1s", -1 },
222 { "2s", -1 },
223 { "3s", -1 },
224 { "4s", -1 }
227 int autofire_delay_values[15] = {
228 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400 };
230 static const struct opt_items particle_settings[8] = {
231 { "5", -1 },
232 { "10", -1 },
233 { "15", -1 },
234 { "20", -1 },
235 { "25", -1 },
236 { "30", -1 },
237 { "35", -1 },
238 { "40", -1 },
241 int particle_values[8] = {
242 5, 10, 15, 20, 25, 30, 35, 40 };
244 static const struct opt_items particle_life_settings[9] = {
245 { "20 cycles", -1 },
246 { "30 cycles", -1 },
247 { "40 cycles", -1 },
248 { "50 cycles", -1 },
249 { "60 cycles", -1 },
250 { "70 cycles", -1 },
251 { "80 cycles", -1 },
252 { "90 cycles", -1 },
253 { "100 cycles", -1 }
256 int particle_life_values[9] = {
257 20, 30, 40, 50, 60, 70, 80, 90, 100 };
259 static const struct opt_items gravity_settings[4] = {
260 { "Off", -1 },
261 { "Weak", -1 },
262 { "Moderate", -1 },
263 { "Strong", -1 },
266 int gravity_values[4] = {
267 0, 30, 20, 10 };
269 #ifdef HAVE_LCD_COLOR
271 static const struct opt_items rocket_settings[3] = {
272 { "No", -1 },
273 { "Yes (no trails)", -1 },
274 { "Yes (with trails)", -1 },
276 int rocket_values[4] = {
277 2, 1, 0 };
279 #else
281 static const struct opt_items rocket_settings[2] = {
282 { "No", -1 },
283 { "Yes", -1 },
285 int rocket_values[4] = {
286 1, 0 };
288 #endif
290 static const struct opt_items fps_settings[9] = {
291 { "20 FPS", -1 },
292 { "25 FPS", -1 },
293 { "30 FPS", -1 },
294 { "35 FPS", -1 },
295 { "40 FPS", -1 },
296 { "45 FPS", -1 },
297 { "50 FPS", -1 },
298 { "55 FPS", -1 },
299 { "60 FPS", -1 }
302 int fps_values[9] = {
303 20, 25, 30, 35, 40, 45, 50, 55, 60 };
305 MENUITEM_STRINGLIST(menu, "Fireworks Menu", NULL,
306 "Start Demo", "Auto-Fire", "Particles Per Firework",
307 "Particle Life", "Gravity", "Show Rockets",
308 "FPS (Speed)", "Playback Control", "Quit");
310 /* called on startup. initializes all variables, etc */
311 void init_all(void)
313 int j;
315 for(j=0; j<MAX_ROCKETS; j++)
317 rocket_phase[j] = -1;
318 firework_phase[j] = -1;
322 /* called when a rocket hits its destination height.
323 * prepares all associated fireworks to be expelled. */
324 void init_explode(int x, int y, int firework, int points)
326 int i;
328 for(i=0; i<points; i++)
330 rb->srand(*rb->current_tick * i);
332 firework_xpoints[firework][i] = x;
333 firework_ypoints[firework][i] = y;
335 firework_xspeed[firework][i] = (rb->rand() % FIREWORK_MOVEMENT_RANGE)
336 - FIREWORK_MOVEMENT_RANGE/2;
337 firework_yspeed[firework][i] = (rb->rand() % FIREWORK_MOVEMENT_RANGE)
338 - FIREWORK_MOVEMENT_RANGE/2;
340 #ifdef HAVE_LCD_COLOR
341 firework_color[firework][i] = rb->rand() % 7;
342 #endif
346 /* called when a rocket is launched.
347 * prepares said rocket to start moving towards its destination. */
348 void init_rocket(int rocket)
350 rb->srand(*rb->current_tick);
352 rocket_xpos[rocket] = rb->rand() % LCD_WIDTH;
353 rocket_ypos[rocket] = LCD_HEIGHT;
355 rocket_xspeed[rocket] = (rb->rand() % ROCKET_MOVEMENT_RANGE)
356 - ROCKET_MOVEMENT_RANGE/2;
357 rocket_yspeed[rocket] = 3;
359 rocket_phase[rocket] = 0;
360 rocket_targetphase[rocket] = (ROCKET_LIFE + (rb->rand() % ROCKET_LIFE_VAR))
361 / rocket_yspeed[rocket];
364 /* startup/configuration menu. */
365 void fireworks_menu(void)
367 int selected = 0, result;
368 bool menu_quit = false;
370 rb->lcd_setfont(FONT_UI);
371 #ifdef HAVE_LCD_COLOR
372 rb->lcd_set_background(LCD_BLACK);
373 rb->lcd_set_foreground(LCD_WHITE);
374 #endif
375 rb->lcd_clear_display();
376 rb->lcd_update();
378 rb->button_clear_queue();
380 while(!menu_quit)
382 result = rb->do_menu(&menu, &selected, NULL, false);
384 switch(result)
386 case 0:
387 rb->lcd_setfont(FONT_SYSFIXED);
389 #ifdef HAVE_LCD_COLOR
390 rb->lcd_set_background(LCD_BLACK);
391 rb->lcd_set_foreground(LCD_WHITE);
392 #endif
394 rb->lcd_clear_display();
395 rb->lcd_update();
397 init_all();
398 menu_quit = true;
399 break;
401 case 1:
402 rb->set_option("Auto-Fire", &autofire_delay, INT,
403 autofire_delay_settings, 15, NULL);
404 break;
406 case 2:
407 rb->set_option("Particles Per Firework", &particles_per_firework,
408 INT, particle_settings, 8, NULL);
409 break;
411 case 3:
412 rb->set_option("Particle Life", &particle_life, INT,
413 particle_life_settings, 9, NULL);
414 break;
416 case 4:
417 rb->set_option("Gravity", &gravity, INT,
418 gravity_settings, 4, NULL);
419 break;
421 case 5:
422 rb->set_option("Show Rockets", &show_rockets, INT,
423 rocket_settings, 3, NULL);
424 break;
426 case 6:
427 rb->set_option("FPS (Speed)", &frames_per_second, INT,
428 fps_settings, 9, NULL);
429 break;
431 case 7:
432 playback_control(NULL);
433 break;
435 case 8:
436 quit_plugin = true;
437 menu_quit = true;
438 break;
443 /* this is the plugin entry point */
444 enum plugin_status plugin_start(const void* parameter)
446 (void)parameter;
448 int j, i;
449 int thisrocket=0;
450 int start_tick, elapsed_tick;
451 int button;
453 /* set everything up.. no BL timeout, no backdrop,
454 white-text-on-black-background. */
455 backlight_force_on(); /* backlight control in lib/helper.c */
456 #if LCD_DEPTH > 1
457 rb->lcd_set_backdrop(NULL);
458 rb->lcd_set_background(LCD_BLACK);
459 rb->lcd_set_foreground(LCD_WHITE);
460 #endif
462 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
463 rb->cpu_boost(true);
464 #endif
466 fireworks_menu();
468 start_tick = *rb->current_tick;
470 while(!quit_plugin)
472 rb->lcd_clear_display();
474 /* loop through every possible rocket */
475 for(j=0; j<MAX_ROCKETS; j++)
477 /* if the current rocket is actually moving/"alive" then go on and
478 * move/update/explode it */
479 if(rocket_phase[j] > -1)
481 #ifdef HAVE_LCD_COLOR /* draw trail, if requested */
482 if(show_rockets==2)
484 rb->lcd_set_foreground(LCD_RGBPACK(128,128,128));
485 rb->lcd_fillrect(rocket_xpos[j], rocket_ypos[j],
486 ROCKET_SIZE, ROCKET_SIZE);
487 rb->lcd_set_foreground(LCD_RGBPACK(64,64,64));
488 rb->lcd_fillrect(rocket_xpos[j]-rocket_xspeed[j],
489 rocket_ypos[j]+rocket_yspeed[j],
490 ROCKET_SIZE, ROCKET_SIZE);
492 #endif
494 /* move rocket */
495 rocket_xpos[j] += rocket_xspeed[j];
496 rocket_ypos[j] -= rocket_yspeed[j];
498 #ifdef HAVE_LCD_COLOR
499 rb->lcd_set_foreground(LCD_WHITE);
500 #endif
501 if(show_rockets==2 || show_rockets==1)
502 rb->lcd_fillrect(rocket_xpos[j], rocket_ypos[j],
503 ROCKET_SIZE, ROCKET_SIZE);
505 /* if(rocket isn't "there" yet) keep moving
506 * if(rocket IS there) explode it. */
507 if(rocket_phase[j] < rocket_targetphase[j])
508 rocket_phase[j]++;
509 else
511 rocket_phase[j] = -1;
513 firework_phase[j] = 0;
514 init_explode(rocket_xpos[j], rocket_ypos[j], j,
515 particle_values[particles_per_firework]);
519 /* and now onto the fireworks for this particular rocket... */
520 if(firework_phase[j] > -1)
522 for(i=0; i<particle_values[particles_per_firework]; i++)
524 firework_xpoints[j][i] += firework_xspeed[j][i];
525 firework_ypoints[j][i] += firework_yspeed[j][i];
527 if(gravity != 0)
528 firework_ypoints[j][i] += firework_phase[j]
529 /gravity_values[gravity];
531 #ifdef HAVE_LCD_COLOR
532 rb->lcd_set_foreground(
533 firework_darkest_colors[firework_color[j][i]]);
534 rb->lcd_fillrect(firework_xpoints[j][i]-1,
535 firework_ypoints[j][i]-1,
536 FIREWORK_SIZE+2, FIREWORK_SIZE+2);
538 int phase_left = particle_life_values[particle_life]
539 - firework_phase[j];
540 if(phase_left > 10)
541 rb->lcd_set_foreground(
542 firework_colors[firework_color[j][i]]);
543 else if(phase_left > 7)
544 rb->lcd_set_foreground(
545 firework_dark_colors[firework_color[j][i]]);
546 else if(phase_left > 3)
547 rb->lcd_set_foreground(
548 firework_darker_colors[firework_color[j][i]]);
549 else
550 rb->lcd_set_foreground(
551 firework_darkest_colors[firework_color[j][i]]);
552 #endif
553 rb->lcd_fillrect(firework_xpoints[j][i],
554 firework_ypoints[j][i],
555 FIREWORK_SIZE, FIREWORK_SIZE);
556 /* WIP - currently ugly explosion effect
557 #ifdef HAVE_LCD_COLOR
558 if(firework_phase[j] < 10)
560 rb->lcd_set_foreground(EXPLOSION_COLOR);
561 rb->lcd_fillrect(rocket_xpos[j]-firework_phase[j],
562 rocket_ypos[j]-firework_phase[j],
563 firework_phase[j]*2, firework_phase[j]*2);
565 #endif */
568 #ifdef HAVE_LCD_COLOR
569 rb->lcd_set_foreground(LCD_WHITE);
570 #endif
572 /* firework at its destination age?
573 * no = keep aging; yes = delete it. */
574 if(firework_phase[j] < particle_life_values[particle_life])
575 firework_phase[j]++;
576 else
577 firework_phase[j] = -1;
581 /* is autofire on? */
582 if(autofire_delay != 0)
584 elapsed_tick = *rb->current_tick - start_tick;
586 if(elapsed_tick > autofire_delay_values[autofire_delay])
588 init_rocket(thisrocket);
589 if(++thisrocket == MAX_ROCKETS)
590 thisrocket = 0;
592 start_tick = *rb->current_tick;
596 rb->lcd_update();
598 button = rb->button_get_w_tmo(HZ/fps_values[frames_per_second]);
599 switch(button)
601 case BTN_MENU: /* back to config menu */
602 fireworks_menu();
603 break;
605 case BTN_FIRE: /* fire off rockets manually */
606 case BTN_FIRE|BUTTON_REPEAT:
607 init_rocket(thisrocket);
608 if(++thisrocket == MAX_ROCKETS)
609 thisrocket=0;
610 break;
613 /* Turn on backlight timeout (revert to settings) */
614 backlight_use_settings(); /* backlight control in lib/helper.c */
616 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
617 rb->cpu_boost(false);
618 #endif
620 return PLUGIN_OK;