rtt-f030/examples/gui/demo_view_benchmark.c
chaos.proton@gmail.com db06460208 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
2012-04-18 15:06:12 +00:00

112 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/container.h>
#include "demo_view.h"
#define RAND(x1, x2) ((rand() % (x2 - x1)) + x1)
static struct rtgui_container *container = RT_NULL;
static int running = 0;
void _onidle(struct rtgui_object *object, rtgui_event_t *event)
{
rtgui_color_t color;
rtgui_rect_t rect, draw_rect;
struct rtgui_dc *dc;
/* 获得控件所属的DC */
// dc = rtgui_dc_hw_create(RTGUI_WIDGET(container));
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(container));
if (dc == RT_NULL)
return;
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);
color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container)) = color;
rtgui_dc_fill_rect(dc, &draw_rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
void _draw_default(struct rtgui_object *object, rtgui_event_t* event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
struct rtgui_dc* dc;
rtgui_rect_t rect;
/* 因为用的是demo container上面本身有一部分控件所以在绘图时先要让demo container先绘图 */
rtgui_container_event_handler(object, event);
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) /* 如果不能正常获得DC返回如果控件或父控件是隐藏状态DC是获取不成功的 */
return;
/* 获得demo container允许绘图的区域 */
demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
/* 擦除所有 */
RTGUI_WIDGET_BACKGROUND(widget) = default_background;
rtgui_dc_fill_rect(dc, &rect);
/* 显示提示 */
rtgui_dc_draw_text(dc, "按任意键开始/停止测试...", &rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
if (event->type == RTGUI_EVENT_PAINT)
{
_draw_default(object, event);
}
else if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd*)event;
if (RTGUI_KBD_IS_UP(kbd))
{
if (running)
{
/* stop */
rtgui_application_set_onidle(RT_NULL);
_draw_default(object, event);
}
else
{
/* run */
rtgui_application_set_onidle(_onidle);
}
running = !running;
}
return RT_TRUE;
}
else
{
/* 调用默认的事件处理函数 */
return rtgui_container_event_handler(object, event);
}
return RT_FALSE;
}
rtgui_container_t *demo_view_benchmark(void)
{
srand(100);
container = demo_view("绘图测试");
rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
return container;
}