Add PolygonActor
This commit is contained in:
parent
81503a33c9
commit
46f9dae888
|
|
@ -32,7 +32,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
ShapeActor::ShapeActor(Geometry geometry)
|
||||
ShapeActor::ShapeActor(Geometry const& geometry)
|
||||
: ShapeActor()
|
||||
{
|
||||
SetGeometry(geometry);
|
||||
|
|
@ -80,7 +80,7 @@ namespace kiwano
|
|||
stroke_style_ = stroke_style;
|
||||
}
|
||||
|
||||
void ShapeActor::SetGeometry(Geometry geometry)
|
||||
void ShapeActor::SetGeometry(Geometry const& geometry)
|
||||
{
|
||||
geo_ = geometry;
|
||||
if (geo_)
|
||||
|
|
@ -134,13 +134,7 @@ namespace kiwano
|
|||
|
||||
void LineActor::SetPoint(Point const& point)
|
||||
{
|
||||
Geometry geo = Geometry::CreateLine(Point{}, point);
|
||||
|
||||
if (geo)
|
||||
{
|
||||
point_ = point;
|
||||
SetGeometry(geo);
|
||||
}
|
||||
SetGeometry(Geometry::CreateLine(Point{}, point));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -163,13 +157,7 @@ namespace kiwano
|
|||
|
||||
void RectActor::SetRectSize(Size const& size)
|
||||
{
|
||||
Geometry geo = Geometry::CreateRect(Rect{ Point{}, size });
|
||||
|
||||
if (geo)
|
||||
{
|
||||
rect_size_ = size;
|
||||
SetGeometry(geo);
|
||||
}
|
||||
SetGeometry(Geometry::CreateRect(Rect{ Point{}, size }));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -202,13 +190,7 @@ namespace kiwano
|
|||
|
||||
void RoundRectActor::SetRoundedRect(Size const& size, Vec2 const& radius)
|
||||
{
|
||||
Geometry geo = Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius);
|
||||
|
||||
if (geo)
|
||||
{
|
||||
rect_size_ = size;
|
||||
SetGeometry(geo);
|
||||
}
|
||||
SetGeometry(Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -232,12 +214,7 @@ namespace kiwano
|
|||
|
||||
void CircleActor::SetRadius(Float32 radius)
|
||||
{
|
||||
Geometry geo = Geometry::CreateCircle(Point{}, radius);
|
||||
|
||||
if (geo)
|
||||
{
|
||||
SetGeometry(geo);
|
||||
}
|
||||
SetGeometry(Geometry::CreateCircle(Point{ radius, radius }, radius));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -260,11 +237,38 @@ namespace kiwano
|
|||
|
||||
void EllipseActor::SetRadius(Vec2 const& radius)
|
||||
{
|
||||
Geometry geo = Geometry::CreateEllipse(Point{}, radius);
|
||||
SetGeometry(Geometry::CreateEllipse(radius, radius));
|
||||
}
|
||||
|
||||
if (geo)
|
||||
|
||||
//-------------------------------------------------------
|
||||
// PolygonActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
PolygonActor::PolygonActor()
|
||||
{
|
||||
}
|
||||
|
||||
PolygonActor::PolygonActor(Vector<Point> const& points)
|
||||
{
|
||||
SetVertices(points);
|
||||
}
|
||||
|
||||
PolygonActor::~PolygonActor()
|
||||
{
|
||||
}
|
||||
|
||||
void PolygonActor::SetVertices(Vector<Point> const& points)
|
||||
{
|
||||
if (points.size() > 1)
|
||||
{
|
||||
SetGeometry(geo);
|
||||
SetGeometry(
|
||||
GeometrySink()
|
||||
.BeginPath(points[0])
|
||||
.AddLines(&points[1], points.size() - 1)
|
||||
.EndPath(true)
|
||||
.GetGeometry()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace kiwano
|
|||
ShapeActor();
|
||||
|
||||
ShapeActor(
|
||||
Geometry geometry
|
||||
Geometry const& geometry
|
||||
);
|
||||
|
||||
virtual ~ShapeActor();
|
||||
|
|
@ -75,7 +75,7 @@ namespace kiwano
|
|||
void SetStrokeStyle(StrokeStyle stroke_style);
|
||||
|
||||
// ÉèÖÃÐÎ×´
|
||||
void SetGeometry(Geometry geometry);
|
||||
void SetGeometry(Geometry const& geometry);
|
||||
|
||||
void OnRender(RenderTarget* rt) override;
|
||||
|
||||
|
|
@ -218,6 +218,25 @@ namespace kiwano
|
|||
};
|
||||
|
||||
|
||||
// 多边形角色
|
||||
class KGE_API PolygonActor
|
||||
: public ShapeActor
|
||||
{
|
||||
public:
|
||||
PolygonActor();
|
||||
|
||||
PolygonActor(
|
||||
Vector<Point> const& points
|
||||
);
|
||||
|
||||
virtual ~PolygonActor();
|
||||
|
||||
void SetVertices(
|
||||
Vector<Point> const& points
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// ·¾¶½ÇÉ«
|
||||
class KGE_API PathActor
|
||||
: public ShapeActor
|
||||
|
|
|
|||
|
|
@ -90,10 +90,10 @@ namespace kiwano
|
|||
void ClearPath();
|
||||
|
||||
// »ñȡ·Ïß
|
||||
inline Geometry GetPath() const { return path_; }
|
||||
inline Geometry const& GetPath() const { return path_; }
|
||||
|
||||
// ÉèÖ÷¾¶
|
||||
inline void SetPath(Geometry path) { path_ = path; }
|
||||
inline void SetPath(Geometry const& path) { path_ = path; }
|
||||
|
||||
protected:
|
||||
void Init(ActorPtr target) override;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ namespace kiwano
|
|||
KGE_DECLARE_SMART_PTR(RoundRectActor);
|
||||
KGE_DECLARE_SMART_PTR(CircleActor);
|
||||
KGE_DECLARE_SMART_PTR(EllipseActor);
|
||||
KGE_DECLARE_SMART_PTR(PolygonActor);
|
||||
KGE_DECLARE_SMART_PTR(PathActor);
|
||||
|
||||
KGE_DECLARE_SMART_PTR(Action);
|
||||
|
|
|
|||
|
|
@ -246,6 +246,14 @@ namespace kiwano
|
|||
return (*this);
|
||||
}
|
||||
|
||||
GeometrySink& kiwano::GeometrySink::AddLines(const Point* points, UInt32 count)
|
||||
{
|
||||
if (!sink_) BeginPath();
|
||||
|
||||
sink_->AddLines(reinterpret_cast<const D2D_POINT_2F*>(points), count);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
GeometrySink& GeometrySink::AddBezier(Point const& point1, Point const& point2, Point const& point3)
|
||||
{
|
||||
if (!sink_) BeginPath();
|
||||
|
|
|
|||
|
|
@ -151,6 +151,12 @@ namespace kiwano
|
|||
Vector<Point> const& points
|
||||
);
|
||||
|
||||
// 添加多条线段
|
||||
GeometrySink& AddLines(
|
||||
const Point* points,
|
||||
UInt32 count
|
||||
);
|
||||
|
||||
// 添加一条三次方贝塞尔曲线
|
||||
GeometrySink& AddBezier(
|
||||
Point const& point1, /* 贝塞尔曲线的第一个控制点 */
|
||||
|
|
@ -162,7 +168,7 @@ namespace kiwano
|
|||
GeometrySink& AddArc(
|
||||
Point const& point, /* 终点 */
|
||||
Size const& radius, /* 椭圆半径 */
|
||||
Float32 rotation, /* ÍÖÔ²Ðýת½Ç¶È */
|
||||
Float32 rotation, /* 椭圆旋转角度 */
|
||||
bool clockwise = true, /* 顺时针 or 逆时针 */
|
||||
bool is_small = true /* 是否取小于 180° 的弧 */
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue