summaryrefslogtreecommitdiff
path: root/apps/plugins/demystify.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/demystify.c')
-rw-r--r--apps/plugins/demystify.c140
1 files changed, 81 insertions, 59 deletions
diff --git a/apps/plugins/demystify.c b/apps/plugins/demystify.c
index 4ebb6496ca..bfcbd2fa25 100644
--- a/apps/plugins/demystify.c
+++ b/apps/plugins/demystify.c
@@ -54,6 +54,10 @@ PLUGIN_HEADER
54#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ 54#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
55 (CONFIG_KEYPAD == IRIVER_H300_PAD) 55 (CONFIG_KEYPAD == IRIVER_H300_PAD)
56#define DEMYSTIFY_RC_QUIT BUTTON_RC_STOP 56#define DEMYSTIFY_RC_QUIT BUTTON_RC_STOP
57#define DEMYSTIFY_RC_ADD_POLYGON BUTTON_RC_BITRATE
58#define DEMYSTIFY_RC_REMOVE_POLYGON BUTTON_RC_SOURCE
59#define DEMYSTIFY_RC_INCREASE_SPEED BUTTON_RC_VOL_UP
60#define DEMYSTIFY_RC_DECREASE_SPEED BUTTON_RC_VOL_DOWN
57#endif 61#endif
58#endif 62#endif
59 63
@@ -103,13 +107,13 @@ struct polygon
103/* 107/*
104 * Generates a random polygon (which fits the screen size though) 108 * Generates a random polygon (which fits the screen size though)
105 */ 109 */
106void polygon_init(struct polygon * polygon) 110void polygon_init(struct polygon * polygon, struct screen * display)
107{ 111{
108 int i; 112 int i;
109 for(i=0;i<NB_POINTS;++i) 113 for(i=0;i<NB_POINTS;++i)
110 { 114 {
111 polygon->points[i].x=(rb->rand() % (LCD_WIDTH)); 115 polygon->points[i].x=(rb->rand() % (display->width));
112 polygon->points[i].y=(rb->rand() % (LCD_HEIGHT)); 116 polygon->points[i].y=(rb->rand() % (display->height));
113 } 117 }
114} 118}
115 119
@@ -117,15 +121,15 @@ void polygon_init(struct polygon * polygon)
117 * Draw the given polygon onto the screen 121 * Draw the given polygon onto the screen
118 */ 122 */
119 123
120void polygon_draw(struct polygon * polygon) 124void polygon_draw(struct polygon * polygon, struct screen * display)
121{ 125{
122 int i; 126 int i;
123 for(i=0;i<NB_POINTS-1;++i) 127 for(i=0;i<NB_POINTS-1;++i)
124 { 128 {
125 rb->lcd_drawline(polygon->points[i].x, polygon->points[i].y, 129 display->drawline(polygon->points[i].x, polygon->points[i].y,
126 polygon->points[i+1].x, polygon->points[i+1].y); 130 polygon->points[i+1].x, polygon->points[i+1].y);
127 } 131 }
128 rb->lcd_drawline(polygon->points[0].x, polygon->points[0].y, 132 display->drawline(polygon->points[0].x, polygon->points[0].y,
129 polygon->points[NB_POINTS-1].x, 133 polygon->points[NB_POINTS-1].x,
130 polygon->points[NB_POINTS-1].y); 134 polygon->points[NB_POINTS-1].y);
131} 135}
@@ -154,7 +158,7 @@ void polygon_move_init(struct polygon_move * polygon_move)
154 * Update the given polygon's position according to the given informations in 158 * Update the given polygon's position according to the given informations in
155 * polygon_move (polygon_move may be updated) 159 * polygon_move (polygon_move may be updated)
156 */ 160 */
157void polygon_update(struct polygon *polygon, struct polygon_move *polygon_move) 161void polygon_update(struct polygon *polygon, struct screen * display, struct polygon_move *polygon_move)
158{ 162{
159 int i, x, y, step; 163 int i, x, y, step;
160 for(i=0;i<NB_POINTS;++i) 164 for(i=0;i<NB_POINTS;++i)
@@ -167,9 +171,9 @@ void polygon_update(struct polygon *polygon, struct polygon_move *polygon_move)
167 x=1; 171 x=1;
168 polygon_move->move_steps[i].x=get_new_step(step); 172 polygon_move->move_steps[i].x=get_new_step(step);
169 } 173 }
170 else if(x>=LCD_WIDTH) 174 else if(x>=display->width)
171 { 175 {
172 x=LCD_WIDTH-1; 176 x=display->width-1;
173 polygon_move->move_steps[i].x=get_new_step(step); 177 polygon_move->move_steps[i].x=get_new_step(step);
174 } 178 }
175 polygon->points[i].x=x; 179 polygon->points[i].x=x;
@@ -182,9 +186,9 @@ void polygon_update(struct polygon *polygon, struct polygon_move *polygon_move)
182 y=1; 186 y=1;
183 polygon_move->move_steps[i].y=get_new_step(step); 187 polygon_move->move_steps[i].y=get_new_step(step);
184 } 188 }
185 else if(y>=LCD_HEIGHT) 189 else if(y>=display->height)
186 { 190 {
187 y=LCD_HEIGHT-1; 191 y=display->height-1;
188 polygon_move->move_steps[i].y=get_new_step(step); 192 polygon_move->move_steps[i].y=get_new_step(step);
189 } 193 }
190 polygon->points[i].y=y; 194 polygon->points[i].y=y;
@@ -243,30 +247,25 @@ struct polygon * fifo_pop(struct polygon_fifo * fifo)
243 * Drawing stuffs 247 * Drawing stuffs
244 */ 248 */
245 249
246void polygons_draw(struct polygon_fifo * polygons) 250void polygons_draw(struct polygon_fifo * polygons, struct screen * display)
247{ 251{
248 int i, j; 252 int i, j;
249 for(i=0, j=polygons->fifo_tail;i<polygons->nb_items;++i, ++j) 253 for(i=0, j=polygons->fifo_tail;i<polygons->nb_items;++i, ++j)
250 { 254 {
251 if(j>=MAX_POLYGONS) 255 if(j>=MAX_POLYGONS)
252 j=0; 256 j=0;
253 polygon_draw(&(polygons->tab[j])); 257 polygon_draw(&(polygons->tab[j]), display);
254 } 258 }
255} 259}
256 260
257
258
259static struct polygon_fifo polygons;
260static struct polygon_move move; /* This describes the movement of the leading
261 polygon, the others just follow */
262static struct polygon leading_polygon;
263
264
265void cleanup(void *parameter) 261void cleanup(void *parameter)
266{ 262{
267 (void)parameter; 263 (void)parameter;
268 264
269 rb->backlight_set_timeout(rb->global_settings->backlight_timeout); 265 rb->screens[SCREEN_MAIN]->backlight_set_timeout(rb->global_settings->backlight_timeout);
266#if NB_SCREENS==2
267 rb->screens[SCREEN_REMOTE]->backlight_set_timeout(rb->global_settings->remote_backlight_timeout);
268#endif
270} 269}
271 270
272/* 271/*
@@ -278,37 +277,46 @@ int plugin_main(void)
278 int button; 277 int button;
279 int sleep_time=DEFAULT_WAIT_TIME; 278 int sleep_time=DEFAULT_WAIT_TIME;
280 int nb_wanted_polygons=DEFAULT_NB_POLYGONS; 279 int nb_wanted_polygons=DEFAULT_NB_POLYGONS;
281 280 int i;
282 fifo_init(&polygons); 281 struct polygon_fifo polygons[NB_SCREENS];
283 polygon_move_init(&move); 282 struct polygon_move move[NB_SCREENS]; /* This describes the movement of the leading
284 polygon_init(&leading_polygon); 283 polygon, the others just follow */
285 284 struct polygon leading_polygon[NB_SCREENS];
285 FOR_NB_SCREENS(i)
286 {
287 fifo_init(&polygons[i]);
288 polygon_move_init(&move[i]);
289 polygon_init(&leading_polygon[i], rb->screens[i]);
290 }
286 while (true) 291 while (true)
287 { 292 {
288 if(polygons.nb_items>nb_wanted_polygons) 293 FOR_NB_SCREENS(i)
289 { /* We have too many polygons, we must drop some of them */ 294 {
290 fifo_pop(&polygons); 295 struct screen * display=rb->screens[i];
291 } 296 if(polygons[i].nb_items>nb_wanted_polygons)
292 if(nb_wanted_polygons==polygons.nb_items) 297 { /* We have too many polygons, we must drop some of them */
293 { /* We have the good number of polygons, we can safely drop the last 298 fifo_pop(&polygons[i]);
294 one to add the new one later */ 299 }
295 fifo_pop(&polygons); 300 if(nb_wanted_polygons==polygons[i].nb_items)
301 { /* We have the good number of polygons, we can safely drop
302 the last one to add the new one later */
303 fifo_pop(&polygons[i]);
304 }
305 fifo_push(&polygons[i], &leading_polygon[i]);
306
307 /*
308 * Then we update the leading polygon for the next round acording to
309 * current move (the move may be altered in case of sreen border
310 * collision)
311 */
312 polygon_update(&leading_polygon[i], display, &move[i]);
313
314 /* Now the drawing part */
315
316 display->clear_display();
317 polygons_draw(&polygons[i], display);
318 display->update();
296 } 319 }
297 fifo_push(&polygons, &leading_polygon);
298
299 /*
300 * Then we update the leading polygon for the next round acording to
301 * current move (the move may be altered in case of sreen border
302 * collision)
303 */
304 polygon_update(&leading_polygon, &move);
305
306 /* Now the drawing part */
307
308 rb->lcd_clear_display();
309 polygons_draw(&polygons);
310 rb->lcd_update();
311
312 /* Speed handling*/ 320 /* Speed handling*/
313 if (sleep_time<0)/* full speed */ 321 if (sleep_time<0)/* full speed */
314 rb->yield(); 322 rb->yield();
@@ -322,26 +330,37 @@ int plugin_main(void)
322#ifdef DEMYSTIFY_RC_QUIT 330#ifdef DEMYSTIFY_RC_QUIT
323 case DEMYSTIFY_RC_QUIT : 331 case DEMYSTIFY_RC_QUIT :
324#endif 332#endif
325 case (DEMYSTIFY_QUIT): 333 case DEMYSTIFY_QUIT:
326 cleanup(NULL); 334 cleanup(NULL);
327 return PLUGIN_OK; 335 return PLUGIN_OK;
328 336#ifdef DEMYSTIFY_RC_ADD_POLYGON
329 case (DEMYSTIFY_ADD_POLYGON): 337 case DEMYSTIFY_RC_ADD_POLYGON:
338#endif
339 case DEMYSTIFY_ADD_POLYGON:
330 if(nb_wanted_polygons<MAX_POLYGONS) 340 if(nb_wanted_polygons<MAX_POLYGONS)
331 ++nb_wanted_polygons; 341 ++nb_wanted_polygons;
332 break; 342 break;
333 343
334 case (DEMYSTIFY_REMOVE_POLYGON): 344#ifdef DEMYSTIFY_RC_REMOVE_POLYGON
345 case DEMYSTIFY_RC_REMOVE_POLYGON:
346#endif
347 case DEMYSTIFY_REMOVE_POLYGON:
335 if(nb_wanted_polygons>MIN_POLYGONS) 348 if(nb_wanted_polygons>MIN_POLYGONS)
336 --nb_wanted_polygons; 349 --nb_wanted_polygons;
337 break; 350 break;
338 351
339 case (DEMYSTIFY_INCREASE_SPEED): 352#ifdef DEMYSTIFY_RC_INCREASE_SPEED
353 case DEMYSTIFY_RC_INCREASE_SPEED:
354#endif
355 case DEMYSTIFY_INCREASE_SPEED:
340 if(sleep_time>=0) 356 if(sleep_time>=0)
341 --sleep_time; 357 --sleep_time;
342 break; 358 break;
343 359
344 case (DEMYSTIFY_DECREASE_SPEED): 360#ifdef DEMYSTIFY_RC_DECREASE_SPEED
361 case DEMYSTIFY_RC_DECREASE_SPEED:
362#endif
363 case DEMYSTIFY_DECREASE_SPEED:
345 ++sleep_time; 364 ++sleep_time;
346 break; 365 break;
347 366
@@ -363,8 +382,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
363 rb = api; /* copy to global api pointer */ 382 rb = api; /* copy to global api pointer */
364 (void)parameter; 383 (void)parameter;
365 if (rb->global_settings->backlight_timeout > 0) 384 if (rb->global_settings->backlight_timeout > 0)
366 rb->backlight_set_timeout(1);/* keep the light on */ 385 {
367 386 int i;
387 FOR_NB_SCREENS(i)
388 rb->screens[i]->backlight_set_timeout(1);/* keep the light on */
389 }
368 ret = plugin_main(); 390 ret = plugin_main();
369 391
370 return ret; 392 return ret;