rt-thread-official/examples/gui/demo_view_animation.c

142 lines
3.7 KiB
C
Raw Normal View History

#include <rtgui/dc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/container.h>
#include "demo_view.h"
/*
* ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<EFBFBD>ϻ<EFBFBD>ͼ<EFBFBD><EFBFBD>ʵ<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>"
*/
static rt_int8_t dx = 1, dy = 1;
static rtgui_rect_t text_rect;
static rtgui_timer_t *timer;
void timeout(struct rtgui_timer *timer, void *parameter)
{
struct rtgui_dc *dc;
struct rtgui_rect rect;
struct rtgui_widget *widget;
/* <20>ؼ<EFBFBD>(container)ͨ<><CDA8>parameter<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>ʱ<EFBFBD><CAB1> */
widget = RTGUI_WIDGET(parameter);
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44><43><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>򸸿ؼ<F2B8B8BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>DC<44>ǻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ɹ<EFBFBD><C9B9>ģ<EFBFBD> */
return ;
/* <20><><EFBFBD><EFBFBD>demo container<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>жϱ߽<CFB1> */
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
rect.y2 -= 5;
/* <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ǵ<EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼ */
if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
{
rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
}
else
{
/* <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD> */
rtgui_dc_fill_rect(dc, &text_rect);
}
/* <20><><EFBFBD><EFBFBD>dx<64><78>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;
/* <20>ƶ<EFBFBD><C6B6>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB> */
text_rect.x1 += dx;
text_rect.x2 += dx;
text_rect.y1 += dy;
text_rect.y2 += dy;
/* <20><>ͼ */
rtgui_dc_draw_text(dc, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>", &text_rect);
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
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);
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc *dc;
rtgui_rect_t rect;
/* <20><>Ϊ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>demo container<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B1BE><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֿؼ<D6BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ͼʱ<CDBC><CAB1>Ҫ<EFBFBD><D2AA>demo container<65>Ȼ<EFBFBD>ͼ */
rtgui_container_event_handler(object, event);
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44><43><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>򸸿ؼ<F2B8B8BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>DC<44>ǻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ɹ<EFBFBD><C9B9>ģ<EFBFBD> */
return RT_FALSE;
/* <20><><EFBFBD><EFBFBD>demo container<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
rtgui_dc_fill_rect(dc, &rect);
/* <20><>ͼ */
rtgui_dc_draw_text(dc, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>", &text_rect);
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
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
{
/* <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
return rtgui_container_event_handler(object, event);
}
return RT_FALSE;
}
rtgui_container_t *demo_view_animation()
{
rtgui_container_t *container;
container = demo_view("DC <20><><EFBFBD><EFBFBD>");
if (container != RT_NULL)
rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler);
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(container), "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>", &text_rect);
rtgui_rect_moveto(&text_rect, 0, 45);
timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container);
return container;
}