Bump version numbers for 3.13
[maemo-rb.git] / apps / plugins / snow.c
blob74efb8ea0008830acd0bb798f13ebcd2805a3180
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"
24 #include "lib/pluginlib_actions.h"
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 #else
31 #define NUM_PARTICLES 10
32 #define SNOW_HEIGHT 14
33 #define SNOW_WIDTH 20
34 #endif
36 static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
38 /* PLA definitions */
39 #define SNOW_QUIT PLA_EXIT
40 #define SNOW_QUIT2 PLA_CANCEL
42 static short particles[NUM_PARTICLES][2];
44 #ifdef HAVE_LCD_BITMAP
45 #if LCD_WIDTH >= 160
46 #define FLAKE_WIDTH 5
47 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
48 #else
49 #define FLAKE_WIDTH 3
50 static const unsigned char flake[] = {0x02,0x07,0x02};
51 #endif
52 #endif
54 static bool particle_exists(int particle)
56 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
57 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
58 return true;
59 else
60 return false;
63 static int create_particle(void)
65 int i;
67 for (i=0; i<NUM_PARTICLES; i++) {
68 if (!particle_exists(i)) {
69 particles[i][0]=(rb->rand()%SNOW_WIDTH);
70 particles[i][1]=0;
71 return i;
74 return -1;
77 static void snow_move(void)
79 int i;
81 if (!(rb->rand()%2))
82 create_particle();
84 for (i=0; i<NUM_PARTICLES; i++) {
85 if (particle_exists(i)) {
86 mylcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
87 #ifdef HAVE_LCD_BITMAP
88 rb->lcd_fillrect(particles[i][0],particles[i][1],
89 FLAKE_WIDTH,FLAKE_WIDTH);
90 #else
91 pgfx_drawpixel(particles[i][0],particles[i][1]);
92 #endif
93 mylcd_set_drawmode(DRMODE_SOLID);
94 #ifdef HAVE_REMOTE_LCD
95 if (particles[i][0] <= LCD_REMOTE_WIDTH
96 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
97 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
98 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
99 FLAKE_WIDTH,FLAKE_WIDTH);
100 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
102 #endif
103 switch ((rb->rand()%7)) {
104 case 0:
105 particles[i][0]++;
106 break;
108 case 1:
109 particles[i][0]--;
110 break;
112 case 2:
113 break;
115 default:
116 particles[i][1]++;
117 break;
119 if (particle_exists(i))
120 #ifdef HAVE_LCD_BITMAP
121 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
122 FLAKE_WIDTH,FLAKE_WIDTH);
123 #else
124 pgfx_drawpixel(particles[i][0],particles[i][1]);
125 #endif
126 #ifdef HAVE_REMOTE_LCD
127 if (particles[i][0] <= LCD_REMOTE_WIDTH
128 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
129 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
130 FLAKE_WIDTH,FLAKE_WIDTH);
132 #endif
138 static void snow_init(void)
140 int i;
142 for (i=0; i<NUM_PARTICLES; i++) {
143 particles[i][0]=-1;
144 particles[i][1]=-1;
146 #ifdef HAVE_LCD_CHARCELLS
147 pgfx_display(0, 0); /* display three times */
148 pgfx_display(4, 0);
149 pgfx_display(8, 0);
150 #endif
151 mylcd_clear_display();
152 #ifdef HAVE_REMOTE_LCD
153 rb->lcd_remote_clear_display();
154 #endif
157 enum plugin_status plugin_start(const void* parameter)
159 int button;
160 (void)(parameter);
162 #ifdef HAVE_LCD_CHARCELLS
163 if (!pgfx_init(4, 2))
165 rb->splash(HZ*2, "Old LCD :(");
166 return PLUGIN_OK;
168 #endif
169 #ifdef HAVE_LCD_COLOR
170 rb->lcd_clear_display();
171 rb->lcd_set_foreground(LCD_WHITE);
172 rb->lcd_set_background(LCD_DEFAULT_BG);
173 #endif
174 snow_init();
175 while (1) {
176 snow_move();
177 mylcd_update();
178 #ifdef HAVE_REMOTE_LCD
179 rb->lcd_remote_update();
180 #endif
181 rb->sleep(HZ/20);
183 /*We get button from PLA this way */
184 button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts,
185 ARRAYLEN(plugin_contexts));
187 if ((button == SNOW_QUIT) || (button == SNOW_QUIT2))
189 #ifdef HAVE_LCD_CHARCELLS
190 pgfx_release();
191 #endif
192 return PLUGIN_OK;
194 else
195 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
197 #ifdef HAVE_LCD_CHARCELLS
198 pgfx_release();
199 #endif
200 return PLUGIN_USB_CONNECTED;