1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Zakk Roberts
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "oldmenuapi.h"
25 static struct plugin_api
* rb
;
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
38 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
39 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
40 #define BTN_MENU BUTTON_MENU
41 #define BTN_FIRE BUTTON_SELECT
42 #elif (CONFIG_KEYPAD == RECORDER_PAD)
43 #define BTN_MENU BUTTON_OFF
44 #define BTN_FIRE BUTTON_PLAY
45 #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
46 #define BTN_MENU BUTTON_OFF
47 #define BTN_FIRE BUTTON_SELECT
48 #elif (CONFIG_KEYPAD == ONDIO_PAD)
49 #define BTN_MENU BUTTON_MENU
50 #define BTN_FIRE BUTTON_UP
51 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
52 #define BTN_MENU BUTTON_POWER
53 #define BTN_FIRE BUTTON_SELECT
54 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
55 #define BTN_MENU BUTTON_MODE
56 #define BTN_FIRE BUTTON_SELECT
57 #elif (CONFIG_KEYPAD == GIGABEAT_PAD) || \
58 (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
59 (CONFIG_KEYPAD == MROBE100_PAD)
60 #define BTN_MENU BUTTON_MENU
61 #define BTN_FIRE BUTTON_SELECT
62 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
63 (CONFIG_KEYPAD == SANSA_C200_PAD)
64 #define BTN_MENU BUTTON_POWER
65 #define BTN_FIRE BUTTON_SELECT
66 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
67 #define BTN_MENU BUTTON_POWER
68 #define BTN_FIRE BUTTON_PLAY
69 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
70 #define BTN_MENU BUTTON_RC_REC
71 #define BTN_FIRE BUTTON_RC_PLAY
72 #elif (CONFIG_KEYPAD == COWOND2_PAD)
73 #define BTN_MENU BUTTON_MENU
74 #define BTN_FIRE BUTTON_SELECT
76 #error No keymap defined!
79 /* The lowdown on source terminology:
80 * a ROCKET is launched from the LCD bottom.
81 * FIREWORKs are ejected from the rocket when it explodes. */
83 #define MAX_ROCKETS 40
84 #define ROCKET_LIFE (LCD_HEIGHT/2)
85 #define ROCKET_LIFE_VAR (LCD_HEIGHT/4)
87 #define ROCKET_MOVEMENT_RANGE 4
88 #define ROCKET_TRAIL_PARTICLES 50
90 #define MAX_FIREWORKS 40
91 #define FIREWORK_MOVEMENT_RANGE 6
92 #define FIREWORK_SIZE 2
94 /* position, speed, "phase" (age), color of all fireworks */
95 int firework_xpoints
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
96 int firework_ypoints
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
97 int firework_xspeed
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
98 int firework_yspeed
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
99 int firework_phase
[MAX_ROCKETS
+1];
100 #ifdef HAVE_LCD_COLOR
101 int firework_color
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
104 /* position, speed, "phase" (age) of all rockets */
105 int rocket_xpos
[MAX_ROCKETS
+1];
106 int rocket_ypos
[MAX_ROCKETS
+1];
107 int rocket_xspeed
[MAX_ROCKETS
+1];
108 int rocket_yspeed
[MAX_ROCKETS
+1];
109 int rocket_phase
[MAX_ROCKETS
+1];
110 int rocket_targetphase
[MAX_ROCKETS
+1];
112 /* settings values. these should eventually be saved to
113 * disk. maybe a preset loading/saving system? */
114 int autofire_delay
= 0;
115 int particles_per_firework
= 2;
116 int particle_life
= 1;
118 int show_rockets
= 1;
119 int frames_per_second
= 4;
120 bool quit_plugin
= false;
123 * firework_colors = brightest firework color, used most of the time.
124 * DARK colors = fireworks are nearly burnt out.
125 * DARKER colors = fireworks are several frames away from burning out.
126 * DARKEST colors = fireworks are a couple frames from burning out. */
127 #ifdef HAVE_LCD_COLOR
128 static const unsigned firework_colors
[] = {
129 LCD_RGBPACK(0,255,64), LCD_RGBPACK(61,255,249), LCD_RGBPACK(255,200,61),
130 LCD_RGBPACK(217,22,217), LCD_RGBPACK(22,217,132), LCD_RGBPACK(67,95,254),
131 LCD_RGBPACK(151,84,213) };
133 static const unsigned firework_dark_colors
[] = {
134 LCD_RGBPACK(0,128,32), LCD_RGBPACK(30,128,128), LCD_RGBPACK(128,100,30),
135 LCD_RGBPACK(109,11,109), LCD_RGBPACK(11,109,66), LCD_RGBPACK(33,47,128),
136 LCD_RGBPACK(75,42,105) };
138 static const unsigned firework_darker_colors
[] = {
139 LCD_RGBPACK(0,64,16), LCD_RGBPACK(15,64,64), LCD_RGBPACK(64,50,15),
140 LCD_RGBPACK(55,5,55), LCD_RGBPACK(5,55,33), LCD_RGBPACK(16,24,64),
141 LCD_RGBPACK(38,21,52) };
143 static const unsigned firework_darkest_colors
[] = {
144 LCD_RGBPACK(0,32,8), LCD_RGBPACK(7,32,32), LCD_RGBPACK(32,25,7),
145 LCD_RGBPACK(27,2,27), LCD_RGBPACK(2,27,16), LCD_RGBPACK(8,12,32),
146 LCD_RGBPACK(19,10,26) };
148 #define EXPLOSION_COLOR LCD_RGBPACK(255,240,0)
152 static const struct opt_items autofire_delay_settings
[15] = {
170 int autofire_delay_values
[15] = {
171 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400 };
173 static const struct opt_items particle_settings
[8] = {
184 int particle_values
[8] = {
185 5, 10, 15, 20, 25, 30, 35, 40 };
187 static const struct opt_items particle_life_settings
[9] = {
199 int particle_life_values
[9] = {
200 20, 30, 40, 50, 60, 70, 80, 90, 100 };
202 static const struct opt_items gravity_settings
[4] = {
209 int gravity_values
[4] = {
212 #ifdef HAVE_LCD_COLOR
214 static const struct opt_items rocket_settings
[3] = {
216 { "Yes (no trails)", -1 },
217 { "Yes (with trails)", -1 },
219 int rocket_values
[4] = {
224 static const struct opt_items rocket_settings
[2] = {
228 int rocket_values
[4] = {
233 static const struct opt_items fps_settings
[9] = {
245 int fps_values
[9] = {
246 20, 25, 30, 35, 40, 45, 50, 55, 60 };
248 static const struct menu_item items
[] = {
249 { "Start Demo", NULL
},
250 { "Auto-Fire", NULL
},
251 { "Particles Per Firework", NULL
},
252 { "Particle Life", NULL
},
254 { "Show Rockets", NULL
},
255 { "FPS (Speed)", NULL
},
259 /* called on startup. initializes all variables, etc */
264 for(j
=0; j
<MAX_ROCKETS
; j
++)
265 firework_phase
[j
] = -1;
268 /* called when a rocket hits its destination height.
269 * prepares all associated fireworks to be expelled. */
270 void init_explode(int x
, int y
, int firework
, int points
)
274 for(i
=0; i
<points
; i
++)
276 rb
->srand(*rb
->current_tick
* i
);
278 firework_xpoints
[firework
][i
] = x
;
279 firework_ypoints
[firework
][i
] = y
;
281 firework_xspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
) - FIREWORK_MOVEMENT_RANGE
/2;
282 firework_yspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
) - FIREWORK_MOVEMENT_RANGE
/2;
284 #ifdef HAVE_LCD_COLOR
285 firework_color
[firework
][i
] = rb
->rand() % 7;
290 /* called when a rocket is launched.
291 * prepares said rocket to start moving towards its destination. */
292 void init_rocket(int rocket
)
294 rb
->srand(*rb
->current_tick
);
296 rocket_xpos
[rocket
] = rb
->rand() % LCD_WIDTH
;
297 rocket_ypos
[rocket
] = LCD_HEIGHT
;
299 rocket_xspeed
[rocket
] = (rb
->rand() % ROCKET_MOVEMENT_RANGE
) - ROCKET_MOVEMENT_RANGE
/2;
300 rocket_yspeed
[rocket
] = 3;
302 rocket_targetphase
[rocket
] = (ROCKET_LIFE
+ (rb
->rand() % ROCKET_LIFE_VAR
)) / rocket_yspeed
[rocket
];
305 /* startup/configuration menu. */
306 void fireworks_menu(void)
309 bool menu_quit
= false;
311 rb
->lcd_setfont(FONT_UI
);
312 #ifdef HAVE_LCD_COLOR
313 rb
->lcd_set_background(LCD_BLACK
);
314 rb
->lcd_set_foreground(LCD_WHITE
);
316 rb
->lcd_clear_display();
319 m
= menu_init(rb
, items
, sizeof(items
) / sizeof(*items
),
320 NULL
, NULL
, NULL
, NULL
);
322 rb
->button_clear_queue();
326 result
= menu_show(m
);
331 rb
->lcd_setfont(FONT_SYSFIXED
);
333 #ifdef HAVE_LCD_COLOR
334 rb
->lcd_set_background(LCD_BLACK
);
335 rb
->lcd_set_foreground(LCD_WHITE
);
338 rb
->lcd_clear_display();
346 rb
->set_option("Auto-Fire", &autofire_delay
, INT
, autofire_delay_settings
, 15, NULL
);
350 rb
->set_option("Particles Per Firework", &particles_per_firework
, INT
, particle_settings
, 8, NULL
);
354 rb
->set_option("Particle Life", &particle_life
, INT
, particle_life_settings
, 9, NULL
);
358 rb
->set_option("Gravity", &gravity
, INT
, gravity_settings
, 4, NULL
);
362 rb
->set_option("Show Rockets", &show_rockets
, INT
, rocket_settings
, 3, NULL
);
366 rb
->set_option("FPS (Speed)", &frames_per_second
, INT
, fps_settings
, 9, NULL
);
379 /* this is the plugin entry point */
380 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
386 int j
, i
, autofire
=0;
388 int start_tick
, elapsed_tick
;
391 /* set everything up.. no BL timeout, no backdrop,
392 white-text-on-black-background. */
393 backlight_force_on(rb
); /* backlight control in lib/helper.c */
395 rb
->lcd_set_backdrop(NULL
);
396 rb
->lcd_set_background(LCD_BLACK
);
397 rb
->lcd_set_foreground(LCD_WHITE
);
400 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
406 start_tick
= *rb
->current_tick
;
410 rb
->lcd_clear_display();
412 /* loop through every possible rocket */
413 for(j
=0; j
<MAX_ROCKETS
; j
++)
415 /* if the current rocket is actually moving/"alive" then go on and
416 * move/update/explode it */
417 if(rocket_phase
[j
] > -1)
419 #ifdef HAVE_LCD_COLOR /* draw trail, if requested */
422 rb
->lcd_set_foreground(LCD_RGBPACK(128,128,128));
423 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
424 ROCKET_SIZE
, ROCKET_SIZE
);
425 rb
->lcd_set_foreground(LCD_RGBPACK(64,64,64));
426 rb
->lcd_fillrect(rocket_xpos
[j
]-rocket_xspeed
[j
], rocket_ypos
[j
]+rocket_yspeed
[j
],
427 ROCKET_SIZE
, ROCKET_SIZE
);
432 rocket_xpos
[j
] += rocket_xspeed
[j
];
433 rocket_ypos
[j
] -= rocket_yspeed
[j
];
435 #ifdef HAVE_LCD_COLOR
436 rb
->lcd_set_foreground(LCD_WHITE
);
438 if(show_rockets
==2 || show_rockets
==1)
439 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
440 ROCKET_SIZE
, ROCKET_SIZE
);
442 /* if(rocket isn't "there" yet) keep moving
443 * if(rocket IS there) explode it. */
444 if(rocket_phase
[j
] < rocket_targetphase
[j
])
448 rocket_phase
[j
] = -1;
450 firework_phase
[j
] = 0;
451 init_explode(rocket_xpos
[j
], rocket_ypos
[j
], j
, particle_values
[particles_per_firework
]);
455 /* and now onto the fireworks for this particular rocket... */
456 if(firework_phase
[j
] > -1)
458 for(i
=0; i
<particle_values
[particles_per_firework
]; i
++)
460 firework_xpoints
[j
][i
] += firework_xspeed
[j
][i
];
461 firework_ypoints
[j
][i
] += firework_yspeed
[j
][i
];
464 firework_ypoints
[j
][i
] += firework_phase
[j
]/gravity_values
[gravity
];
466 #ifdef HAVE_LCD_COLOR
467 rb
->lcd_set_foreground(firework_darkest_colors
[firework_color
[j
][i
]]);
468 rb
->lcd_fillrect(firework_xpoints
[j
][i
]-1,
469 firework_ypoints
[j
][i
]-1,
470 FIREWORK_SIZE
+2, FIREWORK_SIZE
+2);
472 if(firework_phase
[j
] < particle_life_values
[particle_life
]-10)
473 rb
->lcd_set_foreground(firework_colors
[firework_color
[j
][i
]]);
474 else if(firework_phase
[j
] < particle_life_values
[particle_life
]-7)
475 rb
->lcd_set_foreground(firework_dark_colors
[firework_color
[j
][i
]]);
476 else if(firework_phase
[j
] < particle_life_values
[particle_life
]-3)
477 rb
->lcd_set_foreground(firework_darker_colors
[firework_color
[j
][i
]]);
479 rb
->lcd_set_foreground(firework_darkest_colors
[firework_color
[j
][i
]]);
481 rb
->lcd_fillrect(firework_xpoints
[j
][i
],
482 firework_ypoints
[j
][i
],
483 FIREWORK_SIZE
, FIREWORK_SIZE
);
484 /* WIP - currently ugly explosion effect
485 #ifdef HAVE_LCD_COLOR
486 if(firework_phase[j] < 10)
488 rb->lcd_set_foreground(EXPLOSION_COLOR);
489 rb->lcd_fillrect(rocket_xpos[j]-firework_phase[j],
490 rocket_ypos[j]-firework_phase[j],
491 firework_phase[j]*2, firework_phase[j]*2);
496 #ifdef HAVE_LCD_COLOR
497 rb
->lcd_set_foreground(LCD_WHITE
);
500 /* firework at its destination age?
501 * no = keep aging; yes = delete it. */
502 if(firework_phase
[j
] < particle_life_values
[particle_life
])
505 firework_phase
[j
] = -1;
509 /* is autofire on? */
510 if(autofire_delay
!= 0)
512 elapsed_tick
= *rb
->current_tick
- start_tick
;
514 if(elapsed_tick
> autofire_delay_values
[autofire_delay
])
516 rocket_phase
[autofire
] = 0;
517 init_rocket(autofire
);
519 start_tick
= *rb
->current_tick
;
521 if(autofire
< MAX_ROCKETS
)
530 button
= rb
->button_get_w_tmo(HZ
/fps_values
[frames_per_second
]);
533 case BTN_MENU
: /* back to config menu */
537 case BTN_FIRE
: /* fire off rockets manually */
538 case BTN_FIRE
|BUTTON_REPEAT
:
539 if(thisrocket
< MAX_ROCKETS
)
544 rocket_phase
[thisrocket
] = 0;
545 init_rocket(thisrocket
);
549 /* Turn on backlight timeout (revert to settings) */
550 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
552 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
553 rb
->cpu_boost(false);