Prepare new maemo release
[maemo-rb.git] / apps / plugins / logo.c
blobaae9e54562dbcd77f47d1ef74b890937bffe51a2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Jonas H�gqvist
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/pluginlib_actions.h"
25 /* this set the context to use with PLA */
26 static const struct button_mapping *plugin_contexts[]
27 = { pla_main_ctx,
28 #ifdef HAVE_REMOTE_LCD
29 pla_remote_ctx,
30 #endif
33 #ifdef HAVE_LCD_BITMAP
34 #define DISPLAY_WIDTH LCD_WIDTH
35 #define DISPLAY_HEIGHT LCD_HEIGHT
36 #define RAND_SCALE 5
38 #ifdef HAVE_REMOTE_LCD
39 #define REMOTE_WIDTH LCD_REMOTE_WIDTH
40 #define REMOTE_HEIGHT LCD_REMOTE_HEIGHT
41 #include "pluginbitmaps/remote_rockboxlogo.h"
42 #define REMOTE_LOGO_WIDTH BMPWIDTH_remote_rockboxlogo
43 #define REMOTE_LOGO_HEIGHT BMPHEIGHT_remote_rockboxlogo
44 #define REMOTE_LOGO remote_rockboxlogo
45 extern const fb_remote_data remote_rockboxlogo[];
46 #endif /* HAVE_REMOTE_LCD */
48 #define LOGO rockboxlogo
49 #include "pluginbitmaps/rockboxlogo.h"
50 #define LOGO_WIDTH BMPWIDTH_rockboxlogo
51 #define LOGO_HEIGHT BMPHEIGHT_rockboxlogo
52 extern const fb_data rockboxlogo[];
54 #else /* !LCD_BITMAP */
55 #define DISPLAY_WIDTH 55
56 #define DISPLAY_HEIGHT 14
57 #define RAND_SCALE 2
58 #define LOGO_WIDTH 16
59 #define LOGO_HEIGHT 7
60 #define LOGO rockbox16x7
61 const unsigned char rockbox16x7[] = {
62 0x47, 0x18, 0xa6, 0xd8, 0x66, 0xde, 0xb7, 0x9b,
63 0x76, 0xdb, 0x26, 0xdb, 0x66, 0xde,
65 #endif /* !LCD_BITMAP */
67 /* We use PLA */
68 #define LP_QUIT PLA_EXIT
69 #define LP_QUIT2 PLA_CANCEL
70 #define LP_DEC_X PLA_LEFT
71 #define LP_DEC_X_REPEAT PLA_LEFT_REPEAT
72 #define LP_INC_X PLA_RIGHT
73 #define LP_INC_X_REPEAT PLA_RIGHT_REPEAT
74 #define LP_DEC_Y PLA_DOWN
75 #define LP_DEC_Y_REPEAT PLA_DOWN_REPEAT
76 #define LP_INC_Y PLA_UP
77 #define LP_INC_Y_REPEAT PLA_UP_REPEAT
79 enum plugin_status plugin_start(const void* parameter) {
80 int button;
81 int timer = 10;
82 int x = (DISPLAY_WIDTH / 2) - (LOGO_WIDTH / 2);
83 int y = (DISPLAY_HEIGHT / 2) - (LOGO_HEIGHT / 2);
84 int dx;
85 int dy;
86 #ifdef HAVE_LCD_CHARCELLS
87 int cpos = -1;
88 int old_cpos = -1;
89 #endif
91 (void)parameter;
93 #ifdef HAVE_LCD_CHARCELLS
94 if (!pgfx_init(4, 2)) {
95 rb->splash(HZ*2, "Old LCD :(");
96 return PLUGIN_OK;
98 #endif
99 rb->srand(*rb->current_tick);
100 dx = rb->rand()%(2*RAND_SCALE+1) - RAND_SCALE;
101 dy = rb->rand()%(2*RAND_SCALE+1) - RAND_SCALE;
103 while (1) {
104 #ifdef HAVE_LCD_BITMAP
105 rb->lcd_clear_display();
106 rb->lcd_bitmap(LOGO, x, y, LOGO_WIDTH, LOGO_HEIGHT);
107 #ifdef REMOTE_LOGO
108 rb->lcd_remote_clear_display();
109 rb->lcd_remote_bitmap(REMOTE_LOGO,
110 (x * (REMOTE_WIDTH - REMOTE_LOGO_WIDTH)) / (DISPLAY_WIDTH - LOGO_WIDTH),
111 (y * (REMOTE_HEIGHT - REMOTE_LOGO_HEIGHT)) / (DISPLAY_HEIGHT - LOGO_HEIGHT),
112 REMOTE_LOGO_WIDTH, REMOTE_LOGO_HEIGHT);
113 #endif
114 #else
115 pgfx_clear_display();
116 pgfx_mono_bitmap(LOGO, x % 5, y, LOGO_WIDTH, LOGO_HEIGHT);
117 cpos = x / 5;
118 #endif
120 x += dx;
121 if (x < 0) {
122 dx = -dx;
123 x = 0;
125 if (x > DISPLAY_WIDTH - LOGO_WIDTH) {
126 dx = -dx;
127 x = DISPLAY_WIDTH - LOGO_WIDTH;
130 y += dy;
131 if (y < 0) {
132 dy = -dy;
133 y = 0;
135 if (y > DISPLAY_HEIGHT - LOGO_HEIGHT) {
136 dy = -dy;
137 y = DISPLAY_HEIGHT - LOGO_HEIGHT;
140 #ifdef HAVE_LCD_BITMAP
141 rb->lcd_update();
142 #ifdef REMOTE_LOGO
143 rb->lcd_remote_update();
144 #endif
145 #else
146 if (cpos != old_cpos) {
147 rb->lcd_clear_display();
148 pgfx_display(cpos, 0);
149 old_cpos = cpos;
151 pgfx_update();
152 #endif
153 rb->sleep(HZ/timer);
157 /*We get button from PLA this way */
158 button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts,
159 ARRAYLEN(plugin_contexts));
161 switch (button) {
162 case LP_QUIT:
163 case LP_QUIT2:
164 #ifdef HAVE_LCD_CHARCELLS
165 pgfx_release();
166 #endif
167 return PLUGIN_OK;
168 case LP_DEC_X:
169 case LP_DEC_X_REPEAT:
170 if (dx)
171 dx += (dx < 0) ? 1 : -1;
172 break;
173 case LP_INC_X:
174 case LP_INC_X_REPEAT:
175 dx += (dx < 0) ? -1 : 1;
176 break;
177 case LP_DEC_Y:
178 case LP_DEC_Y_REPEAT:
179 if (dy)
180 dy += (dy < 0) ? 1 : -1;
181 break;
182 case LP_INC_Y:
183 case LP_INC_Y_REPEAT:
184 dy += (dy < 0) ? -1 : 1;
185 break;
187 default:
188 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
189 #ifdef HAVE_LCD_CHARCELLS
190 pgfx_release();
191 #endif
192 return PLUGIN_USB_CONNECTED;
194 break;