Add 2008 to the copyright notice.
[Rockbox.git] / apps / plugins / snow.c
blobf2e76b19f200b308f015163cf30fb67902f4845a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Itai Shaked
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 **************************************************************************/
19 #include "plugin.h"
20 #include "playergfx.h"
22 PLUGIN_HEADER
24 #ifdef HAVE_LCD_BITMAP
25 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
26 #define SNOW_HEIGHT LCD_HEIGHT
27 #define SNOW_WIDTH LCD_WIDTH
28 #define MYLCD(fn) rb->lcd_ ## fn
29 #else
30 #define NUM_PARTICLES 10
31 #define SNOW_HEIGHT 14
32 #define SNOW_WIDTH 20
33 #define MYLCD(fn) pgfx_ ## fn
34 #endif
36 /* variable button definitions */
37 #if CONFIG_KEYPAD == PLAYER_PAD
38 #define SNOW_QUIT BUTTON_STOP
39 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
40 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
41 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
42 #define SNOW_QUIT BUTTON_MENU
43 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
44 #define SNOW_QUIT BUTTON_PLAY
45 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
46 #define SNOW_QUIT BUTTON_POWER
47 #elif CONFIG_KEYPAD == GIGABEAT_PAD
48 #define SNOW_QUIT BUTTON_POWER
49 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
50 (CONFIG_KEYPAD == SANSA_C200_PAD)
51 #define SNOW_QUIT BUTTON_POWER
52 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
53 #define SNOW_QUIT BUTTON_POWER
54 #elif CONFIG_KEYPAD == MROBE500_PAD
55 #define SNOW_QUIT BUTTON_POWER
56 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
57 #define SNOW_QUIT BUTTON_BACK
58 #else
59 #define SNOW_QUIT BUTTON_OFF
60 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
61 #define SNOW_RC_QUIT BUTTON_RC_STOP
62 #endif
63 #endif
65 static short particles[NUM_PARTICLES][2];
66 static struct plugin_api* rb;
68 #ifdef HAVE_LCD_BITMAP
69 #if LCD_WIDTH >= 160
70 #define FLAKE_WIDTH 5
71 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
72 #else
73 #define FLAKE_WIDTH 3
74 static const unsigned char flake[] = {0x02,0x07,0x02};
75 #endif
76 #endif
78 static bool particle_exists(int particle)
80 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
81 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
82 return true;
83 else
84 return false;
87 static int create_particle(void)
89 int i;
91 for (i=0; i<NUM_PARTICLES; i++) {
92 if (!particle_exists(i)) {
93 particles[i][0]=(rb->rand()%SNOW_WIDTH);
94 particles[i][1]=0;
95 return i;
98 return -1;
101 static void snow_move(void)
103 int i;
105 if (!(rb->rand()%2))
106 create_particle();
108 for (i=0; i<NUM_PARTICLES; i++) {
109 if (particle_exists(i)) {
110 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
111 #ifdef HAVE_LCD_BITMAP
112 rb->lcd_fillrect(particles[i][0],particles[i][1],
113 FLAKE_WIDTH,FLAKE_WIDTH);
114 #else
115 pgfx_drawpixel(particles[i][0],particles[i][1]);
116 #endif
117 MYLCD(set_drawmode)(DRMODE_SOLID);
118 #ifdef HAVE_REMOTE_LCD
119 if (particles[i][0] <= LCD_REMOTE_WIDTH
120 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
121 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
122 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
123 FLAKE_WIDTH,FLAKE_WIDTH);
124 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
126 #endif
127 switch ((rb->rand()%7)) {
128 case 0:
129 particles[i][0]++;
130 break;
132 case 1:
133 particles[i][0]--;
134 break;
136 case 2:
137 break;
139 default:
140 particles[i][1]++;
141 break;
143 if (particle_exists(i))
144 #ifdef HAVE_LCD_BITMAP
145 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
146 FLAKE_WIDTH,FLAKE_WIDTH);
147 #else
148 pgfx_drawpixel(particles[i][0],particles[i][1]);
149 #endif
150 #ifdef HAVE_REMOTE_LCD
151 if (particles[i][0] <= LCD_REMOTE_WIDTH
152 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
153 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
154 FLAKE_WIDTH,FLAKE_WIDTH);
156 #endif
162 static void snow_init(void)
164 int i;
166 for (i=0; i<NUM_PARTICLES; i++) {
167 particles[i][0]=-1;
168 particles[i][1]=-1;
170 #ifdef HAVE_LCD_CHARCELLS
171 pgfx_display(0, 0); /* display three times */
172 pgfx_display(4, 0);
173 pgfx_display(8, 0);
174 #endif
175 MYLCD(clear_display)();
176 #ifdef HAVE_REMOTE_LCD
177 rb->lcd_remote_clear_display();
178 #endif
181 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
183 int button;
184 (void)(parameter);
185 rb = api;
187 #ifdef HAVE_LCD_CHARCELLS
188 if (!pgfx_init(rb, 4, 2))
190 rb->splash(HZ*2, "Old LCD :(");
191 return PLUGIN_OK;
193 #endif
194 #ifdef HAVE_LCD_COLOR
195 rb->lcd_clear_display();
196 rb->lcd_set_foreground(LCD_WHITE);
197 rb->lcd_set_background(LCD_DEFAULT_BG);
198 #endif
199 snow_init();
200 while (1) {
201 snow_move();
202 MYLCD(update)();
203 #ifdef HAVE_REMOTE_LCD
204 rb->lcd_remote_update();
205 #endif
206 rb->sleep(HZ/20);
208 button = rb->button_get(false);
210 if (button == SNOW_QUIT
211 #ifdef SNOW_RC_QUIT
212 || button == SNOW_RC_QUIT
213 #endif
216 #ifdef HAVE_LCD_CHARCELLS
217 pgfx_release();
218 #endif
219 return PLUGIN_OK;
221 else
222 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
224 #ifdef HAVE_LCD_CHARCELLS
225 pgfx_release();
226 #endif
227 return PLUGIN_USB_CONNECTED;