2012-09-07 09:50:13 +08:00
|
|
|
|
#include <stdlib.h>
|
2012-04-18 23:06:12 +08:00
|
|
|
|
#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;
|
2012-09-07 09:50:13 +08:00
|
|
|
|
static rt_tick_t ticks;
|
|
|
|
|
static long long area;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
|
|
|
|
void _onidle(struct rtgui_object *object, rtgui_event_t *event)
|
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_color_t color;
|
|
|
|
|
rtgui_rect_t rect, draw_rect;
|
|
|
|
|
struct rtgui_dc *dc;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
|
|
|
|
|
// dc = rtgui_dc_hw_create(RTGUI_WIDGET(container));
|
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(container));
|
|
|
|
|
if (dc == RT_NULL)
|
|
|
|
|
return;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
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);
|
2012-09-07 09:50:13 +08:00
|
|
|
|
area += rtgui_rect_width(draw_rect) * rtgui_rect_height(draw_rect);
|
2012-08-13 16:32:01 +08:00
|
|
|
|
color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
|
|
|
|
|
RTGUI_WIDGET_BACKGROUND(container) = color;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_dc_fill_rect(dc, &draw_rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
2012-09-07 09:50:13 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
void _draw_default(struct rtgui_object *object, rtgui_event_t *event)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
|
|
|
|
struct rtgui_dc *dc;
|
|
|
|
|
rtgui_rect_t rect;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <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);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <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;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>demo container<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
RTGUI_WIDGET_BACKGROUND(widget) = default_background;
|
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><>ʾ<EFBFBD><CABE>ʾ */
|
|
|
|
|
rtgui_dc_draw_text(dc, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ/ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>...", &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *event)
|
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
if (event->type == RTGUI_EVENT_PAINT)
|
|
|
|
|
{
|
|
|
|
|
_draw_default(object, event);
|
|
|
|
|
}
|
2012-09-07 09:50:13 +08:00
|
|
|
|
else if (event->type == RTGUI_EVENT_SHOW)
|
|
|
|
|
{
|
|
|
|
|
rtgui_container_event_handler(object, event);
|
|
|
|
|
_benchmark_onshow(object, event);
|
|
|
|
|
}
|
2012-08-13 16:32:01 +08:00
|
|
|
|
else if (event->type == RTGUI_EVENT_KBD)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd *)event;
|
|
|
|
|
|
|
|
|
|
if (kbd->key == RTGUIK_LEFT || kbd->key == RTGUIK_RIGHT)
|
|
|
|
|
return RT_FALSE;
|
|
|
|
|
|
|
|
|
|
if (RTGUI_KBD_IS_UP(kbd))
|
|
|
|
|
{
|
|
|
|
|
if (running)
|
|
|
|
|
{
|
|
|
|
|
/* stop */
|
|
|
|
|
rtgui_app_set_onidle(RT_NULL);
|
|
|
|
|
_draw_default(object, event);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* run */
|
2012-09-07 09:50:13 +08:00
|
|
|
|
ticks = rt_tick_get();
|
|
|
|
|
area = 0;
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_app_set_onidle(_onidle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
running = !running;
|
|
|
|
|
}
|
|
|
|
|
return RT_TRUE;
|
|
|
|
|
}
|
|
|
|
|
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;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rt_bool_t _benchmark_onshow(struct rtgui_object *obj, struct rtgui_event *ev)
|
2012-07-20 20:37:56 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_widget_focus(RTGUI_WIDGET(obj));
|
|
|
|
|
return RT_TRUE;
|
2012-07-20 20:37:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 23:06:12 +08:00
|
|
|
|
rtgui_container_t *demo_view_benchmark(void)
|
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
srand(100);
|
|
|
|
|
container = demo_view("<EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
|
|
|
|
rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
return container;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|