/* 控件绘图函数 */
static void rtgui_mywidget_ondraw(struct rtgui_mywidget* me)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
	rt_uint16_t x, y;

	/* 获得目标DC,开始绘�?*/
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(me));
	if (dc == RT_NULL) return;

	/* 获得窗口的尺�?*/
	rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
	/* 绘制背景�?*/
	RTGUI_DC_BC(dc) = white;
	rtgui_dc_fill_rect(dc, &rect);

	/* 计算中心原点 */
	x = (rect.x2 + rect.x1)/2;
	y = (rect.y2 + rect.y1)/2;

	/* 绘制十字�?*/
	RTGUI_DC_FC(dc) = black;
	rtgui_dc_draw_hline(dc, rect.x1, rect.x2, y);
	rtgui_dc_draw_vline(dc, x, rect.y1, rect.y2);

	/* 根据状态绘制圆�?*/
	if (me->status == MYWIDGET_STATUS_ON)
		RTGUI_DC_FC(dc) = green;
	else
		RTGUI_DC_FC(dc) = red;
	rtgui_dc_fill_circle(dc, x, y, 5);

	/* 结束绘图 */
	rtgui_dc_end_drawing(dc);
	return;
}
Ejemplo n.º 2
0
rt_bool_t calibration_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) break;

		/* get rect information */
		rtgui_widget_get_rect(widget, &rect);

		/* clear whole window */
		RTGUI_WIDGET_BACKGROUND(widget) = white;
		rtgui_dc_fill_rect(dc, &rect);

		/* reset color */
		RTGUI_WIDGET_BACKGROUND(widget) = green;
		RTGUI_WIDGET_FOREGROUND(widget) = black;

		switch (calibration_ptr->step)
		{
			case CALIBRATION_STEP_LEFTTOP:
				rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_RIGHTTOP:
				rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
					calibration_ptr->width, CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_LEFTBOTTOM:
				rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_RIGHTBOTTOM:
				rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
					calibration_ptr->width, calibration_ptr->height - CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_CENTER:
				rtgui_dc_draw_hline(dc, calibration_ptr->width/2 - CALIBRATION_WIDTH, calibration_ptr->width/2 + CALIBRATION_WIDTH, calibration_ptr->height/2);
				rtgui_dc_draw_vline(dc, calibration_ptr->width/2, calibration_ptr->height/2 - CALIBRATION_HEIGHT, calibration_ptr->height/2 + CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width/2, calibration_ptr->height/2, 4);
				break;
		}
		rtgui_dc_end_drawing(dc);
	}
		break;

	case RTGUI_EVENT_COMMAND:
		{
			struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;

			switch (ecmd->command_id)
			{
			case TOUCH_WIN_UPDATE:
				rtgui_widget_update(widget);
				break;
			case TOUCH_WIN_CLOSE:
				rtgui_win_close(RTGUI_WIN(widget));
				break;
			}
		}
		return RT_TRUE;

	default:
		rtgui_win_event_handler(widget, event);
	}

	return RT_FALSE;
}
/*
 * container的事件处理函数
 */
rt_bool_t instrument_panel_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
    struct rtgui_widget *widget = RTGUI_WIDGET(object);
    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 arrowx[] = {120 + 75, 120 + 75, 120 + 85};
        const int arrowy[] = {170 - 5,  170 + 5,  170};

        /*
         * 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
         * 先绘图
         */
        rtgui_container_event_handler(RTGUI_OBJECT(widget), event);

        /************************************************************************/
        /* 下面的是DC的操作                                                     */
        /************************************************************************/

        /* 获得控件所属的DC */
        dc = rtgui_dc_begin_drawing(widget);
        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
        if (dc == RT_NULL)
            return RT_FALSE;

        /* 获得demo container允许绘图的区域 */
        demo_view_get_rect(RTGUI_CONTAINER(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;
                rt_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;
                rt_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_container_event_handler(RTGUI_OBJECT(widget), event);
    }

    return RT_FALSE;
}
Ejemplo n.º 4
0
/*
 * view的事件处理函数
 */
rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
	/* 仅对PAINT事件进行处理 */
	if (event->type == RTGUI_EVENT_PAINT) {
		struct rtgui_dc* dc;
		rtgui_rect_t rect;
		/*		const int vx[] = {20, 50, 60, 45, 60, 20};
				const int vy[] = {150, 50, 90, 60, 45, 50};
		*/
		/*
		 * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo 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_logic_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_rect_t rect = {0, 0, 0x1c, 0x16};
			rtgui_rect_moveto(&rect, 80, 80);
			rtgui_image_blit((rtgui_image_t*)&play_image, dc, &rect);

			rect.x1 = 0;
			rect.y1 = 0;
			rect.x2 = 0x1c;
			rect.y2 = 0x16;
			rtgui_rect_moveto(&rect, 130, 80);
			rtgui_image_blit((rtgui_image_t*)&stop_image, dc, &rect);
		}
		/* 绘制一个圆形 */
		RTGUI_DC_FC(dc) = red;
		rtgui_dc_draw_circle(dc, rect.x1 + 10, rect.y1 + 10, 10);

		/* 填充一个圆形 */
		RTGUI_DC_FC(dc) = green;
		rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10);
#if 0
		/* 画一个圆角矩形 */
		rect.x1 = 150;
		rect.y1 = 180;
		rect.x2 = 210;
		rect.y2 = 260;
		RTGUI_DC_FC(dc) = RTGUI_RGB(25, 70, 150);
		rtgui_dc_draw_round_rect(dc, &rect, 10);

		rect.x1 = 160;
		rect.y1 = 190;
		rect.x2 = 200;
		rect.y2 = 250;
		RTGUI_DC_FC(dc) = RTGUI_RGB(170, 7, 80);
		rtgui_dc_fill_round_rect(dc, &rect, 7);

		/* 画一个圆弧 */
		RTGUI_DC_FC(dc) = RTGUI_RGB(250, 120, 120);
		rtgui_dc_draw_arc(dc, rect.x1 + 120, rect.y1 + 60, 30, 0, 120);

		/* 画一个扇形圆环 */
		RTGUI_DC_FC(dc) = RTGUI_RGB(150, 23, 100);
		rtgui_dc_draw_annulus(dc, 180, 170, 30, 50, 210, 330);

		/* 多边形 */
		RTGUI_DC_FC(dc) = blue;
		rtgui_dc_draw_polygon(dc, vx, vy, 6);

#endif
		RTGUI_DC_FC(dc) = blue;

		/* 绘制不同的边框 */
		{
			rtgui_rect_t rect = {0, 0, 16, 16};
			rtgui_rect_moveto(&rect, 30, 120);

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "raise", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SIMPLE);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "simple", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "sunken", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "box", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "static", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_EXTRA);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "extera", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;
		}

		/* 绘图完成 */
		rtgui_dc_end_drawing(dc);
	} else {
		/* 其他事件,调用默认的事件处理函数 */
		return rtgui_view_event_handler(widget, event);
	}

	return RT_FALSE;
}