/** * rtgui server thread's entry */ static void rtgui_server_entry(void *parameter) { #ifdef _WIN32_NATIVE /* set the server thread to highest */ HANDLE hCurrentThread = GetCurrentThread(); SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); #endif /* create rtgui server application */ rtgui_server_application = rtgui_app_create("rtgui"); if (rtgui_server_application == RT_NULL) return; rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_application), rtgui_server_event_handler); /* init mouse and show */ rtgui_mouse_init(); #ifdef RTGUI_USING_MOUSE_CURSOR rtgui_mouse_show_cursor(); #endif rtgui_app_run(rtgui_server_application); rtgui_app_destroy(rtgui_server_application); rtgui_server_application = RT_NULL; }
static void app_lcd(void *parameter) { /* create application */ struct rtgui_app *app; struct rtgui_rect rect1 = {0, 0, 240, 320}; struct rtgui_button* btn; struct rtgui_label *lb; app = rtgui_app_create("lcd_app"); if (!app) { rt_kprintf("Create application \"lcd_app\" failed!\n"); return; } /* create main window */ win_main = rtgui_win_create(RT_NULL, "main", &rect1, RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE); if (win_main == RT_NULL) { rt_kprintf("Create window \"main\" failed!\n"); rtgui_app_destroy(app); return; } RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win_main)) = green; rect1.x1 = rect1.y1 = 50; rect1.x2 -= 50; rect1.y2 -= 50; lb = rtgui_label_create("I am a transparent label!!!!!!!!!"); rtgui_widget_set_rect(RTGUI_WIDGET(lb), &rect1); RTGUI_WIDGET_FLAG(RTGUI_WIDGET(lb)) |= RTGUI_WIDGET_FLAG_TRANSPARENT; rect1.x1 += 20; rect1.y1 += 20; notebook = rtgui_notebook_create(&rect1, 0); /* create lable in main container */ btn = rtgui_button_create("Here I am."); rtgui_notebook_add(notebook, "btn A", RTGUI_WIDGET(btn)); rtgui_button_set_onbutton(btn, remove_myself); btn = rtgui_button_create("There I am."); rtgui_notebook_add(notebook, "btn B", RTGUI_WIDGET(btn)); rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(lb)); rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(notebook)); rtgui_win_show(win_main, RT_FALSE); rtgui_app_run(app); rtgui_app_destroy(app); }
void picture_show(void) { /* create application */ struct rtgui_app *app; struct rtgui_rect rect1; struct rtgui_win *win_main; rtgui_timer_t *timer; app = rtgui_app_create(rt_thread_self(), "gui_app"); if (app == RT_NULL) { rt_kprintf("Create application \"gui_app\" failed!\n"); return; } rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect1); /* create main window */ win_main = rtgui_win_create(RT_NULL, "main", &rect1, RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE); if (win_main == RT_NULL) { rt_kprintf("Create window \"main\" failed!\n"); rtgui_app_destroy(app); return; } /* create container in main window */ container = rtgui_container_create(); if (container == RT_NULL) { rt_kprintf("Create container failed!\n"); return; } rtgui_widget_set_rect(RTGUI_WIDGET(container), &rect1); rtgui_object_set_event_handler(RTGUI_OBJECT(container), picture_view_event_handler); rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(container)); timer = rtgui_timer_create(500, RT_TIMER_FLAG_PERIODIC, timeout, RT_NULL); rtgui_timer_start(timer); rtgui_win_set_onkey(win_main, onkey_handle); rtgui_win_show(win_main, RT_FALSE); /* show next picture */ picture_show_next(); rtgui_app_run(app); rtgui_app_destroy(app); }
static void app_lcd(void *parameter) { /* create application */ struct rtgui_app *app; struct rtgui_rect rect1 = {0, 0, 240, 320}; struct rtgui_win *win_main; struct rtgui_button* btn; app = rtgui_app_create(rt_thread_self(), "lcd_app"); if (!app) { rt_kprintf("Create application \"lcd_app\" failed!\n"); return; } /* create main window */ win_main = rtgui_win_create(RT_NULL, "main", &rect1, RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE); if (win_main == RT_NULL) { rt_kprintf("Create window \"main\" failed!\n"); rtgui_app_destroy(app); return; } notebook = rtgui_notebook_create(&rect1, 0); /* create lable in main container */ btn = rtgui_button_create("Here I am."); rtgui_notebook_add(notebook, "btn A", RTGUI_WIDGET(btn)); rtgui_button_set_onbutton(btn, remove_myself); btn = rtgui_button_create("There I am."); rtgui_notebook_add(notebook, "btn B", RTGUI_WIDGET(btn)); rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(notebook)); rtgui_win_show(win_main, RT_FALSE); rtgui_app_run(app); rtgui_app_destroy(app); }
void app_mgr_entry(void* parameter) { struct rtgui_app* application; application = rtgui_app_create(rt_thread_self(), "AppMgr"); if (application != RT_NULL) { /* set as window manager */ rtgui_app_set_as_wm(); /* initialize status bar */ statusbar_init(); app_mgr_win_init(); /* set our event handler */ rtgui_object_set_event_handler(RTGUI_OBJECT(application), event_handler); rtgui_app_run(application); rtgui_app_destroy(application); } }
void picture_show(void* parameter) { /* create application */ struct rtgui_app *app; struct rtgui_rect rect1; rtgui_timer_t *timer; app = rtgui_app_create(rt_thread_self(), "picture"); if (app == RT_NULL) { rt_kprintf("Create application \"picture\" failed!\n"); return; } rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect1); /* create main window */ win = rtgui_mainwin_create(RT_NULL, "main", RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE); if (win == RT_NULL) { rt_kprintf("Create window \"main\" failed!\n"); rtgui_app_destroy(app); return; } timer = rtgui_timer_create(500, RT_TIMER_FLAG_PERIODIC, timeout, (void*)win); rtgui_timer_start(timer); rtgui_object_set_event_handler(RTGUI_OBJECT(win), picture_view_event_handler); rtgui_win_set_onkey(win, onkey_handle); rtgui_win_show(win, RT_FALSE); /* show next picture */ picture_show_next(RTGUI_WIDGET(win)); rtgui_app_run(app); rtgui_app_destroy(app); }
void rt_init_thread_entry(void* parameter) { extern void rtgui_startup(); extern void rt_hw_lcd_init(); extern void rtgui_touch_hw_init(void); struct rtgui_app* app; app = rtgui_app_create("guiapp"); RT_ASSERT(app != RT_NULL); create_wins(app, parameter); window_focus(); rtgui_app_run(app); rtgui_app_destroy(app); rt_kprintf("app destroyed\n"); }
static void app_mainmenu_entry(void *parameter) { struct rtgui_app *application; application = rtgui_app_create("menu"); if (application != RT_NULL) { /* set as window manager */ rtgui_app_set_as_wm(application); /* initialize status bar */ statusbar_init(); app_mainmenu_init(); /* set our event handler */ rtgui_object_set_event_handler(RTGUI_OBJECT(application), event_handler); tasklist_win = tasklist_win_create(RT_NULL); rtgui_app_run(application); rtgui_app_destroy(application); } }
void create_wins(struct rtgui_app *app, void *parameter) { struct rtgui_win *win1, *win2, *win3, *win4; struct rtgui_label *label; struct rtgui_rect rect; if (parameter) { struct rtgui_win *dsk; rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect); dsk = rtgui_win_create(RT_NULL, "desktop", &rect, RTGUI_WIN_STYLE_ONBTM); rtgui_win_show(dsk, RT_FALSE); } rect.x1 = 40, rect.y1 = 40, rect.x2 = 200, rect.y2 = 80; win1 = rtgui_win_create(RT_NULL, "test window", &rect, RTGUI_WIN_STYLE_DEFAULT); rtgui_win_set_onclose(win1, on_window_close); rect.x1 += 20; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; label = rtgui_label_create("window in modal mode"); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(win1), RTGUI_WIDGET(label)); rtgui_win_show(win1, RT_TRUE); rt_kprintf("win1 terminated\n"); /*rtgui_win_destroy(win1);*/ rect.x1 = 20; rect.y1 = 80; rect.x2 = 180; rect.y2 = 90; win2 = rtgui_win_create(win1, "test window2", &rect, RTGUI_WIN_STYLE_DEFAULT); rtgui_win_set_onclose(win2, on_window_close); rtgui_win_show(win1, RT_FALSE); /*rtgui_win_show(win2, RT_TRUE);*/ /* create second window tree */ rect.y1 = 150; rect.y2 = rect.y1 + 50; win3 = rtgui_win_create(RT_NULL, "test tree2", &rect, RTGUI_WIN_STYLE_DEFAULT); rtgui_win_set_onclose(win3, on_window_close); rect.x1 += 20; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; label = rtgui_label_create("window in modal mode"); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(win3), RTGUI_WIDGET(label)); rect.x1 = 20; rect.y1 = 180; rect.x2 = 180; rect.y2 = 190; win4 = rtgui_win_create(win3, "test tree2.1", &rect, RTGUI_WIN_STYLE_DEFAULT); rtgui_win_set_onclose(win4, on_window_close); rtgui_win_show(win3, RT_FALSE); /*rtgui_win_show(win4, RT_TRUE);*/ rtgui_app_run(app); rtgui_win_destroy(win1); rtgui_win_destroy(win2); rtgui_win_destroy(win3); rtgui_win_destroy(win4); }
static void application_entry(void *parameter) { struct rtgui_app *app; struct rtgui_rect rect; app = rtgui_app_create("gui_demo"); if (app == RT_NULL) return; /* create a full screen window */ rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect); main_win = rtgui_win_create(RT_NULL, "demo_win", &rect, RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE); if (main_win == RT_NULL) { rtgui_app_destroy(app); return; } rtgui_win_set_onkey(main_win, demo_handle_key); /* create a no title notebook that we can switch demo on it easily. */ the_notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_NOTAB); if (the_notebook == RT_NULL) { rtgui_win_destroy(main_win); rtgui_app_destroy(app); return; } rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(the_notebook)); //demo_view_box(); /* 初始化各个例子的视图 */ demo_view_benchmark(); demo_view_dc(); #ifdef RTGUI_USING_TTF demo_view_ttf(); #endif #ifndef RTGUI_USING_SMALL_SIZE demo_view_dc_buffer(); #endif //demo_view_animation(); #ifndef RTGUI_USING_SMALL_SIZE demo_view_instrument_panel(); #endif demo_view_buffer_animation(); demo_view_window(); demo_view_label(); demo_view_button(); demo_view_checkbox(); demo_view_progressbar(); demo_view_scrollbar(); demo_view_radiobox(); demo_view_textbox(); demo_view_listbox(); demo_view_menu(); demo_view_listctrl(); demo_view_combobox(); demo_view_slider(); demo_view_notebook(); demo_view_mywidget(); demo_plot(); demo_view_digtube(); #if defined(RTGUI_USING_DFS_FILERW) demo_view_edit(); //demo_view_bmp(); #endif #if defined(RTGUI_USING_DFS_FILERW) demo_fn_view(); #endif #if 0 #if defined(RTGUI_USING_DFS_FILERW) demo_view_image(); #endif #ifdef RT_USING_MODULE #if defined(RTGUI_USING_DFS_FILERW) demo_view_module(); #endif #endif demo_listview_view(); demo_listview_icon_view(); #endif rtgui_win_show(main_win, RT_FALSE); /* 执行工作台事件循环 */ rtgui_app_run(app); rtgui_app_destroy(app); }
void win_thread_entry(void* parameter) { struct rtgui_app* app; struct rtgui_win *win; struct rtgui_panel *panel; struct rtgui_box *box; struct rtgui_label *label; struct rtgui_notebook *notebook; struct rtgui_rect rect = {50, 50, 350, 350}; app = rtgui_app_create(rt_thread_self(), "MyApp"); RT_ASSERT(app != RT_NULL); win = rtgui_mainwin_create(RT_NULL, "MyWindow", RTGUI_WIN_STYLE_DEFAULT); box = rtgui_box_create(RTGUI_VERTICAL, 10); rtgui_container_set_box(RTGUI_CONTAINER(win), box); /* create a panel */ panel = rtgui_panel_create(RTGUI_BORDER_BOX); RTGUI_WIDGET_ALIGN(panel) = RTGUI_ALIGN_EXPAND; rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(panel)); /* create sub-child for panel */ box = rtgui_box_create(RTGUI_VERTICAL, 10); rtgui_container_set_box(RTGUI_CONTAINER(panel), box); label = rtgui_label_create("hello panel!"); rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label)); /* create a notebook */ notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_TOP); RTGUI_WIDGET_ALIGN(notebook) = RTGUI_ALIGN_EXPAND; rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(notebook)); _notebook = notebook; /* create tab-page for notebook */ panel = rtgui_panel_create(RTGUI_BORDER_STATIC); _panel = panel; box = rtgui_box_create(RTGUI_VERTICAL, 10); rtgui_container_set_box(RTGUI_CONTAINER(panel), box); label = rtgui_label_create("hello panel!"); rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label)); rtgui_notebook_add(notebook, "Panel", RTGUI_WIDGET(panel)); /* create another page with label */ label = rtgui_label_create("hello notebook"); rtgui_notebook_add(notebook, "Text", RTGUI_WIDGET(label)); /* layout for window */ rtgui_container_layout(RTGUI_CONTAINER(win)); rtgui_win_show(win, RT_FALSE); rtgui_app_run(app); rtgui_win_destroy(win); rtgui_app_destroy(app); rt_kprintf("MyApp Quit.\n"); }
rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal) { rt_base_t exit_code = -1; struct rtgui_app *app; struct rtgui_event_win_show eshow; app = rtgui_app_self(); RTGUI_EVENT_WIN_SHOW_INIT(&eshow); eshow.wid = win; if (win == RT_NULL) return exit_code; /* if it does not register into server, create it in server */ if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED)) { if (_rtgui_win_create_in_server(win) == RT_FALSE) return exit_code; } /* set window unhidden before notify the server */ rtgui_widget_show(RTGUI_WIDGET(win)); if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow), sizeof(struct rtgui_event_win_show)) != RT_EOK) { /* It could not be shown if a parent window is hidden. */ rtgui_widget_hide(RTGUI_WIDGET(win)); return exit_code; } if (win->focused_widget == RT_NULL) rtgui_widget_focus(RTGUI_WIDGET(win)); /* set main window */ if (app->main_object == RT_NULL) rtgui_app_set_main_win(win); if (is_modal == RT_TRUE) { struct rtgui_app *app; struct rtgui_event_win_modal_enter emodal; RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal); emodal.wid = win; app = rtgui_app_self(); RT_ASSERT(app != RT_NULL); win->flag |= RTGUI_WIN_FLAG_MODAL; if (rtgui_server_post_event_sync((struct rtgui_event*)&emodal, sizeof(emodal)) != RT_EOK) return exit_code; app->modal_object = RTGUI_OBJECT(win); exit_code = rtgui_app_run(app); app->modal_object = RT_NULL; win->flag &= ~RTGUI_WIN_FLAG_MODAL; if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE) { rtgui_win_destroy(win); } } return exit_code; }