rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench)
{
	rtgui_view_t *view;

	view = demo_view(workbench, "DC 缓冲区动画");
	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)), "缓冲动画", &text_rect);
	if (dc_buffer == RT_NULL)
	{
		rtgui_rect_t rect;

		rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2;
		rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2;

		/* 创建 DC Buffer,长 50,宽 50 */
		dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
		RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view));
		rtgui_dc_fill_rect(dc_buffer, &rect);
		RTGUI_DC_FC(dc_buffer) = black;
		rect.x1 = 1; rect.y1 = 1;
		rtgui_dc_draw_text(dc_buffer, "缓冲动画", &rect);
	}

	/* 启动定时器以触发动画 */
	timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view);
	rtgui_timer_start(timer);

	return view;
}
Beispiel #2
0
static rt_bool_t rtgui_slider_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
{
	rtgui_rect_t rect;
	rtgui_widget_t *widget;
	struct rtgui_dc *dc;

	RT_ASSERT(object);
	widget = RTGUI_WIDGET(object);

	dc = rtgui_dc_begin_drawing(widget);
	if(dc == RT_NULL) return RT_FALSE;

	rtgui_widget_get_rect(widget, &rect);

	if(!RTGUI_WIDGET_IS_FOCUSED(widget))
	{
		/* only clear focus rect */
		rtgui_color_t color = RTGUI_DC_FC(dc);
		RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
		rtgui_dc_draw_focus_rect(dc, &rect);
		RTGUI_DC_FC(dc) = color;
	}

	rtgui_dc_end_drawing(dc);
	return RT_TRUE;
}
Beispiel #3
0
static void _rtgui_plot_curve_onpaint(
    struct rtgui_dc *dc,
    struct rtgui_plot *plot,
    struct rtgui_plot_curve *curve,
    rt_uint16_t start_idx,
    rt_uint16_t stop_idx)
{
    struct rtgui_rect rect;
    rt_uint16_t height;
    int last_x, last_y;
    rtgui_color_t old_color;
    rtgui_plot_curve_dtype *x_data, *y_data;

    rtgui_dc_get_rect(dc, &rect);
    height = rtgui_rect_height(rect);

    old_color = RTGUI_DC_FC(dc);
    RTGUI_DC_FC(dc) = curve->color;

    x_data = rtgui_plot_curve_get_x(curve);
    y_data = rtgui_plot_curve_get_y(curve);
    if (x_data)
    {
        rt_size_t i;

        last_x = _rtgui_plot_curve_calc_x(plot, x_data[start_idx]);
        last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
        for (i = start_idx + 1; i < stop_idx; i++)
        {
            int cur_x = _rtgui_plot_curve_calc_x(plot, x_data[i]);
            int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
            rtgui_dc_draw_line(dc,
                               last_x, last_y,
                               cur_x, cur_y);
            last_x = cur_x;
            last_y = cur_y;
        }
    }
    else
    {
        rt_size_t i;

        last_x = _rtgui_plot_curve_calc_x(plot, start_idx);
        last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
        for (i = start_idx + 1; i < stop_idx; i++)
        {
            int cur_x = _rtgui_plot_curve_calc_x(plot, i);
            int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
            rtgui_dc_draw_line(dc,
                               last_x, last_y,
                               cur_x, cur_y);
            last_x = cur_x;
            last_y = cur_y;
        }
    }
    RTGUI_DC_FC(dc) = old_color;
}
void tetris_refreshmap(struct rtgui_dc *dc)                               //刷新地图
{
    rt_uint8_t i, j;
    rt_uint8_t buf[5];
    rtgui_rect_t rect = {XOFFSET, YOFFSET, XOFFSET + 240, YOFFSET + 400};
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x55, 0x55, 0x55);
    rtgui_dc_fill_rect_forecolor(dc, &rect);
    rect.x1 -= 10;
    rect.x2 += 150;
    rect.y1 -= 10;
    rect.y2 += 10;
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0xff);
    rtgui_dc_draw_rect(dc, &rect);
    rect.x1 += 290;
    rect.x2 -= 30;
    rect.y1 += 40;
    rect.y2 -= 360;
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0x00);
    rtgui_dc_draw_text(dc, "下一个", &rect);
    rect.y1 += 130;
    rect.y2 += 130;
    rtgui_dc_draw_text(dc, "总得分", &rect);
    rect.y1 += 80;
    rect.y2 += 80;
    rtgui_dc_draw_text(dc, "LEVEL", &rect);
    RTGUI_DC_FC(dc) = RTGUI_RGB(0xff, 0x00, 0x00);
    rect.x1 += 20;
    rect.x2 += 20;
    rect.y1 -= 60;
    rect.y2 -= 60;
    rt_sprintf(buf, "%d", score);
    rtgui_dc_fill_rect(dc, &rect);
    rtgui_dc_draw_text(dc, buf, &rect);
    rect.y1 += 80;
    rect.y2 += 80;
    rt_sprintf(buf, "%d", level);
    rtgui_dc_fill_rect(dc, &rect);
    rtgui_dc_draw_text(dc, buf, &rect);


    for (i = 0; i < 25; i++)
    {
        for (j = 0; j < 15; j++)
        {
            if (tetris_map[j][i] != 0)
            {
                tetris_drawbox(dc, j, i, tetris_colors[tetris_map[j][i]]);
            }
        }
    }
}
void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect)
{
	rtgui_color_t bc;
	rt_uint16_t index;
	
	bc = RTGUI_DC_FC(dc);
	RTGUI_DC_FC(dc) = selected_color;

	rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, rect->y1 + 1);
	rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, rect->y2 - 2);

	rtgui_dc_draw_vline(dc, rect->x1 + 2, rect->y1 + 2, rect->y2 - 2);
	rtgui_dc_draw_vline(dc, rect->x2 - 2, rect->y1 + 2, rect->y2 - 2);

	for (index = rect->y1 + 1; index < rect->y2 - 2; index ++)
		rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, index);

	RTGUI_DC_FC(dc) = bc;
}
void tetris_drawbox(struct rtgui_dc *dc, rt_uint16_t bx, rt_uint16_t by, rtgui_color_t bcolor)
{
    rtgui_rect_t rect = (rtgui_rect_t)
    {
        bx * 16 + XOFFSET,
        by * 16 + YOFFSET,
        bx * 16 + 15 + XOFFSET,
        by * 16 + 15 + YOFFSET
    };
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0xff);
    rtgui_dc_draw_rect(dc, &rect);
    rect.x1++;
    rect.x2--;
    rect.y1++;
    rect.y2--;
    RTGUI_DC_FC(dc) = bcolor;
    rtgui_dc_fill_rect_forecolor(dc, &rect);

}
void tetris_removebox(struct rtgui_dc *dc, rt_uint16_t bx, rt_uint16_t by)
{
    rtgui_rect_t rect = (rtgui_rect_t)
    {
        bx * 16 + XOFFSET,
        by * 16 + YOFFSET,
        bx * 16 + 15 + XOFFSET,
        by * 16 + + 15 + YOFFSET
    };
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x55, 0x55, 0x55);
    rtgui_dc_fill_rect_forecolor(dc, &rect);
}
/* 创建用于DC Buffer操作演示用的视图 */
rtgui_view_t *demo_gui_dc_buffer(rtgui_view_t* parent_view)
{
	rtgui_view_t *view;

	if (dc_buffer == RT_NULL) {
		rtgui_rect_t rect = {0, 0, 50, 50};

		/* 创建 DC Buffer,长 50,宽 50 */
		dc_buffer = rtgui_dc_buffer_create(50, 50);
		RTGUI_DC_FC(dc_buffer) = blue;
		rtgui_dc_fill_rect(dc_buffer, &rect);

		RTGUI_DC_FC(dc_buffer) = red;
		rtgui_dc_draw_circle(dc_buffer, 25, 25, 10);
	}

	view = demo_view_create(parent_view, "缓冲DC演示");
	if (view == RT_NULL) return RT_NULL;
	/* 设置成自己的事件处理函数 */
	rtgui_widget_set_event_handler(view, dc_buffer_event_handler);

	return view;
}
Beispiel #9
0
void rtgui_combo_ondraw(rtgui_combo_t *cbo)
{
	rtgui_rect_t rect;
	rtgui_dc_t* dc;

	RT_ASSERT(cbo != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(cbo);
	if(dc == RT_NULL)return;

	rtgui_widget_get_rect(cbo, &rect);

	rtgui_rect_inflate(&rect,-RTGUI_WIDGET_BORDER_SIZE(cbo));
	if(RTGUI_WIDGET_IS_ENABLE(cbo))
		RTGUI_DC_BC(dc) = theme.blankspace;
	else
		RTGUI_DC_BC(dc) = theme.background;
	rtgui_dc_fill_rect(dc, &rect);

	rtgui_rect_inflate(&rect,RTGUI_WIDGET_BORDER_SIZE(cbo));
	rtgui_dc_draw_border(dc, &rect,RTGUI_WIDGET_BORDER_STYLE(cbo));

	if(RC_H(rect)<RTGUI_COMBO_HEIGHT)return;

	/* draw downarrow button */
	rect.x1 = rect.x2-RTGUI_COMBO_BUTTON_WIDTH;
	RTGUI_DC_BC(dc) = theme.background;
	rtgui_dc_fill_rect(dc, &rect);

	if(cbo->style & RTGUI_COMBO_STYLE_DOWNARROW_UP)
	{
		rtgui_dc_draw_border(dc, &rect, theme.style);
		rtgui_dc_draw_byte(dc,rect.x1+(rect.x2-rect.x1-7)/2, rect.y1+(rect.y2-rect.y1-4)/2, 4, combo_down_bmp);
	}
	else if(cbo->style & RTGUI_COMBO_STYLE_DOWNARROW_DOWN)
	{
		rtgui_dc_draw_border(dc, &rect, theme.style);
		rtgui_dc_draw_byte(dc,rect.x1+(rect.x2-rect.x1-7)/2+1, rect.y1+(rect.y2-rect.y1-4)/2+1, 4, combo_down_bmp);
	}

	if(cbo->tbox != RT_NULL)
	{
		RTGUI_DC_FC(dc) = theme.foreground;
		rtgui_textbox_ondraw(cbo->tbox);
	}

	rtgui_dc_end_drawing(dc);
}
/* 控件绘图函数 */
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;
}
/* 创建用于DC Buffer操作演示用的视图 */
rtgui_container_t *demo_view_dc_buffer()
{
	rtgui_container_t *view;

	if (dc_buffer == RT_NULL)
	{
		rtgui_rect_t rect = {0, 0, 50, 50};

		/* 创建 DC Buffer,长 50,宽 50 */
		dc_buffer = rtgui_dc_buffer_create(50, 50);
		RTGUI_DC_FC(dc_buffer) = blue;
		rtgui_dc_fill_rect(dc_buffer, &rect);

		RTGUI_DC_FC(dc_buffer) = red;
		rtgui_dc_draw_circle(dc_buffer, 25, 25, 10);
	}

	view = demo_view("缓冲DC演示");
	if (view != RT_NULL)
		/* 设置成自己的事件处理函数 */
		rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler);

	return view;
}
/* 创建用于DC Buffer操作演示用的视图 */
rtgui_view_t *demo_view_dc_buffer(rtgui_workbench_t* workbench)
{
	rtgui_view_t *view;

	if (dc_buffer == RT_NULL)
	{
		rtgui_rect_t rect = {0, 0, 50, 50};

		/* 创建 DC Buffer,长 50,宽 50 */
		dc_buffer = rtgui_dc_buffer_create(50, 50);
		RTGUI_DC_FC(dc_buffer) = blue;
		rtgui_dc_fill_rect(dc_buffer, &rect);

		RTGUI_DC_FC(dc_buffer) = red;
		rtgui_dc_draw_circle(dc_buffer, 25, 25, 10);
	}

	view = demo_view(workbench, "缓冲DC演示");
	if (view != RT_NULL)
		/* 设置成自己的事件处理函数 */
		rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_buffer_event_handler);

	return view;
}
Beispiel #13
0
/* update fileview */
void rtgui_fileview_update_current(rtgui_fileview_t* fview)
{
	rtgui_fileview_item_t *item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t *dc;

	RT_ASSERT(fview != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(fview);
	if(dc == RT_NULL)return;

	/* if directory is null, no dispost */
	if(fview->items==RT_NULL)return;

	rtgui_widget_get_rect(fview, &rect);
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	if((fview->old_item >= fview->first_item) &&
	        (fview->old_item < fview->first_item+fview->item_per_page) &&
	        (fview->old_item != fview->now_item))
	{
		/* these condition dispell blinked when drawed */
		/* get old item rect */
		item_rect = rect;
		item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += ((fview->old_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
		item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

		/* get image rect */
		image_rect.x1 = RTGUI_MARGIN;
		image_rect.y1 = 0;
		image_rect.x2 = RTGUI_MARGIN + file_image->w;
		image_rect.y2 = file_image->h;
		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

		/* draw old item */
		item = &(fview->items[fview->old_item]);
		if(item->type == RTGUI_FITEM_FILE) /* draw item image */
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect,Black);

		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		RTGUI_DC_BC(dc) = theme.blankspace;
		RTGUI_DC_FC(dc) = theme.foreground;
		rtgui_dc_fill_rect(dc,&item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}
	/* draw current item */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += ((fview->now_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_MARGIN + file_image->w;
	image_rect.y2 = file_image->h;
	rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

	item = &(fview->items[fview->now_item]);
	if(item->type == RTGUI_FITEM_FILE) /* draw item image */
		rtgui_image_paste(file_image, dc, &image_rect, Black);
	else
		rtgui_image_paste(folder_image, dc, &image_rect, Black);

	if(fview->dlg != RT_NULL)
	{
		if(fview->dlg->filename != RT_NULL)
		{
			rt_free(fview->dlg->filename);
			fview->dlg->filename = RT_NULL;
		}
		fview->dlg->filename = rt_strdup(item->name);
	}

	item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
	item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);

	{
		if(RTGUI_WIDGET_IS_FOCUSED(fview))
		{
			RTGUI_DC_BC(dc) = DarkBlue;
			RTGUI_DC_FC(dc) = theme.blankspace;
		}
		else
		{
			RTGUI_DC_BC(dc) = Gray;
			RTGUI_DC_FC(dc) = theme.foreground;
		}
		rtgui_dc_fill_rect(dc, &item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}

	if(fview->dlg != RT_NULL)
	{
		if(item->type == RTGUI_FITEM_FILE)
		{
			if(fview->dlg->tbox_filename != RT_NULL)
			{
				rtgui_textbox_set_value(fview->dlg->tbox_filename,fview->dlg->filename);
				RTGUI_DC_FC(dc) = theme.foreground;
				rtgui_textbox_ondraw(fview->dlg->tbox_filename);
			}
		}
	}

	rtgui_dc_end_drawing(dc);
}
/*
 * 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;
}
Beispiel #15
0
static void snake_draw(struct rtgui_widget *widget)
{
    struct rtgui_dc *dc;
    struct rtgui_rect rect;
    rt_uint32_t i;

    dc = rtgui_dc_begin_drawing(widget);
    if (dc == RT_NULL)
    {
        rt_kprintf("dc == RT_NULL\r\n");
        return;
    }

    /* get room size, run once frist. */
    if ((room_size_x == 0) || (room_size_y == 0))
    {
        rt_size_t tmp;

        rtgui_widget_get_rect(widget, &rect);
        rt_kprintf("rect => x1:%d x2:%d, y1:%d y2:%d\r\n", rect.x1, rect.x2, rect.y1, rect.y2);

        room_size_x = rect.x2 - rect.x1;
        room_size_y = rect.y2 - rect.y1;
        memcpy(&room_rect, &rect, sizeof(struct rtgui_rect));
        rt_kprintf("room_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
                   room_rect.x1, room_rect.x2,
                   room_rect.y1, room_rect.y2);

        lattice_size_x = (room_rect.x2 - room_rect.x1) / LATTICE_SIZE;
        lattice_size_y = (room_rect.y2 - room_rect.y1) / LATTICE_SIZE;
        lattice_size_x -= 2;
        lattice_size_y -= 2;
        rt_kprintf("lattice_size_x:%d lattice_size_y:%d\r\n",
                   lattice_size_x,
                   lattice_size_y);

        tmp = (room_rect.x2 - room_rect.x1) - (LATTICE_SIZE * lattice_size_x);
        lattice_rect.x1 = room_rect.x1 + (tmp / 2);
        lattice_rect.x2 = lattice_rect.x1 + (LATTICE_SIZE * lattice_size_x);

        tmp = (room_rect.y2 - room_rect.y1) - (LATTICE_SIZE * lattice_size_y);
        lattice_rect.y1 = room_rect.y1 + (tmp / 2);
        lattice_rect.y2 = lattice_rect.y1 + (LATTICE_SIZE * lattice_size_y);
        rt_kprintf("lattice_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
                   lattice_rect.x1, lattice_rect.x2,
                   lattice_rect.y1, lattice_rect.y2);

        /* create snake. */
        {
            point_t start;
            map = map_init(lattice_size_x, lattice_size_y);
            if (map != RT_NULL)
            {
                start.x = snake_init_pointx;
                start.y = snake_init_pointy;
                run_state = SNAKE_DIR_DOWN;

                if (snake_init(&start, snake_length_init, run_state, map))
                {
                    food_num = 1;
                    food_init(map, food_num);
                }
                else
                {
                    map_deinit(map);
                    map = RT_NULL;
                }
            }
        }
    }

    RTGUI_DC_BC(dc) = BACKGROUND_COLOR;
    rtgui_dc_fill_rect(dc, &room_rect);

    memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
    rect.x2 += 1;
    rect.y2 += 1;
    RTGUI_DC_FC(dc) = WALL_COLOR;
    rtgui_dc_draw_rect(dc, &rect);

    for (i = 1; i < lattice_size_y; i++)
    {
        memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
        rect.x1 += 1;
        rect.x2 -= 1;
        rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2,
                                      rect.y1 + (LATTICE_SIZE * i));
    }

    for (i = 1; i < lattice_size_x; i++)
    {
        memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
        rect.y1 += 1;
        rect.y2 -= 1;
        rtgui_dc_draw_vertical_line(dc, rect.x1 + (LATTICE_SIZE * i),
                                    rect.y1, rect.y2);
    }

    /* draw snake. */
    {
        rt_int32_t x, y;
        rt_bool_t first_node = RT_TRUE;

        for (y = 0; y < map->height; y++)
        {
            for (x = 0; x < map->width; x++)
            {
                switch (map->range[y * map->width + x])
                {
                case NORMAL:
                    break;
                case FOOD:
                    snake_fill_lattice(dc, x, y, FOOD_COLOR);
                    break;
                case OVER:
                    if (first_node)
                    {
                        first_node = RT_FALSE;
                        second_node.x = x;
                        second_node.y = y;
                        snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR);
                    }
                    else
                    {
                        snake_fill_lattice(dc, x, y, SNAKE_COLOR);
                    }
                    break;
                }
            }

        }
    }

    rtgui_dc_end_drawing(dc);

    return;
}
/*
 * 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;
}
Beispiel #17
0
Datei: edit.c Projekt: amsl/RTGUI
void rtgui_edit_ondraw(struct rtgui_edit *edit)
{
	rtgui_rect_t rect, r;
	struct rtgui_dc *dc;
#ifdef RTGUI_EDIT_USING_SCROLL
	int hscroll_flag=0;
	int vscroll_flag=0;
#endif
	
	RT_ASSERT(edit != RT_NULL);

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
	if(dc == RT_NULL) return;

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
	rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER_SIZE(edit));

	/* fill widget rect with edit background color */
	RTGUI_DC_BC(dc) = RTGUI_WIDGET_BC(edit);
	rtgui_dc_fill_rect(dc, &rect);

	rtgui_rect_inflate(&rect, RTGUI_WIDGET_BORDER_SIZE(edit));
	/* draw border */
	rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(edit));

	rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit)));

#ifdef RTGUI_EDIT_USING_SCROLL
	if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
	{
		rect.x2 = rect.x2 - rtgui_rect_width(edit->vscroll->parent.extent);
	}
	if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
	{
		rect.y2 = rect.y2 - rtgui_rect_height(edit->hscroll->parent.extent);
	}
#endif
	r = rect;
	
	/* draw text */
	if(edit->head != RT_NULL)
	{
		struct edit_line *line = edit->first_line;
		int num=0;
		
		rect.y2 = rect.y1 + edit->item_height;
		while(line)
		{
			rt_uint32_t tmp_pos=0, ofs;
			char *str = line->text+edit->upleft.x;
			
			if(edit->upleft.x < line->len)
			{
				rtgui_point_t p = edit->visual;
				edit->visual.x = 0;
				identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
				ofs = tmp_pos % 2;
				if(ofs == 1)
				{
					char dbl_bmp[3];
					rtgui_point_t pot = {0};
					rtgui_rect_t r = {0};
					
					pot.x = edit->font_width;
					r.x2 = edit->font_width*2;
					r.y2 = edit->font_height;
					dbl_bmp[0] = *(str-1);
					dbl_bmp[1] = *str;
					dbl_bmp[2] = '\0';
					RTGUI_DC_BC(edit->dbl_buf) = RTGUI_WIDGET_BC(edit);
					rtgui_dc_fill_rect(edit->dbl_buf, &r);
					RTGUI_DC_FC(edit->dbl_buf) = RTGUI_WIDGET_FC(edit);
					rtgui_dc_draw_text(edit->dbl_buf, dbl_bmp, &r);
					rtgui_dc_blit(edit->dbl_buf, pot.x, pot.y, dc, rect.x1, rect.y1, 
						edit->font_width, edit->font_height);
				}
				rect.x1 += ofs * edit->font_width;
				rtgui_dc_draw_text(dc, line->text+edit->upleft.x+ofs, &rect);
				rect.x1 -= ofs * edit->font_width;
				edit->visual = p;
			}
			
			line = line->next;
			rect.y1 += edit->item_height;
			if((rect.y1 + edit->item_height) < r.y2)
				rect.y2 = rect.y1 + edit->item_height;
			else
				rect.y2 = r.y2;
			
			if(num++ >= edit->row_per_page)
				break;
		}
	}

#ifdef RTGUI_EDIT_USING_SCROLL
	if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
	{
		hscroll_flag = 1;
		rtgui_scrollbar_ondraw(edit->hscroll);
	}
	if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
	{
		vscroll_flag = 1;
		rtgui_scrollbar_ondraw(edit->vscroll);
	}

	if(hscroll_flag && vscroll_flag)
	{
		rtgui_color_t _bc;
		rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
		rect.x1 = rect.x2-RTGUI_WIDGET_BORDER_SIZE(edit);
		rect.y1 = rect.y2-RTGUI_WIDGET_BORDER_SIZE(edit);
		_bc = RTGUI_DC_BC(dc);
		RTGUI_DC_BC(dc) = theme.background;
		rtgui_dc_fill_rect(dc,&rect);
		RTGUI_DC_BC(dc) = _bc;
	}
#endif
	rtgui_dc_end_drawing(dc);
}
Beispiel #18
0
void rtgui_fileview_ondraw(rtgui_fileview_t* fview)
{
	rt_uint16_t first, i,rx2;
	rtgui_fileview_item_t* item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t* dc;

	RT_ASSERT(fview != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(fview);
	if(dc == RT_NULL)return;

	rtgui_widget_get_rect(fview, &rect);
	rtgui_dc_draw_border(dc, &rect,RTGUI_WIDGET_BORDER_STYLE(fview));
	rtgui_rect_inflate(&rect,-RTGUI_WIDGET_BORDER_SIZE(fview));
	RTGUI_DC_BC(dc) = theme.blankspace;
	rtgui_dc_fill_rect(dc,&rect);
	rtgui_rect_inflate(&rect,RTGUI_WIDGET_BORDER_SIZE(fview));
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	rect.x2 -=1;
	rect.y2 -= 1;

	/* get item base rect */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	rx2 = item_rect.x2;
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_MARGIN + file_image->w;
	image_rect.y2 = file_image->h;
	rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

	/* get current page */
	first = fview->first_item;
	for(i = 0; i < fview->item_per_page; i ++)
	{
		char str_size[32];

		if(first + i >= fview->item_count) break;

		item = &(fview->items[first + i]);

		/* draw item image */
		if(item->type == RTGUI_FITEM_FILE)
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect, Black);

		/* draw text */
		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		if(first + i == fview->now_item)
		{
			if(RTGUI_WIDGET_IS_FOCUSED(fview))
			{
				RTGUI_DC_BC(dc) = DarkBlue;
				RTGUI_DC_FC(dc) = theme.blankspace;
			}
			else
			{
				RTGUI_DC_BC(dc) = Gray;
				RTGUI_DC_FC(dc) = theme.foreground;
			}
			rtgui_dc_fill_rect(dc, &item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}
		else
		{
			/* draw background */
			RTGUI_DC_BC(dc) = theme.blankspace;
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_fill_rect(dc,&item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}

#if (1) /* please turn off it when need. */
		if(item->type == RTGUI_FITEM_FILE)
		{
			rtgui_rect_t rect=item_rect;
			/* print file information */
			rt_snprintf(str_size, 16, "(%dB)",item->size);
			rect.x1 = rect.x2 + RTGUI_MARGIN;
			rect.x2 = rect.x1 + rt_strlen(str_size) * FONT_W(RTGUI_WIDGET_FONT(fview));
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_draw_text(dc, str_size, &rect);
		}
#endif
		item_rect.x1 -= RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = rx2;
		/* move to next item position */
		item_rect.y1 += (RTGUI_SEL_H + 1);
		item_rect.y2 += (RTGUI_SEL_H + 1);

		image_rect.y1 += (RTGUI_SEL_H + 1);
		image_rect.y2 += (RTGUI_SEL_H + 1);
	}

	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
	{
		rtgui_scrollbar_ondraw(fview->sbar);
	}

	rtgui_dc_end_drawing(dc);
}
Beispiel #19
0
static void player_update_tag_info()
{
    char line[32];
	struct rtgui_dc* dc;
    rtgui_color_t bc, fc;

    rtgui_rect_t rect;
	rtgui_image_t *button;

	/* get dc */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
	if (dc == RT_NULL) return;

	/* save old foreground and background color */
    fc = RTGUI_DC_FC(dc);
	bc = RTGUI_DC_BC(dc);

    /* draw playing information */
    rect.x1 = 25;
    rect.y1 = 20;
    rect.x2 = 220;
    rect.y2 = rect.y1 + 16;
	RTGUI_DC_BC(dc) = RTGUI_RGB(0, 134, 206);
	rtgui_dc_fill_rect(dc, &rect);

    RTGUI_DC_FC(dc) = black;
    if (player_mode == PLAYER_STOP)
    {
        rt_snprintf(line, sizeof(line), "网络收音机");
        rtgui_dc_draw_text(dc, line, &rect);
    }
    else
        rtgui_dc_draw_text(dc, tinfo.title, &rect);

	/* reset progress bar */
#if 0
	if (tinfo.position != 0)
	{
		rt_snprintf(line, sizeof(line), "%3d:%02d", item->duration / 60, item->duration % 60);
	}
	else
#endif
	{
		RTGUI_DC_FC(dc) = RTGUI_RGB(82, 199, 16);
		rtgui_dc_draw_hline(dc, 14, 226, 75);
	}

    rect.x1 = 25;
    rect.y1 = 48;
    rect.x2 = 220;
    rect.y2 = rect.y1 + 16;
	RTGUI_DC_BC(dc) = RTGUI_RGB(0, 125, 198);
	rtgui_dc_fill_rect(dc, &rect);

    RTGUI_DC_FC(dc) = black;
    if (player_mode == PLAYER_STOP)
    {
        rt_snprintf(line, sizeof(line), "radio.rt-thread.org");
        rtgui_dc_draw_text(dc, line, &rect);
    }
    else
    {
        rtgui_dc_draw_text(dc, tinfo.artist, &rect);
    }

    if ((tinfo.duration != 0) && player_mode == PLAYER_PLAY_FILE)
    {
        play_time = 0;

        rect.x1 = 172;
        rt_snprintf(line, sizeof(line), "  0:00");
        rtgui_dc_draw_text(dc, line, &rect);
    }

	/* update playing button */
	if (player_mode == PLAYER_STOP)
		button = (rtgui_image_t*)&stop_image;
	else
		button = (rtgui_image_t*)&play_image;

	rect.x1 = 32;
	rect.y1 = 92;
	rect.x2 = 61;
	rect.y2 = 114;
	rtgui_image_blit(button, dc, &rect);

    RTGUI_DC_FC(dc) = fc;
	RTGUI_DC_BC(dc) = bc;

	rtgui_dc_end_drawing(dc);
}