when changing settings from the Talk and Voice window also update the main widgets...
[Rockbox.git] / apps / plugins / snow.c
blob56ebb2eae46becfbfc390e8e5796155f43dade00
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 == MROBE100_PAD
57 #define SNOW_QUIT BUTTON_POWER
58 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
59 #define SNOW_QUIT BUTTON_BACK
60 #else
61 #define SNOW_QUIT BUTTON_OFF
62 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
63 #define SNOW_RC_QUIT BUTTON_RC_STOP
64 #endif
65 #endif
67 static short particles[NUM_PARTICLES][2];
68 static struct plugin_api* rb;
70 #ifdef HAVE_LCD_BITMAP
71 #if LCD_WIDTH >= 160
72 #define FLAKE_WIDTH 5
73 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
74 #else
75 #define FLAKE_WIDTH 3
76 static const unsigned char flake[] = {0x02,0x07,0x02};
77 #endif
78 #endif
80 static bool particle_exists(int particle)
82 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
83 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
84 return true;
85 else
86 return false;
89 static int create_particle(void)
91 int i;
93 for (i=0; i<NUM_PARTICLES; i++) {
94 if (!particle_exists(i)) {
95 particles[i][0]=(rb->rand()%SNOW_WIDTH);
96 particles[i][1]=0;
97 return i;
100 return -1;
103 static void snow_move(void)
105 int i;
107 if (!(rb->rand()%2))
108 create_particle();
110 for (i=0; i<NUM_PARTICLES; i++) {
111 if (particle_exists(i)) {
112 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
113 #ifdef HAVE_LCD_BITMAP
114 rb->lcd_fillrect(particles[i][0],particles[i][1],
115 FLAKE_WIDTH,FLAKE_WIDTH);
116 #else
117 pgfx_drawpixel(particles[i][0],particles[i][1]);
118 #endif
119 MYLCD(set_drawmode)(DRMODE_SOLID);
120 #ifdef HAVE_REMOTE_LCD
121 if (particles[i][0] <= LCD_REMOTE_WIDTH
122 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
123 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
124 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
125 FLAKE_WIDTH,FLAKE_WIDTH);
126 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
128 #endif
129 switch ((rb->rand()%7)) {
130 case 0:
131 particles[i][0]++;
132 break;
134 case 1:
135 particles[i][0]--;
136 break;
138 case 2:
139 break;
141 default:
142 particles[i][1]++;
143 break;
145 if (particle_exists(i))
146 #ifdef HAVE_LCD_BITMAP
147 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
148 FLAKE_WIDTH,FLAKE_WIDTH);
149 #else
150 pgfx_drawpixel(particles[i][0],particles[i][1]);
151 #endif
152 #ifdef HAVE_REMOTE_LCD
153 if (particles[i][0] <= LCD_REMOTE_WIDTH
154 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
155 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
156 FLAKE_WIDTH,FLAKE_WIDTH);
158 #endif
164 static void snow_init(void)
166 int i;
168 for (i=0; i<NUM_PARTICLES; i++) {
169 particles[i][0]=-1;
170 particles[i][1]=-1;
172 #ifdef HAVE_LCD_CHARCELLS
173 pgfx_display(0, 0); /* display three times */
174 pgfx_display(4, 0);
175 pgfx_display(8, 0);
176 #endif
177 MYLCD(clear_display)();
178 #ifdef HAVE_REMOTE_LCD
179 rb->lcd_remote_clear_display();
180 #endif
183 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
185 int button;
186 (void)(parameter);
187 rb = api;
189 #ifdef HAVE_LCD_CHARCELLS
190 if (!pgfx_init(rb, 4, 2))
192 rb->splash(HZ*2, "Old LCD :(");
193 return PLUGIN_OK;
195 #endif
196 #ifdef HAVE_LCD_COLOR
197 rb->lcd_clear_display();
198 rb->lcd_set_foreground(LCD_WHITE);
199 rb->lcd_set_background(LCD_DEFAULT_BG);
200 #endif
201 snow_init();
202 while (1) {
203 snow_move();
204 MYLCD(update)();
205 #ifdef HAVE_REMOTE_LCD
206 rb->lcd_remote_update();
207 #endif
208 rb->sleep(HZ/20);
210 button = rb->button_get(false);
212 if (button == SNOW_QUIT
213 #ifdef SNOW_RC_QUIT
214 || button == SNOW_RC_QUIT
215 #endif
218 #ifdef HAVE_LCD_CHARCELLS
219 pgfx_release();
220 #endif
221 return PLUGIN_OK;
223 else
224 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
226 #ifdef HAVE_LCD_CHARCELLS
227 pgfx_release();
228 #endif
229 return PLUGIN_USB_CONNECTED;