diff options
| author | [email protected] <[email protected]> | 2012-09-07 01:50:13 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-09-07 01:50:13 +0000 |
| commit | 9707b6ce0beb142d5444b8256510cb2d96912091 (patch) | |
| tree | 9e89357cc7916280877d21054bad94d4b86f318d /examples | |
| parent | fd425e792d517e69dcceab3fc009bf4fdfec5217 (diff) | |
sync RTGUI with github(https://github.com/RT-Thread/RTGUI)
a8dac7ed473f381b7042cf9d14028488192624c5
As always, full log is in GitHub.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2276 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/gui/SConscript | 3 | ||||
| -rw-r--r-- | examples/gui/demo_application.c | 14 | ||||
| -rw-r--r-- | examples/gui/demo_plot.c | 65 | ||||
| -rw-r--r-- | examples/gui/demo_view.c | 10 | ||||
| -rw-r--r-- | examples/gui/demo_view_animation.c | 45 | ||||
| -rw-r--r-- | examples/gui/demo_view_benchmark.c | 21 | ||||
| -rw-r--r-- | examples/gui/demo_view_bmp.c | 304 | ||||
| -rw-r--r-- | examples/gui/demo_view_buffer_animation.c | 45 | ||||
| -rw-r--r-- | examples/gui/demo_view_dc_buffer.c | 9 | ||||
| -rw-r--r-- | examples/gui/demo_view_edit.c | 80 | ||||
| -rw-r--r-- | examples/gui/demo_view_module.c | 30 | ||||
| -rw-r--r-- | examples/gui/demo_view_progressbar.c | 26 | ||||
| -rw-r--r-- | examples/gui/demo_view_window.c | 17 |
13 files changed, 582 insertions, 87 deletions
diff --git a/examples/gui/SConscript b/examples/gui/SConscript index 2523cccbfd..85b1e65017 100644 --- a/examples/gui/SConscript +++ b/examples/gui/SConscript @@ -14,6 +14,7 @@ demo_view_module.c src = Split(""" demo_application.c demo_view.c +demo_xml.c demo_view_benchmark.c demo_view_dc.c demo_view_ttf.c @@ -38,6 +39,8 @@ demo_view_notebook.c demo_view_mywidget.c demo_view_box.c demo_view_edit.c +demo_view_bmp.c +demo_plot.c mywidget.c """) diff --git a/examples/gui/demo_application.c b/examples/gui/demo_application.c index b0ca552282..d57987943b 100644 --- a/examples/gui/demo_application.c +++ b/examples/gui/demo_application.c @@ -94,19 +94,25 @@ static void application_entry(void *parameter) demo_view_slider(); demo_view_notebook(); demo_view_mywidget(); - demo_view_edit(); + demo_plot(); + +#if defined(RTGUI_USING_DFS_FILERW) + demo_view_edit(); + demo_view_bmp(); +#endif + #if 0 -#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) +#if defined(RTGUI_USING_DFS_FILERW) demo_view_image(); #endif #ifdef RT_USING_MODULE -#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) +#if defined(RTGUI_USING_DFS_FILERW) demo_view_module(); #endif #endif demo_listview_view(); demo_listview_icon_view(); -#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) +#if defined(RTGUI_USING_DFS_FILERW) demo_fn_view(); #endif #endif diff --git a/examples/gui/demo_plot.c b/examples/gui/demo_plot.c new file mode 100644 index 0000000000..51f4471d1b --- /dev/null +++ b/examples/gui/demo_plot.c @@ -0,0 +1,65 @@ + +#include <rtgui/widgets/plot.h> + +#include "demo_view.h" + +/* sin data */ +rt_int16_t sin_ydata[] = { + 0, 9, 19, 29, 38, 47, 56, 64, 71, 78, 84, 89, 93, 96, 98, 99, 99, 99, 97, + 94, 90, 86, 80, 74, 67, 59, 51, 42, 33, 23, 14, 4, -5, -15, -25, -35, -44, + -52, -61, -68, -75, -81, -87, -91, -95, -97, -99, -99, -99, -98, -95, -92, + -88, -83, -77, -70, -63, -55, -46, -37, -27, -18, -8, 1, 11, 21, 31 +}; +rt_int16_t cos_ydata[] = { + 50, 49, 46, 41, 34, 27, 18, 8, -1, -11, -20, -29, -36, -42, -47, -49, -49, + -48, -44, -39, -32, -24, -15, -5, 4, 14, 23, 31, 38, 44, 48, 49, 49, 47, + 43, 37, 30, 21, 12, 2, -7, -16, -25, -33, -40, -45, -48, -49, -49, -46, + -41, -35, -28, -19, -9, 0, 10, 19, 28, 36, 42, 46, 49, 49, 48, 45, 40, 33, + 25, 16, 6, -3, -12, -22, -30, -37, -43, -47, -49, -49, -47, -44, -38, -31, + -23, -13, -3, 6, 15, 24, 33, 39, 45, 48, 49, 49, 46, 42, 36, 29, 20, 10, 1, + -8, -18, -27, -35, -41, -46, -49, -49, -48, -45, -41, -34, -26, -17, -8, 1, + 11, 21, 29, 37, 43, 47, 49, 49, 48, 44, 39, 32, 24, 14, 5, -4, -14, -23, + -32, -39, -44, -48, -49, -49, -47, -43, -37, -30, -21, -12, -2, 7, 17, 26, + 34, 40, 45, 48, 49, 49, 46, 41, 35, 27, 18, 9, 0, -10, -20, -28, -36, -42, + -46, -49, -49, -48, -45, -40, -33, -25, -16, -6, 3, 13, 22, 31, 38, 43, 47, + 49, 49, 47, 43, 38 +}; + +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("����ͼ"); + + curve1 = rtgui_plot_curve_create(); + curve1->y_data = sin_ydata; + curve1->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); + curve1->color = red; + + plot = rtgui_plot_create(curve1); + + curve2 = rtgui_plot_curve_create(); + curve2->y_data = cos_ydata; + curve2->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]); + curve2->color = blue; + rtgui_plot_append_curve(plot, curve2); + + curve3 = rtgui_plot_curve_create(); + curve3->x_data = cos_ydata; + curve3->y_data = sin_ydata; + curve3->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); + curve3->color = black; + rtgui_plot_append_curve(plot, curve3); + + 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_container_add_child(cnt, RTGUI_WIDGET(plot)); + + return cnt; +} diff --git a/examples/gui/demo_view.c b/examples/gui/demo_view.c index 2597dc081a..42f0680b88 100644 --- a/examples/gui/demo_view.c +++ b/examples/gui/demo_view.c @@ -48,7 +48,7 @@ rtgui_container_t *demo_view(const char *title) rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect); rect.x1 += 5; rect.y1 += 5; - rect.x2 -= 5; + rect.x2 = rect.x1 + rt_strlen(title)*8; rect.y2 = rect.y1 + 20; /* ���������õı�ǩ */ @@ -57,9 +57,11 @@ rtgui_container_t *demo_view(const char *title) rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* ���ӱ�ǩ����ͼ�� */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); - - rect.y1 += 20; - rect.y2 += 20; + + rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect); + rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect); + rect.y1 += 20 + 5; + rect.y2 = rect.y1 + 2; /* ����һ��ˮƽ�� staticline �� */ line = rtgui_staticline_create(RTGUI_HORIZONTAL); /* ���þ�̬�ߵ�λ����Ϣ */ diff --git a/examples/gui/demo_view_animation.c b/examples/gui/demo_view_animation.c index 3a676ee57c..4145ba2055 100644 --- a/examples/gui/demo_view_animation.c +++ b/examples/gui/demo_view_animation.c @@ -61,6 +61,22 @@ void timeout(struct rtgui_timer *timer, void *parameter) rtgui_dc_end_drawing(dc); } +static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event) +{ + rt_kprintf("animation on show\n"); + if (timer != RT_NULL) + rtgui_timer_start(timer); + return RT_TRUE; +} + +static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event) +{ + rt_kprintf("animation on hide\n"); + if (timer != RT_NULL) + rtgui_timer_stop(timer); + return RT_TRUE; +} + rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event) { struct rtgui_widget *widget = RTGUI_WIDGET(object); @@ -90,6 +106,16 @@ rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *ev /* ��ͼ��� */ rtgui_dc_end_drawing(dc); } + else if (event->type == RTGUI_EVENT_SHOW) + { + rtgui_container_event_handler(object, event); + animation_on_show(object, event); + } + else if (event->type == RTGUI_EVENT_HIDE) + { + rtgui_container_event_handler(object, event); + animation_on_hide(object, event); + } else { /* ����Ĭ�ϵ��¼��������� */ @@ -99,22 +125,6 @@ rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *ev return RT_FALSE; } -static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event) -{ - rt_kprintf("animation on show\n"); - if (timer != RT_NULL) - rtgui_timer_start(timer); - return RT_TRUE; -} - -static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event) -{ - rt_kprintf("animation on hide\n"); - if (timer != RT_NULL) - rtgui_timer_stop(timer); - return RT_TRUE; -} - rtgui_container_t *demo_view_animation() { rtgui_container_t *container; @@ -127,8 +137,5 @@ rtgui_container_t *demo_view_animation() rtgui_rect_moveto(&text_rect, 0, 45); timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container); - rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show); - rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide); - return container; } diff --git a/examples/gui/demo_view_benchmark.c b/examples/gui/demo_view_benchmark.c index f87304733f..9655d99875 100644 --- a/examples/gui/demo_view_benchmark.c +++ b/examples/gui/demo_view_benchmark.c @@ -1,3 +1,4 @@ +#include <stdlib.h> #include <rtgui/dc.h> #include <rtgui/dc_hw.h> #include <rtgui/rtgui_system.h> @@ -8,6 +9,8 @@ static struct rtgui_container *container = RT_NULL; static int running = 0; +static rt_tick_t ticks; +static long long area; void _onidle(struct rtgui_object *object, rtgui_event_t *event) { @@ -26,7 +29,7 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event) 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); - + 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; @@ -34,6 +37,14 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event) /* ��ͼ��� */ rtgui_dc_end_drawing(dc); + if(rt_tick_get()-ticks >= RT_TICK_PER_SECOND) + { + char buf[16]; + sprintf(buf, "%.2f", (double)area/(800*480)); + rt_kprintf("frames per second: %s fps\n", buf); + area = 0; + ticks = rt_tick_get(); + } } void _draw_default(struct rtgui_object *object, rtgui_event_t *event) @@ -70,6 +81,11 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev { _draw_default(object, event); } + else if (event->type == RTGUI_EVENT_SHOW) + { + rtgui_container_event_handler(object, event); + _benchmark_onshow(object, event); + } else if (event->type == RTGUI_EVENT_KBD) { struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd *)event; @@ -88,6 +104,8 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev else { /* run */ + ticks = rt_tick_get(); + area = 0; rtgui_app_set_onidle(_onidle); } @@ -116,7 +134,6 @@ rtgui_container_t *demo_view_benchmark(void) 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; } diff --git a/examples/gui/demo_view_bmp.c b/examples/gui/demo_view_bmp.c new file mode 100644 index 0000000000..304f3defcf --- /dev/null +++ b/examples/gui/demo_view_bmp.c @@ -0,0 +1,304 @@ +/* +* �����嵥��bmp_zoom��ʾ +*/ +#include "demo_view.h" +#include <rtgui/dc.h> +#include <rtgui/image.h> +#include <rtgui/image_bmp.h> +#include <rtgui/widgets/label.h> +#include <rtgui/widgets/button.h> +#include <rtgui/widgets/textbox.h> +#include <rtgui/widgets/container.h> + +#if defined(RTGUI_USING_DFS_FILERW) +struct demo_bmp_dt +{ + float scale, angle; + char *filename; + struct rtgui_image *image; + struct rtgui_image *showimg; + rtgui_container_t *showbox; + rtgui_textbox_t *box; + rtgui_rect_t lastrect; +}bmpdt; + +rt_bool_t demo_bitmap_showbox(struct rtgui_object* object, struct rtgui_event* event) +{ + rtgui_container_t *container; + rtgui_widget_t *widget; + + RT_ASSERT(object != RT_NULL); + + container = RTGUI_CONTAINER(object); + widget = RTGUI_WIDGET(object); + + if(event->type == RTGUI_EVENT_PAINT) + { + int w, h; + rtgui_rect_t rect; + struct rtgui_dc *dc; + struct rtgui_image *image = bmpdt.showimg; + /* �����������ǩ�л�����ǰ��ǩ, imageӦ����RT_NULL, ������ */ + if(image == RT_NULL && bmpdt.image != RT_NULL) + { + image = bmpdt.image; + bmpdt.scale = 1.0f; + bmpdt.angle = 0.0f; + rtgui_widget_get_rect(RTGUI_WIDGET(bmpdt.showbox), &bmpdt.lastrect); + rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(bmpdt.showbox)); + } + + dc = rtgui_dc_begin_drawing(widget); + if (dc == RT_NULL) + return RT_FALSE; + + rtgui_widget_get_rect(widget, &rect); + /* �ڻ��Ʊ߿��, �ٽ�rect��С��䱳��, ���Խ�����˸���� */ + rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(widget)); + rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER(widget)); + w = rtgui_rect_width(bmpdt.lastrect); + h = rtgui_rect_height(bmpdt.lastrect); + if(w > rtgui_rect_width(rect)) w = rtgui_rect_width(rect); + if(h > rtgui_rect_height(rect)) h = rtgui_rect_height(rect); + + /* fill container with background */ + /* + * ����lastrect���¼��һ�λ�ͼ�������� + * ÿ���ػ�ʱ,ֻ����lastrect�Ƚ�,���ɵ�֪��Щ����������Ҫˢ�� + * ���統�Ŵ�ͼƬʱ,lastrect�ȵ�ǰ��ͼ��С,����������±�����, + * ����СͼƬʱ, Ҳ����Ҫ���»�ͼ����lastrect�������. + */ + if(image != RT_NULL) + { /* ���ٲ���Ҫ�Ļ�ͼ */ + rtgui_rect_t rc; + if(w > image->w) + { + rc.x1 = image->w; + rc.y1 = bmpdt.lastrect.y1; + rc.x2 = bmpdt.lastrect.x2; + rc.y2 = (h > image->h) ? image->h : bmpdt.lastrect.y2; + rtgui_dc_fill_rect(dc, &rc); + } + if(h > image->h) + { + rc.x1 = bmpdt.lastrect.x1; + rc.y1 = image->h; + rc.x2 = bmpdt.lastrect.x2; + rc.y2 = bmpdt.lastrect.y2; + rtgui_dc_fill_rect(dc, &rc); + } + } + else + rtgui_dc_fill_rect(dc, &bmpdt.lastrect); + + /* ��ͼ������blit�������� */ + if (image != RT_NULL) + { + int value; + rtgui_image_blit(image, dc, &rect); + bmpdt.lastrect.x1 = bmpdt.lastrect.y1 = RTGUI_WIDGET_BORDER(bmpdt.showbox); + + if(image->w > rtgui_rect_width(rect)) + value = rtgui_rect_width(rect); + else + value = image->w; + bmpdt.lastrect.x2 = bmpdt.lastrect.x1 + value; + + if(image->h > rtgui_rect_height(rect)) + value = rtgui_rect_height(rect); + else + value = image->h; + bmpdt.lastrect.y2 = bmpdt.lastrect.y1 + value; + } + + rtgui_dc_end_drawing(dc); + return RT_FALSE; + } + return rtgui_container_event_handler(object, event); +} + +void demo_bitmap_open(struct rtgui_object* object, struct rtgui_event* event) +{ + char *str; + rtgui_button_t *button = RTGUI_BUTTON(object); + /* ��textbox�ؼ���ȡ���ļ��� */ + str = (char*)rtgui_textbox_get_value(bmpdt.box); + if(str == RT_NULL) return; + if(*str == '/' && (rt_strstr(str, ".bmp")!=RT_NULL || rt_strstr(str, ".BMP")!=RT_NULL)) + { /* �����bmp�ļ�, ���ļ�����Ч, �����ͼ������ */ + if(bmpdt.filename != RT_NULL) + rt_free(bmpdt.filename); + bmpdt.filename = rt_strdup(str); + + if(bmpdt.image != RT_NULL) + rtgui_image_destroy(bmpdt.image); + + bmpdt.image = rtgui_image_create_from_file("bmp", bmpdt.filename, RT_TRUE); + + if(bmpdt.image != RT_NULL) + { + bmpdt.showimg = bmpdt.image; + bmpdt.scale = 1.0; + bmpdt.angle = 0.0; + rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox)); + } + } + else + rt_kprintf("Bad filename!"); +} + +void demo_image_zoom_in(struct rtgui_object* object, struct rtgui_event* event) +{ + rtgui_button_t *button = RTGUI_BUTTON(object); + + if (bmpdt.image == RT_NULL) return; + + if (bmpdt.scale > 0.45) + { /* �������ű��� */ + if (bmpdt.scale > 1.0) bmpdt.scale -= (float)0.5; + else bmpdt.scale -= (float)0.1; + } + /* �������ű���, ����ԭʼͼ��, ���õ���ͼ�ε�ָ�� */ + bmpdt.showimg = rtgui_image_zoom(bmpdt.image, bmpdt.scale, bmpdt.scale, RTGUI_IMG_ZOOM_BILINEAR); + if (bmpdt.showimg != RT_NULL) + rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox)); + else + return; + if(bmpdt.showimg != bmpdt.image) + { /* �ͷŵ���ͼ�����õ���Դ */ + rtgui_image_destroy(bmpdt.showimg); + bmpdt.showimg = RT_NULL; + } +} + +void demo_image_zoom_out(struct rtgui_object* object, struct rtgui_event* event) +{ + rtgui_button_t *button = RTGUI_BUTTON(object); + + if (bmpdt.image == RT_NULL) return; + + if (bmpdt.scale < 4.95) + { /* �������ű��� */ + if (bmpdt.scale > 0.95) bmpdt.scale += (float)0.5; + else bmpdt.scale += (float)0.1; + } + + bmpdt.showimg = rtgui_image_zoom(bmpdt.image, bmpdt.scale, bmpdt.scale, RTGUI_IMG_ZOOM_BILINEAR); + if (bmpdt.showimg != RT_NULL) + rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox)); + else + return; + if(bmpdt.showimg != bmpdt.image) + { + rtgui_image_destroy(bmpdt.showimg); + bmpdt.showimg = RT_NULL; + } +} + +void demo_image_rotate(struct rtgui_object* object, struct rtgui_event* event) +{ + rtgui_button_t *button = RTGUI_BUTTON(object); + + if (bmpdt.image == RT_NULL) return; + /* ����ͼ����ת�Ƕ� */ + if (bmpdt.angle < 360.0) + bmpdt.angle += (float)1.0; + else + bmpdt.angle = 0.0; + /* ������ת����ִ����ת, ��ȡ��һ���µ�ͼ��ָ�� */ + bmpdt.showimg = rtgui_image_rotate(bmpdt.image, bmpdt.angle); + if (bmpdt.showimg != RT_NULL) + rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox)); + else + return; + if(bmpdt.showimg != bmpdt.image) + { + rtgui_image_destroy(bmpdt.showimg); + bmpdt.showimg = RT_NULL; + } +} + +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; +} +#endif diff --git a/examples/gui/demo_view_buffer_animation.c b/examples/gui/demo_view_buffer_animation.c index 4b81700193..6f17feaea0 100644 --- a/examples/gui/demo_view_buffer_animation.c +++ b/examples/gui/demo_view_buffer_animation.c @@ -59,6 +59,22 @@ static void timeout(struct rtgui_timer *timer, void *parameter) rtgui_dc_end_drawing(dc); } +static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event) +{ + rt_kprintf("buffer animation on show\n"); + rtgui_timer_start(timer); + + return RT_TRUE; +} + +static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event) +{ + rt_kprintf("buffer animation on hide\n"); + rtgui_timer_stop(timer); + + return RT_TRUE; +} + static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event) { struct rtgui_widget *widget = RTGUI_WIDGET(object); @@ -87,6 +103,16 @@ static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_even /* ��ͼ��� */ rtgui_dc_end_drawing(dc); } + else if (event->type == RTGUI_EVENT_SHOW) + { + rtgui_container_event_handler(object, event); + animation_on_show(object, event); + } + else if (event->type == RTGUI_EVENT_HIDE) + { + rtgui_container_event_handler(object, event); + animation_on_hide(object, event); + } else { /* ����Ĭ�ϵ��¼��������� */ @@ -96,22 +122,6 @@ static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_even return RT_FALSE; } -static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event) -{ - rt_kprintf("buffer animation on show\n"); - rtgui_timer_start(timer); - - return RT_TRUE; -} - -static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event) -{ - rt_kprintf("buffer animation on hide\n"); - rtgui_timer_stop(timer); - - return RT_TRUE; -} - struct rtgui_container *demo_view_buffer_animation(void) { struct rtgui_container *container; @@ -143,8 +153,5 @@ struct rtgui_container *demo_view_buffer_animation(void) /* ������ʱ���Դ������� */ timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container); - rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show); - rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide); - return container; } diff --git a/examples/gui/demo_view_dc_buffer.c b/examples/gui/demo_view_dc_buffer.c index 3bd9b13963..b8ba4a5ca6 100644 --- a/examples/gui/demo_view_dc_buffer.c +++ b/examples/gui/demo_view_dc_buffer.c @@ -10,8 +10,6 @@ #include <rtgui/widgets/slider.h> #include <rtgui/image.h> -static rtgui_image_t *background; -static struct rtgui_dc *dc_buffer; /* * view���¼��������� @@ -19,6 +17,7 @@ static struct rtgui_dc *dc_buffer; static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_event_t *event) { struct rtgui_widget *widget = RTGUI_WIDGET(object); + struct rtgui_dc *dc_buffer; /* ����PAINT�¼����д��� */ if (event->type == RTGUI_EVENT_PAINT) @@ -31,7 +30,7 @@ static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_even * �Ȼ�ͼ */ rtgui_container_event_handler(object, event); - + dc_buffer = (struct rtgui_dc*)widget->user_data; /* ��ÿؼ�������DC */ dc = rtgui_dc_begin_drawing(widget); /* ��������������DC�����أ�����ؼ��ؼ�������״̬��DC�ǻ�ȡ���ɹ��ģ� */ @@ -61,6 +60,7 @@ static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_even rtgui_container_t *demo_view_dc_buffer() { rtgui_container_t *view; + struct rtgui_dc *dc_buffer=RT_NULL; if (dc_buffer == RT_NULL) { @@ -68,7 +68,7 @@ rtgui_container_t *demo_view_dc_buffer() /* ���� DC Buffer���� 50���� 50 */ dc_buffer = rtgui_dc_buffer_create(50, 50); - RTGUI_DC_FC(dc_buffer) = blue; + RTGUI_DC_BC(dc_buffer) = blue; rtgui_dc_fill_rect(dc_buffer, &rect); RTGUI_DC_FC(dc_buffer) = red; @@ -79,6 +79,7 @@ rtgui_container_t *demo_view_dc_buffer() if (view != RT_NULL) /* ���ó��Լ����¼��������� */ rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler); + RTGUI_WIDGET(view)->user_data = (rt_uint32_t)dc_buffer; return view; } diff --git a/examples/gui/demo_view_edit.c b/examples/gui/demo_view_edit.c index 07368eb8c9..3ee31b7994 100644 --- a/examples/gui/demo_view_edit.c +++ b/examples/gui/demo_view_edit.c @@ -6,16 +6,19 @@ #include "demo_view.h" #include <rtgui/dc.h> +#include <rtgui/filerw.h> #include <rtgui/rtgui_system.h> #include <rtgui/widgets/edit.h> +#include <rtgui/widgets/label.h> #include <rtgui/widgets/button.h> +#ifdef RTGUI_USING_DFS_FILERW void demo_edit_readin_file(struct rtgui_object *object, struct rtgui_event *event) { rtgui_button_t *button; struct rtgui_edit *edit; const char *filename = "/test_readin.txt"; - int fd; + struct rtgui_filerw *file; RT_ASSERT(object != RT_NULL); button = RTGUI_BUTTON(object); @@ -23,15 +26,15 @@ void demo_edit_readin_file(struct rtgui_object *object, struct rtgui_event *even edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data); /* 判断文件是否存在 */ - fd = open(filename, O_RDONLY, 0); - if (fd < 0) + file = rtgui_filerw_create_file(filename, "rb"); + if (file == RT_NULL) { /* 不存在存在,则创建它 */ rt_kprintf("file:\"%s\" does not exist!\n", filename); return; } - close(fd); + rtgui_filerw_close(file); rt_kprintf("read-in file:\"%s\"\n", filename); rtgui_edit_readin_file(edit, filename); @@ -42,7 +45,7 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even rtgui_button_t *button; struct rtgui_edit *edit; const char* filename = "/test_saveas.txt"; - int fd; + struct rtgui_filerw *file; RT_ASSERT(object != RT_NULL); button = RTGUI_BUTTON(object); @@ -50,12 +53,12 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data); /* 判断文件是否存在, 如果存在则删除之 */ - fd = open(filename, O_RDONLY, 0); - if (fd > 0) + file = rtgui_filerw_create_file(filename, "rb"); + if (file != RT_NULL) { - close(fd); + rtgui_filerw_close(file); /* 如果是在win32中调试, 请手工删除该文件吧, NT中文件是只读的,unlink删除不掉 */ - if (unlink(filename) == -1) + if (rtgui_filerw_unlink(filename) == -1) rt_kprintf("Could not delete %s\n", filename); } @@ -63,12 +66,42 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even rtgui_edit_saveas_file(edit, filename); } +void demo_edit_get_mem(struct rtgui_object* object, struct rtgui_event* event) +{ + rtgui_button_t *button; + struct rtgui_edit *edit; + + RT_ASSERT(object != RT_NULL); + + button = RTGUI_BUTTON(object); + edit = RTGUI_EDIT( RTGUI_WIDGET(button)->user_data ); + rt_kprintf("edit mem consume: %d\n", rtgui_edit_get_mem_consume(edit)); +} + +rt_bool_t demo_edit_event_handler(struct rtgui_object* object, struct rtgui_event *event) +{ + rt_bool_t result; + char buf[32]; + rtgui_point_t p; + struct rtgui_edit *edit = RTGUI_EDIT(object); + struct rtgui_label *label = (struct rtgui_label*)RTGUI_WIDGET(edit)->user_data; + + result = rtgui_edit_event_handler(object, event); + + p = rtgui_edit_get_current_point(edit); + rt_sprintf(buf, "TRACK: line:%d, col:%d", p.y, p.x); + rtgui_label_set_text(label, buf); + + return result; +} + /* 创建用于演示edit控件的视图 */ rtgui_container_t *demo_view_edit(void) { rtgui_rect_t rect; rtgui_container_t *container; struct rtgui_edit *edit; + struct rtgui_label *label; struct rtgui_button *button; /* 先创建一个演示用的视图 */ @@ -84,6 +117,7 @@ rtgui_container_t *demo_view_edit(void) "rtgui_edit_insert_line\n" "rtgui_edit_delete_line\n" "rtgui_edit_connect_line\n" + "双字节测试\n" "a\n" "b\n" "c\n" @@ -116,5 +150,33 @@ rtgui_container_t *demo_view_edit(void) /* 使用user_data传递edit指针 */ RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit; + /* 创建一个标签, 显示EDIT的主要参数 */ + demo_view_get_rect(container, &rect); + rect.x1 += 10; + rect.x2 = rect.x1 + 220; + rect.y1 += 225; + rect.y2 = rect.y1 + 18; + label = rtgui_label_create("TRACK:"); + RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL; + RTGUI_WIDGET_FOREGROUND(label) = blue; + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + rtgui_container_add_child(container, RTGUI_WIDGET(label)); + + RTGUI_WIDGET(edit)->user_data = (rt_uint32_t)label; + rtgui_object_set_event_handler(RTGUI_OBJECT(edit), demo_edit_event_handler); + + /* 创建一个按钮, 读取EDIT的内存消耗 */ + demo_view_get_rect(container, &rect); + rect.x1 += 150; + rect.x2 = rect.x1 + 80; + rect.y1 -= 42; + rect.y2 = rect.y1 + 20; + button = rtgui_button_create("Get Mem"); + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(container, RTGUI_WIDGET(button)); + rtgui_button_set_onbutton(button, demo_edit_get_mem); + RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit; + return container; } +#endif diff --git a/examples/gui/demo_view_module.c b/examples/gui/demo_view_module.c index bdce8dae10..9649ce7bef 100644 --- a/examples/gui/demo_view_module.c +++ b/examples/gui/demo_view_module.c @@ -1,7 +1,7 @@ /* - * 3��D��??�̣���oDC��???��?��????Y��? + * �����嵥��DC����ʾͼ����ʾ * - * ?a??��y����?��?�����?��3?��?view��???��?��??? + * ������ӻ��ڴ�������view����ʾͼ�� */ #include "demo_view.h" @@ -10,63 +10,63 @@ #include <string.h> #ifdef RT_USING_MODULE -#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) +#if defined(RTGUI_USING_DFS_FILERW) static rtgui_container_t *_view = RT_NULL; -/* �䨰?a���?����???�̡�o����y */ +/* ��ť�Ļص����� */ static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event) { rtgui_filelist_view_t *view; rtgui_workbench_t *workbench; rtgui_rect_t rect; - /* ??��??��2?��?workbench */ + /* ��ö����workbench */ workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget)); rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); - /* WIN32??������?o��??���̨�����?��?��?3?��??��??��|���� */ + /* WIN32ƽ̨�Ϻ���ʵ�豸�ϵij�ʼ·������ */ #ifdef _WIN32 view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect); #else view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect); #endif - /* ?�ꨬ???��?��??????t��D����������?��?��?����1???��??��????��??????t */ + /* ģ̬��ʾһ���ļ��б���ͼ�����ṩ���û�ѡ��ͼ���ļ� */ if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK) { char path[32], name[8]; - /* ����?????t?��??��?����?? */ + /* �����ļ�·���ı�ǩ */ rtgui_filelist_view_get_fullpath(view, path, sizeof(path)); rt_memset(name, 0, sizeof(name)); - /* ??��?��|��??��?����?����D�� */ + /* ���Ӧ��ģ������� */ if (rt_strstr(path, ".mo") != RT_NULL || rt_strstr(path, ".so") != RT_NULL) { rt_module_open(path); } } - /* ��?3y ???t��D���� ������? */ + /* ɾ�� �ļ��б� ��ͼ */ rtgui_container_destroy(RTGUI_CONTAINER(view)); rtgui_container_show(_view, RT_FALSE); } -/* ���?����?����??��?��|��??��?����??Y��?������? */ +/* ����������ʾӦ��ģ�����ʾ��ͼ */ rtgui_container_t *demo_view_module(rtgui_workbench_t *workbench) { rtgui_rect_t rect; rtgui_button_t *open_btn; - /* ?�����?����????Y��?������? */ - _view = demo_view(workbench, "��|��??��?��?Y��?"); + /* �ȴ���һ����ʾ��ͼ */ + _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("�䨰?a��|��??��?��"); + 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); diff --git a/examples/gui/demo_view_progressbar.c b/examples/gui/demo_view_progressbar.c index 1f890c41e2..91e30e4d90 100644 --- a/examples/gui/demo_view_progressbar.c +++ b/examples/gui/demo_view_progressbar.c @@ -33,6 +33,29 @@ static rt_bool_t stop_timer(struct rtgui_object *object, struct rtgui_event *eve return RT_TRUE; } +static rt_bool_t progressbar_event_handler(struct rtgui_object *object, rtgui_event_t *event) +{ + struct rtgui_widget *widget = RTGUI_WIDGET(object); + + if (event->type == RTGUI_EVENT_SHOW) + { + rtgui_container_event_handler(object, event); + start_timer(object, event); + } + else if (event->type == RTGUI_EVENT_HIDE) + { + rtgui_container_event_handler(object, event); + stop_timer(object, event); + } + else + { + /* ����Ĭ�ϵ��¼��������� */ + return rtgui_progressbar_event_handler(object, event); + } + + return RT_FALSE; +} + rtgui_container_t *demo_view_progressbar(void) { rtgui_container_t *container; @@ -75,9 +98,6 @@ rtgui_container_t *demo_view_progressbar(void) 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; } diff --git a/examples/gui/demo_view_window.c b/examples/gui/demo_view_window.c index 975882e37d..222dc7dde1 100644 --- a/examples/gui/demo_view_window.c +++ b/examples/gui/demo_view_window.c @@ -14,7 +14,7 @@ static struct rtgui_timer *timer; static struct rtgui_label *label; -static struct rtgui_win *msgbox = RT_NULL; +static struct rtgui_win *autowin = RT_NULL; static char label_text[80]; static rt_uint8_t cnt = 5; @@ -92,7 +92,7 @@ void diag_close(struct rtgui_timer *timer, void *parameter) if (cnt == 0) { /* ��ʱ���رնԻ��� */ - rtgui_win_destroy(msgbox); + rtgui_win_destroy(autowin); } } @@ -107,6 +107,7 @@ rt_bool_t auto_window_close(struct rtgui_object *object, struct rtgui_event *eve timer = RT_NULL; } + autowin = RT_NULL; return RT_TRUE; } @@ -120,12 +121,12 @@ static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *ev struct rtgui_rect rect = {50, 50, 200, 200}; /* don't create the window twice */ - if (msgbox) + if (autowin) return; - msgbox = rtgui_win_create(main_win, "Information", + autowin = rtgui_win_create(main_win, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); - if (msgbox == RT_NULL) + if (autowin == RT_NULL) return; cnt = 5; @@ -136,13 +137,13 @@ static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *ev rect.y1 += 5; rect.y2 = rect.y1 + 20; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); - rtgui_container_add_child(RTGUI_CONTAINER(msgbox), + rtgui_container_add_child(RTGUI_CONTAINER(autowin), RTGUI_WIDGET(label)); /* ���ùرմ���ʱ�Ķ��� */ - rtgui_win_set_onclose(msgbox, auto_window_close); + rtgui_win_set_onclose(autowin, auto_window_close); - rtgui_win_show(msgbox, RT_FALSE); + rtgui_win_show(autowin, RT_FALSE); /* ����һ����ʱ�� */ timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL); rtgui_timer_start(timer); |
