4 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
10 * \author Bernardo Innocenti <bernie@develer.com>
12 * \brief Windowing system test.
17 *#* Revision 1.4 2006/04/27 05:43:07 bernie
18 *#* Fix naming conventions.
20 *#* Revision 1.3 2006/04/11 00:07:32 bernie
21 *#* Implemenent MF_SAVESEL flag.
23 *#* Revision 1.2 2006/03/27 04:49:50 bernie
24 *#* Add bouncing logo demo.
26 *#* Revision 1.1 2006/03/22 09:52:13 bernie
27 *#* Add demo application.
29 *#* Revision 1.1 2006/01/23 23:14:29 bernie
30 *#* Implement simple, but impressive windowing system.
34 #include <emul/emul.h>
35 #include <kern/proc.h>
36 #include <drv/timer.h>
37 #include <drv/buzzer.h>
38 #include <drv/lcd_gfx.h>
44 #include <icons/logo.h>
45 #include <mware/menu.h>
46 #include <cfg/macros.h>
49 /* SETTINGS SUBMENU ***************************/
51 static struct MenuItem settings_items[] =
53 { (const_iptr_t)"System", 0, (MenuHook)0, (iptr_t)0 },
54 { (const_iptr_t)"Mouse", 0, (MenuHook)0, (iptr_t)0 },
55 { (const_iptr_t)"Keyboard", 0, (MenuHook)0, (iptr_t)0 },
56 { (const_iptr_t)"Networking", 0, (MenuHook)0, (iptr_t)0 },
57 { (const_iptr_t)"Date & Time",0, (MenuHook)0, (iptr_t)0 },
58 { (const_iptr_t)"Power Saving", MIF_TOGGLE, (MenuHook)0, (iptr_t)0 },
59 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
61 static struct Menu settings_menu = { settings_items, "Settings Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 };
63 /*** DISPLAY MENU ****************************/
65 static struct MenuItem display_items[] =
67 { (const_iptr_t)"Background", 0, (MenuHook)0, (iptr_t)0 },
68 { (const_iptr_t)"Colors", 0, (MenuHook)0, (iptr_t)0 },
69 { (const_iptr_t)"Style", 0, (MenuHook)0, (iptr_t)0 },
70 { (const_iptr_t)"Icon Theme", 0, (MenuHook)0, (iptr_t)0 },
71 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
73 static struct Menu display_menu = { display_items, "Display Menu", MF_SAVESEL, &lcd_bitmap, 0 };
76 /*** SETUP MENU ******************************/
78 static struct MenuItem setup_items[] =
80 { (const_iptr_t)"Setup 0", 0, (MenuHook)NULL, (iptr_t)0 },
81 { (const_iptr_t)"Setup 1", 0, (MenuHook)NULL, (iptr_t)0 },
82 { (const_iptr_t)"Setup 2", 0, (MenuHook)NULL, (iptr_t)0 },
83 { (const_iptr_t)"Setup 3", 0, (MenuHook)NULL, (iptr_t)0 },
84 { (const_iptr_t)0, 0, NULL, NULL }
86 static struct Menu setup_menu = { setup_items, "Setup Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 };
89 /*** MAIN MENU *******************************/
91 static struct MenuItem main_items[] =
93 { (const_iptr_t)"Settings", 0, (MenuHook)menu_handle, (iptr_t)&settings_menu },
94 { (const_iptr_t)"Display", 0, (MenuHook)menu_handle, (iptr_t)&display_menu },
95 { (const_iptr_t)"Setup", 0, (MenuHook)menu_handle, (iptr_t)&setup_menu },
96 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
98 static struct Menu main_menu = { main_items, "Main Menu", MF_STICKY, &lcd_bitmap, 0 };
100 static void magic(struct Bitmap *bitmap, coord_t x, coord_t y)
102 static const coord_t coords[] = { 120, 34, 90, 90, 30, 90, 0, 34, 60, 0, 90, 90, 0, 34, 120, 34, 30, 90, 60, 0 };
105 gfx_moveTo(bitmap, coords[countof(coords)-2]/2 + x, coords[countof(coords)-1]/3 + y);
106 for (i = 0; i < countof(coords); i += 2)
107 gfx_lineTo(bitmap, coords[i]/2 + x, coords[i+1]/3 + y);
114 // win_compose(&root_win);
115 lcd_blitBitmap(root_win.bitmap);
120 void hello_world(void)
122 gfx_bitmapClear(&lcd_bitmap);
123 extern const Font font_10x20;
124 extern const Font font_helvB10;
125 extern const Font font_courB08;
126 extern const Font font_courB14;
127 extern const Font font_mono17;
128 extern const Font font_luBS14;
129 extern const Font font_ncenB18;
130 gfx_setFont(&lcd_bitmap, &font_luBS14);
132 text_xprintf(&lcd_bitmap, 1, 0, STYLEF_BOLD | TEXT_FILL | TEXT_CENTER, "Hello, world!");
133 for (int i = 0; i < 1000; ++i)
135 lcd_blitBitmap(&lcd_bitmap);
141 * Show the splash screen
143 void bouncing_logo(void)
145 const long SPEED_SCALE = 1000;
146 const long GRAVITY_ACCEL = 10;
147 const long BOUNCE_ELASTICITY = 2;
148 long h = (long)(-project_grl_logo.height) * SPEED_SCALE;
151 /* Repeat until logo stands still on the bottom edge */
152 while (!((speed == 0) && (h == 0)))
157 /* Gravity acceleration */
158 speed += GRAVITY_ACCEL;
160 if (h > 0 && speed > 0)
163 speed = - (speed / BOUNCE_ELASTICITY);
167 /* Update graphics */
168 gfx_bitmapClear(&lcd_bitmap);
169 gfx_blitImage(&lcd_bitmap,
170 (lcd_bitmap.width - project_grl_logo.width) / 2,
173 lcd_blitBitmap(&lcd_bitmap);
179 int main(int argc, char *argv[])
181 emul_init(&argc, argv);
191 const coord_t small_left = 45, small_top = 30, small_width = 50, small_height = 30;
192 const coord_t large_left = -10, large_top = 10, large_width = 85, large_height = 41;
194 Window small_win, large_win;
195 Bitmap small_bm, large_bm;
196 uint8_t small_raster[RASTER_SIZE(small_width, small_height)];
197 uint8_t large_raster[RASTER_SIZE(large_width, large_height)];
199 win_create(&root_win, &lcd_bitmap);
201 gfx_bitmapInit(&large_bm, large_raster, large_width, large_height);
202 win_create(&large_win, &large_bm);
203 win_open(&large_win, &root_win);
204 win_move(&large_win, large_left, large_top);
206 gfx_bitmapInit(&small_bm, small_raster, small_width, small_height);
207 win_create(&small_win, &small_bm);
208 win_open(&small_win, &root_win);
209 win_move(&small_win, small_left, small_top);
212 coord_t x = 0, y = LCD_WIDTH / 2;
213 coord_t xdir = +1, ydir = -1;
214 coord_t xdir_large = +1;
215 coord_t ydir_small = +1;
216 int raise_counter = 0;
222 /* Background animation */
225 /* gfx_setClipRect(bm, 0, 0, bm->width, bm->height);
226 gfx_rectDraw(bm, 10, 10, bm->width-10, bm->height-10);
227 gfx_setClipRect(bm, 11, 11, bm->width-11, bm->height-11);
231 if (x >= bm->width) xdir = -1;
232 if (x <= -50) xdir = +1;
233 if (y >= bm->height) ydir = -1;
234 if (y <= -50) ydir = +1;
236 menu_handle(&main_menu);
238 /* Large window animation */
239 bm = large_win.bitmap;
241 for (i = 0; i < bm->height / 2; i += 2)
242 gfx_rectDraw(bm, 0 + i, 0 + i, bm->width - i, bm->height - i);
245 /* Small window animation */
246 bm = small_win.bitmap;
248 gfx_rectDraw(bm, 0, 0, bm->width, bm->height);
249 gfx_line(bm, 0, 0, bm->width, bm->height);
250 gfx_line(bm, bm->width, 0, 0, bm->height);
252 /* Move windows around */
253 win_move(&large_win, large_win.geom.xmin + xdir_large, large_top);
254 if (large_win.geom.xmin < -20) xdir_large = +1;
255 if (large_win.geom.xmin > RECT_WIDTH(&root_win.geom) - 5) xdir_large = -1;
257 win_move(&small_win, small_left, small_win.geom.ymin + ydir_small);
258 if (small_win.geom.ymin < -20) ydir_small = +1;
259 if (small_win.geom.ymin > RECT_HEIGHT(&root_win.geom) - 5) ydir_small = -1;
262 if (raise_counter % 997 == 0)
263 win_raise(&small_win);
264 else if (raise_counter % 731 == 0)
265 win_raise(&large_win);
267 win_compose(&root_win);
268 lcd_blitBitmap(root_win.bitmap);