Updated our source code header to explicitly mention that we are GPL v2 or
[Rockbox.git] / apps / plugins / mosaique.c
blobdbd647330fc8a4767ac9041e34d933379295fe58
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 "playergfx.h"
24 PLUGIN_HEADER
26 #ifdef HAVE_LCD_BITMAP
27 #define MYLCD(fn) rb->lcd_ ## fn
28 #define GFX_X (LCD_WIDTH/2-1)
29 #define GFX_Y (LCD_HEIGHT/2-1)
30 #if LCD_WIDTH != LCD_HEIGHT
31 #define GFX_WIDTH GFX_X
32 #define GFX_HEIGHT GFX_Y
33 #else
34 #define GFX_WIDTH GFX_X
35 #define GFX_HEIGHT (4*GFX_Y/5)
36 #endif
37 #else
38 #define MYLCD(fn) pgfx_ ## fn
39 #define GFX_X 9
40 #define GFX_Y 6
41 #define GFX_WIDTH 9
42 #define GFX_HEIGHT 6
43 #endif
45 /* variable button definitions */
46 #if CONFIG_KEYPAD == RECORDER_PAD
47 #define MOSAIQUE_QUIT BUTTON_OFF
48 #define MOSAIQUE_SPEED BUTTON_F1
49 #define MOSAIQUE_RESTART BUTTON_PLAY
51 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
52 #define MOSAIQUE_QUIT BUTTON_OFF
53 #define MOSAIQUE_SPEED BUTTON_F1
54 #define MOSAIQUE_RESTART BUTTON_SELECT
56 #elif CONFIG_KEYPAD == PLAYER_PAD
57 #define MOSAIQUE_QUIT BUTTON_STOP
58 #define MOSAIQUE_SPEED BUTTON_MENU
59 #define MOSAIQUE_RESTART BUTTON_PLAY
61 #elif CONFIG_KEYPAD == ONDIO_PAD
62 #define MOSAIQUE_QUIT BUTTON_OFF
63 #define MOSAIQUE_SPEED BUTTON_MENU
64 #define MOSAIQUE_RESTART BUTTON_RIGHT
66 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
67 (CONFIG_KEYPAD == IRIVER_H300_PAD)
68 #define MOSAIQUE_QUIT BUTTON_OFF
69 #define MOSAIQUE_SPEED BUTTON_MODE
70 #define MOSAIQUE_RESTART BUTTON_ON
72 #define MOSAIQUE_RC_QUIT BUTTON_RC_STOP
74 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
75 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
76 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
77 #define MOSAIQUE_QUIT BUTTON_MENU
78 #define MOSAIQUE_SPEED BUTTON_SELECT
79 #define MOSAIQUE_RESTART BUTTON_PLAY
81 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
82 #define MOSAIQUE_QUIT BUTTON_PLAY
83 #define MOSAIQUE_SPEED BUTTON_MODE
84 #define MOSAIQUE_RESTART BUTTON_SELECT
86 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
87 #define MOSAIQUE_QUIT BUTTON_POWER
88 #define MOSAIQUE_SPEED BUTTON_SELECT
89 #define MOSAIQUE_RESTART BUTTON_PLAY
91 #elif CONFIG_KEYPAD == GIGABEAT_PAD
92 #define MOSAIQUE_QUIT BUTTON_POWER
93 #define MOSAIQUE_SPEED BUTTON_A
94 #define MOSAIQUE_RESTART BUTTON_SELECT
96 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
97 (CONFIG_KEYPAD == SANSA_C200_PAD)
98 #define MOSAIQUE_QUIT BUTTON_POWER
99 #define MOSAIQUE_SPEED BUTTON_DOWN
100 #define MOSAIQUE_RESTART BUTTON_SELECT
102 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
103 #define MOSAIQUE_QUIT BUTTON_POWER
104 #define MOSAIQUE_SPEED BUTTON_FF
105 #define MOSAIQUE_RESTART BUTTON_PLAY
107 #elif CONFIG_KEYPAD == MROBE500_PAD
108 #define MOSAIQUE_QUIT BUTTON_POWER
109 #define MOSAIQUE_SPEED BUTTON_RC_FF
110 #define MOSAIQUE_RESTART BUTTON_RC_PLAY
112 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
113 #define MOSAIQUE_QUIT BUTTON_BACK
114 #define MOSAIQUE_SPEED BUTTON_SELECT
115 #define MOSAIQUE_RESTART BUTTON_MENU
117 #elif CONFIG_KEYPAD == MROBE100_PAD
118 #define MOSAIQUE_QUIT BUTTON_POWER
119 #define MOSAIQUE_SPEED BUTTON_DISPLAY
120 #define MOSAIQUE_RESTART BUTTON_SELECT
122 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
123 #define MOSAIQUE_QUIT BUTTON_RC_REC
124 #define MOSAIQUE_SPEED BUTTON_RC_MENU
125 #define MOSAIQUE_RESTART BUTTON_RC_PLAY
127 #elif CONFIG_KEYPAD == COWOND2_PAD
128 #define MOSAIQUE_QUIT BUTTON_POWER
130 #else
131 #error No keymap defined!
132 #endif
134 #ifdef HAVE_TOUCHPAD
135 #ifndef MOSAIQUE_QUIT
136 #define MOSAIQUE_QUIT BUTTON_TOPLEFT
137 #endif
138 #ifndef MOSAIQUE_SPEED
139 #define MOSAIQUE_SPEED BUTTON_MIDRIGHT
140 #endif
141 #ifndef MOSAIQUE_RESTART
142 #define MOSAIQUE_RESTART BUTTON_CENTER
143 #endif
144 #endif
146 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
148 int button;
149 int timer = 10;
150 int x=0;
151 int y=0;
152 int sx = 3;
153 int sy = 3;
154 const struct plugin_api* rb = api;
155 (void)parameter;
157 #ifdef HAVE_LCD_CHARCELLS
158 if (!pgfx_init(rb, 4, 2))
160 rb->splash(HZ*2, "Old LCD :(");
161 return PLUGIN_OK;
163 pgfx_display(3, 0);
164 #endif
165 MYLCD(clear_display)();
166 MYLCD(set_drawmode)(DRMODE_COMPLEMENT);
167 while (1) {
169 x+=sx;
170 if (x>GFX_WIDTH)
172 x = 2*GFX_WIDTH-x;
173 sx=-sx;
176 if (x<0)
178 x = -x;
179 sx = -sx;
182 y+=sy;
183 if (y>GFX_HEIGHT)
185 y = 2*GFX_HEIGHT-y;
186 sy=-sy;
189 if (y<0)
191 y = -y;
192 sy = -sy;
195 MYLCD(fillrect)(GFX_X-x, GFX_Y-y, 2*x+1, 1);
196 MYLCD(fillrect)(GFX_X-x, GFX_Y+y, 2*x+1, 1);
197 MYLCD(fillrect)(GFX_X-x, GFX_Y-y+1, 1, 2*y-1);
198 MYLCD(fillrect)(GFX_X+x, GFX_Y-y+1, 1, 2*y-1);
199 MYLCD(update)();
201 rb->sleep(HZ/timer);
203 button = rb->button_get(false);
204 switch (button)
206 #ifdef MOSAIQUE_RC_QUIT
207 case MOSAIQUE_RC_QUIT:
208 #endif
209 case MOSAIQUE_QUIT:
210 MYLCD(set_drawmode)(DRMODE_SOLID);
211 #ifdef HAVE_LCD_CHARCELLS
212 pgfx_release();
213 #endif
214 return PLUGIN_OK;
216 case MOSAIQUE_SPEED:
217 timer = timer+5;
218 if (timer>20)
219 timer=5;
220 break;
222 case MOSAIQUE_RESTART:
224 sx = rb->rand() % (GFX_HEIGHT/2) + 1;
225 sy = rb->rand() % (GFX_HEIGHT/2) + 1;
226 x=0;
227 y=0;
228 MYLCD(clear_display)();
229 break;
232 default:
233 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
235 MYLCD(set_drawmode)(DRMODE_SOLID);
236 #ifdef HAVE_LCD_CHARCELLS
237 pgfx_release();
238 #endif
239 return PLUGIN_USB_CONNECTED;
241 break;