1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
22 #include "lib/helper.h"
23 #include "lib/playback_control.h"
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.
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 == COWOND2_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 == ONDAVX747_PAD)
103 #define BTN_MENU (BUTTON_MENU|BUTTON_REL)
105 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
106 #define BTN_MENU BUTTON_LEFT
107 #define BTN_FIRE BUTTON_PLAY
109 #elif defined(HAVE_TOUCHSCREEN)
110 /* This is a touchscreen target */
112 #error No keymap defined!
115 #ifdef HAVE_TOUCHSCREEN
117 #define BTN_MENU (BUTTON_TOPLEFT|BUTTON_REL)
120 #define BTN_FIRE BUTTON_CENTER
124 /* The lowdown on source terminology:
125 * a ROCKET is launched from the LCD bottom.
126 * FIREWORKs are ejected from the rocket when it explodes. */
128 #define MAX_ROCKETS 40
129 #define ROCKET_LIFE (LCD_HEIGHT/2)
130 #define ROCKET_LIFE_VAR (LCD_HEIGHT/4)
131 #define ROCKET_SIZE 2
132 #define ROCKET_MOVEMENT_RANGE 4
133 #define ROCKET_TRAIL_PARTICLES 50
135 #define MAX_FIREWORKS 40
136 #define FIREWORK_MOVEMENT_RANGE 6
137 #define FIREWORK_SIZE 2
139 /* position, speed, "phase" (age), color of all fireworks */
140 int firework_xpoints
[MAX_ROCKETS
][MAX_FIREWORKS
];
141 int firework_ypoints
[MAX_ROCKETS
][MAX_FIREWORKS
];
142 int firework_xspeed
[MAX_ROCKETS
][MAX_FIREWORKS
];
143 int firework_yspeed
[MAX_ROCKETS
][MAX_FIREWORKS
];
144 int firework_phase
[MAX_ROCKETS
];
145 #ifdef HAVE_LCD_COLOR
146 int firework_color
[MAX_ROCKETS
][MAX_FIREWORKS
];
149 /* position, speed, "phase" (age) of all rockets */
150 int rocket_xpos
[MAX_ROCKETS
];
151 int rocket_ypos
[MAX_ROCKETS
];
152 int rocket_xspeed
[MAX_ROCKETS
];
153 int rocket_yspeed
[MAX_ROCKETS
];
154 int rocket_phase
[MAX_ROCKETS
];
155 int rocket_targetphase
[MAX_ROCKETS
];
157 /* settings values. these should eventually be saved to
158 * disk. maybe a preset loading/saving system? */
159 int autofire_delay
= 0;
160 int particles_per_firework
= 2;
161 int particle_life
= 1;
163 int show_rockets
= 1;
164 int frames_per_second
= 4;
165 bool quit_plugin
= false;
168 * firework_colors = brightest firework color, used most of the time.
169 * DARK colors = fireworks are nearly burnt out.
170 * DARKER colors = fireworks are several frames away from burning out.
171 * DARKEST colors = fireworks are a couple frames from burning out. */
172 #ifdef HAVE_LCD_COLOR
173 static const unsigned firework_colors
[] = {
174 LCD_RGBPACK(0,255,64), LCD_RGBPACK(61,255,249), LCD_RGBPACK(255,200,61),
175 LCD_RGBPACK(217,22,217), LCD_RGBPACK(22,217,132), LCD_RGBPACK(67,95,254),
176 LCD_RGBPACK(151,84,213) };
178 static const unsigned firework_dark_colors
[] = {
179 LCD_RGBPACK(0,128,32), LCD_RGBPACK(30,128,128), LCD_RGBPACK(128,100,30),
180 LCD_RGBPACK(109,11,109), LCD_RGBPACK(11,109,66), LCD_RGBPACK(33,47,128),
181 LCD_RGBPACK(75,42,105) };
183 static const unsigned firework_darker_colors
[] = {
184 LCD_RGBPACK(0,64,16), LCD_RGBPACK(15,64,64), LCD_RGBPACK(64,50,15),
185 LCD_RGBPACK(55,5,55), LCD_RGBPACK(5,55,33), LCD_RGBPACK(16,24,64),
186 LCD_RGBPACK(38,21,52) };
188 static const unsigned firework_darkest_colors
[] = {
189 LCD_RGBPACK(0,32,8), LCD_RGBPACK(7,32,32), LCD_RGBPACK(32,25,7),
190 LCD_RGBPACK(27,2,27), LCD_RGBPACK(2,27,16), LCD_RGBPACK(8,12,32),
191 LCD_RGBPACK(19,10,26) };
193 #define EXPLOSION_COLOR LCD_RGBPACK(255,240,0)
197 static const struct opt_items autofire_delay_settings
[15] = {
215 int autofire_delay_values
[15] = {
216 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400 };
218 static const struct opt_items particle_settings
[8] = {
229 int particle_values
[8] = {
230 5, 10, 15, 20, 25, 30, 35, 40 };
232 static const struct opt_items particle_life_settings
[9] = {
244 int particle_life_values
[9] = {
245 20, 30, 40, 50, 60, 70, 80, 90, 100 };
247 static const struct opt_items gravity_settings
[4] = {
254 int gravity_values
[4] = {
257 #ifdef HAVE_LCD_COLOR
259 static const struct opt_items rocket_settings
[3] = {
261 { "Yes (no trails)", -1 },
262 { "Yes (with trails)", -1 },
264 int rocket_values
[4] = {
269 static const struct opt_items rocket_settings
[2] = {
273 int rocket_values
[4] = {
278 static const struct opt_items fps_settings
[9] = {
290 int fps_values
[9] = {
291 20, 25, 30, 35, 40, 45, 50, 55, 60 };
293 MENUITEM_STRINGLIST(menu
, "Fireworks Menu", NULL
,
294 "Start Demo", "Auto-Fire", "Particles Per Firework",
295 "Particle Life", "Gravity", "Show Rockets",
296 "FPS (Speed)", "Playback Control", "Quit");
298 /* called on startup. initializes all variables, etc */
303 for(j
=0; j
<MAX_ROCKETS
; j
++)
305 rocket_phase
[j
] = -1;
306 firework_phase
[j
] = -1;
310 /* called when a rocket hits its destination height.
311 * prepares all associated fireworks to be expelled. */
312 void init_explode(int x
, int y
, int firework
, int points
)
316 for(i
=0; i
<points
; i
++)
318 rb
->srand(*rb
->current_tick
* i
);
320 firework_xpoints
[firework
][i
] = x
;
321 firework_ypoints
[firework
][i
] = y
;
323 firework_xspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
)
324 - FIREWORK_MOVEMENT_RANGE
/2;
325 firework_yspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
)
326 - FIREWORK_MOVEMENT_RANGE
/2;
328 #ifdef HAVE_LCD_COLOR
329 firework_color
[firework
][i
] = rb
->rand() % 7;
334 /* called when a rocket is launched.
335 * prepares said rocket to start moving towards its destination. */
336 void init_rocket(int rocket
)
338 rb
->srand(*rb
->current_tick
);
340 rocket_xpos
[rocket
] = rb
->rand() % LCD_WIDTH
;
341 rocket_ypos
[rocket
] = LCD_HEIGHT
;
343 rocket_xspeed
[rocket
] = (rb
->rand() % ROCKET_MOVEMENT_RANGE
)
344 - ROCKET_MOVEMENT_RANGE
/2;
345 rocket_yspeed
[rocket
] = 3;
347 rocket_phase
[rocket
] = 0;
348 rocket_targetphase
[rocket
] = (ROCKET_LIFE
+ (rb
->rand() % ROCKET_LIFE_VAR
))
349 / rocket_yspeed
[rocket
];
352 /* startup/configuration menu. */
353 void fireworks_menu(void)
355 int selected
= 0, result
;
356 bool menu_quit
= false;
358 rb
->lcd_setfont(FONT_UI
);
359 #ifdef HAVE_LCD_COLOR
360 rb
->lcd_set_background(LCD_BLACK
);
361 rb
->lcd_set_foreground(LCD_WHITE
);
363 rb
->lcd_clear_display();
366 rb
->button_clear_queue();
370 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
375 rb
->lcd_setfont(FONT_SYSFIXED
);
377 #ifdef HAVE_LCD_COLOR
378 rb
->lcd_set_background(LCD_BLACK
);
379 rb
->lcd_set_foreground(LCD_WHITE
);
382 rb
->lcd_clear_display();
390 rb
->set_option("Auto-Fire", &autofire_delay
, INT
,
391 autofire_delay_settings
, 15, NULL
);
395 rb
->set_option("Particles Per Firework", &particles_per_firework
,
396 INT
, particle_settings
, 8, NULL
);
400 rb
->set_option("Particle Life", &particle_life
, INT
,
401 particle_life_settings
, 9, NULL
);
405 rb
->set_option("Gravity", &gravity
, INT
,
406 gravity_settings
, 4, NULL
);
410 rb
->set_option("Show Rockets", &show_rockets
, INT
,
411 rocket_settings
, 3, NULL
);
415 rb
->set_option("FPS (Speed)", &frames_per_second
, INT
,
416 fps_settings
, 9, NULL
);
420 playback_control(NULL
);
431 /* this is the plugin entry point */
432 enum plugin_status
plugin_start(const void* parameter
)
438 int start_tick
, elapsed_tick
;
441 /* set everything up.. no BL timeout, no backdrop,
442 white-text-on-black-background. */
443 backlight_force_on(); /* backlight control in lib/helper.c */
445 rb
->lcd_set_backdrop(NULL
);
446 rb
->lcd_set_background(LCD_BLACK
);
447 rb
->lcd_set_foreground(LCD_WHITE
);
450 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
456 start_tick
= *rb
->current_tick
;
460 rb
->lcd_clear_display();
462 /* loop through every possible rocket */
463 for(j
=0; j
<MAX_ROCKETS
; j
++)
465 /* if the current rocket is actually moving/"alive" then go on and
466 * move/update/explode it */
467 if(rocket_phase
[j
] > -1)
469 #ifdef HAVE_LCD_COLOR /* draw trail, if requested */
472 rb
->lcd_set_foreground(LCD_RGBPACK(128,128,128));
473 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
474 ROCKET_SIZE
, ROCKET_SIZE
);
475 rb
->lcd_set_foreground(LCD_RGBPACK(64,64,64));
476 rb
->lcd_fillrect(rocket_xpos
[j
]-rocket_xspeed
[j
],
477 rocket_ypos
[j
]+rocket_yspeed
[j
],
478 ROCKET_SIZE
, ROCKET_SIZE
);
483 rocket_xpos
[j
] += rocket_xspeed
[j
];
484 rocket_ypos
[j
] -= rocket_yspeed
[j
];
486 #ifdef HAVE_LCD_COLOR
487 rb
->lcd_set_foreground(LCD_WHITE
);
489 if(show_rockets
==2 || show_rockets
==1)
490 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
491 ROCKET_SIZE
, ROCKET_SIZE
);
493 /* if(rocket isn't "there" yet) keep moving
494 * if(rocket IS there) explode it. */
495 if(rocket_phase
[j
] < rocket_targetphase
[j
])
499 rocket_phase
[j
] = -1;
501 firework_phase
[j
] = 0;
502 init_explode(rocket_xpos
[j
], rocket_ypos
[j
], j
,
503 particle_values
[particles_per_firework
]);
507 /* and now onto the fireworks for this particular rocket... */
508 if(firework_phase
[j
] > -1)
510 for(i
=0; i
<particle_values
[particles_per_firework
]; i
++)
512 firework_xpoints
[j
][i
] += firework_xspeed
[j
][i
];
513 firework_ypoints
[j
][i
] += firework_yspeed
[j
][i
];
516 firework_ypoints
[j
][i
] += firework_phase
[j
]
517 /gravity_values
[gravity
];
519 #ifdef HAVE_LCD_COLOR
520 rb
->lcd_set_foreground(
521 firework_darkest_colors
[firework_color
[j
][i
]]);
522 rb
->lcd_fillrect(firework_xpoints
[j
][i
]-1,
523 firework_ypoints
[j
][i
]-1,
524 FIREWORK_SIZE
+2, FIREWORK_SIZE
+2);
526 int phase_left
= particle_life_values
[particle_life
]
529 rb
->lcd_set_foreground(
530 firework_colors
[firework_color
[j
][i
]]);
531 else if(phase_left
> 7)
532 rb
->lcd_set_foreground(
533 firework_dark_colors
[firework_color
[j
][i
]]);
534 else if(phase_left
> 3)
535 rb
->lcd_set_foreground(
536 firework_darker_colors
[firework_color
[j
][i
]]);
538 rb
->lcd_set_foreground(
539 firework_darkest_colors
[firework_color
[j
][i
]]);
541 rb
->lcd_fillrect(firework_xpoints
[j
][i
],
542 firework_ypoints
[j
][i
],
543 FIREWORK_SIZE
, FIREWORK_SIZE
);
544 /* WIP - currently ugly explosion effect
545 #ifdef HAVE_LCD_COLOR
546 if(firework_phase[j] < 10)
548 rb->lcd_set_foreground(EXPLOSION_COLOR);
549 rb->lcd_fillrect(rocket_xpos[j]-firework_phase[j],
550 rocket_ypos[j]-firework_phase[j],
551 firework_phase[j]*2, firework_phase[j]*2);
556 #ifdef HAVE_LCD_COLOR
557 rb
->lcd_set_foreground(LCD_WHITE
);
560 /* firework at its destination age?
561 * no = keep aging; yes = delete it. */
562 if(firework_phase
[j
] < particle_life_values
[particle_life
])
565 firework_phase
[j
] = -1;
569 /* is autofire on? */
570 if(autofire_delay
!= 0)
572 elapsed_tick
= *rb
->current_tick
- start_tick
;
574 if(elapsed_tick
> autofire_delay_values
[autofire_delay
])
576 init_rocket(thisrocket
);
577 if(++thisrocket
== MAX_ROCKETS
)
580 start_tick
= *rb
->current_tick
;
586 button
= rb
->button_get_w_tmo(HZ
/fps_values
[frames_per_second
]);
589 case BTN_MENU
: /* back to config menu */
593 case BTN_FIRE
: /* fire off rockets manually */
594 case BTN_FIRE
|BUTTON_REPEAT
:
595 init_rocket(thisrocket
);
596 if(++thisrocket
== MAX_ROCKETS
)
601 /* Turn on backlight timeout (revert to settings) */
602 backlight_use_settings(); /* backlight control in lib/helper.c */
604 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
605 rb
->cpu_boost(false);