rtt-f030/examples/gui/demo_view_animation.c

114 lines
2.8 KiB
C
Raw Normal View History

#include <rtgui/dc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.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;
rtgui_rect_t rect;
rtgui_widget_t *widget;
/* <20>ؼ<EFBFBD>(view)ͨ<><CDA8>parameter<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>ʱ<EFBFBD><CAB1> */
widget = (rtgui_widget_t*)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 view<65><77><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_VIEW(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);
}
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;
/* <20><>Ϊ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>demo view<65><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B1BE><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֿؼ<D6BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ͼʱ<CDBC><CAB1>Ҫ<EFBFBD><D2AA>demo view<65>Ȼ<EFBFBD>ͼ */
rtgui_view_event_handler(widget, 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 view<65><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
demo_view_get_rect(RTGUI_VIEW(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
{
/* <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
return rtgui_view_event_handler(widget, event);
}
return RT_FALSE;
}
rtgui_view_t *demo_view_animation(rtgui_workbench_t* workbench)
{
rtgui_view_t *view;
view = demo_view(workbench, "DC <20><><EFBFBD><EFBFBD>");
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)), "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>", &text_rect);
rtgui_rect_moveto(&text_rect, 0, 45);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view);
rtgui_timer_start(timer);
return view;
}