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