git-svn-id: https://rt-thread.googlecode.com/svn/trunk@920 bbd45198-f89e-11dd-88c7-29a3b14d5316

This commit is contained in:
richard.lion.heart.gl 2010-09-20 07:13:12 +00:00
parent de32e95033
commit af76e75ed9
1 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,150 @@
/*
* DC操作演示
*
* view上进行DC操作的演示
*/
#include "demo_view.h"
#include <rtgui/dc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/slider.h>
#include <rtgui/image_hdc.h>
#include <math.h>
/*
* view的事件处理函数
*/
rt_bool_t instrument_panel_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
char ac[4];
int i;
int x0 = 120;
int y0 = 170;
int x, y;
int default_color;
/* 仅对PAINT事件进行处理 */
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
const int vx[] = {85, 85, 105, 105};
const int vy[] = {60, 100, 100, 60};
const int arrowx[] = {x0+75, x0+75, x0+85};
const int arrowy[] = {y0-5, y0+5, y0};
/*
* demo viewdemo view
*
*/
rtgui_view_event_handler(widget, event);
/************************************************************************/
/* 下面的是DC的操作 */
/************************************************************************/
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
/* 如果不能正常获得DC返回如果控件或父控件是隐藏状态DC是获取不成功的 */
if (dc == RT_NULL)
return RT_FALSE;
/* 获得demo view允许绘图的区域 */
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
/* 显示GUI的版本信息 */
#ifdef RTGUI_USING_SMALL_SIZE
rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
#else
rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
#endif
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL;
RTGUI_DC_FC(dc) = blue;
rect.y2 = 270;
rtgui_dc_draw_text(dc, "rtgui-panel", &rect);
for(i = 0; i < 6; i++)
{
rtgui_dc_draw_arc(dc, x0, y0, 117-i, 150, 30);
}
RTGUI_DC_FC(dc) = black;
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT;
for(i = 0; i <= 23; i++)
{
if(i < 12)
{
x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180);
y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180);
rect.x1 = x;
rect.y1 = y;
rect.x2 = rect.x1 + 12 * 3;
rect.y2 = rect.y1 + 12;
sprintf(ac, "%d", 10 * i);
rtgui_dc_draw_text(dc, ac, &rect);
}
else
{
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT;
x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180);
y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180);
rect.x1 = x - 12 * 3;
rect.y1 = y;
rect.x2 = rect.x1 + 12 * 3;
rect.y2 = rect.y1 + 12;
sprintf(ac, "%d", 10 * i);
rtgui_dc_draw_text(dc, ac, &rect);
}
x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180);
y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180);
rtgui_dc_fill_circle(dc, x, y, 3);
}
RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166);
rtgui_dc_fill_circle(dc, x0, y0, 3);
RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30);
rtgui_dc_draw_circle(dc, x0, y0, 5);
default_color = RTGUI_DC_BC(dc);
RTGUI_DC_BC(dc) = red;
rect.x1 = x0 + 7;
rect.y1 = y0 - 1;
rect.x2 = x0 + 75;
rect.y2 = y0 + 1;
rtgui_dc_fill_rect(dc, &rect);
RTGUI_DC_BC(dc) = default_color;
rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else
{
/* 其他事件,调用默认的事件处理函数 */
return rtgui_view_event_handler(widget, event);
}
return RT_FALSE;
}
/* 创建用于DC操作演示用的视图 */
rtgui_view_t *demo_view_instrument_panel(rtgui_workbench_t* workbench)
{
rtgui_view_t *view;
view = demo_view(workbench, "instrument panel Demo");
if (view != RT_NULL)
/* 设置成自己的事件处理函数 */
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), instrument_panel_event_handler);
return view;
}