Prepare new maemo release
[maemo-rb.git] / apps / plugins / mosaique.c
blob68938a1f136ebd6f03ef0d7dfe49e13acfd8678c
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"
27 #ifdef HAVE_LCD_BITMAP
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 GFX_X 9
39 #define GFX_Y 6
40 #define GFX_WIDTH 9
41 #define GFX_HEIGHT 6
42 #endif
44 /* this set the context to use with PLA */
45 static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
47 #define MOSAIQUE_QUIT PLA_EXIT
48 #define MOSAIQUE_QUIT2 PLA_CANCEL
49 #define MOSAIQUE_SPEED PLA_UP
50 #define MOSAIQUE_RESTART PLA_SELECT
52 enum plugin_status plugin_start(const void* parameter)
54 int button;
55 int timer = 10;
56 int x=0;
57 int y=0;
58 int sx = 3;
59 int sy = 3;
60 (void)parameter;
62 #ifdef HAVE_LCD_CHARCELLS
63 if (!pgfx_init(4, 2))
65 rb->splash(HZ*2, "Old LCD :(");
66 return PLUGIN_OK;
68 pgfx_display(3, 0);
69 #endif
70 mylcd_clear_display();
71 mylcd_set_drawmode(DRMODE_COMPLEMENT);
72 while (1) {
74 x+=sx;
75 if (x>GFX_WIDTH)
77 x = 2*GFX_WIDTH-x;
78 sx=-sx;
81 if (x<0)
83 x = -x;
84 sx = -sx;
87 y+=sy;
88 if (y>GFX_HEIGHT)
90 y = 2*GFX_HEIGHT-y;
91 sy=-sy;
94 if (y<0)
96 y = -y;
97 sy = -sy;
100 mylcd_fillrect(GFX_X-x, GFX_Y-y, 2*x+1, 1);
101 mylcd_fillrect(GFX_X-x, GFX_Y+y, 2*x+1, 1);
102 mylcd_fillrect(GFX_X-x, GFX_Y-y+1, 1, 2*y-1);
103 mylcd_fillrect(GFX_X+x, GFX_Y-y+1, 1, 2*y-1);
104 mylcd_update();
106 rb->sleep(HZ/timer);
108 /*We get button from PLA this way */
109 button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts,
110 ARRAYLEN(plugin_contexts));
112 switch (button)
114 #ifdef MOSAIQUE_RC_QUIT
115 case MOSAIQUE_RC_QUIT:
116 #endif
117 case MOSAIQUE_QUIT:
118 case MOSAIQUE_QUIT2:
119 mylcd_set_drawmode(DRMODE_SOLID);
120 #ifdef HAVE_LCD_CHARCELLS
121 pgfx_release();
122 #endif
123 return PLUGIN_OK;
125 case MOSAIQUE_SPEED:
126 timer = timer+5;
127 if (timer>20)
128 timer=5;
129 break;
131 case MOSAIQUE_RESTART:
133 sx = rb->rand() % (GFX_HEIGHT/2) + 1;
134 sy = rb->rand() % (GFX_HEIGHT/2) + 1;
135 x=0;
136 y=0;
137 mylcd_clear_display();
138 break;
141 default:
142 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
144 mylcd_set_drawmode(DRMODE_SOLID);
145 #ifdef HAVE_LCD_CHARCELLS
146 pgfx_release();
147 #endif
148 return PLUGIN_USB_CONNECTED;
150 break;