Add proper svn:mime-type
[maemo-rb.git] / apps / plugins / snow.c
blob22ffee98807801cbcfffaeaa93b6448f78699cff
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"
23 #include "lib/mylcd.h"
27 #ifdef HAVE_LCD_BITMAP
28 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
29 #define SNOW_HEIGHT LCD_HEIGHT
30 #define SNOW_WIDTH LCD_WIDTH
31 #else
32 #define NUM_PARTICLES 10
33 #define SNOW_HEIGHT 14
34 #define SNOW_WIDTH 20
35 #endif
37 /* variable button definitions */
38 #if CONFIG_KEYPAD == PLAYER_PAD
39 #define SNOW_QUIT BUTTON_STOP
41 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
42 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
44 #define SNOW_QUIT BUTTON_MENU
46 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) || \
47 (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
48 #define SNOW_QUIT BUTTON_PLAY
50 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
51 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
52 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
53 (CONFIG_KEYPAD == SANSA_M200_PAD) || \
54 (CONFIG_KEYPAD == MROBE500_PAD) || \
55 (CONFIG_KEYPAD == IRIVER_H10_PAD) || \
56 (CONFIG_KEYPAD == MROBE100_PAD) || \
57 (CONFIG_KEYPAD == COWON_D2_PAD) || \
58 (CONFIG_KEYPAD == IAUDIO67_PAD) || \
59 (CONFIG_KEYPAD == ONDAVX747_PAD) || \
60 (CONFIG_KEYPAD == ONDAVX777_PAD) || \
61 (CONFIG_KEYPAD == GIGABEAT_PAD) || \
62 (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
63 #define SNOW_QUIT BUTTON_POWER
65 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
66 #define SNOW_QUIT (BUTTON_HOME|BUTTON_REPEAT)
68 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
69 (CONFIG_KEYPAD == CREATIVEZVM_PAD)
70 #define SNOW_QUIT BUTTON_BACK
72 #elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
73 (CONFIG_KEYPAD == PHILIPS_HDD6330_PAD) || \
74 (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
75 #define SNOW_QUIT BUTTON_POWER
77 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
78 #define SNOW_QUIT BUTTON_REC
79 #define SNOW_RC_QUIT BUTTON_RC_REC
81 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
82 #define SNOW_QUIT BUTTON_REC
84 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
85 #define SNOW_QUIT (BUTTON_REC|BUTTON_PLAY)
87 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
88 #define SNOW_QUIT (BUTTON_REC|BUTTON_REPEAT)
90 #else
91 #define SNOW_QUIT BUTTON_OFF
92 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
93 #define SNOW_RC_QUIT BUTTON_RC_STOP
94 #endif
95 #endif
97 static short particles[NUM_PARTICLES][2];
99 #ifdef HAVE_LCD_BITMAP
100 #if LCD_WIDTH >= 160
101 #define FLAKE_WIDTH 5
102 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
103 #else
104 #define FLAKE_WIDTH 3
105 static const unsigned char flake[] = {0x02,0x07,0x02};
106 #endif
107 #endif
109 static bool particle_exists(int particle)
111 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
112 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
113 return true;
114 else
115 return false;
118 static int create_particle(void)
120 int i;
122 for (i=0; i<NUM_PARTICLES; i++) {
123 if (!particle_exists(i)) {
124 particles[i][0]=(rb->rand()%SNOW_WIDTH);
125 particles[i][1]=0;
126 return i;
129 return -1;
132 static void snow_move(void)
134 int i;
136 if (!(rb->rand()%2))
137 create_particle();
139 for (i=0; i<NUM_PARTICLES; i++) {
140 if (particle_exists(i)) {
141 mylcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
142 #ifdef HAVE_LCD_BITMAP
143 rb->lcd_fillrect(particles[i][0],particles[i][1],
144 FLAKE_WIDTH,FLAKE_WIDTH);
145 #else
146 pgfx_drawpixel(particles[i][0],particles[i][1]);
147 #endif
148 mylcd_set_drawmode(DRMODE_SOLID);
149 #ifdef HAVE_REMOTE_LCD
150 if (particles[i][0] <= LCD_REMOTE_WIDTH
151 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
152 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
153 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
154 FLAKE_WIDTH,FLAKE_WIDTH);
155 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
157 #endif
158 switch ((rb->rand()%7)) {
159 case 0:
160 particles[i][0]++;
161 break;
163 case 1:
164 particles[i][0]--;
165 break;
167 case 2:
168 break;
170 default:
171 particles[i][1]++;
172 break;
174 if (particle_exists(i))
175 #ifdef HAVE_LCD_BITMAP
176 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
177 FLAKE_WIDTH,FLAKE_WIDTH);
178 #else
179 pgfx_drawpixel(particles[i][0],particles[i][1]);
180 #endif
181 #ifdef HAVE_REMOTE_LCD
182 if (particles[i][0] <= LCD_REMOTE_WIDTH
183 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
184 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
185 FLAKE_WIDTH,FLAKE_WIDTH);
187 #endif
193 static void snow_init(void)
195 int i;
197 for (i=0; i<NUM_PARTICLES; i++) {
198 particles[i][0]=-1;
199 particles[i][1]=-1;
201 #ifdef HAVE_LCD_CHARCELLS
202 pgfx_display(0, 0); /* display three times */
203 pgfx_display(4, 0);
204 pgfx_display(8, 0);
205 #endif
206 mylcd_clear_display();
207 #ifdef HAVE_REMOTE_LCD
208 rb->lcd_remote_clear_display();
209 #endif
212 enum plugin_status plugin_start(const void* parameter)
214 int button;
215 (void)(parameter);
217 #ifdef HAVE_LCD_CHARCELLS
218 if (!pgfx_init(4, 2))
220 rb->splash(HZ*2, "Old LCD :(");
221 return PLUGIN_OK;
223 #endif
224 #ifdef HAVE_LCD_COLOR
225 rb->lcd_clear_display();
226 rb->lcd_set_foreground(LCD_WHITE);
227 rb->lcd_set_background(LCD_DEFAULT_BG);
228 #endif
229 snow_init();
230 while (1) {
231 snow_move();
232 mylcd_update();
233 #ifdef HAVE_REMOTE_LCD
234 rb->lcd_remote_update();
235 #endif
236 rb->sleep(HZ/20);
238 button = rb->button_get(false);
240 if (button == SNOW_QUIT
241 #ifdef SNOW_RC_QUIT
242 || button == SNOW_RC_QUIT
243 #endif
246 #ifdef HAVE_LCD_CHARCELLS
247 pgfx_release();
248 #endif
249 return PLUGIN_OK;
251 else
252 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
254 #ifdef HAVE_LCD_CHARCELLS
255 pgfx_release();
256 #endif
257 return PLUGIN_USB_CONNECTED;