QPainterPath绘图路径

本文引用http://blog.chinaunix.net/uid-24219701-id-4044473.html

绘图路径(painter path)由基本图元(矩形,椭圆,直线,曲线)组成,绘图路径可以是闭合的路径,如矩形和圆,或者是非闭合的路径,如直线和曲线。

绘图路径在Qt中使用QPainterPth类表示,它提供了绘图操作的容器,可以使图形能够复用。绘图路径可以进行填充,显示轮廓和裁剪。要生成可填充的轮廓的绘图路径,可以使用QPainterPathStroker类.

使用QPainterPath的优点是复杂的图形只需创建一次,就可以多次使用。QPainterPath对象可以时只有起点的空路径,或者从其他QPainterPath对象复制,创建了QPainterPath对象后,可以使用lineTo(),cubicTo(),quadTo() 函数将直线和曲线添加到路径中来,直线和曲线从currentPosition()开始绘制。currentPosition()总是返回最后的子路经绘制的终点。使用moveTo()函数可以在不增加路径的情况下移动currentPositon(),它关闭了一个子路经,开始一个新的子路经。closeSubPath()也可以关闭当前路径,并从currentPosition()连接一条直线到绘图路径的起点。

QPainter可以使用addEllipse(),addPath(),addRect(),addRegion(),addText()将Qt的一些基本图元加入绘图路径。一个已有的绘图路径可以通过connectPath()函数加入到另一个绘图路径中。如下代码绘制了一个箭头:

QPainterPath path;
path.moveTo(10,100);
path.cubicTo(10,100,100,10,200,70);
path.lineTo(200,50);
path.lineTo(220,80);
path.lineTo(200,110);
path.lineTo(200,90);
path.cuticTo(200,100,100,50,50,100);
QPainter painter(this);
QPen pen(QColor(255,0,0),2);
painter.setPen(pen);
painter.drawPath(path);

Qt提供了两种填充方式,Qt::OddEventFill和Qt::WindingFill.Qt::OddEvent时默认的填充规则,它指定QPainterPath使用奇偶填充规则,该规则判断一个点是否在论经图形内的方法是从该店画一条水平线到路径外,计算水平线和路径的交点数,如果交点时奇数个则说明该点在路径图形内。QPainterPath还有一些函数可以获取路径信息,如elementAt()函数可以取出指定的子路经元素,
isEmpty() 函数判断当前路径是否为空。controlPointRect()函数返回路径中所有的点和控制点的矩形,该函数运行速度比返回精确包容框 boundingRect()函数快得多。contains()函数判断一个点或一个矩形是否在路径内。intersects()判断指定的矩形与路径是 否相交.QPainterPath可以将矩形图形转换为其他图形,如使用toFillPolygon(), toFillPolygon(),toSubpathPOlygons()函数将路径转化为多边形。

QPainterPath还可以使用文字作为路径,下面的代码演示了文字路径,并使用线性渐变填充。

QLinearGradient linearGrad(QPointF(200,0),QPointF(1000,0));
linearGrad.setColorAt(0,Qt::black);
linearGrad.setColorAt(1,Qt::white);
QFont font("隶书",80);
font.setBold(true);
QPainterPath textPath();
textPath.addText(200,300,font,tr("电子工业出版社"));
painter.setBrush(linearGrad);
painter.drawPath(textPath);

 

Whether you are making a road, a ramp, a path or a river, Path Painter makes terrain based path creation and texturing a breeze! Path Painter allows you to: - Create paths; - Create ramps; - Create roads; - Create plateaus for secret forts; - Create lake and river beds; - Change terrain elevation along path; - Re-texture along path embankments; - Clear grass and trees along path; - Use various algorithms for natural clearing; - Standard Unity terrain compatible! Path Painter is a collaboration between Frank Slater and Procedural Worlds, and we are very excited to be working together. Note: This asset is provided in DLL form rather than with source code. If you would also like to purchase the source then please contact us directly. Our Product Suite: Gaia - A world generation system for creating, texturing, planting and populating scenes from low poly mobile, VR and through to high end desktop. GeNa 2 - A sophisticated localised level design tool that augments Gaia’s broad brush strokes, by working intuitively to give fine grained control. Path Painter - A powerful path and easy to use road, path and river bed painting system for Unity 3D. CTS - Nominated by Unity of as one of the best assets in 2017, a PBR terrain shading system that significantly improves terrain look, performance and usability. SECTR - A suite of performance-enhancing tools that enable open world streaming, massive mobile games and includes the latest techniques in audio occlusion and propagation. Pegasus - A system that can drive anything along a path. Great for cut-scenes, and even has an ambient ai that supports formations, animation and local avoidance for your npc's and animals! Want To Know More ? Unity Forum Path Painter Tutorials Have A Chat Ticketed Support NOTE: Path Painter does not create meshes, so if you are making rivers you would typically also use another tool as well to shade the river component.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值