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