diff options
| author | [email protected] <[email protected]> | 2012-11-26 02:42:52 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-11-26 02:42:52 +0000 |
| commit | 62447b2cd84b529f7dbf6712c29d7ac4ff0c1e12 (patch) | |
| tree | 399aa1bbc0d4c632d7dc2804ed76e5c62b5cec27 /examples | |
| parent | 9789907ca1b4c43ee34fac6e94e5a48f76aaca3c (diff) | |
sync RTGUI with github(https://github.com/RT-Thread/RTGUI) 9ae08379da5b698d6facc40bd0415de2e254ae9c
As always, full log is in GitHub.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2449 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/gui/SConscript | 10 | ||||
| -rw-r--r-- | examples/gui/demo_plot.c | 37 | ||||
| -rw-r--r-- | examples/gui/demo_view_benchmark.c | 9 | ||||
| -rw-r--r-- | examples/gui/demo_view_scrollbar.c | 42 | ||||
| -rw-r--r-- | examples/gui/mywidget.c | 28 |
5 files changed, 59 insertions, 67 deletions
diff --git a/examples/gui/SConscript b/examples/gui/SConscript index 85b1e65017..b4d2e952f8 100644 --- a/examples/gui/SConscript +++ b/examples/gui/SConscript @@ -1,4 +1,5 @@ from building import * +import os ''' demo_view_dc_buffer.c @@ -44,7 +45,14 @@ demo_plot.c mywidget.c """) - +if GetDepend('RTGUI_USING_FONT_COMPACT'): + import stract_cjk as sf + fl1 = sf.get_font_lib('hz16') + fl2 = sf.get_font_lib('hz12') + cwd = GetCurrentDir() + for i in src: + fl1.push_file(open(os.path.join(cwd, i), 'r')) + fl2.push_file(open(os.path.join(cwd, i), 'r')) group = DefineGroup('gui_examples', src, depend = ['RT_USING_RTGUI']) diff --git a/examples/gui/demo_plot.c b/examples/gui/demo_plot.c index 51f4471d1b..fa524aefa7 100644 --- a/examples/gui/demo_plot.c +++ b/examples/gui/demo_plot.c @@ -1,5 +1,5 @@ - #include <rtgui/widgets/plot.h> +#include <rtgui/widgets/plot_curve.h> #include "demo_view.h" @@ -34,30 +34,39 @@ struct rtgui_container* demo_plot(void) cnt = demo_view("����ͼ"); + plot = rtgui_plot_create(); + curve1 = rtgui_plot_curve_create(); - curve1->y_data = sin_ydata; - curve1->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); + 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; - - plot = rtgui_plot_create(curve1); + rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve1), RTGUI_MV_VIEW(plot)); curve2 = rtgui_plot_curve_create(); - curve2->y_data = cos_ydata; - curve2->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]); + 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_plot_append_curve(plot, curve2); + rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve2), RTGUI_MV_VIEW(plot)); curve3 = rtgui_plot_curve_create(); - curve3->x_data = cos_ydata; - curve3->y_data = sin_ydata; - curve3->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); + 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_plot_append_curve(plot, curve3); + 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_point(plot, - rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2); + rtgui_plot_set_base(plot, + -rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2); rtgui_container_add_child(cnt, RTGUI_WIDGET(plot)); diff --git a/examples/gui/demo_view_benchmark.c b/examples/gui/demo_view_benchmark.c index 21ee4649cc..005db4799f 100644 --- a/examples/gui/demo_view_benchmark.c +++ b/examples/gui/demo_view_benchmark.c @@ -6,6 +6,7 @@ #include "demo_view.h" #define RAND(x1, x2) ((rand() % (x2 - x1)) + x1) +#define _int_swap(x, y) do {x ^= y; y ^= x; x ^= y; } while(0) static struct rtgui_container *container = RT_NULL; static int running = 0; @@ -34,8 +35,12 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event) demo_view_get_logic_rect(RTGUI_CONTAINER(container), &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); - draw_rect.y2 = RAND(draw_rect.y1, rect.y2); + draw_rect.x2 = RAND(rect.x1, rect.x2); + draw_rect.y2 = RAND(rect.y1, rect.y2); + + if(draw_rect.x1 > draw_rect.x2) _int_swap(draw_rect.x1, draw_rect.x2); + if(draw_rect.y1 > draw_rect.y2) _int_swap(draw_rect.y1, draw_rect.y2); + area += rtgui_rect_width(draw_rect) * rtgui_rect_height(draw_rect); color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255); RTGUI_WIDGET_BACKGROUND(container) = color; diff --git a/examples/gui/demo_view_scrollbar.c b/examples/gui/demo_view_scrollbar.c index 0835640714..363748d5a3 100644 --- a/examples/gui/demo_view_scrollbar.c +++ b/examples/gui/demo_view_scrollbar.c @@ -16,35 +16,33 @@ rtgui_container_t *demo_view_scrollbar(void) /* get demo container rect */ demo_view_get_rect(container, &rect); + rect.x1 += 5; + rect.x2 -= 5; + rect.y1 += 5; + rect.y2 = rect.y1 + 20; label = rtgui_label_create("horizontal bar:"); + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); 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)); + + hbar = rtgui_scrollbar_create(container, 5, 70, 20, 200, RTGUI_HORIZONTAL); + rtgui_scrollbar_set_line_step(hbar, 1); + rtgui_scrollbar_set_page_step(hbar, 3); + rtgui_scrollbar_set_range(hbar, 20); /* get demo container rect */ demo_view_get_rect(container, &rect); + rect.x1 += 5; + rect.x2 -= 5; + rect.y1 += 5+40; + rect.y2 = rect.y1 + 20; label = rtgui_label_create("vertical bar:"); + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); 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); + + vbar = rtgui_scrollbar_create(container, 10, 110, 20, 200, RTGUI_VERTICAL); + rtgui_scrollbar_set_line_step(vbar, 1); + rtgui_scrollbar_set_page_step(vbar, 5); + rtgui_scrollbar_set_range(vbar, 20); return container; } diff --git a/examples/gui/mywidget.c b/examples/gui/mywidget.c index 961db9cbe5..514cd755da 100644 --- a/examples/gui/mywidget.c +++ b/examples/gui/mywidget.c @@ -1,94 +1,73 @@ #include <rtgui/dc.h> #include "mywidget.h" -/* 控件绘图函数 */ static void rtgui_mywidget_ondraw(struct rtgui_mywidget *me) { struct rtgui_dc *dc; struct rtgui_rect rect; rt_uint16_t x, y; - /* 获得目标DC,开始绘�?*/ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(me)); if (dc == RT_NULL) return; - /* 获得窗口的尺�?*/ rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect); - /* 绘制背景�?*/ RTGUI_DC_BC(dc) = white; rtgui_dc_fill_rect(dc, &rect); - /* 计算中心原点 */ x = (rect.x2 + rect.x1) / 2; y = (rect.y2 + rect.y1) / 2; - /* 绘制十字�?*/ RTGUI_DC_FC(dc) = black; rtgui_dc_draw_hline(dc, rect.x1, rect.x2, y); rtgui_dc_draw_vline(dc, x, rect.y1, rect.y2); - /* 根据状态绘制圆�?*/ if (me->status == MYWIDGET_STATUS_ON) RTGUI_DC_FC(dc) = green; else RTGUI_DC_FC(dc) = red; rtgui_dc_fill_circle(dc, x, y, 5); - /* 结束绘图 */ rtgui_dc_end_drawing(dc); return; } -/* 鼠标事件处理函数 */ static void rtgui_mywidget_onmouse(struct rtgui_mywidget *me, struct rtgui_event_mouse *mouse) { struct rtgui_rect rect; rt_uint16_t x, y; - /* 仅对鼠标抬起动作进行处理 */ if (!(mouse->button & RTGUI_MOUSE_BUTTON_UP)) return; - /* 获得控件的位�?*/ rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect); - /* get_rect函数获得是控件的相对位置,而鼠标事件给出的坐标是绝对坐标,需要做一个转�?*/ rtgui_widget_rect_to_device(RTGUI_WIDGET(me), &rect); - /* 计算中心原点 */ x = (rect.x2 + rect.x1) / 2; y = (rect.y2 + rect.y1) / 2; - /* 比较鼠标坐标是否在圈�?*/ if ((mouse->x < x + 5 && mouse->x > x - 5) && (mouse->y < y + 5 && mouse->y > y - 5)) { - /* 更改控件状�?*/ if (me->status & MYWIDGET_STATUS_ON) me->status = MYWIDGET_STATUS_OFF; else me->status = MYWIDGET_STATUS_ON; - /* 刷新(重新绘制)控件 */ rtgui_mywidget_ondraw(me); } } -/* mywidget控件的事件处理函�?*/ rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object *object, struct rtgui_event *event) { - /* 调用事件处理函数时,widget指针指向控件本身,所以先获得相应控件对象的指�?*/ struct rtgui_mywidget *me = RTGUI_MYWIDGET(object); switch (event->type) { case RTGUI_EVENT_PAINT: - /* 绘制事件,调用绘图函数绘�?*/ rtgui_mywidget_ondraw(me); break; case RTGUI_EVENT_MOUSE_BUTTON: - /* 鼠标事件 */ rtgui_mywidget_onmouse(RTGUI_MYWIDGET(me), (struct rtgui_event_mouse *) event); break; - /* 其他事件调用父类的事件处理函�?*/ default: return rtgui_widget_event_handler(object, event); } @@ -96,15 +75,11 @@ rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object *object, struct rtgui return RT_FALSE; } -/* 自定义控件的构造函�?*/ static void _rtgui_mywidget_constructor(rtgui_mywidget_t *mywidget) { - /* 默认这个控件接收聚焦 */ RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; - /* 初始化控件并设置事件处理函数 */ rtgui_object_set_event_handler(RTGUI_OBJECT(mywidget), rtgui_mywidget_event_handler); - /* 初始状态时OFF */ mywidget->status = MYWIDGET_STATUS_OFF; } @@ -114,12 +89,10 @@ DEFINE_CLASS_TYPE(mywidget, "mywidget", RT_NULL, sizeof(struct rtgui_mywidget)); -/* 创建一个自定义控件 */ struct rtgui_mywidget *rtgui_mywidget_create(rtgui_rect_t *r) { struct rtgui_mywidget *me; - /* 让rtgui_widget创建出一个指定类型:RTGUI_MYWIDGET_TYPE类型的控�?*/ me = (struct rtgui_mywidget *) rtgui_widget_create(RTGUI_MYWIDGET_TYPE); if (me != RT_NULL) { @@ -129,7 +102,6 @@ struct rtgui_mywidget *rtgui_mywidget_create(rtgui_rect_t *r) return me; } -/* 删除一个自定义控件 */ void rtgui_mywidget_destroy(struct rtgui_mywidget *me) { rtgui_widget_destroy(RTGUI_WIDGET(me)); |
