示例#1
0
void BlackEdgeTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
	if(text.isEmpty())
		return;

	painter->setRenderHint(QPainter::Antialiasing);

	if(outline > 0){
		QPen pen(Qt::black);
		pen.setWidth(outline);
		painter->setPen(pen);
	}

	QFontMetrics metric(font);
	int height = metric.height() - metric.descent() + skip;

	for(int i = 0; i < text.length(); i++){
		QString text;
		text.append(this->text.at(i));

		QPainterPath path;
		path.addText(metric.width(this->text.left(i)), height, font, text);

		if(outline > 0)
			painter->drawPath(path);

		painter->fillPath(path, color);
	}

	if(hasFocus()){
		QPen red_pen(Qt::red);
		painter->setPen(red_pen);
		QRectF rect = boundingRect();
		painter->drawRect(-1, -1, rect.width() + 2, rect.height() + 2);
	}
}
示例#2
0
    SkillTitle(const QString &kingdom, const QString &text)
        :title_text(NULL), frame(NULL)
    {
        title_text = new AATextItem(text, this);
        title_text->setFont(Config.value("CardEditor/SkillTitleFont").value<QFont>());
        title_text->setPos(Config.value("CardEditor/TitleTextOffset", QPointF(10, -2)).toPointF());
        title_text->document()->setDocumentMargin(0);

        setKingdom(kingdom);
        setFlag(QGraphicsItem::ItemIsFocusable);

        frame = new QGraphicsRectItem(this);
        frame->setRect(-1, -1, 70+2, 30+2);
        QPen red_pen(Qt::red);
        frame->setPen(red_pen);
        frame->hide();
    }
示例#3
0
void WindCtrl::OnPaint()
{
    CPaintDC dc(this); // device context for painting
	CRect rect;
	GetClientRect(&rect);
    unsigned width = rect.right;
    unsigned height = rect.bottom;
    
    // frame
    dc.Ellipse(0, 0, width, height);

    // current vector
    CPen red_pen(PS_SOLID, 1, RGB(255, 0, 0));
    CPen *old = dc.SelectObject(&red_pen);
    dc.MoveTo(width/2, height/2);
    dc.LineTo(int(width/2*(1+power*cos(angle))), int(height/2*(1-power*sin(angle))));
    dc.SelectObject(old);

    // zero zone
    dc.Ellipse( int(width*(0.5-ZERO_ZONE/2)), int(height*(0.5-ZERO_ZONE/2)),
                int(width*(0.5+ZERO_ZONE/2)), int(double(height)*(0.5+ZERO_ZONE/2)) );
}
PRIVATE void svg_renderer_render_object(SvgRenderObject* render_object, Graphics* graphics){
	SvgRenderObject* child;
	BOOL is_container = FALSE;
	Pen pen(Color::Transparent, 0);
	SolidBrush brush(Color::Transparent);
	BOOL is_use_object = FALSE;
	GraphicsContainer container = graphics->BeginContainer();
	Matrix matrix;
	NUMBER* transform = NULL;
	GraphicsPath path(FillModeWinding);
	BOOL has_fill, has_stroke;
	SvgClipPathRenderObject* clip_path_render_object = NULL;
	return_if_fail(render_object);

	graphics->SetSmoothingMode(SmoothingModeHighQuality);

	//implement transform
	transform = svg_render_object_get_transform(render_object);
	matrix.SetElements(
		transform[0], transform[3], transform[1],
		transform[4], transform[2], transform[5]);
	graphics->MultiplyTransform(&matrix);

	//set pen for stroking
	has_stroke = svg_render_object_has_stroke((SvgRenderObject*)render_object);
	if(has_stroke){
		LineCap linecap = LineCapFlat;
		ARRAY dash_array = svg_render_object_get_stroke_dasharray(render_object);
		//stroke & stroke-opacity
		pen.SetColor(
			Color(
				COLORREF_TO_ARGB(
					svg_render_object_get_stroke_color(render_object), 
					svg_render_object_get_stroke_opacity(render_object))));
		//stroke-width
		pen.SetWidth(svg_render_object_get_stroke_width(render_object));
		//stroke-dasharray
		pen.SetDashStyle(DashStyleCustom);
		pen.SetDashPattern((float*)dash_array.data, dash_array.length);
		//stroke-dashoffset
		pen.SetDashOffset(svg_render_object_get_stroke_dashoffset(render_object));
		//stroke-linecap
		linecap = svg_render_object_get_stroke_linecap(render_object);
		pen.SetLineCap(linecap, linecap, DashCapFlat);
		//stroke-linejoin
		pen.SetLineJoin(svg_render_object_get_stroke_linejoin(render_object));
		//stroke-miterlimit
		pen.SetMiterLimit(svg_render_object_get_stroke_miterlimit(render_object));
	}
	//set brush for filling
	has_fill = svg_render_object_has_fill((SvgRenderObject*)render_object);
	if(has_fill){
		//fill & fill-opacity
		brush.SetColor(
			Color(
				COLORREF_TO_ARGB(
				svg_render_object_get_fill_color(render_object),
				svg_render_object_get_fill_opacity(render_object))));
		//fill-rule
		path.SetFillMode(svg_render_object_get_fill_rule((SvgRenderObject*) render_object));
	}

	//set clip path
	clip_path_render_object = svg_render_object_get_clip_path_element(render_object);
	if(clip_path_render_object){
		set_clip_path(clip_path_render_object, graphics);
	}

	//fetch information from render object
	switch(svg_render_object_get_type(render_object)){
	case SVG_TAG_TYPE_PATH: add_path((SvgPathRenderObject*)render_object, &path);break;
	case SVG_TAG_TYPE_RECT: add_rect_path((SvgRectRenderObject*)render_object, &path);break;
	case SVG_TAG_TYPE_CIRCLE: add_circle_path((SvgCircleRenderObject*)render_object, &path); break;
	case SVG_TAG_TYPE_ELLIPSE: add_ellipse_path((SvgEllipseRenderObject*)render_object, &path); break;
	case SVG_TAG_TYPE_LINE: add_line_path((SvgLineRenderObject*)render_object, &path);break;
	case SVG_TAG_TYPE_POLYLINE: add_polyline_path((SvgPolylineRenderObject*)render_object, &path);break;
	case SVG_TAG_TYPE_POLYGON: add_polygon_path((SvgPolygonRenderObject*)render_object, &path);break;
	case SVG_TAG_TYPE_SVG:{
		Pen red_pen(Color(128, 255, 0, 0));
		is_container = TRUE;
		LENGTH width = svg_svg_render_object_get_width((SvgSvgRenderObject*)render_object);
		LENGTH height = svg_svg_render_object_get_height((SvgSvgRenderObject*)render_object);
		if(width.unit_id == UNIT_ID_PERCENTAGE){
			width.number *= g_client_area.Width / svg_renderer_scale_ratio;// divide scale ratio to offset the scale transform
			width.unit_id = UNIT_ID_PX;
		}
		g_viewport_size.Width = width.number;//保存viewport宽度的计算值
		if(height.unit_id == UNIT_ID_PERCENTAGE){
			height.number *= g_client_area.Height / svg_renderer_scale_ratio;
			height.unit_id = UNIT_ID_PX;
		}
		g_viewport_size.Height = height.number;//保存viewport高度的计算值
		RectF rect(0, 0, width.number + 1, height.number + 1);//这里width和height各加一是为了正确clip
		graphics->DrawRectangle(&red_pen, rect);
		//set the initial clipping path
		graphics->SetClip(rect);

		if(svg_svg_render_object_has_view_box((SvgSvgRenderObject*)render_object)){
			ViewBox view_box = svg_svg_render_object_get_view_box((SvgSvgRenderObject*)render_object);
			PRESERVE_ASPECT_RATIO par = svg_svg_render_object_get_preserve_aspect_ratio((SvgSvgRenderObject*)render_object);
			NUMBER uniform_scale_ratio, x_scale_ratio, y_scale_ratio;
			x_scale_ratio = width.number / view_box.width;
			y_scale_ratio = height.number / view_box.height;
			if(par.meet_or_slice == PRESERVE_ASPECT_RATIO_MORS_MEET){
				uniform_scale_ratio = min(x_scale_ratio, y_scale_ratio);
			}else{
				uniform_scale_ratio = max(x_scale_ratio, y_scale_ratio);
			}
			if(par.align == PRESERVE_ASPECT_RATIO_ALIGN_NONE){
				//Stretch to fit non-uniformly.
				graphics->ScaleTransform(x_scale_ratio, y_scale_ratio);
			}else{
				//Force uniform scaling.
				graphics->ScaleTransform(uniform_scale_ratio, uniform_scale_ratio);
				switch(par.align){
				case PRESERVE_ASPECT_RATIO_ALIGN_XMIN_YMIN:
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMID_YMIN:
					graphics->TranslateTransform((width.number / uniform_scale_ratio - view_box.width) / 2, 0);
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMAX_YMIN:
					graphics->TranslateTransform(width.number / uniform_scale_ratio - view_box.width, 0);
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMIN_YMID:
					graphics->TranslateTransform(0, (height.number / uniform_scale_ratio - view_box.height) / 2);
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMID_YMID:
					graphics->TranslateTransform(
						(width.number / uniform_scale_ratio - view_box.width) / 2, 
						(height.number / uniform_scale_ratio - view_box.height) / 2);
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMAX_YMID:
					graphics->TranslateTransform(
						width.number / uniform_scale_ratio - view_box.width, 
						(height.number / uniform_scale_ratio - view_box.height) / 2);
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMIN_YMAX:
					graphics->TranslateTransform(0, height.number / uniform_scale_ratio - view_box.height);
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMID_YMAX:
					graphics->TranslateTransform(
						(width.number / uniform_scale_ratio - view_box.width) / 2, 
						height.number / uniform_scale_ratio - view_box.height);
					break;
				case PRESERVE_ASPECT_RATIO_ALIGN_XMAX_YMAX:;
					graphics->TranslateTransform(
						width.number / uniform_scale_ratio - view_box.width, 
						height.number / uniform_scale_ratio - view_box.height);
					break;
				}//switch
			}//else
			graphics->TranslateTransform(-view_box.min_x, -view_box.min_y);
		}//if
		break;
						  }
	case SVG_TAG_TYPE_G: is_container = TRUE; break;
	case SVG_TAG_TYPE_USE:
		is_container = TRUE;
		graphics->TranslateTransform(
			(float)svg_use_render_object_get_x((SvgUseRenderObject*)render_object), 
			(float)svg_use_render_object_get_y((SvgUseRenderObject*)render_object));
		 break;
	}

	//rendering
	if(!is_container){//render myself
		if(has_fill) graphics->FillPath(&brush, &path);
		if(has_stroke) graphics->DrawPath(&pen, &path);
	}else{//render child
		child = svg_render_object_get_first_child(render_object);
		while(is_container && child){
			svg_renderer_render_object(child, graphics);
			child = svg_render_object_get_next_sibling(child);
		}
	}
	graphics->EndContainer(container);
}