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/oldmenuapi.h"
23 #include "lib/helper.h"
27 static const struct plugin_api
* rb
;
30 * FIREWORKS.C by ZAKK ROBERTS
31 * Rockbox plugin simulating a fireworks display.
32 * Supports all bitmap LCDs, fully scalable.
33 * Currently disabled for Archos Recorder - runs too slow.
36 /* All sorts of keymappings.. */
37 #if (CONFIG_KEYPAD == IRIVER_H300_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD)
38 #define BTN_MENU BUTTON_OFF
39 #define BTN_FIRE BUTTON_SELECT
40 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
41 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
42 #define BTN_MENU BUTTON_MENU
43 #define BTN_FIRE BUTTON_SELECT
44 #elif (CONFIG_KEYPAD == RECORDER_PAD)
45 #define BTN_MENU BUTTON_OFF
46 #define BTN_FIRE BUTTON_PLAY
47 #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
48 #define BTN_MENU BUTTON_OFF
49 #define BTN_FIRE BUTTON_SELECT
50 #elif (CONFIG_KEYPAD == ONDIO_PAD)
51 #define BTN_MENU BUTTON_MENU
52 #define BTN_FIRE BUTTON_UP
53 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
54 #define BTN_MENU BUTTON_POWER
55 #define BTN_FIRE BUTTON_SELECT
56 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
57 #define BTN_MENU BUTTON_MODE
58 #define BTN_FIRE BUTTON_SELECT
59 #elif (CONFIG_KEYPAD == GIGABEAT_PAD) || \
60 (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
61 (CONFIG_KEYPAD == MROBE100_PAD)
62 #define BTN_MENU BUTTON_MENU
63 #define BTN_FIRE BUTTON_SELECT
64 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
65 (CONFIG_KEYPAD == SANSA_C200_PAD)
66 #define BTN_MENU BUTTON_POWER
67 #define BTN_FIRE BUTTON_SELECT
68 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
69 #define BTN_MENU BUTTON_POWER
70 #define BTN_FIRE BUTTON_PLAY
71 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
72 #define BTN_MENU BUTTON_RC_REC
73 #define BTN_FIRE BUTTON_RC_PLAY
74 #elif (CONFIG_KEYPAD == COWOND2_PAD)
75 #define BTN_MENU (BUTTON_MENU|BUTTON_REL)
76 #elif CONFIG_KEYPAD == IAUDIO67_PAD
77 #define BTN_MENU BUTTON_MENU
78 #define BTN_FIRE BUTTON_PLAY
80 #error No keymap defined!
83 #ifdef HAVE_TOUCHSCREEN
85 #define BTN_MENU (BUTTON_TOPLEFT|BUTTON_REL)
88 #define BTN_FIRE BUTTON_CENTER
92 /* The lowdown on source terminology:
93 * a ROCKET is launched from the LCD bottom.
94 * FIREWORKs are ejected from the rocket when it explodes. */
96 #define MAX_ROCKETS 40
97 #define ROCKET_LIFE (LCD_HEIGHT/2)
98 #define ROCKET_LIFE_VAR (LCD_HEIGHT/4)
100 #define ROCKET_MOVEMENT_RANGE 4
101 #define ROCKET_TRAIL_PARTICLES 50
103 #define MAX_FIREWORKS 40
104 #define FIREWORK_MOVEMENT_RANGE 6
105 #define FIREWORK_SIZE 2
107 /* position, speed, "phase" (age), color of all fireworks */
108 int firework_xpoints
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
109 int firework_ypoints
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
110 int firework_xspeed
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
111 int firework_yspeed
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
112 int firework_phase
[MAX_ROCKETS
+1];
113 #ifdef HAVE_LCD_COLOR
114 int firework_color
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
117 /* position, speed, "phase" (age) of all rockets */
118 int rocket_xpos
[MAX_ROCKETS
+1];
119 int rocket_ypos
[MAX_ROCKETS
+1];
120 int rocket_xspeed
[MAX_ROCKETS
+1];
121 int rocket_yspeed
[MAX_ROCKETS
+1];
122 int rocket_phase
[MAX_ROCKETS
+1];
123 int rocket_targetphase
[MAX_ROCKETS
+1];
125 /* settings values. these should eventually be saved to
126 * disk. maybe a preset loading/saving system? */
127 int autofire_delay
= 0;
128 int particles_per_firework
= 2;
129 int particle_life
= 1;
131 int show_rockets
= 1;
132 int frames_per_second
= 4;
133 bool quit_plugin
= false;
136 * firework_colors = brightest firework color, used most of the time.
137 * DARK colors = fireworks are nearly burnt out.
138 * DARKER colors = fireworks are several frames away from burning out.
139 * DARKEST colors = fireworks are a couple frames from burning out. */
140 #ifdef HAVE_LCD_COLOR
141 static const unsigned firework_colors
[] = {
142 LCD_RGBPACK(0,255,64), LCD_RGBPACK(61,255,249), LCD_RGBPACK(255,200,61),
143 LCD_RGBPACK(217,22,217), LCD_RGBPACK(22,217,132), LCD_RGBPACK(67,95,254),
144 LCD_RGBPACK(151,84,213) };
146 static const unsigned firework_dark_colors
[] = {
147 LCD_RGBPACK(0,128,32), LCD_RGBPACK(30,128,128), LCD_RGBPACK(128,100,30),
148 LCD_RGBPACK(109,11,109), LCD_RGBPACK(11,109,66), LCD_RGBPACK(33,47,128),
149 LCD_RGBPACK(75,42,105) };
151 static const unsigned firework_darker_colors
[] = {
152 LCD_RGBPACK(0,64,16), LCD_RGBPACK(15,64,64), LCD_RGBPACK(64,50,15),
153 LCD_RGBPACK(55,5,55), LCD_RGBPACK(5,55,33), LCD_RGBPACK(16,24,64),
154 LCD_RGBPACK(38,21,52) };
156 static const unsigned firework_darkest_colors
[] = {
157 LCD_RGBPACK(0,32,8), LCD_RGBPACK(7,32,32), LCD_RGBPACK(32,25,7),
158 LCD_RGBPACK(27,2,27), LCD_RGBPACK(2,27,16), LCD_RGBPACK(8,12,32),
159 LCD_RGBPACK(19,10,26) };
161 #define EXPLOSION_COLOR LCD_RGBPACK(255,240,0)
165 static const struct opt_items autofire_delay_settings
[15] = {
183 int autofire_delay_values
[15] = {
184 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400 };
186 static const struct opt_items particle_settings
[8] = {
197 int particle_values
[8] = {
198 5, 10, 15, 20, 25, 30, 35, 40 };
200 static const struct opt_items particle_life_settings
[9] = {
212 int particle_life_values
[9] = {
213 20, 30, 40, 50, 60, 70, 80, 90, 100 };
215 static const struct opt_items gravity_settings
[4] = {
222 int gravity_values
[4] = {
225 #ifdef HAVE_LCD_COLOR
227 static const struct opt_items rocket_settings
[3] = {
229 { "Yes (no trails)", -1 },
230 { "Yes (with trails)", -1 },
232 int rocket_values
[4] = {
237 static const struct opt_items rocket_settings
[2] = {
241 int rocket_values
[4] = {
246 static const struct opt_items fps_settings
[9] = {
258 int fps_values
[9] = {
259 20, 25, 30, 35, 40, 45, 50, 55, 60 };
261 static const struct menu_item items
[] = {
262 { "Start Demo", NULL
},
263 { "Auto-Fire", NULL
},
264 { "Particles Per Firework", NULL
},
265 { "Particle Life", NULL
},
267 { "Show Rockets", NULL
},
268 { "FPS (Speed)", NULL
},
272 /* called on startup. initializes all variables, etc */
277 for(j
=0; j
<MAX_ROCKETS
; j
++)
278 firework_phase
[j
] = -1;
281 /* called when a rocket hits its destination height.
282 * prepares all associated fireworks to be expelled. */
283 void init_explode(int x
, int y
, int firework
, int points
)
287 for(i
=0; i
<points
; i
++)
289 rb
->srand(*rb
->current_tick
* i
);
291 firework_xpoints
[firework
][i
] = x
;
292 firework_ypoints
[firework
][i
] = y
;
294 firework_xspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
) - FIREWORK_MOVEMENT_RANGE
/2;
295 firework_yspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
) - FIREWORK_MOVEMENT_RANGE
/2;
297 #ifdef HAVE_LCD_COLOR
298 firework_color
[firework
][i
] = rb
->rand() % 7;
303 /* called when a rocket is launched.
304 * prepares said rocket to start moving towards its destination. */
305 void init_rocket(int rocket
)
307 rb
->srand(*rb
->current_tick
);
309 rocket_xpos
[rocket
] = rb
->rand() % LCD_WIDTH
;
310 rocket_ypos
[rocket
] = LCD_HEIGHT
;
312 rocket_xspeed
[rocket
] = (rb
->rand() % ROCKET_MOVEMENT_RANGE
) - ROCKET_MOVEMENT_RANGE
/2;
313 rocket_yspeed
[rocket
] = 3;
315 rocket_targetphase
[rocket
] = (ROCKET_LIFE
+ (rb
->rand() % ROCKET_LIFE_VAR
)) / rocket_yspeed
[rocket
];
318 /* startup/configuration menu. */
319 void fireworks_menu(void)
322 bool menu_quit
= false;
324 rb
->lcd_setfont(FONT_UI
);
325 #ifdef HAVE_LCD_COLOR
326 rb
->lcd_set_background(LCD_BLACK
);
327 rb
->lcd_set_foreground(LCD_WHITE
);
329 rb
->lcd_clear_display();
332 m
= menu_init(rb
, items
, sizeof(items
) / sizeof(*items
),
333 NULL
, NULL
, NULL
, NULL
);
335 rb
->button_clear_queue();
339 result
= menu_show(m
);
344 rb
->lcd_setfont(FONT_SYSFIXED
);
346 #ifdef HAVE_LCD_COLOR
347 rb
->lcd_set_background(LCD_BLACK
);
348 rb
->lcd_set_foreground(LCD_WHITE
);
351 rb
->lcd_clear_display();
359 rb
->set_option("Auto-Fire", &autofire_delay
, INT
, autofire_delay_settings
, 15, NULL
);
363 rb
->set_option("Particles Per Firework", &particles_per_firework
, INT
, particle_settings
, 8, NULL
);
367 rb
->set_option("Particle Life", &particle_life
, INT
, particle_life_settings
, 9, NULL
);
371 rb
->set_option("Gravity", &gravity
, INT
, gravity_settings
, 4, NULL
);
375 rb
->set_option("Show Rockets", &show_rockets
, INT
, rocket_settings
, 3, NULL
);
379 rb
->set_option("FPS (Speed)", &frames_per_second
, INT
, fps_settings
, 9, NULL
);
392 /* this is the plugin entry point */
393 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
)
399 int j
, i
, autofire
=0;
401 int start_tick
, elapsed_tick
;
404 /* set everything up.. no BL timeout, no backdrop,
405 white-text-on-black-background. */
406 backlight_force_on(rb
); /* backlight control in lib/helper.c */
408 rb
->lcd_set_backdrop(NULL
);
409 rb
->lcd_set_background(LCD_BLACK
);
410 rb
->lcd_set_foreground(LCD_WHITE
);
413 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
419 start_tick
= *rb
->current_tick
;
423 rb
->lcd_clear_display();
425 /* loop through every possible rocket */
426 for(j
=0; j
<MAX_ROCKETS
; j
++)
428 /* if the current rocket is actually moving/"alive" then go on and
429 * move/update/explode it */
430 if(rocket_phase
[j
] > -1)
432 #ifdef HAVE_LCD_COLOR /* draw trail, if requested */
435 rb
->lcd_set_foreground(LCD_RGBPACK(128,128,128));
436 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
437 ROCKET_SIZE
, ROCKET_SIZE
);
438 rb
->lcd_set_foreground(LCD_RGBPACK(64,64,64));
439 rb
->lcd_fillrect(rocket_xpos
[j
]-rocket_xspeed
[j
], rocket_ypos
[j
]+rocket_yspeed
[j
],
440 ROCKET_SIZE
, ROCKET_SIZE
);
445 rocket_xpos
[j
] += rocket_xspeed
[j
];
446 rocket_ypos
[j
] -= rocket_yspeed
[j
];
448 #ifdef HAVE_LCD_COLOR
449 rb
->lcd_set_foreground(LCD_WHITE
);
451 if(show_rockets
==2 || show_rockets
==1)
452 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
453 ROCKET_SIZE
, ROCKET_SIZE
);
455 /* if(rocket isn't "there" yet) keep moving
456 * if(rocket IS there) explode it. */
457 if(rocket_phase
[j
] < rocket_targetphase
[j
])
461 rocket_phase
[j
] = -1;
463 firework_phase
[j
] = 0;
464 init_explode(rocket_xpos
[j
], rocket_ypos
[j
], j
, particle_values
[particles_per_firework
]);
468 /* and now onto the fireworks for this particular rocket... */
469 if(firework_phase
[j
] > -1)
471 for(i
=0; i
<particle_values
[particles_per_firework
]; i
++)
473 firework_xpoints
[j
][i
] += firework_xspeed
[j
][i
];
474 firework_ypoints
[j
][i
] += firework_yspeed
[j
][i
];
477 firework_ypoints
[j
][i
] += firework_phase
[j
]/gravity_values
[gravity
];
479 #ifdef HAVE_LCD_COLOR
480 rb
->lcd_set_foreground(firework_darkest_colors
[firework_color
[j
][i
]]);
481 rb
->lcd_fillrect(firework_xpoints
[j
][i
]-1,
482 firework_ypoints
[j
][i
]-1,
483 FIREWORK_SIZE
+2, FIREWORK_SIZE
+2);
485 if(firework_phase
[j
] < particle_life_values
[particle_life
]-10)
486 rb
->lcd_set_foreground(firework_colors
[firework_color
[j
][i
]]);
487 else if(firework_phase
[j
] < particle_life_values
[particle_life
]-7)
488 rb
->lcd_set_foreground(firework_dark_colors
[firework_color
[j
][i
]]);
489 else if(firework_phase
[j
] < particle_life_values
[particle_life
]-3)
490 rb
->lcd_set_foreground(firework_darker_colors
[firework_color
[j
][i
]]);
492 rb
->lcd_set_foreground(firework_darkest_colors
[firework_color
[j
][i
]]);
494 rb
->lcd_fillrect(firework_xpoints
[j
][i
],
495 firework_ypoints
[j
][i
],
496 FIREWORK_SIZE
, FIREWORK_SIZE
);
497 /* WIP - currently ugly explosion effect
498 #ifdef HAVE_LCD_COLOR
499 if(firework_phase[j] < 10)
501 rb->lcd_set_foreground(EXPLOSION_COLOR);
502 rb->lcd_fillrect(rocket_xpos[j]-firework_phase[j],
503 rocket_ypos[j]-firework_phase[j],
504 firework_phase[j]*2, firework_phase[j]*2);
509 #ifdef HAVE_LCD_COLOR
510 rb
->lcd_set_foreground(LCD_WHITE
);
513 /* firework at its destination age?
514 * no = keep aging; yes = delete it. */
515 if(firework_phase
[j
] < particle_life_values
[particle_life
])
518 firework_phase
[j
] = -1;
522 /* is autofire on? */
523 if(autofire_delay
!= 0)
525 elapsed_tick
= *rb
->current_tick
- start_tick
;
527 if(elapsed_tick
> autofire_delay_values
[autofire_delay
])
529 rocket_phase
[autofire
] = 0;
530 init_rocket(autofire
);
532 start_tick
= *rb
->current_tick
;
534 if(autofire
< MAX_ROCKETS
)
543 button
= rb
->button_get_w_tmo(HZ
/fps_values
[frames_per_second
]);
546 case BTN_MENU
: /* back to config menu */
550 case BTN_FIRE
: /* fire off rockets manually */
551 case BTN_FIRE
|BUTTON_REPEAT
:
552 if(thisrocket
< MAX_ROCKETS
)
557 rocket_phase
[thisrocket
] = 0;
558 init_rocket(thisrocket
);
562 /* Turn on backlight timeout (revert to settings) */
563 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
565 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
566 rb
->cpu_boost(false);