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.3 2006/04/11 00:07:32 bernie
18 *#* Implemenent MF_SAVESEL flag.
20 *#* Revision 1.2 2006/03/27 04:49:50 bernie
21 *#* Add bouncing logo demo.
23 *#* Revision 1.1 2006/03/22 09:52:13 bernie
24 *#* Add demo application.
26 *#* Revision 1.1 2006/01/23 23:14:29 bernie
27 *#* Implement simple, but impressive windowing system.
31 #include <emul/emul.h>
32 #include <kern/proc.h>
33 #include <drv/timer.h>
34 #include <drv/buzzer.h>
35 #include <drv/lcd_gfx.h>
41 #include <icons/logo.h>
42 #include <mware/menu.h>
43 #include <cfg/macros.h>
46 /* SETTINGS SUBMENU ***************************/
48 static struct MenuItem settings_items[] =
50 { (const_iptr_t)"System", 0, (MenuHook)0, (iptr_t)0 },
51 { (const_iptr_t)"Mouse", 0, (MenuHook)0, (iptr_t)0 },
52 { (const_iptr_t)"Keyboard", 0, (MenuHook)0, (iptr_t)0 },
53 { (const_iptr_t)"Networking", 0, (MenuHook)0, (iptr_t)0 },
54 { (const_iptr_t)"Date & Time",0, (MenuHook)0, (iptr_t)0 },
55 { (const_iptr_t)"Power Saving", MIF_TOGGLE, (MenuHook)0, (iptr_t)0 },
56 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
58 static struct Menu settings_menu = { settings_items, "Settings Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 };
60 /*** DISPLAY MENU ****************************/
62 static struct MenuItem display_items[] =
64 { (const_iptr_t)"Background", 0, (MenuHook)0, (iptr_t)0 },
65 { (const_iptr_t)"Colors", 0, (MenuHook)0, (iptr_t)0 },
66 { (const_iptr_t)"Style", 0, (MenuHook)0, (iptr_t)0 },
67 { (const_iptr_t)"Icon Theme", 0, (MenuHook)0, (iptr_t)0 },
68 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
70 static struct Menu display_menu = { display_items, "Display Menu", MF_SAVESEL, &lcd_bitmap, 0 };
73 /*** SETUP MENU ******************************/
75 static struct MenuItem setup_items[] =
77 { (const_iptr_t)"Setup 0", 0, (MenuHook)NULL, (iptr_t)0 },
78 { (const_iptr_t)"Setup 1", 0, (MenuHook)NULL, (iptr_t)0 },
79 { (const_iptr_t)"Setup 2", 0, (MenuHook)NULL, (iptr_t)0 },
80 { (const_iptr_t)"Setup 3", 0, (MenuHook)NULL, (iptr_t)0 },
81 { (const_iptr_t)0, 0, NULL, NULL }
83 static struct Menu setup_menu = { setup_items, "Setup Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 };
86 /*** MAIN MENU *******************************/
88 static struct MenuItem main_items[] =
90 { (const_iptr_t)"Settings", 0, (MenuHook)menu_handle, (iptr_t)&settings_menu },
91 { (const_iptr_t)"Display", 0, (MenuHook)menu_handle, (iptr_t)&display_menu },
92 { (const_iptr_t)"Setup", 0, (MenuHook)menu_handle, (iptr_t)&setup_menu },
93 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
95 static struct Menu main_menu = { main_items, "Main Menu", MF_STICKY, &lcd_bitmap, 0 };
97 static void magic(struct Bitmap *bitmap, coord_t x, coord_t y)
99 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 };
102 gfx_moveTo(bitmap, coords[countof(coords)-2]/2 + x, coords[countof(coords)-1]/3 + y);
103 for (i = 0; i < countof(coords); i += 2)
104 gfx_lineTo(bitmap, coords[i]/2 + x, coords[i+1]/3 + y);
111 // win_compose(&root_win);
112 lcd_blit_bitmap(root_win.bitmap);
117 void hello_world(void)
119 gfx_bitmapClear(&lcd_bitmap);
120 extern const Font font_10x20;
121 extern const Font font_helvB10;
122 extern const Font font_courB08;
123 extern const Font font_courB14;
124 extern const Font font_mono17;
125 extern const Font font_luBS14;
126 extern const Font font_ncenB18;
127 gfx_setFont(&lcd_bitmap, &font_luBS14);
129 text_xprintf(&lcd_bitmap, 1, 0, STYLEF_BOLD | TEXT_FILL | TEXT_CENTER, "Hello, world!");
130 for (int i = 0; i < 1000; ++i)
132 lcd_blit_bitmap(&lcd_bitmap);
138 * Show the splash screen
140 void bouncing_logo(void)
142 const long SPEED_SCALE = 1000;
143 const long GRAVITY_ACCEL = 10;
144 const long BOUNCE_ELASTICITY = 2;
145 long h = (long)(-project_grl_logo.height) * SPEED_SCALE;
148 /* Repeat until logo stands still on the bottom edge */
149 while (!((speed == 0) && (h == 0)))
154 /* Gravity acceleration */
155 speed += GRAVITY_ACCEL;
157 if (h > 0 && speed > 0)
160 speed = - (speed / BOUNCE_ELASTICITY);
164 /* Update graphics */
165 gfx_bitmapClear(&lcd_bitmap);
166 gfx_blitImage(&lcd_bitmap,
167 (lcd_bitmap.width - project_grl_logo.width) / 2,
170 lcd_blit_bitmap(&lcd_bitmap);
176 int main(int argc, char *argv[])
178 emul_init(&argc, argv);
188 const coord_t small_left = 45, small_top = 30, small_width = 50, small_height = 30;
189 const coord_t large_left = -10, large_top = 10, large_width = 85, large_height = 41;
191 Window small_win, large_win;
192 Bitmap small_bm, large_bm;
193 uint8_t small_raster[RASTER_SIZE(small_width, small_height)];
194 uint8_t large_raster[RASTER_SIZE(large_width, large_height)];
196 win_create(&root_win, &lcd_bitmap);
198 gfx_bitmapInit(&large_bm, large_raster, large_width, large_height);
199 win_create(&large_win, &large_bm);
200 win_open(&large_win, &root_win);
201 win_move(&large_win, large_left, large_top);
203 gfx_bitmapInit(&small_bm, small_raster, small_width, small_height);
204 win_create(&small_win, &small_bm);
205 win_open(&small_win, &root_win);
206 win_move(&small_win, small_left, small_top);
209 coord_t x = 0, y = LCD_WIDTH / 2;
210 coord_t xdir = +1, ydir = -1;
211 coord_t xdir_large = +1;
212 coord_t ydir_small = +1;
213 int raise_counter = 0;
219 /* Background animation */
222 /* gfx_setClipRect(bm, 0, 0, bm->width, bm->height);
223 gfx_rectDraw(bm, 10, 10, bm->width-10, bm->height-10);
224 gfx_setClipRect(bm, 11, 11, bm->width-11, bm->height-11);
228 if (x >= bm->width) xdir = -1;
229 if (x <= -50) xdir = +1;
230 if (y >= bm->height) ydir = -1;
231 if (y <= -50) ydir = +1;
233 menu_handle(&main_menu);
235 /* Large window animation */
236 bm = large_win.bitmap;
238 for (i = 0; i < bm->height / 2; i += 2)
239 gfx_rectDraw(bm, 0 + i, 0 + i, bm->width - i, bm->height - i);
242 /* Small window animation */
243 bm = small_win.bitmap;
245 gfx_rectDraw(bm, 0, 0, bm->width, bm->height);
246 gfx_line(bm, 0, 0, bm->width, bm->height);
247 gfx_line(bm, bm->width, 0, 0, bm->height);
249 /* Move windows around */
250 win_move(&large_win, large_win.geom.xmin + xdir_large, large_top);
251 if (large_win.geom.xmin < -20) xdir_large = +1;
252 if (large_win.geom.xmin > RECT_WIDTH(&root_win.geom) - 5) xdir_large = -1;
254 win_move(&small_win, small_left, small_win.geom.ymin + ydir_small);
255 if (small_win.geom.ymin < -20) ydir_small = +1;
256 if (small_win.geom.ymin > RECT_HEIGHT(&root_win.geom) - 5) ydir_small = -1;
259 if (raise_counter % 997 == 0)
260 win_raise(&small_win);
261 else if (raise_counter % 731 == 0)
262 win_raise(&large_win);
264 win_compose(&root_win);
265 lcd_blit_bitmap(root_win.bitmap);