add more GUI example.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@335 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
1e67026b13
commit
45a9c5f258
|
@ -16,11 +16,11 @@ rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench)
|
|||
rtgui_button_t* open_btn;
|
||||
rtgui_font_t* font;
|
||||
|
||||
view = demo_view(workbench);
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
|
||||
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: ");
|
||||
|
@ -28,7 +28,7 @@ rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench)
|
|||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
|
||||
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
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");
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/button.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
#include <rtgui/widgets/staticline.h>
|
||||
|
||||
static rtgui_view_t* demo_view_list[32];
|
||||
static rt_uint32_t demo_view_current = 0;
|
||||
|
@ -29,7 +30,7 @@ static void demo_view_prev(struct rtgui_widget* widget, rtgui_event_t *event)
|
|||
}
|
||||
}
|
||||
|
||||
rtgui_view_t* demo_view(rtgui_workbench_t* workbench)
|
||||
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
|
||||
{
|
||||
char view_name[32];
|
||||
struct rtgui_view* view;
|
||||
|
@ -54,13 +55,13 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench)
|
|||
/* get view's rect */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rect.x1 += 5; rect.y1 += 5;
|
||||
rect.x2 -= 5; rect.y2 -= 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
rect.x2 -= 5; rect.y2 = rect.y1 + 20;
|
||||
|
||||
/* create view label */
|
||||
label = rtgui_label_create("Demo Label");
|
||||
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;
|
||||
line = rtgui_staticline_create(RTGUI_HORIZONTAL);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
|
||||
|
@ -99,6 +100,7 @@ void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect)
|
|||
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), rect);
|
||||
/* remove the command button rect */
|
||||
rect->y1 += 45;
|
||||
rect->y2 -= 25;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <rtgui/widgets/box.h>
|
||||
#endif
|
||||
|
||||
rtgui_view_t* demo_view(rtgui_workbench_t* workbench);
|
||||
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title);
|
||||
void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect);
|
||||
void demo_view_show(void);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ rtgui_view_t* demo_view_box(rtgui_workbench_t* workbench)
|
|||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "Box View");
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
||||
return view;
|
||||
|
|
|
@ -9,7 +9,7 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
rtgui_font_t* font;
|
||||
|
||||
/* create a demo view */
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "Button View");
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
|
|
|
@ -9,7 +9,7 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
rtgui_font_t* font;
|
||||
|
||||
/* create a demo view */
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "CheckBox View");
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
#include "demo_view.h"
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/label.h>
|
||||
#include <rtgui/widgets/slider.h>
|
||||
|
||||
rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
{
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
rt_uint32_t vx[] = {20, 50, 60, 45, 60, 20};
|
||||
rt_uint32_t vy[] = {150, 50, 90, 60, 45, 50};
|
||||
|
||||
/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让它先绘图 */
|
||||
rtgui_view_event_handler(widget, event);
|
||||
|
||||
/************************************************************************/
|
||||
/* 下面的是DC的处理 */
|
||||
/************************************************************************/
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
|
||||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
|
||||
|
||||
/* 绘制一个圆形 */
|
||||
rtgui_dc_set_color(dc, red);
|
||||
rtgui_dc_draw_circle(dc, rect.x1 + 10, rect.y1 + 10, 10);
|
||||
|
||||
/* 填充一个圆形 */
|
||||
rtgui_dc_set_color(dc, green);
|
||||
rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10);
|
||||
|
||||
/* 多边形 */
|
||||
rtgui_dc_set_color(dc, blue);
|
||||
rtgui_dc_draw_polygon(dc, vx, vy, 6);
|
||||
|
||||
/* 绘图完成 */
|
||||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_view_t *demo_view_dc(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
|
||||
view = demo_view(workbench, "DC Demo");
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_event_handler);
|
||||
|
||||
return view;
|
||||
}
|
|
@ -9,7 +9,7 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
rtgui_font_t* font;
|
||||
|
||||
/* create a demo view */
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "Label View");
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
|
|
|
@ -25,7 +25,7 @@ rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench)
|
|||
rtgui_label_t *label;
|
||||
|
||||
/* create a demo view */
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "ProgressBar View");
|
||||
|
||||
/* get demo view rect */
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
|
|
@ -21,7 +21,7 @@ rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench)
|
|||
rtgui_view_t* view;
|
||||
rtgui_radiobox_t* radiobox;
|
||||
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "RadioBox View");
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
|
@ -35,7 +35,7 @@ rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench)
|
|||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 = 5 + 5 * 25; rect.y2 = rect.y1 + 60;
|
||||
rect.y1 += 5 + 5 * 25; rect.y2 = rect.y1 + 60;
|
||||
|
||||
radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
|
||||
rtgui_radiobox_set_selection(radiobox, 0);
|
||||
|
|
|
@ -11,7 +11,7 @@ rtgui_view_t *demo_view_slider(rtgui_workbench_t* workbench)
|
|||
rtgui_slider_t *slider;
|
||||
|
||||
/* create a demo view */
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "Slider View");
|
||||
|
||||
/* get demo view rect */
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/label.h>
|
||||
#include <rtgui/widgets/textbox.h>
|
||||
|
||||
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;
|
||||
|
||||
/* create a demo view */
|
||||
view = demo_view(workbench, "TextBox View");
|
||||
|
||||
/* add label */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 30;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
label = rtgui_label_create("Ãû×Ö: ");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
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;
|
||||
text = rtgui_textbox_create("bernard");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
|
||||
|
||||
rect.y1 += 23; rect.y2 = rect.y1 + 20;
|
||||
label = rtgui_label_create("Óʼþ: ");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
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;
|
||||
text = rtgui_textbox_create("bernard.xiong@gmail.com");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
|
||||
|
||||
rect.y1 += 23; rect.y2 = rect.y1 + 20;
|
||||
label = rtgui_label_create("ÃÜÂë: ");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
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;
|
||||
text = rtgui_textbox_create("rt-thread");
|
||||
text->flag |= RTGUI_TEXTBOX_MASK;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
|
||||
|
||||
rect.y1 += 23; rect.y2 = rect.y1 + 20;
|
||||
label = rtgui_label_create("Ö÷Ò³: ");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
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;
|
||||
text = rtgui_textbox_create("http://www.rt-thread.org");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
|
||||
|
||||
return view;
|
||||
}
|
|
@ -86,7 +86,7 @@ rtgui_view_t* demo_view_window(rtgui_workbench_t* workbench)
|
|||
rtgui_view_t* view;
|
||||
rtgui_button_t *button;
|
||||
|
||||
view = demo_view(workbench);
|
||||
view = demo_view(workbench, "Window Demo");
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
|
|
|
@ -55,14 +55,16 @@ static void workbench_entry(void* parameter)
|
|||
/* 在工作台上添加一个视图 */
|
||||
rtgui_workbench_add_view(workbench, view);
|
||||
|
||||
demo_view_dc(workbench);
|
||||
demo_view_window(workbench);
|
||||
demo_view_label(workbench);
|
||||
demo_view_button(workbench);
|
||||
demo_view_checkbox(workbench);
|
||||
demo_view_progressbar(workbench);
|
||||
demo_view_radiobox(workbench);
|
||||
demo_fn_view(workbench);
|
||||
demo_view_textbox(workbench);
|
||||
demo_view_slider(workbench);
|
||||
demo_fn_view(workbench);
|
||||
|
||||
/* 显示视图 */
|
||||
demo_view_show();
|
||||
|
|
Loading…
Reference in New Issue