rtgui_view_t* demo_view_window(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t* view; rtgui_button_t *button; /* 创建一个演示用的视图 */ view = demo_view(workbench, "Window Demo"); demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建按钮用于显示正常窗口 */ button = rtgui_button_create("Normal Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置onbutton为demo_win_onbutton函数 */ rtgui_button_set_onbutton(button, demo_win_onbutton); demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; /* 创建按钮用于显示一个自动关闭的窗口 */ button = rtgui_button_create("Auto Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置onbutton为demo_autowin_onbutton函数 */ rtgui_button_set_onbutton(button, demo_autowin_onbutton); demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建按钮用于触发一个模式窗口 */ button = rtgui_button_create("Modal Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置onbutton为demo_modalwin_onbutton函数 */ rtgui_button_set_onbutton(button, demo_modalwin_onbutton); demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建按钮用于触发一个不包含标题的窗口 */ button = rtgui_button_create("NoTitle Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置onbutton为demo_ntitlewin_onbutton函数 */ rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton); return view; }
/* 创建用于演示列表视图的视图 */ rtgui_view_t* demo_listview_icon_view(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t *view; rtgui_button_t* open_btn; view = demo_view(workbench, "图标视图演示"); if (item_icon == RT_NULL) item_icon = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE); if (exit_icon == RT_NULL) exit_icon = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)exit_xpm, sizeof(exit_xpm), RT_TRUE); /* 添加动作按钮 */ demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 80; rect.y1 += 30; rect.y2 = rect.y1 + 20; open_btn = rtgui_button_create("打开图标列表"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn)); rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect); rtgui_button_set_onbutton(open_btn, open_btn_onbutton); return view; }
int main(int argc, char** argv) { struct rtgui_app* application; struct rtgui_win* win; struct rtgui_button *button; application = rtgui_app_create("button"); if (application != RT_NULL) { rtgui_rect_t rect; win = rtgui_mainwin_create(RT_NULL, "button", RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); rtgui_widget_get_extent(RTGUI_WIDGET(win), &rect); /* create lable in app window */ button = rtgui_button_create("close"); rtgui_button_set_onbutton(button, _on_close); rect.x2 -= 5; rect.y2 -= 5; rect.x1 = rect.x2 - 80; rect.y1 = rect.y2 - 25; rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button)); rtgui_win_show(win, RT_TRUE); rtgui_app_destroy(application); } return 0; }
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); }
static void gui_win_entry(void* parameter) { const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default(); struct rt_messagequeue *mq; rtgui_win_t *win; rtgui_button_t *button; rtgui_point_t p; rtgui_rect_t rect = {0,0,200,180}; rtgui_label_t *label; rtgui_font_t *font; /* 创建GUI应用需要的消息队列 */ mq = rt_mq_create("demo_win", 256, 32, RT_IPC_FLAG_FIFO); /* 注册当前线程 */ rtgui_thread_register(rt_thread_self(), mq); /* 窗口居中 */ rtgui_rect_moveto(&rect, (gd->width - rtgui_rect_width(rect))/2, (gd->height - rtgui_rect_height(rect))/2); /* 创建窗口 */ win = rtgui_win_create(RT_NULL,"demo_win",&rect,RTGUI_WIN_DEFAULT); if(win == RT_NULL) return; /* 取得客户区坐标零点 */ p = rtgui_win_get_client_zero(win); label = rtgui_label_create(win, "hello world!", p.x+5, p.y+5, 100,25); font = rtgui_font_refer("asc", 12); RTGUI_WIDGET_FONT(label) = font; button = rtgui_button_create(win, "Exit", (rtgui_rect_width(rect)-50)/2, rtgui_rect_height(rect)-40,50,25); rtgui_button_set_onbutton(button,rtgui_win_close); rtgui_widget_set_event_handler(win, demo_gui_win_event_handler); rtgui_win_show(win,RT_FALSE); /* 执行工作台事件循环 */ rtgui_win_event_loop(win); demo_win_inited = RT_FALSE; /* 去注册GUI线程 */ rtgui_thread_deregister(rt_thread_self()); rt_mq_delete(mq); }
/* 触发无标题窗口显示 */ static void demo_ntitlewin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event) { rtgui_win_t *win; rtgui_label_t *label; rtgui_button_t *button; rtgui_toplevel_t *parent; rtgui_rect_t widget_rect, rect = {0, 0, 150, 80}; parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget)); rtgui_rect_moveto(&rect, delta_x, delta_y); delta_x += 20; delta_y += 20; /* 创建一个窗口,风格为无标题及无边框 */ win = rtgui_win_create(parent, "no title", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER); RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win)) = white; /* 创建一个文本标签 */ label = rtgui_label_create("无边框窗口"); rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)), "无边框窗口", &widget_rect); rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); widget_rect.y1 += 20; widget_rect.y2 += 20; rtgui_widget_set_rect(RTGUI_WIDGET(label), &widget_rect); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label)); RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white; /* 创建一个关闭按钮 */ widget_rect.x1 = 0; widget_rect.y1 = 0; widget_rect.x2 = 40; widget_rect.y2 = 20; rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); widget_rect.y1 += 40; widget_rect.y2 += 40; button = rtgui_button_create("关闭"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, window_demo_close); /* 非模态显示窗口 */ rtgui_win_show(win, RT_FALSE); }
/* 创建用于显示应用模块的演示视图 */ rtgui_view_t* demo_view_module(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_button_t* open_btn; /* 先创建一个演示视图 */ _view = demo_view(workbench, "应用模块演示"); /* 添加一个按钮 */ demo_view_get_rect(_view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 120; rect.y2 = rect.y1 + 20; open_btn = rtgui_button_create("打开应用模块"); rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn)); rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect); rtgui_button_set_onbutton(open_btn, open_btn_onbutton); return _view; }
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); }
/* 创建用于演示列表视图的视图 */ rtgui_container_t *demo_listview_view(void) { rtgui_rect_t rect; rtgui_container_t *container; rtgui_button_t *open_btn; container = demo_view("列表视图演示"); /* 添加动作按钮 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 80; rect.y1 += 30; rect.y2 = rect.y1 + 20; open_btn = rtgui_button_create("打开列表"); rtgui_container_add_child(container, RTGUI_WIDGET(open_btn)); rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect); rtgui_button_set_onbutton(open_btn, open_btn_onbutton); return container; }
/* 创建用于演示文件列表视图的视图 */ rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t* view; rtgui_button_t* open_btn; rtgui_font_t* font; /* 默认采用12字体的显示 */ font = rtgui_font_refer("asc", 12); /* 创建演示用的视图 */ view = demo_view(workbench, "FileList View"); /* 获得演示视图的位置信息 */ demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建显示文件路径用的文本标签 */ label = rtgui_label_create("fn: "); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font; /* 获得演示视图的位置信息 */ demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 80; rect.y1 += 30; rect.y2 = rect.y1 + 20; /* 创建按钮以触发一个新的文件列表视图 */ open_btn = rtgui_button_create("Open File"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn)); rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect); RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font; rtgui_button_set_onbutton(open_btn, open_btn_onbutton); return view; }
/* 创建用于显示图像的演示视图 */ rtgui_view_t* demo_view_image(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_button_t* open_btn; /* 先创建一个演示视图 */ _view = demo_view(workbench, "图像演示"); if (_view != RT_NULL) /* 设置默认的事件处理函数到demo_view_event_handler函数 */ rtgui_widget_set_event_handler(RTGUI_WIDGET(_view), demo_view_event_handler); /* 添加一个按钮 */ demo_view_get_rect(_view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 120; rect.y2 = rect.y1 + 20; open_btn = rtgui_button_create("打开图像文件"); rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn)); rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect); rtgui_button_set_onbutton(open_btn, open_btn_onbutton); return _view; }
rtgui_container_t *demo_view_bmp(void) { rtgui_rect_t rect; rtgui_container_t *container, *showbox; rtgui_button_t *button; rtgui_textbox_t *box; /* 用bmpdt结构体记录一些参数 */ rt_memset(&bmpdt, 0, sizeof(struct demo_bmp_dt)); bmpdt.scale = 1.0; bmpdt.angle = 0.0; /* 创建用于演示本代码的容器控件 */ container = demo_view("Bmp File:"); demo_view_get_rect(container, &rect); rect.x1 += 85; rect.x2 -= 5; rect.y1 -= 42; rect.y2 = rect.y1 + 20; box = rtgui_textbox_create("", RTGUI_TEXTBOX_SINGLE); rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(box)); bmpdt.box = box; /* create a button "open" */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 60; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("open"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_bitmap_open); /* create a button "zoom in" */ demo_view_get_rect(container, &rect); rect.x1 += 85; rect.x2 = rect.x1 + 70; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("zoom in"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_image_zoom_in); /* create a button "zoom out" */ demo_view_get_rect(container, &rect); rect.x1 += 165; rect.x2 = rect.x1 + 70; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("zoom out"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_image_zoom_out); /* create a button "rotate" */ demo_view_get_rect(container, &rect); rect.x1 += 245; rect.x2 = rect.x1 + 70; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("rotate"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_image_rotate); /* create a container "showbox" */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 20; rect.y2 -= 0; showbox = rtgui_container_create(); rtgui_widget_set_rect(RTGUI_WIDGET(showbox), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(showbox)); rtgui_widget_set_border(RTGUI_WIDGET(showbox), RTGUI_BORDER_SIMPLE); bmpdt.showbox = showbox; rtgui_object_set_event_handler(RTGUI_OBJECT(showbox), demo_bitmap_showbox); rtgui_widget_get_rect(RTGUI_WIDGET(showbox), &bmpdt.lastrect); rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(showbox)); return container; }
/* 创建一个演示视图,需提供父workbench和演示用的标题 */ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title) { struct rtgui_view* view; /* 设置视图的名称 */ view = rtgui_view_create(title); if (view == RT_NULL) return RT_NULL; /* 创建成功后,添加到数组中 */ demo_view_list[demo_view_number] = view; demo_view_number ++; /* 添加到父workbench中 */ rtgui_workbench_add_view(workbench, view); /* 添加下一个视图和前一个视图按钮 */ { struct rtgui_rect rect; struct rtgui_button *next_btn, *prev_btn; struct rtgui_label *label; struct rtgui_staticline *line; /* 获得视图的位置信息(在加入到workbench中时,workbench会自动调整视图的大小) */ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect); rect.x1 += 5; rect.y1 += 5; rect.x2 -= 5; rect.y2 = rect.y1 + 20; /* 创建标题用的标签 */ label = rtgui_label_create(title); /* 设置标签位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加标签到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.y1 += 20; rect.y2 += 20; /* 创建一个水平的staticline线 */ line = rtgui_staticline_create(RTGUI_HORIZONTAL); /* 设置静态线的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect); /* 添加静态线到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(line)); /* 获得视图的位置信息 */ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect); rect.x2 -= 5; rect.y2 -= 5; rect.x1 = rect.x2 - 100; rect.y1 = rect.y2 - 25; /* 创建"下一个"按钮 */ next_btn = rtgui_button_create("下一个"); /* 设置onbutton动作到demo_view_next函数 */ rtgui_button_set_onbutton(next_btn, demo_view_next); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect); /* 添加按钮到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(next_btn)); /* 获得视图的位置信息 */ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect); rect.x1 += 5; rect.y2 -= 5; rect.x2 = rect.x1 + 100; rect.y1 = rect.y2 - 25; /* 创建"上一个"按钮 */ prev_btn = rtgui_button_create("上一个"); /* 设置onbutton动作到demo_view_prev函数 */ rtgui_button_set_onbutton(prev_btn, demo_view_prev); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect); /* 添加按钮到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(prev_btn)); } /* 返回创建的视图 */ return view; }
static void function_action_setup(struct rtgui_widget* widget, void* paramter) { rtgui_view_t* view; rtgui_rect_t rect; rtgui_label_t* label; struct rtgui_button* cancel_button, *apply_button, *save_button; rtgui_workbench_t* workbench = father_workbench; /* create a demo view */ view = rtgui_view_create("Slider View"); /* 添加到父workbench中 */ rtgui_workbench_add_view(workbench, view); //设置服务函数 rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler); /* get demo view rect */ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect); label = rtgui_label_create("默认音量:"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.y1 += 20; rect.y2 = rect.y1 + 18; slider_volume = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider_volume)); rtgui_widget_set_rect(RTGUI_WIDGET(slider_volume), &rect); rtgui_slider_set_value(slider_volume, radio_setup.default_volume); /* get demo view rect */ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect); label = rtgui_label_create("LCD背光亮度:"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 50; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.y1 += 20; rect.y2 = rect.y1 + 18; slider_brightness = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider_brightness)); rtgui_widget_set_rect(RTGUI_WIDGET(slider_brightness), &rect); rtgui_slider_set_value(slider_brightness, radio_setup.lcd_brightness); //得到 "取消" 按键的位置 rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect); rect.x1 += 20; rect.x2 = rect.x1 + 60; rect.y2 -= 20; rect.y1 = rect.y2 - 20; //创建 "取消" 按钮(兼返回) cancel_button = rtgui_button_create("取消"); /* 设置onbutton动作到demo_view_next函数 */ rtgui_button_set_onbutton(cancel_button, cancel_handler); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(cancel_button), &rect); /* 添加按钮到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(cancel_button)); rect.x1 = rect.x2 + 10; rect.x2 = rect.x1 + 60; apply_button = rtgui_button_create("应用"); /* 设置onbutton动作到demo_view_next函数 */ rtgui_button_set_onbutton(apply_button, apply_handler); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(apply_button), &rect); /* 添加按钮到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(apply_button)); //得到 "保存" 按键的位置 rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect); rect.x2 -= 20; rect.x1 = rect.x2 - 60; rect.y2 -= 20; rect.y1 = rect.y2 - 20; /* 创建 "保存" 按钮 */ save_button = rtgui_button_create("保存"); /* 设置onbutton动作到demo_view_prev函数 */ rtgui_button_set_onbutton(save_button, save_handler); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(save_button), &rect); /* 添加按钮到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(save_button)); rtgui_view_show(view, RT_FALSE); }
static void creat_switch2pt_win(rtgui_widget_t* widget) { rtgui_label_t *label; rtgui_button_t *cancel_button; rtgui_button_t *sure_button; rtgui_toplevel_t *parent; rtgui_rect_t rect = {60, 45, 260, 160}; parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget)); switch2pt_confirm_win = rtgui_win_create(parent, "警告", &rect, RTGUI_WIN_STYLE_MODAL); rtgui_widget_get_extent(RTGUI_WIDGET(switch2pt_confirm_win), &rect); rect.x1 += 30; rect.x2 -= 30; rect.y1 += 20; rect.y2 = rect.y1 + 30; label = rtgui_label_create("确定切换到PT侧?"); if (NULL != label) { rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(switch2pt_confirm_win), RTGUI_WIDGET(label)); } rtgui_widget_get_extent(RTGUI_WIDGET(switch2pt_confirm_win),&rect); rect.x1 += 20; rect.x2 -= 120; rect.y1 += 70; rect.y2 -= 20; sure_button = rtgui_button_create("确定"); if (NULL != sure_button) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(sure_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(sure_button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(switch2pt_confirm_win), RTGUI_WIDGET(sure_button)); rtgui_button_set_onbutton(sure_button, sure_btn_onbutton); } else { printf_syn("creat sure button fail\n"); } rtgui_widget_get_extent(RTGUI_WIDGET(switch2pt_confirm_win),&rect); rect.x1 += 120; rect.x2 -= 20; rect.y1 += 70; rect.y2 -= 20; cancel_button = rtgui_button_create("取消"); if (NULL != cancel_button) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(cancel_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(cancel_button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(switch2pt_confirm_win), RTGUI_WIDGET(cancel_button)); rtgui_button_set_onbutton(cancel_button, cancel_btn_onbutton); } else { printf_syn("creat cancel button fail\n"); } /* 模态显示窗口 */ rtgui_win_show(switch2pt_confirm_win, RT_TRUE); /* 采用模态显示窗口,关闭时不会自行删除窗口,需要主动删除窗口 */ rtgui_win_destroy(switch2pt_confirm_win); switch2pt_confirm_win = NULL; return; }
/* * 构建应用视图 */ int app_view_structure(struct rtgui_workbench *workbench, struct rtgui_view *view) { int ret = SUCC; rtgui_rect_t rect, body_rect; rtgui_label_t* label; char str[48]; //rtgui_radiobox_t *radiobox; //rtgui_button_t* button; struct tm *ptime; #if 1==DISPLAY_OVERLOAD_INFO rtgui_label_t *rx_overload_label; #endif app_view_get_can_use_rect(view, &rect); zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, rect.x1, rect.y1, rect.x2, rect.y2)); body_rect.x1 = 0; body_rect.y1 = 0; body_rect.x2 = rect.x2; body_rect.y2 = TITLE_PANEL_HEIGHT; label = rtgui_label_create(DEVICE_NAME); if (NULL != label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(label), &body_rect); /* view是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); } else { printf_syn("creat title label fail\n"); } body_rect.x1 = 0; body_rect.y1 = TITLE_PANEL_HEIGHT; body_rect.x2 = rect.x2; body_rect.y2 = rect.y2; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); zvd_notebook = rtgui_notebook_create(&body_rect, RTGUI_NOTEBOOK_TOP); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(zvd_notebook)); re_form = rtgui_form_create(re_form_head, RE_FORM_ROWS, RE_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "接收端", RTGUI_WIDGET(re_form)); #if 1 set_form_px_col(re_form); i2str(str, avg_val[AVI_RE_PA]); rtgui_form_set_item(re_form, str, RE_PA_AVG_VALUE_ROW, RE_PA_AVG_VALUE_COL, 0); rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PA_OVER_RANGE_ROW, RE_PA_OVER_RANGE_COL, 0); i2str(str, avg_val[AVI_RE_PB]); rtgui_form_set_item(re_form, str, RE_PB_AVG_VALUE_ROW, RE_PB_AVG_VALUE_COL, 0); rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PB_OVER_RANGE_ROW, RE_PB_OVER_RANGE_COL, 0); i2str(str, avg_val[AVI_RE_PC]); rtgui_form_set_item(re_form, str, RE_PC_AVG_VALUE_ROW, RE_PC_AVG_VALUE_COL, 0); rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PC_OVER_RANGE_ROW, RE_PC_OVER_RANGE_COL, 0); #endif se_form = rtgui_form_create(se_form_head, SE_FORM_ROWS, SE_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "发射端", RTGUI_WIDGET(se_form)); #if 1 set_form_px_col(se_form); rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PA_OVER_RANGE_ROW, SE_PA_OVER_RANGE_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PA_POWER_DOWN_ROW, SE_PA_POWER_DOWN_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PB_OVER_RANGE_ROW, SE_PB_OVER_RANGE_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PB_POWER_DOWN_ROW, SE_PB_POWER_DOWN_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PC_OVER_RANGE_ROW, SE_PC_OVER_RANGE_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PC_POWER_DOWN_ROW, SE_PC_POWER_DOWN_COL, 0); #endif sys_form = rtgui_form_create(sys_form_head, SYS_FORM_ROWS, SYS_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "系统", RTGUI_WIDGET(sys_form)); #if 1 rtgui_form_set_item(sys_form, "接收端", 1, 0, 0); i2str(str, sys_temper[STI_RE_CPU_T]); rtgui_form_set_item(sys_form, str, RE_RE_CPU_TEMP_ROW, RE_RE_CPU_TEMP_COL, 0); i2str(str, sys_temper[STI_RE_CTB_T]); rtgui_form_set_item(sys_form, str, RE_RE_BOX_TEMP_ROW, RE_RE_BOX_TEMP_COL, 0); convert_ver2str(re_version, str); rtgui_form_set_item(sys_form, str, RE_RE_SOFT_VER_ROW, RE_RE_SOFT_VER_COL, 0); rtgui_form_set_item(sys_form, "发射端", 2, 0, 0); i2str(str, sys_temper[STI_SE_CPU_T]); rtgui_form_set_item(sys_form, str, RE_SE_CPU_TEMP_ROW, RE_SE_CPU_TEMP_COL, 0); i2str(str, sys_temper[STI_SE_CTB_T]); rtgui_form_set_item(sys_form, str, RE_SE_BOX_TEMP_ROW, RE_SE_BOX_TEMP_COL, 0); convert_ver2str(se_version, str); rtgui_form_set_item(sys_form, str, RE_SE_SOFT_VER_ROW, RE_SE_SOFT_VER_COL, 0); creat_devsn(str, sizeof(str), 0); rtgui_form_set_row(sys_form, str, TE_SN_ROW); creat_devsn(str, sizeof(str), 1); rtgui_form_set_row(sys_form, str, RE_SN_ROW); #endif other_form = rtgui_form_create(other_form_head, OTHER_FORM_ROWS, OTHER_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "掉电", RTGUI_WIDGET(other_form)); #if 1 rtgui_form_set_item(other_form, "次数", 1, 0, 0); rtgui_form_set_item(other_form, "n", 2, 0, 0); rtgui_form_set_item(other_form, "n-1", 3, 0, 0); rtgui_form_set_item(other_form, "n-2", 4, 0, 0); update_tx_poweroff_info_of_otherform(); update_rx_poweroff_info_of_otherform(); #endif body_rect.x1 = FRAME_GAP; body_rect.y1 = body_rect.y2 + WIDGET_ROW_GAP; body_rect.x2 = FRAME_GAP + 8 * rt_strlen(RE_IF_SWITCH2CABLE_STR); body_rect.y2 = body_rect.y1 + 16; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); switch_cable_label = rtgui_label_create(RE_IF_SWITCH2CABLE_STR); if (NULL != switch_cable_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch_cable_label)) = RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch_cable_label)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(switch_cable_label), &body_rect); /* view是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch_cable_label)); } else { printf_syn("creat cable label fail\n"); } #if 1 body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 16 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); switch_cable_yn_textview = rtgui_textview_create(print_info_str[PIS_ID_FOU], &body_rect); if (NULL != switch_cable_yn_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch_cable_yn_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch_cable_yn_textview)) = red; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch_cable_yn_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #if 1 body_rect.x1 = body_rect.x2 + 2 + 2*8; body_rect.x2 = body_rect.x1 + 8*rt_strlen(TE_HAD_POWEROFF_STR); zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); tx_poweroff_label = rtgui_label_create(TE_HAD_POWEROFF_STR); if (NULL != tx_poweroff_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(tx_poweroff_label)) = RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(tx_poweroff_label), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(tx_poweroff_label)); } else { printf_syn("tx poweroff label fail\n"); } body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 16 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); tx_poweroff_yn_textview = rtgui_textview_create(print_info_str[PIS_ID_FOU], &body_rect); if (NULL != tx_poweroff_yn_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(tx_poweroff_yn_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(tx_poweroff_yn_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #if 1 body_rect.x1 = FRAME_GAP; body_rect.y1 = body_rect.y2 + WIDGET_ROW_GAP; body_rect.x2 = FRAME_GAP + (8+1) * rt_strlen(RE_BUZZER_DISABLE_STR); body_rect.y2 = body_rect.y1 + 16 + 2*WIDGET_ROW_GAP; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); buzzer_button = rtgui_pushbutton_create(RE_BUZZER_DISABLE_STR); if (NULL != buzzer_button) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(buzzer_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(buzzer_button)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(buzzer_button), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(buzzer_button)); rtgui_button_set_onbutton(buzzer_button, buzzer_btn_onbutton); } else { printf_syn("creat buzzer pushbutton fail\n"); } body_rect.x1 = body_rect.x2 + FRAME_GAP; /* body_rect.y1 = body_rect.y1; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ body_rect.x2 = body_rect.x1 + (8+1) * rt_strlen(SWITCH_TO_PT_STR);; /* body_rect.y2 = body_rect.y2; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ switch2pt_button = rtgui_pushbutton_create(SWITCH_TO_PT_STR); if (NULL != switch2pt_button) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch2pt_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch2pt_button)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(switch2pt_button), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch2pt_button)); rtgui_button_set_onbutton(switch2pt_button, switch2pt_btn_onbutton); } else { printf_syn("creat switch button fail\n"); } #if USE_OPTICX_200S_VERSION body_rect.x1 = body_rect.x2 + FRAME_GAP; /* body_rect.y1 = body_rect.y1; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ body_rect.x2 = body_rect.x1 + (8) * rt_strlen(RE_CUR_CHANNEL_NO_STR) + 2; /* body_rect.y2 = body_rect.y2; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); rxe_cur_channel_label = rtgui_label_create(RE_CUR_CHANNEL_NO_STR); if (NULL != rxe_cur_channel_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rxe_cur_channel_label)) = RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(rxe_cur_channel_label), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rxe_cur_channel_label)); } else { printf_syn("rxe cru channel label fail\n"); } body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 8 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); str[0] = convert_cur_channel_to_char(); str[1] = '\0'; rxe_cur_channel_no_textview = rtgui_textview_create(str, &body_rect); if (NULL != rxe_cur_channel_no_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rxe_cur_channel_no_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rxe_cur_channel_no_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #endif #if 1==DISPLAY_OVERLOAD_INFO body_rect.x1 = body_rect.x2 + 2 + 7*8; body_rect.x2 = body_rect.x1 + 8*rt_strlen(RE_OVERLOAD_CNT_STR); zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); rx_overload_label = rtgui_label_create(RE_OVERLOAD_CNT_STR); if (NULL != rx_overload_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rx_overload_label)) = RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(rx_overload_label), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rx_overload_label)); } else { printf_syn("tx poweroff label fail\n"); } body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 16 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); rx_overload_cnt_textview = rtgui_textview_create("0", &body_rect); if (NULL != rx_overload_cnt_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rx_overload_cnt_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rx_overload_cnt_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #if 1 /* 创建时间标签, 2013-03-18 09:20 */ rtc_dev = rt_device_find("rtc"); if (NULL != rtc_dev) { time_t time; rt_device_control(rtc_dev, RT_DEVICE_CTRL_RTC_GET_TIME, &time); ptime = localtime(&time); rt_sprintf(sys_time_str, "%4d-%02d-%02d %02d:%02d:%02d", (ptime->tm_year+1900), (ptime->tm_mon+1), ptime->tm_mday, ptime->tm_hour, ptime->tm_min, ptime->tm_sec); body_rect.x2 = rtgui_graphic_driver_get_default()->width; body_rect.y2 = rtgui_graphic_driver_get_default()->height; body_rect.x1 = body_rect.x2 - (8+1) * 19; body_rect.y1 = body_rect.y2 - 20; #if SYS_TIME_USE_TEXTBOX sys_time_textbox = rtgui_textbox_create(sys_time_str, RTGUI_TEXTBOX_SINGLE | RTGUI_TEXTBOX_CARET_HIDE); if (NULL != sys_time_textbox) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(sys_time_textbox)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue; RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue; //default_background; //RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)); rtgui_widget_set_rect(RTGUI_WIDGET(sys_time_textbox), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(sys_time_textbox)); } else { printf_syn("creat sys time textbox fail\n"); } #else sys_time_textview = rtgui_textview_create(sys_time_str, &body_rect); if (NULL != sys_time_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(sys_time_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(sys_time_textview)); } else { printf_syn("creat sys time textview fail\n"); } #endif } else { printf_syn("find rtc device fail\n"); } #endif rtgui_view_show(view, RT_FALSE); /* 显示视图 */ return ret; }
rtgui_container_t *demo_view_window(void) { rtgui_rect_t rect; rtgui_container_t *container; rtgui_button_t *button; /* 创建一个演示用的视图 */ container = demo_view("Window Demo"); create_normal_win(); demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建按钮用于显示正常窗口 */ button = rtgui_button_create("Normal Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button)); /* 设置onbutton为demo_win_onbutton函数 */ rtgui_button_set_onbutton(button, demo_normal_window_onbutton); demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; /* 创建按钮用于显示一个自动关闭的窗口 */ button = rtgui_button_create("Auto Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button)); /* 设置onbutton为demo_autowin_onbutton函数 */ rtgui_button_set_onbutton(button, demo_autowin_onbutton); demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建按钮用于触发一个模式窗口 */ button = rtgui_button_create("Modal Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button)); /* 设置onbutton为demo_modalwin_onbutton函数 */ rtgui_button_set_onbutton(button, demo_modalwin_onbutton); demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建按钮用于触发一个不包含标题的窗口 */ button = rtgui_button_create("NoTitle Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button)); /* 设置onbutton为demo_ntitlewin_onbutton函数 */ rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton); return container; }
rtgui_container_t *demo_view(const char *title) { struct rtgui_container *container; struct rtgui_label *label; struct rtgui_staticline *line; struct rtgui_button *next_btn, *prev_btn; struct rtgui_rect rect; container = rtgui_container_create(); if (container == RT_NULL) return RT_NULL; rtgui_notebook_add(the_notebook, title, RTGUI_WIDGET(container)); /* 获得视图的位置信息(在加入到 notebook 中时,notebook 会自动调整 container * 的大小) */ rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect); rect.x1 += 5; rect.y1 += 5; rect.x2 = rect.x1 + rt_strlen(title)*8; rect.y2 = rect.y1 + 20; /* 创建标题用的标签 */ label = rtgui_label_create(title); /* 设置标签位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加标签到视图中 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect); rect.y1 += 20 + 5; rect.y2 = rect.y1 + 2; /* 创建一个水平的 staticline 线 */ line = rtgui_staticline_create(RTGUI_HORIZONTAL); /* 设置静态线的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect); /* 添加静态线到视图中 */ rtgui_container_add_child(container, RTGUI_WIDGET(line)); /* 获得视图的位置信息 */ rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect); rect.x2 -= 5; rect.y2 -= 5; rect.x1 = rect.x2 - 100; rect.y1 = rect.y2 - 25; /* 创建"下一个"按钮 */ next_btn = rtgui_button_create("下一个"); /* 设置onbutton动作到demo_view_next函数 */ rtgui_button_set_onbutton(next_btn, demo_view_next); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect); /* 添加按钮到视图中 */ rtgui_container_add_child(container, RTGUI_WIDGET(next_btn)); /* 获得视图的位置信息 */ rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect); rect.x1 += 5; rect.y2 -= 5; rect.x2 = rect.x1 + 100; rect.y1 = rect.y2 - 25; /* 创建"上一个"按钮 */ prev_btn = rtgui_button_create("上一个"); /* 设置onbutton动作到demo_view_prev函数 */ rtgui_button_set_onbutton(prev_btn, demo_view_prev); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect); /* 添加按钮到视图中 */ rtgui_container_add_child(container, RTGUI_WIDGET(prev_btn)); /* 返回创建的视图 */ return container; }
rt_bool_t window_focus(void) { rtgui_label_t *label; rtgui_button_t* start_btn; rtgui_button_t* stop_btn; rtgui_win_t *picture_win; rtgui_rect_t rect = {0, 20, 240, 320}; /* 创建一个窗口 */ main_win = rtgui_win_create(RT_NULL, "主窗口", &rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); /* 获得视图的位置信息 */ rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect); rect.x1 += 10; rect.x2 -= 5; rect.y2 = rect.y1 + 20; /* 创建标题用的标签 */ label = rtgui_label_create("主窗口"); /* 设置标签位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加标签到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(label)); /* 获得视图的位置信息 */ rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect); rect.x1 += 10; rect.y2 -= 10; rect.y1 = rect.y2 - 25; rect.x2 = rect.x1 + 50; /* 创建"启动"按钮 */ start_btn = rtgui_button_create("按钮1"); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(start_btn), &rect); rtgui_button_set_onbutton(start_btn, show_modal_info); /* 添加按钮到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(start_btn)); /* 添加停止按钮*/ rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect); rect.x2 -= 10; rect.y2 -= 10; rect.x1 = rect.x2 - 50; rect.y1 = rect.y2 - 25; /* 创建"停止"按钮 */ stop_btn = rtgui_button_create("按钮2"); /* 设置按钮的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(stop_btn), &rect); rtgui_button_set_onbutton(stop_btn, echo_btn_pressed); /* 添加按钮到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(stop_btn)); /*创建一个绘图Windows控件*/ rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect); rect.x1 += 10; rect.y1 += 20; rect.x2 = rect.x1 + 200; rect.y2 = rect.y1 + 150; picture_win = rtgui_win_create(main_win, "绘图窗口", &rect, RTGUI_WIN_STYLE_NO_TITLE|RTGUI_WIN_STYLE_NO_BORDER|RTGUI_WIN_STYLE_NO_FOCUS); //创建窗口,没有标题栏,没有最小化窗口,也不能获取焦点 /* 添加windows的事件*/ /* all of the windows are managed by topwin. Never set a window as other * window's child. * *rtgui_container_add_child(RTGUI_CONTAINER(main_win), * RTGUI_WIDGET(picture_win)); */ rtgui_object_set_event_handler(RTGUI_OBJECT(picture_win), picture_win_onpaint); /* 非模态显示窗口 */ rtgui_widget_focus(RTGUI_WIDGET(main_win));//设定主窗体获取焦点 rtgui_win_show(main_win, RT_FALSE); rtgui_win_show(picture_win,RT_FALSE); return RT_TRUE; }