00001
00040 #include <emul/emul.h>
00041 #include <kern/proc.h>
00042 #include <kern/msg.h>
00043 #include <drv/timer.h>
00044 #include <drv/buzzer.h>
00045 #include <drv/lcd_gfx.h>
00046 #include <drv/kbd.h>
00047 #include <gfx/gfx.h>
00048 #include <gfx/win.h>
00049 #include <gfx/text.h>
00050 #include <gfx/font.h>
00051 #include <gui/menu.h>
00052 #include <icons/logo.h>
00053 #include <cfg/macros.h>
00054
00058 void schedule(void)
00059 {
00060 lcd_blitBitmap(&lcd_bitmap);
00061 emul_idle();
00062 }
00063
00067 static void magic(struct Bitmap *bitmap, coord_t x, coord_t y)
00068 {
00069 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 };
00070 unsigned int i;
00071
00072 gfx_moveTo(bitmap, coords[countof(coords)-2]/2 + x, coords[countof(coords)-1]/3 + y);
00073 for (i = 0; i < countof(coords); i += 2)
00074 gfx_lineTo(bitmap, coords[i]/2 + x, coords[i+1]/3 + y);
00075 }
00076
00077 static void hello_world(Bitmap *bm)
00078 {
00079 extern const Font font_ncenB18;
00080 const Font *old_font = bm->font;
00081
00082 gfx_bitmapClear(bm);
00083
00084
00085 gfx_setFont(bm, &font_ncenB18);
00086
00087 text_xprintf(bm, 1, 0, STYLEF_BOLD | TEXT_FILL | TEXT_CENTER,
00088 "Hello, world!");
00089
00090 lcd_blitBitmap(bm);
00091 timer_delay(1000);
00092
00093
00094 gfx_setFont(bm, old_font);
00095 }
00096
00100 static void bouncing_logo(Bitmap *bm)
00101 {
00102 const long SPEED_SCALE = 1000;
00103 const long GRAVITY_ACCEL = 10;
00104 const long BOUNCE_ELASTICITY = 2;
00105 long h = (long)(-bertos_logo.height) * SPEED_SCALE;
00106 long speed = 1000;
00107
00108
00109 while (!((speed == 0) && (h == 0)))
00110 {
00111
00112 h += speed;
00113
00114
00115 speed += GRAVITY_ACCEL;
00116
00117 if (h > 0 && speed > 0)
00118 {
00119
00120 speed = - (speed / BOUNCE_ELASTICITY);
00121
00122 }
00123
00124
00125 gfx_bitmapClear(bm);
00126 gfx_blitImage(bm,
00127 (bm->width - bertos_logo.width) / 2,
00128 h / SPEED_SCALE,
00129 &bertos_logo);
00130 lcd_blitBitmap(bm);
00131
00132 timer_delay(10);
00133 }
00134 }
00135
00136 void win_demo(Bitmap *bm)
00137 {
00138 const coord_t small_left = 45, small_top = 30, small_width = 50, small_height = 30;
00139 const coord_t large_left = -10, large_top = 10, large_width = 85, large_height = 41;
00140
00141 Window root_win, small_win, large_win;
00142 Bitmap small_bm, large_bm;
00143 uint8_t small_raster[RAST_SIZE(small_width, small_height)];
00144 uint8_t large_raster[RAST_SIZE(large_width, large_height)];
00145
00146 win_create(&root_win, bm);
00147
00148 gfx_bitmapInit(&large_bm, large_raster, large_width, large_height);
00149 win_create(&large_win, &large_bm);
00150 win_open(&large_win, &root_win);
00151 win_move(&large_win, large_left, large_top);
00152
00153 gfx_bitmapInit(&small_bm, small_raster, small_width, small_height);
00154 win_create(&small_win, &small_bm);
00155 win_open(&small_win, &root_win);
00156 win_move(&small_win, small_left, small_top);
00157
00158
00159 coord_t x = 0, y = LCD_WIDTH / 2;
00160 coord_t xdir = +1, ydir = -1;
00161 coord_t xdir_large = +1;
00162 coord_t ydir_small = +1;
00163 int raise_counter = 0;
00164 int i;
00165
00166 for(;;)
00167 {
00168
00169 bm = root_win.bitmap;
00170 gfx_bitmapClear(bm);
00171
00172
00173
00174 magic(bm, x, y);
00175 x += xdir;
00176 y += ydir;
00177 if (x >= bm->width) xdir = -1;
00178 if (x <= -50) xdir = +1;
00179 if (y >= bm->height) ydir = -1;
00180 if (y <= -50) ydir = +1;
00181
00182
00183 bm = large_win.bitmap;
00184 gfx_bitmapClear(bm);
00185 for (i = 0; i < bm->height / 2; i += 2)
00186 gfx_rectDraw(bm, 0 + i, 0 + i, bm->width - i, bm->height - i);
00187
00188
00189
00190 bm = small_win.bitmap;
00191 gfx_bitmapClear(bm);
00192 gfx_rectDraw(bm, 0, 0, bm->width, bm->height);
00193 gfx_line(bm, 0, 0, bm->width, bm->height);
00194 gfx_line(bm, bm->width, 0, 0, bm->height);
00195
00196
00197 win_move(&large_win, large_win.geom.xmin + xdir_large, large_top);
00198 if (large_win.geom.xmin < -20) xdir_large = +1;
00199 if (large_win.geom.xmin > RECT_WIDTH(&root_win.geom) - 5) xdir_large = -1;
00200
00201 win_move(&small_win, small_left, small_win.geom.ymin + ydir_small);
00202 if (small_win.geom.ymin < -20) ydir_small = +1;
00203 if (small_win.geom.ymin > RECT_HEIGHT(&root_win.geom) - 5) ydir_small = -1;
00204
00205 ++raise_counter;
00206 if (raise_counter % 997 == 0)
00207 win_raise(&small_win);
00208 else if (raise_counter % 731 == 0)
00209 win_raise(&large_win);
00210
00211 win_compose(&root_win);
00212
00213
00214 if (kbd_peek())
00215 break;
00216 }
00217 }
00218
00219 void proc_demo(void)
00220 {
00221 extern void proc_test(void);
00222
00223 proc_test();
00224 }
00225
00226
00227
00228
00229 static struct MenuItem settings_items[] =
00230 {
00231 { (const_iptr_t)"System", 0, (MenuHook)0, (iptr_t)0 },
00232 { (const_iptr_t)"Language", 0, (MenuHook)0, (iptr_t)0 },
00233 { (const_iptr_t)"Networking", 0, (MenuHook)0, (iptr_t)0 },
00234 { (const_iptr_t)"Date & Time",0, (MenuHook)0, (iptr_t)0 },
00235 { (const_iptr_t)"Power Saving", MIF_TOGGLE, (MenuHook)0, (iptr_t)0 },
00236 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
00237 };
00238 static struct Menu settings_menu = { settings_items, "Settings Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 };
00239
00240
00241
00242
00243 static struct MenuItem mx_items[] =
00244 {
00245 { (const_iptr_t)"Mouse", MIF_CHECKIT | MIF_EXCLUDE_1 | MIF_EXCLUDE_2, (MenuHook)0, (iptr_t)0 },
00246 { (const_iptr_t)"Keyboard", MIF_CHECKED | MIF_CHECKIT | MIF_EXCLUDE_0 | MIF_EXCLUDE_2, (MenuHook)0, (iptr_t)0 },
00247 { (const_iptr_t)"Joystick", MIF_CHECKIT | MIF_EXCLUDE_0 | MIF_EXCLUDE_1, (MenuHook)0, (iptr_t)0 },
00248 { (const_iptr_t)"Autosave", MIF_CHECKED | MIF_CHECKIT | MIF_TOGGLE, (MenuHook)0, (iptr_t)0 },
00249 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
00250 };
00251
00252 static struct Menu mx_menu = { mx_items, (const_iptr_t)0, MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 };
00253
00254
00255
00256
00257 static struct MenuItem display_items[] =
00258 {
00259 { (const_iptr_t)"Background", 0, (MenuHook)0, (iptr_t)0 },
00260 { (const_iptr_t)"Colors", 0, (MenuHook)0, (iptr_t)0 },
00261 { (const_iptr_t)"Style", 0, (MenuHook)0, (iptr_t)0 },
00262 { (const_iptr_t)"Icon Theme", 0, (MenuHook)0, (iptr_t)0 },
00263 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
00264 };
00265 static struct Menu display_menu = { display_items, "Display Menu", MF_SAVESEL, &lcd_bitmap, 0 };
00266
00267
00268
00269
00270 static struct MenuItem main_items[] =
00271 {
00272 { (const_iptr_t)"Win Fly", 0, (MenuHook)win_demo, (iptr_t)&lcd_bitmap },
00273 { (const_iptr_t)"Bounce!", 0, (MenuHook)bouncing_logo,(iptr_t)&lcd_bitmap },
00274 { (const_iptr_t)"Hello World", 0, (MenuHook)hello_world, (iptr_t)&lcd_bitmap },
00275 { (const_iptr_t)"Scheduling", 0, (MenuHook)proc_demo, (iptr_t)&lcd_bitmap },
00276 { (const_iptr_t)"Menu MX", 0, (MenuHook)menu_handle, (iptr_t)&mx_menu },
00277 { (const_iptr_t)"Display", 0, (MenuHook)menu_handle, (iptr_t)&display_menu },
00278 { (const_iptr_t)"Settings", 0, (MenuHook)menu_handle, (iptr_t)&settings_menu },
00279 { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
00280 };
00281 static struct Menu main_menu = { main_items, "Main Menu", MF_STICKY, &lcd_bitmap, 0 };
00282
00283
00284 int main(int argc, char *argv[])
00285 {
00286 emul_init(&argc, argv);
00287 timer_init();
00288 buz_init();
00289 kbd_init();
00290 lcd_init();
00291 proc_init();
00292
00293 menu_handle(&main_menu);
00294
00295 emul_cleanup();
00296 return 0;
00297 }