Update the discussion of themeing in the manual, and put a note in the wps tags appen...
[kugel-rb.git] / apps / plugins / snow.c
blobeb8870efde280c3227719dcb87938691c86b8858
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 == COWON_D2_PAD) || \
59 (CONFIG_KEYPAD == IAUDIO67_PAD) || \
60 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
61 (CONFIG_KEYPAD == ONDAVX747_PAD) || \
62 (CONFIG_KEYPAD == ONDAVX777_PAD) || \
63 (CONFIG_KEYPAD == GIGABEAT_PAD) || \
64 (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
65 #define SNOW_QUIT BUTTON_POWER
67 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
68 #define SNOW_QUIT (BUTTON_HOME|BUTTON_REPEAT)
70 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
71 (CONFIG_KEYPAD == CREATIVEZVM_PAD)
72 #define SNOW_QUIT BUTTON_BACK
74 #elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
75 (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
76 #define SNOW_QUIT BUTTON_POWER
78 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
79 #define SNOW_QUIT BUTTON_REC
80 #define SNOW_RC_QUIT BUTTON_RC_REC
82 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
83 #define SNOW_QUIT BUTTON_REC
85 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
86 #define SNOW_QUIT (BUTTON_REC|BUTTON_PLAY)
88 #else
89 #define SNOW_QUIT BUTTON_OFF
90 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
91 #define SNOW_RC_QUIT BUTTON_RC_STOP
92 #endif
93 #endif
95 static short particles[NUM_PARTICLES][2];
97 #ifdef HAVE_LCD_BITMAP
98 #if LCD_WIDTH >= 160
99 #define FLAKE_WIDTH 5
100 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
101 #else
102 #define FLAKE_WIDTH 3
103 static const unsigned char flake[] = {0x02,0x07,0x02};
104 #endif
105 #endif
107 static bool particle_exists(int particle)
109 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
110 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
111 return true;
112 else
113 return false;
116 static int create_particle(void)
118 int i;
120 for (i=0; i<NUM_PARTICLES; i++) {
121 if (!particle_exists(i)) {
122 particles[i][0]=(rb->rand()%SNOW_WIDTH);
123 particles[i][1]=0;
124 return i;
127 return -1;
130 static void snow_move(void)
132 int i;
134 if (!(rb->rand()%2))
135 create_particle();
137 for (i=0; i<NUM_PARTICLES; i++) {
138 if (particle_exists(i)) {
139 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
140 #ifdef HAVE_LCD_BITMAP
141 rb->lcd_fillrect(particles[i][0],particles[i][1],
142 FLAKE_WIDTH,FLAKE_WIDTH);
143 #else
144 pgfx_drawpixel(particles[i][0],particles[i][1]);
145 #endif
146 MYLCD(set_drawmode)(DRMODE_SOLID);
147 #ifdef HAVE_REMOTE_LCD
148 if (particles[i][0] <= LCD_REMOTE_WIDTH
149 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
150 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
151 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
152 FLAKE_WIDTH,FLAKE_WIDTH);
153 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
155 #endif
156 switch ((rb->rand()%7)) {
157 case 0:
158 particles[i][0]++;
159 break;
161 case 1:
162 particles[i][0]--;
163 break;
165 case 2:
166 break;
168 default:
169 particles[i][1]++;
170 break;
172 if (particle_exists(i))
173 #ifdef HAVE_LCD_BITMAP
174 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
175 FLAKE_WIDTH,FLAKE_WIDTH);
176 #else
177 pgfx_drawpixel(particles[i][0],particles[i][1]);
178 #endif
179 #ifdef HAVE_REMOTE_LCD
180 if (particles[i][0] <= LCD_REMOTE_WIDTH
181 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
182 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
183 FLAKE_WIDTH,FLAKE_WIDTH);
185 #endif
191 static void snow_init(void)
193 int i;
195 for (i=0; i<NUM_PARTICLES; i++) {
196 particles[i][0]=-1;
197 particles[i][1]=-1;
199 #ifdef HAVE_LCD_CHARCELLS
200 pgfx_display(0, 0); /* display three times */
201 pgfx_display(4, 0);
202 pgfx_display(8, 0);
203 #endif
204 MYLCD(clear_display)();
205 #ifdef HAVE_REMOTE_LCD
206 rb->lcd_remote_clear_display();
207 #endif
210 enum plugin_status plugin_start(const void* parameter)
212 int button;
213 (void)(parameter);
215 #ifdef HAVE_LCD_CHARCELLS
216 if (!pgfx_init(4, 2))
218 rb->splash(HZ*2, "Old LCD :(");
219 return PLUGIN_OK;
221 #endif
222 #ifdef HAVE_LCD_COLOR
223 rb->lcd_clear_display();
224 rb->lcd_set_foreground(LCD_WHITE);
225 rb->lcd_set_background(LCD_DEFAULT_BG);
226 #endif
227 snow_init();
228 while (1) {
229 snow_move();
230 MYLCD(update)();
231 #ifdef HAVE_REMOTE_LCD
232 rb->lcd_remote_update();
233 #endif
234 rb->sleep(HZ/20);
236 button = rb->button_get(false);
238 if (button == SNOW_QUIT
239 #ifdef SNOW_RC_QUIT
240 || button == SNOW_RC_QUIT
241 #endif
244 #ifdef HAVE_LCD_CHARCELLS
245 pgfx_release();
246 #endif
247 return PLUGIN_OK;
249 else
250 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
252 #ifdef HAVE_LCD_CHARCELLS
253 pgfx_release();
254 #endif
255 return PLUGIN_USB_CONNECTED;