rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench) { rtgui_view_t *view; view = demo_view(workbench, "DC 缓冲区动画"); if (view != RT_NULL) rtgui_widget_set_event_handler(RTGUI_WIDGET(view), animation_event_handler); rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "缓冲动画", &text_rect); if (dc_buffer == RT_NULL) { rtgui_rect_t rect; rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2; rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2; /* 创建 DC Buffer,长 50,宽 50 */ dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect)); RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)); rtgui_dc_fill_rect(dc_buffer, &rect); RTGUI_DC_FC(dc_buffer) = black; rect.x1 = 1; rect.y1 = 1; rtgui_dc_draw_text(dc_buffer, "缓冲动画", &rect); } /* 启动定时器以触发动画 */ timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view); rtgui_timer_start(timer); 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; }
/* 创建用于演示notebook控件的视图 */ rtgui_view_t* demo_view_notebook(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t* view; rtgui_notebook_t* notebook; rtgui_listbox_t* box; /* 先创建一个演示用的视图 */ view = demo_view(workbench, "Notebook View"); /* 获得视图的位置信息 */ demo_view_get_rect(view, &rect); notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_BOTTOM); /* view是一个container控件,调用add_child方法添加这个notebook控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(notebook)); box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &rect); rtgui_notebook_add(notebook, "Tab 1", RTGUI_WIDGET(box)); box = rtgui_listbox_create(items2, sizeof(items2)/sizeof(struct rtgui_listbox_item), &rect); rtgui_notebook_add(notebook, "Tab 2", RTGUI_WIDGET(box)); return view; }
/* 创建用于演示自定义控件的视图 */ rtgui_container_t *demo_view_mywidget(void) { rtgui_container_t *container; rtgui_rect_t rect; rtgui_mywidget_t *mywidget; /* 先创建一个演示用的视图 */ container = demo_view("MyWidget View"); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.y1 + 80; rect.y1 += 5; rect.y2 = rect.y1 + 80; /* 创建一个自定义控件 */ mywidget = rtgui_mywidget_create(&rect); /* container是一个container控件,调用add_child方法添加这个自控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(mywidget)); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 25; rect.x2 = rect.y1 + 40; rect.y1 += 5 + 100; rect.y2 = rect.y1 + 40; /* 创建一个自定义控件 */ mywidget = rtgui_mywidget_create(&rect); /* container是一个container控件,调用add_child方法添加这个自控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(mywidget)); return container; }
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_container_t *demo_view_benchmark(void) { srand(100); container = demo_view("绘图测试"); rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler); return container; }
rtgui_view_t* demo_view_box(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t* view; view = demo_view(workbench, "Box View"); demo_view_get_rect(view, &rect); return view; }
rtgui_container_t *demo_view_benchmark(void) { srand(100); container = demo_view("绘图测试"); RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler); rtgui_widget_set_onshow(RTGUI_WIDGET(container), _benchmark_onshow); return container; }
/* 创建用于DC操作演示用的视图 */ rtgui_container_t *demo_view_instrument_panel(void) { rtgui_container_t *container; container = demo_view("instrument panel Demo"); if (container != RT_NULL) /* 设置成自己的事件处理函数 */ rtgui_object_set_event_handler(RTGUI_OBJECT(container), instrument_panel_event_handler); return container; }
/* 创建用于DC操作演示用的视图 */ rtgui_view_t *demo_view_instrument_panel(rtgui_workbench_t* workbench) { rtgui_view_t *view; view = demo_view(workbench, "instrument panel Demo"); if (view != RT_NULL) /* 设置成自己的事件处理函数 */ rtgui_widget_set_event_handler(RTGUI_WIDGET(view), instrument_panel_event_handler); return view; }
/* 创建用于DC操作演示用的视图 */ rtgui_view_t *demo_view_dc(rtgui_workbench_t* workbench) { rtgui_view_t *view; view = demo_view(workbench, "DC Demo"); if (view != RT_NULL) /* 设置成自己的事件处理函数 */ rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_event_handler); return view; }
struct rtgui_container* demo_plot(void) { struct rtgui_container *cnt; struct rtgui_plot_curve *curve1, *curve2, *curve3; struct rtgui_plot *plot; struct rtgui_rect rect; cnt = demo_view("ÇúÏß»æͼ"); plot = rtgui_plot_create(); curve1 = rtgui_plot_curve_create(); rtgui_plot_curve_set_y(curve1, sin_ydata); RTGUI_MV_MODEL(curve1)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); curve1->min_x = 0; curve1->max_x = sizeof(sin_ydata)/sizeof(sin_ydata[0]); curve1->min_y = -100; curve1->min_y = 100; curve1->color = red; rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve1), RTGUI_MV_VIEW(plot)); curve2 = rtgui_plot_curve_create(); rtgui_plot_curve_set_y(curve2, cos_ydata); RTGUI_MV_MODEL(curve2)->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]); curve2->min_x = 0; curve2->max_x = sizeof(cos_ydata)/sizeof(cos_ydata[0]); curve1->min_y = -50; curve1->min_y = 50; curve2->color = blue; rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve2), RTGUI_MV_VIEW(plot)); curve3 = rtgui_plot_curve_create(); rtgui_plot_curve_set_x(curve3, cos_ydata); rtgui_plot_curve_set_y(curve3, sin_ydata); RTGUI_MV_MODEL(curve3)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); curve3->color = black; rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve3), RTGUI_MV_VIEW(plot)); rtgui_widget_get_rect(RTGUI_WIDGET(cnt), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(plot), &rect); rtgui_plot_set_base(plot, -rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2); rtgui_container_add_child(cnt, RTGUI_WIDGET(plot)); return cnt; }
rtgui_container_t *demo_view_scrollbar(void) { rtgui_container_t *container; rtgui_rect_t rect; rtgui_label_t *label; rtgui_scrollbar_t *hbar; rtgui_scrollbar_t *vbar; /* create a demo container */ container = demo_view("ScrollBar View"); /* get demo container rect */ demo_view_get_rect(container, &rect); label = rtgui_label_create("horizontal bar:"); rtgui_container_add_child(container, 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; hbar = rtgui_scrollbar_create(RTGUI_HORIZONTAL, &rect); rtgui_container_add_child(container, RTGUI_WIDGET(hbar)); /* get demo container rect */ demo_view_get_rect(container, &rect); label = rtgui_label_create("vertical bar:"); rtgui_container_add_child(container, RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 45; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.x1 += 110; rect.x2 = rect.x1 + 20; rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150; vbar = rtgui_scrollbar_create(RTGUI_VERTICAL, &rect); rtgui_container_add_child(container, RTGUI_WIDGET(vbar)); rtgui_scrollbar_set_line_step(vbar, 1); // RTGUI_WIDGET_DISABLE(vbar); return container; }
rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench) { rtgui_view_t *view; rtgui_rect_t rect; rtgui_label_t *label; /* create a demo view */ view = demo_view(workbench, "ProgressBar View"); /* get demo view rect */ demo_view_get_rect(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; hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(hbar)); /* get demo view rect */ demo_view_get_rect(view, &rect); label = rtgui_label_create("換岷序業訳:"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 45; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.x1 += 110; rect.x2 = rect.x1 + 20; rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150; vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(vbar)); bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC, progressbar_timeout, RT_NULL); rtgui_timer_start(bar_timer); return view; }
rtgui_view_t *demo_view_slider(rtgui_workbench_t* workbench) { rtgui_view_t *view; rtgui_rect_t rect; rtgui_label_t *label; rtgui_slider_t *slider; /* create a demo view */ view = demo_view(workbench, "Slider View"); /* get demo view rect */ demo_view_get_rect(view, &rect); label = rtgui_label_create("horizontal slider:"); 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 = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider)); rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect); /* get demo view rect */ demo_view_get_rect(view, &rect); label = rtgui_label_create("vertical slider:"); 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.x1 += 110; rect.x2 = rect.x1 + 20; rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150; slider = rtgui_slider_create(0, 100, RTGUI_VERTICAL); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider)); rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect); return view; }
/* 创建用于演示radiobox控件的视图 */ rtgui_container_t* demo_view_radiobox(void) { rtgui_rect_t rect; rtgui_container_t* container; rtgui_radiobox_t* radiobox; /* 先创建一个演示用的视图 */ container = demo_view("RadioBox View"); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 5 * 25; /* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */ radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5); /* 设置当前选择的数组是第0项 */ rtgui_radiobox_set_selection(radiobox, 0); /* 添加radiobox控件到视图中 */ rtgui_container_add_child(container, RTGUI_WIDGET(radiobox)); /* 设置radiobox控件的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5 + 5 * 25; rect.y2 = rect.y1 + 60; /* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */ radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3); /* 设置当前选择的数组是第0项 */ rtgui_radiobox_set_selection(radiobox, 0); /* 添加radiobox控件到视图中 */ rtgui_container_add_child(container, RTGUI_WIDGET(radiobox)); /* 设置radiobox控件的位置信息 */ rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); return container; }
/* 创建用于显示应用模块的演示视图 */ 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; }
/* 创建用于演示列表视图的视图 */ 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_container_t *demo_view_progressbar(void) { rtgui_container_t *container; rtgui_rect_t rect; rtgui_label_t *label; /* create a demo container */ container = demo_view("ProgressBar View"); /* get demo container rect */ demo_view_get_rect(container, &rect); label = rtgui_label_create("邦峠序業訳:"); rtgui_container_add_child(container, 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; hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect); rtgui_container_add_child(container, RTGUI_WIDGET(hbar)); /* get demo container rect */ demo_view_get_rect(container, &rect); label = rtgui_label_create("換岷序業訳:"); rtgui_container_add_child(container, RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 45; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.x1 += 110; rect.x2 = rect.x1 + 20; rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150; vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect); rtgui_container_add_child(container, RTGUI_WIDGET(vbar)); bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC, progressbar_timeout, RT_NULL); rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer); rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer); 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; }
/* 创建用于演示combobox控件的视图 */ rtgui_view_t* demo_view_combobox(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t* view; rtgui_combobox_t* box; /* 先创建一个演示用的视图 */ view = demo_view(workbench, "ComboBox View"); /* 获得视图的位置信息 */ demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ box = rtgui_combobox_create(items, sizeof(items)/sizeof(items[0]), &rect); /* view是一个container控件,调用add_child方法添加这个box控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box)); 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; }
/* 创建用于演示label控件的视图 */ rtgui_container_t *demo_view_listctrl(void) { rtgui_rect_t rect; rtgui_container_t *container; rtgui_label_t *label; rtgui_listctrl_t *box; /* 先创建一个演示用的视图 */ container = demo_view("List Control Demo"); if (item_icon == RT_NULL) item_icon = rtgui_image_create_from_mem("xpm", (const rt_uint8_t *)image_xpm, sizeof(image_xpm), RT_TRUE); items[1].image = item_icon; /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("List Control: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* container是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); rect.y1 = rect.y2 + 3; rect.y2 = 250; box = rtgui_listctrl_create(items, sizeof(items) / sizeof(items[0]), &rect, _rtgui_listctrl_item_draw); rtgui_listctrl_set_onitem(box, on_items); /* container是一个container控件,调用add_child方法添加这个listctrl控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(box)); return container; }
rtgui_container_t* demo_view_box(void) { rtgui_rect_t rect; rtgui_container_t* view; struct rtgui_panel *panel; struct rtgui_box *box; struct rtgui_label *label; struct rtgui_button *button; view = demo_view("Box View"); demo_view_get_rect(view, &rect); panel = rtgui_panel_create(RTGUI_BORDER_NONE); rtgui_widget_set_rect(RTGUI_WIDGET(panel), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(panel)); box = rtgui_box_create(RTGUI_VERTICAL, 5); rtgui_container_set_box(RTGUI_CONTAINER(panel), box); label = rtgui_label_create("label 1"); rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label)); label = rtgui_label_create("label 2"); rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label)); button = rtgui_button_create("button 1"); rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button)); button = rtgui_button_create("button 2"); rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button)); rtgui_widget_set_miniheight(RTGUI_WIDGET(button), 25); RTGUI_WIDGET_ALIGN(button) = RTGUI_ALIGN_EXPAND; rtgui_container_layout(RTGUI_CONTAINER(panel)); return view; }
/* 创建用于DC Buffer操作演示用的视图 */ rtgui_container_t *demo_view_dc_buffer() { rtgui_container_t *view; if (dc_buffer == RT_NULL) { rtgui_rect_t rect = {0, 0, 50, 50}; /* 创建 DC Buffer,长 50,宽 50 */ dc_buffer = rtgui_dc_buffer_create(50, 50); RTGUI_DC_FC(dc_buffer) = blue; rtgui_dc_fill_rect(dc_buffer, &rect); RTGUI_DC_FC(dc_buffer) = red; rtgui_dc_draw_circle(dc_buffer, 25, 25, 10); } view = demo_view("缓冲DC演示"); if (view != RT_NULL) /* 设置成自己的事件处理函数 */ rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler); return view; }
/* 创建用于DC Buffer操作演示用的视图 */ rtgui_view_t *demo_view_dc_buffer(rtgui_workbench_t* workbench) { rtgui_view_t *view; if (dc_buffer == RT_NULL) { rtgui_rect_t rect = {0, 0, 50, 50}; /* 创建 DC Buffer,长 50,宽 50 */ dc_buffer = rtgui_dc_buffer_create(50, 50); RTGUI_DC_FC(dc_buffer) = blue; rtgui_dc_fill_rect(dc_buffer, &rect); RTGUI_DC_FC(dc_buffer) = red; rtgui_dc_draw_circle(dc_buffer, 25, 25, 10); } view = demo_view(workbench, "缓冲DC演示"); if (view != RT_NULL) /* 设置成自己的事件处理函数 */ rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_buffer_event_handler); 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; }
/* 创建用于演示textbox控件的视图 */ rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench) { rtgui_rect_t rect, textbox_rect; rtgui_view_t* view; rtgui_label_t* label; rtgui_textbox_t* text; /* 先创建一个演示用的视图 */ view = demo_view(workbench, "TextBox View"); /* 获得视图的位置信息 */ demo_view_get_rect(view, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 30; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("名字: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* view是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); /* 让textbox_rect赋值到rect,以计算textbox控件的位置 */ textbox_rect = rect; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; /* 创建一个textbox控件 */ text = rtgui_textbox_create("bernard",RTGUI_TEXTBOX_SINGLE); /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); /* 计算下一个label控件的位置 */ rect.y1 += 23; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("邮件: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加label控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); textbox_rect = rect; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; /* 创建一个textbox控件 */ text = rtgui_textbox_create("*****@*****.**",RTGUI_TEXTBOX_SINGLE); /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rect.y1 += 23; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("密码: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加label控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); textbox_rect = rect; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; /* 创建一个textbox控件 */ text = rtgui_textbox_create("rt-thread",RTGUI_TEXTBOX_SINGLE); /* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */ text->flag |= RTGUI_TEXTBOX_MASK; /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rect.y1 += 23; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("主页: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加label控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); textbox_rect = rect; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; /* 创建一个textbox控件 */ text = rtgui_textbox_create("http://www.rt-thread.org",RTGUI_TEXTBOX_SINGLE); /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); return view; }
/* 创建用于演示checkbox控件的视图 */ rtgui_container_t *demo_view_checkbox(void) { rtgui_rect_t rect; rtgui_container_t *container; rtgui_checkbox_t *checkbox; rtgui_font_t *font; /* 先创建一个演示用的视图 */ container = demo_view("CheckBox View"); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建一个checkbox控件 */ checkbox = rtgui_checkbox_create("Red", RT_TRUE); /* 设置前景色为红色 */ RTGUI_WIDGET_FOREGROUND(checkbox) = red; /* 设置checkbox的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(checkbox)); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; /* 创建一个checkbox控件 */ checkbox = rtgui_checkbox_create("Blue", RT_TRUE); /* 设置前景色为蓝色 */ RTGUI_WIDGET_FOREGROUND(checkbox) = blue; /* 设置checkbox的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(checkbox)); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建一个checkbox控件 */ checkbox = rtgui_checkbox_create("12 font", RT_TRUE); /* 设置字体为12点阵 */ font = rtgui_font_refer("asc", 12); RTGUI_WIDGET_FONT(checkbox) = font; /* 设置checkbox的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(checkbox)); /* 获得视图的位置信息 */ 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; /* 创建一个checkbox控件 */ checkbox = rtgui_checkbox_create("16 font", RT_TRUE); /* 设置字体为16点阵 */ font = rtgui_font_refer("asc", 16); RTGUI_WIDGET_FONT(checkbox) = font; /* 设置checkbox的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(checkbox)); return container; }
/* 创建用于演示label控件的视图 */ rtgui_container_t *demo_view_label(void) { rtgui_rect_t rect; rtgui_container_t *container; rtgui_label_t *label; rtgui_font_t *font; /* 先创建一个演示用的视图 */ container = demo_view("Label View"); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("Red Left"); /* 设置label控件上的文本对齐方式为:左对齐 */ RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT; /* 设置label控件的前景色为红色 */ RTGUI_WIDGET_FOREGROUND(label) = red; /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* container是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("Blue Right"); /* 设置label控件上的文本对齐方式为:右对齐 */ RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_RIGHT; /* 设置label控件的前景色为蓝色 */ RTGUI_WIDGET_FOREGROUND(label) = blue; /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* container是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("Green Center"); /* 设置label控件的前景色为绿色 */ RTGUI_WIDGET_FOREGROUND(label) = green; /* 设置label控件上的文本对齐方式为:右对齐 */ RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_CENTER_HORIZONTAL; /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* container是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("12 font"); /* 设置字体为12点阵的asc字体 */ font = rtgui_font_refer("asc", 12); RTGUI_WIDGET_FONT(label) = font; /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* container是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.y1 += 5 + 25 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("16 font"); /* 设置字体为16点阵的asc字体 */ font = rtgui_font_refer("asc", 16); RTGUI_WIDGET_FONT(label) = font; /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* container是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); return container; }