diff options
| author | [email protected] <[email protected]> | 2012-04-18 15:06:12 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-04-18 15:06:12 +0000 |
| commit | db0646020812efc16ff0beebe35f9049dcc2bfed (patch) | |
| tree | 5e949e9ba679a07b0198745853e900a016a3834e /examples/gui/demo_view_buffer_animation.c | |
| parent | 06d45f0c42f2aa3678d509403fcf9cd82be106e6 (diff) | |
merge new RTGUI in to trunk
The full log is at https://github.com/RTGUI/RTGUI/commits/merge_1 and it's difficult to merge the new tree commit by commit. I also converted all the file into unix eol so there are many fake diff. Big changes are noted in rtgui/doc/road_map.txt and rtgui/doc/attention.txt. Keep an eye on them if you want to migrate your old code.
Note that the work is still in progress and the bsp is not prepared in trunk so far.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2092 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'examples/gui/demo_view_buffer_animation.c')
| -rw-r--r-- | examples/gui/demo_view_buffer_animation.c | 268 |
1 files changed, 144 insertions, 124 deletions
diff --git a/examples/gui/demo_view_buffer_animation.c b/examples/gui/demo_view_buffer_animation.c index cadc2430e7..d435c787b2 100644 --- a/examples/gui/demo_view_buffer_animation.c +++ b/examples/gui/demo_view_buffer_animation.c @@ -1,124 +1,144 @@ -#include <rtgui/dc.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/view.h>
-#include "demo_view.h"
-
-/*
- * ֱ����DC�ϻ�ͼ��ʵ�ֶ���Ч��
- *
- * �����������ڶ�ʱ�������ģ������·�����ʾ����
- * "�����ҷ�"
- */
-static rt_int8_t dx = 1, dy = 1;
-static rtgui_rect_t text_rect;
-static rtgui_timer_t *timer;
-static struct rtgui_dc *dc_buffer;
-static void timeout(struct rtgui_timer* timer, void* parameter)
-{
- struct rtgui_dc* dc;
- rtgui_rect_t rect;
- rtgui_widget_t *widget;
-
- /* �ؼ�(view)ͨ��parameter�������ݸ���ʱ�� */
- widget = (rtgui_widget_t*)parameter;
-
- /* ��ÿؼ�������DC */
- dc = rtgui_dc_begin_drawing(widget);
- if (dc == RT_NULL) /* ��������������DC�����أ�����ؼ��ؼ�������״̬��DC�ǻ�ȡ���ɹ��ģ� */
- return ;
-
- /* ���demo view������ͼ��������Ҫ�����жϱ߽� */
- demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
- rect.y2 -= 5;
-
- /* �ж��Ƿ��ǵ�һ�λ�ͼ */
- if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
- {
- rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
- }
-
- /* ����dx��dy */
- if (text_rect.x2 >= rect.x2) dx = -1;
- if (text_rect.x1 < rect.x1) dx = 1;
- if (text_rect.y2 >= rect.y2) dy = -1;
- if (text_rect.y1 < rect.y1) dy = 1;
-
- /* �ƶ��ı����λ�� */
- text_rect.x1 += dx; text_rect.x2 += dx;
- text_rect.y1 += dy; text_rect.y2 += dy;
-
- /* ��ͼ */
- rect = text_rect;
- rect.x2 += 2; rect.y2 += 2;
- rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
-
- /* ��ͼ��� */
- rtgui_dc_end_drawing(dc);
-}
-
-static rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
-{
- if (event->type == RTGUI_EVENT_PAINT)
- {
- struct rtgui_dc* dc;
- rtgui_rect_t rect;
-
- /* ��Ϊ�õ���demo view�����汾����һ���ֿؼ��������ڻ�ͼʱ��Ҫ��demo view�Ȼ�ͼ */
- rtgui_view_event_handler(widget, event);
-
- /* ��ÿؼ�������DC */
- dc = rtgui_dc_begin_drawing(widget);
- if (dc == RT_NULL) /* ��������������DC�����أ�����ؼ��ؼ�������״̬��DC�ǻ�ȡ���ɹ��ģ� */
- return RT_FALSE;
-
- /* ���demo view������ͼ������ */
- demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
-
- /* ��ͼ */
- rect = text_rect;
- rtgui_rect_inflate(&rect, +1);
- rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
-
- /* ��ͼ��� */
- rtgui_dc_end_drawing(dc);
- }
- else
- {
- /* ����Ĭ�ϵ��¼��������� */
- return rtgui_view_event_handler(widget, event);
- }
-
- return RT_FALSE;
-}
-
-rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench)
-{
- rtgui_view_t *view;
-
- view = demo_view(workbench, "DC ����������");
- if (view != RT_NULL)
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view), animation_event_handler);
-
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "���嶯��", &text_rect);
- if (dc_buffer == RT_NULL)
- {
- rtgui_rect_t rect;
-
- rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2;
- rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2;
-
- /* ���� DC Buffer���� 50���� 50 */
- dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
- RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view));
- rtgui_dc_fill_rect(dc_buffer, &rect);
- RTGUI_DC_FC(dc_buffer) = black;
- rect.x1 = 1; rect.y1 = 1;
- rtgui_dc_draw_text(dc_buffer, "���嶯��", &rect);
- }
-
- /* ������ʱ���Դ������� */
- timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view);
- rtgui_timer_start(timer);
-
- return view;
-}
+#include <rtgui/dc.h> +#include <rtgui/rtgui_system.h> +#include <rtgui/widgets/container.h> +#include "demo_view.h" + +/* + * ֱ����DC�ϻ�ͼ��ʵ�ֶ���Ч�� + * + * �����������ڶ�ʱ�������ģ������·�����ʾ���� + * "�����ҷ�" + */ +static rt_int8_t dx = 1, dy = 1; +static rtgui_rect_t text_rect; +static rtgui_timer_t *timer; +static struct rtgui_dc *dc_buffer; +static void timeout(struct rtgui_timer* timer, void* parameter) +{ + struct rtgui_dc* dc; + rtgui_rect_t rect; + rtgui_widget_t *widget; + + /* �ؼ�(view)ͨ��parameter�������ݸ���ʱ�� */ + widget = (rtgui_widget_t*)parameter; + + /* ��ÿؼ�������DC */ + dc = rtgui_dc_begin_drawing(widget); + if (dc == RT_NULL) /* ��������������DC�����أ�����ؼ��ؼ�������״̬��DC�ǻ�ȡ���ɹ��ģ� */ + return ; + + /* ���demo view������ͼ��������Ҫ�����жϱ߽� */ + demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect); + rect.y2 -= 5; + + /* �ж��Ƿ��ǵ�һ�λ�ͼ */ + if ((text_rect.x1 == 0) && (text_rect.y1 == 0)) + { + rtgui_rect_moveto(&text_rect, rect.x1, rect.y1); + } + + /* ����dx��dy */ + if (text_rect.x2 >= rect.x2) dx = -1; + if (text_rect.x1 < rect.x1) dx = 1; + if (text_rect.y2 >= rect.y2) dy = -1; + if (text_rect.y1 < rect.y1) dy = 1; + + /* �ƶ��ı����λ�� */ + text_rect.x1 += dx; text_rect.x2 += dx; + text_rect.y1 += dy; text_rect.y2 += dy; + + /* ��ͼ */ + rect = text_rect; + rect.x2 += 2; rect.y2 += 2; + rtgui_dc_blit(dc_buffer, NULL, dc, &rect); + + /* ��ͼ��� */ + rtgui_dc_end_drawing(dc); +} + +static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event) +{ + struct rtgui_widget *widget = RTGUI_WIDGET(object); + + if (event->type == RTGUI_EVENT_PAINT) + { + struct rtgui_dc* dc; + rtgui_rect_t rect; + + /* ��Ϊ�õ���demo view�����汾����һ���ֿؼ��������ڻ�ͼʱ��Ҫ��demo view�Ȼ�ͼ */ + rtgui_container_event_handler(object, event); + + /* ��ÿؼ�������DC */ + dc = rtgui_dc_begin_drawing(widget); + if (dc == RT_NULL) /* ��������������DC�����أ�����ؼ��ؼ�������״̬��DC�ǻ�ȡ���ɹ��ģ� */ + return RT_FALSE; + + /* ���demo view������ͼ������ */ + demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect); + + /* ��ͼ */ + rect = text_rect; + rtgui_rect_inflate(&rect, +1); + rtgui_dc_blit(dc_buffer, NULL, dc, &rect); + + /* ��ͼ��� */ + rtgui_dc_end_drawing(dc); + } + else + { + /* ����Ĭ�ϵ��¼��������� */ + return rtgui_container_event_handler(object, event); + } + + 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; + + container= demo_view("DC ����������"); + if (container!= RT_NULL) + rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler); + + rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(container)), "���嶯��", &text_rect); + if (dc_buffer == RT_NULL) + { + rtgui_rect_t rect; + + rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2; + rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2; + + /* ���� DC Buffer���� 50���� 50 */ + dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect)); + RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container)); + rtgui_dc_fill_rect(dc_buffer, &rect); + RTGUI_DC_FC(dc_buffer) = black; + rect.x1 = 1; rect.y1 = 1; + rtgui_dc_draw_text(dc_buffer, "���嶯��", &rect); + } + + /* ������ʱ���Դ������� */ + 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; +} |
