* Onda VX747: add browse screen, pitchscreen, context menu, quickscreen, rewind...
[kugel-rb.git] / apps / plugins / snow.c
blob01930b7363c584b57a9a4e075a3e8be371a408eb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Itai Shaked
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/playergfx.h"
24 PLUGIN_HEADER
26 #ifdef HAVE_LCD_BITMAP
27 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
28 #define SNOW_HEIGHT LCD_HEIGHT
29 #define SNOW_WIDTH LCD_WIDTH
30 #define MYLCD(fn) rb->lcd_ ## fn
31 #else
32 #define NUM_PARTICLES 10
33 #define SNOW_HEIGHT 14
34 #define SNOW_WIDTH 20
35 #define MYLCD(fn) pgfx_ ## fn
36 #endif
38 /* variable button definitions */
39 #if CONFIG_KEYPAD == PLAYER_PAD
40 #define SNOW_QUIT BUTTON_STOP
42 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
44 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
45 #define SNOW_QUIT BUTTON_MENU
47 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) || \
48 (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
49 #define SNOW_QUIT BUTTON_PLAY
51 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
52 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
53 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
54 (CONFIG_KEYPAD == SANSA_M200_PAD) || \
55 (CONFIG_KEYPAD == MROBE500_PAD) || \
56 (CONFIG_KEYPAD == IRIVER_H10_PAD) || \
57 (CONFIG_KEYPAD == MROBE100_PAD) || \
58 (CONFIG_KEYPAD == COWOND2_PAD) || \
59 (CONFIG_KEYPAD == IAUDIO67_PAD) || \
60 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
61 (CONFIG_KEYPAD == ONDAVX747_PAD) || \
62 (CONFIG_KEYPAD == GIGABEAT_PAD) || \
63 (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
64 #define SNOW_QUIT BUTTON_POWER
66 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
67 #define SNOW_QUIT (BUTTON_HOME|BUTTON_REPEAT)
69 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
70 (CONFIG_KEYPAD == CREATIVEZVM_PAD)
71 #define SNOW_QUIT BUTTON_BACK
73 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
74 #define SNOW_QUIT BUTTON_REC
75 #define SNOW_RC_QUIT BUTTON_RC_REC
77 #else
78 #define SNOW_QUIT BUTTON_OFF
79 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
80 #define SNOW_RC_QUIT BUTTON_RC_STOP
81 #endif
82 #endif
84 static short particles[NUM_PARTICLES][2];
86 #ifdef HAVE_LCD_BITMAP
87 #if LCD_WIDTH >= 160
88 #define FLAKE_WIDTH 5
89 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
90 #else
91 #define FLAKE_WIDTH 3
92 static const unsigned char flake[] = {0x02,0x07,0x02};
93 #endif
94 #endif
96 static bool particle_exists(int particle)
98 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
99 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
100 return true;
101 else
102 return false;
105 static int create_particle(void)
107 int i;
109 for (i=0; i<NUM_PARTICLES; i++) {
110 if (!particle_exists(i)) {
111 particles[i][0]=(rb->rand()%SNOW_WIDTH);
112 particles[i][1]=0;
113 return i;
116 return -1;
119 static void snow_move(void)
121 int i;
123 if (!(rb->rand()%2))
124 create_particle();
126 for (i=0; i<NUM_PARTICLES; i++) {
127 if (particle_exists(i)) {
128 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
129 #ifdef HAVE_LCD_BITMAP
130 rb->lcd_fillrect(particles[i][0],particles[i][1],
131 FLAKE_WIDTH,FLAKE_WIDTH);
132 #else
133 pgfx_drawpixel(particles[i][0],particles[i][1]);
134 #endif
135 MYLCD(set_drawmode)(DRMODE_SOLID);
136 #ifdef HAVE_REMOTE_LCD
137 if (particles[i][0] <= LCD_REMOTE_WIDTH
138 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
139 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
140 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
141 FLAKE_WIDTH,FLAKE_WIDTH);
142 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
144 #endif
145 switch ((rb->rand()%7)) {
146 case 0:
147 particles[i][0]++;
148 break;
150 case 1:
151 particles[i][0]--;
152 break;
154 case 2:
155 break;
157 default:
158 particles[i][1]++;
159 break;
161 if (particle_exists(i))
162 #ifdef HAVE_LCD_BITMAP
163 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
164 FLAKE_WIDTH,FLAKE_WIDTH);
165 #else
166 pgfx_drawpixel(particles[i][0],particles[i][1]);
167 #endif
168 #ifdef HAVE_REMOTE_LCD
169 if (particles[i][0] <= LCD_REMOTE_WIDTH
170 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
171 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
172 FLAKE_WIDTH,FLAKE_WIDTH);
174 #endif
180 static void snow_init(void)
182 int i;
184 for (i=0; i<NUM_PARTICLES; i++) {
185 particles[i][0]=-1;
186 particles[i][1]=-1;
188 #ifdef HAVE_LCD_CHARCELLS
189 pgfx_display(0, 0); /* display three times */
190 pgfx_display(4, 0);
191 pgfx_display(8, 0);
192 #endif
193 MYLCD(clear_display)();
194 #ifdef HAVE_REMOTE_LCD
195 rb->lcd_remote_clear_display();
196 #endif
199 enum plugin_status plugin_start(const void* parameter)
201 int button;
202 (void)(parameter);
204 #ifdef HAVE_LCD_CHARCELLS
205 if (!pgfx_init(4, 2))
207 rb->splash(HZ*2, "Old LCD :(");
208 return PLUGIN_OK;
210 #endif
211 #ifdef HAVE_LCD_COLOR
212 rb->lcd_clear_display();
213 rb->lcd_set_foreground(LCD_WHITE);
214 rb->lcd_set_background(LCD_DEFAULT_BG);
215 #endif
216 snow_init();
217 while (1) {
218 snow_move();
219 MYLCD(update)();
220 #ifdef HAVE_REMOTE_LCD
221 rb->lcd_remote_update();
222 #endif
223 rb->sleep(HZ/20);
225 button = rb->button_get(false);
227 if (button == SNOW_QUIT
228 #ifdef SNOW_RC_QUIT
229 || button == SNOW_RC_QUIT
230 #endif
233 #ifdef HAVE_LCD_CHARCELLS
234 pgfx_release();
235 #endif
236 return PLUGIN_OK;
238 else
239 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
241 #ifdef HAVE_LCD_CHARCELLS
242 pgfx_release();
243 #endif
244 return PLUGIN_USB_CONNECTED;