From ac407d25ae36ed2e4510867133a10009692052b4 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Mon, 15 Nov 2010 00:26:11 +0000 Subject: [PATCH] update GUI examples. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1047 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- examples/gui/demo_view.c | 29 +++++++++++++++++------ examples/gui/demo_view.h | 1 + examples/gui/demo_view_benchmark.c | 4 ++-- examples/gui/demo_view_buffer_animation.c | 4 ++-- examples/gui/demo_view_dc.c | 7 ++++-- examples/gui/demo_view_dc_buffer.c | 2 +- examples/gui/demo_view_progressbar.c | 4 ++-- examples/gui/demo_workbench.c | 4 ++-- 8 files changed, 37 insertions(+), 18 deletions(-) diff --git a/examples/gui/demo_view.c b/examples/gui/demo_view.c index 5a553afba..17cdaa0bd 100644 --- a/examples/gui/demo_view.c +++ b/examples/gui/demo_view.c @@ -56,6 +56,7 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title) /* 获得视图的位置信息(在加入到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; @@ -79,13 +80,14 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title) /* 获得视图的位置信息 */ 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 - 50; - rect.y1 = rect.y2 - 20; + rect.x1 = rect.x2 - 100; + rect.y1 = rect.y2 - 25; /* 创建"下一个"按钮 */ - next_btn = rtgui_button_create("Next"); + next_btn = rtgui_button_create("下一个"); /* 设置onbutton动作到demo_view_next函数 */ rtgui_button_set_onbutton(next_btn, demo_view_next); /* 设置按钮的位置信息 */ @@ -95,13 +97,14 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title) /* 获得视图的位置信息 */ 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 + 50; - rect.y1 = rect.y2 - 20; + rect.x2 = rect.x1 + 100; + rect.y1 = rect.y2 - 25; /* 创建"上一个"按钮 */ - prev_btn = rtgui_button_create("Prev"); + prev_btn = rtgui_button_create("上一个"); /* 设置onbutton动作到demo_view_prev函数 */ rtgui_button_set_onbutton(prev_btn, demo_view_prev); /* 设置按钮的位置信息 */ @@ -121,9 +124,21 @@ void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect) RT_ASSERT(rect != RT_NULL); rtgui_widget_get_rect(RTGUI_WIDGET(view), rect); + rtgui_widget_rect_to_device(RTGUI_WIDGET(view), rect); /* 去除演示标题和下方按钮的区域 */ rect->y1 += 45; - rect->y2 -= 25; + rect->y2 -= 35; +} + +void demo_view_get_logic_rect(rtgui_view_t* view, rtgui_rect_t *rect) +{ + RT_ASSERT(view != RT_NULL); + RT_ASSERT(rect != RT_NULL); + + rtgui_widget_get_rect(RTGUI_WIDGET(view), rect); + /* 去除演示标题和下方按钮的区域 */ + rect->y1 += 45; + rect->y2 -= 35; } /* 当是标准版本时,这个函数用于返回自动布局引擎box控件 */ diff --git a/examples/gui/demo_view.h b/examples/gui/demo_view.h index 98a9ff988..e1c772927 100644 --- a/examples/gui/demo_view.h +++ b/examples/gui/demo_view.h @@ -27,6 +27,7 @@ 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_get_logic_rect(rtgui_view_t* view, rtgui_rect_t *rect); void demo_view_show(void); /* 如果是标准版,可以调用这个函数获得一个自动布局引擎 */ diff --git a/examples/gui/demo_view_benchmark.c b/examples/gui/demo_view_benchmark.c index 5011eb674..89e9ffbf2 100644 --- a/examples/gui/demo_view_benchmark.c +++ b/examples/gui/demo_view_benchmark.c @@ -21,7 +21,7 @@ void _onidle(rtgui_widget_t* widget, rtgui_event_t *event) dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); if (dc == RT_NULL) return ; - demo_view_get_rect(RTGUI_VIEW(view), &rect); + demo_view_get_logic_rect(RTGUI_VIEW(view), &rect); draw_rect.x1 = RAND(rect.x1, rect.x2); draw_rect.y1 = RAND(rect.y1, rect.y2); draw_rect.x2 = RAND(draw_rect.x1, rect.x2); @@ -50,7 +50,7 @@ void _draw_default(rtgui_widget_t* widget, rtgui_event_t* event) return ; /* demo viewͼ */ - demo_view_get_rect(RTGUI_VIEW(widget), &rect); + demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect); /* */ RTGUI_WIDGET_BACKGROUND(widget) = default_background; diff --git a/examples/gui/demo_view_buffer_animation.c b/examples/gui/demo_view_buffer_animation.c index 2e8cc5ce3..cadc2430e 100644 --- a/examples/gui/demo_view_buffer_animation.c +++ b/examples/gui/demo_view_buffer_animation.c @@ -28,7 +28,7 @@ static void timeout(struct rtgui_timer* timer, void* parameter) return ; /* demo viewͼҪжϱ߽ */ - demo_view_get_rect(RTGUI_VIEW(widget), &rect); + demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect); rect.y2 -= 5; /* жǷǵһλͼ */ @@ -72,7 +72,7 @@ static rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t * return RT_FALSE; /* demo viewͼ */ - demo_view_get_rect(RTGUI_VIEW(widget), &rect); + demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect); /* ͼ */ rect = text_rect; diff --git a/examples/gui/demo_view_dc.c b/examples/gui/demo_view_dc.c index c2b50182e..bbe81805a 100644 --- a/examples/gui/demo_view_dc.c +++ b/examples/gui/demo_view_dc.c @@ -46,7 +46,7 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) return RT_FALSE; /* demo viewͼ */ - demo_view_get_rect(RTGUI_VIEW(widget), &rect); + demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect); RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL; /* ʾGUIİ汾Ϣ */ @@ -73,7 +73,7 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) /* һԲ */ RTGUI_DC_FC(dc) = green; rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10); - +#if 0 /* һԲǾ */ rect.x1 = 150; rect.y1 = 180; @@ -101,6 +101,9 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) RTGUI_DC_FC(dc) = blue; rtgui_dc_draw_polygon(dc, vx, vy, 6); +#endif + RTGUI_DC_FC(dc) = blue; + /* Ʋͬı߿ */ { rtgui_rect_t rect = {0, 0, 16, 16}; diff --git a/examples/gui/demo_view_dc_buffer.c b/examples/gui/demo_view_dc_buffer.c index 1b459b220..d3fc4f08f 100644 --- a/examples/gui/demo_view_dc_buffer.c +++ b/examples/gui/demo_view_dc_buffer.c @@ -38,7 +38,7 @@ static rt_bool_t dc_buffer_event_handler(rtgui_widget_t* widget, rtgui_event_t * return RT_FALSE; /* demo viewͼ */ - demo_view_get_rect(RTGUI_VIEW(widget), &rect); + demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect); rect.x1 += 10; rect.y1 += 10; diff --git a/examples/gui/demo_view_progressbar.c b/examples/gui/demo_view_progressbar.c index 3f6b6170b..620668d7d 100644 --- a/examples/gui/demo_view_progressbar.c +++ b/examples/gui/demo_view_progressbar.c @@ -29,7 +29,7 @@ rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench) /* get demo view rect */ demo_view_get_rect(view, &rect); - label = rtgui_label_create("horizontal progress bar:"); + 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; @@ -40,7 +40,7 @@ rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench) /* get demo view rect */ demo_view_get_rect(view, &rect); - label = rtgui_label_create("vertical progress bar:"); + 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; diff --git a/examples/gui/demo_workbench.c b/examples/gui/demo_workbench.c index 30db0ef29..f0718481a 100644 --- a/examples/gui/demo_workbench.c +++ b/examples/gui/demo_workbench.c @@ -52,7 +52,7 @@ static void workbench_entry(void* parameter) /* 初始化各个例子的视图 */ #if RT_VERSION == 4 - // demo_view_benchmark(workbench); + demo_view_benchmark(workbench); #endif demo_view_dc(workbench); @@ -68,7 +68,7 @@ static void workbench_entry(void* parameter) demo_view_animation(workbench); #ifndef RTGUI_USING_SMALL_SIZE demo_view_buffer_animation(workbench); - demo_view_instrument_panel(workbench); + // demo_view_instrument_panel(workbench); #endif demo_view_window(workbench); demo_view_label(workbench);