diff --git a/examples/gui/demo_fnview.c b/examples/gui/demo_fnview.c index 8d69eeaf39..c0fd55ea84 100644 --- a/examples/gui/demo_fnview.c +++ b/examples/gui/demo_fnview.c @@ -16,10 +16,10 @@ 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); - 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; @@ -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"); diff --git a/examples/gui/demo_view.c b/examples/gui/demo_view.c index db89b17c77..7fe9e0df6f 100644 --- a/examples/gui/demo_view.c +++ b/examples/gui/demo_view.c @@ -2,6 +2,7 @@ #include #include #include +#include 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; } diff --git a/examples/gui/demo_view.h b/examples/gui/demo_view.h index 4b5b6a173d..9365ce2e4b 100644 --- a/examples/gui/demo_view.h +++ b/examples/gui/demo_view.h @@ -9,7 +9,7 @@ #include #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); diff --git a/examples/gui/demo_view_box.c b/examples/gui/demo_view_box.c index 23d136826b..eb7043e52a 100644 --- a/examples/gui/demo_view_box.c +++ b/examples/gui/demo_view_box.c @@ -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; diff --git a/examples/gui/demo_view_button.c b/examples/gui/demo_view_button.c index b3b343175e..7b080fa2ce 100644 --- a/examples/gui/demo_view_button.c +++ b/examples/gui/demo_view_button.c @@ -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; diff --git a/examples/gui/demo_view_checkbox.c b/examples/gui/demo_view_checkbox.c index 0e916d0782..587a50a4ce 100644 --- a/examples/gui/demo_view_checkbox.c +++ b/examples/gui/demo_view_checkbox.c @@ -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; diff --git a/examples/gui/demo_view_dc.c b/examples/gui/demo_view_dc.c index e69de29bb2..78b217f285 100644 --- a/examples/gui/demo_view_dc.c +++ b/examples/gui/demo_view_dc.c @@ -0,0 +1,62 @@ +#include "demo_view.h" +#include +#include +#include + +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; +} diff --git a/examples/gui/demo_view_label.c b/examples/gui/demo_view_label.c index aab70f3c4b..a86c7fd520 100644 --- a/examples/gui/demo_view_label.c +++ b/examples/gui/demo_view_label.c @@ -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; diff --git a/examples/gui/demo_view_progressbar.c b/examples/gui/demo_view_progressbar.c index b336b5fb57..3f6b6170bd 100644 --- a/examples/gui/demo_view_progressbar.c +++ b/examples/gui/demo_view_progressbar.c @@ -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); diff --git a/examples/gui/demo_view_radiobox.c b/examples/gui/demo_view_radiobox.c index ce29962158..4bf657e8c9 100644 --- a/examples/gui/demo_view_radiobox.c +++ b/examples/gui/demo_view_radiobox.c @@ -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; @@ -33,9 +33,9 @@ rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench) rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox)); rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); - demo_view_get_rect(view, &rect); + 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); diff --git a/examples/gui/demo_view_slider.c b/examples/gui/demo_view_slider.c index 28f5f0ceaf..e8efdd729c 100644 --- a/examples/gui/demo_view_slider.c +++ b/examples/gui/demo_view_slider.c @@ -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); diff --git a/examples/gui/demo_view_textbox.c b/examples/gui/demo_view_textbox.c index e69de29bb2..edf3cc9c25 100644 --- a/examples/gui/demo_view_textbox.c +++ b/examples/gui/demo_view_textbox.c @@ -0,0 +1,61 @@ +#include "demo_view.h" +#include +#include + +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; +} diff --git a/examples/gui/demo_view_window.c b/examples/gui/demo_view_window.c index f99bf0030e..9786198717 100644 --- a/examples/gui/demo_view_window.c +++ b/examples/gui/demo_view_window.c @@ -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; diff --git a/examples/gui/demo_workbench.c b/examples/gui/demo_workbench.c index f4cbfc202b..6bb6538c56 100644 --- a/examples/gui/demo_workbench.c +++ b/examples/gui/demo_workbench.c @@ -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();