[deploy] Add Shape::CreatePolygon

This commit is contained in:
Nomango 2020-10-04 04:47:49 +08:00
parent 678b47b9bd
commit 767f619a8f
6 changed files with 37 additions and 15 deletions

View File

@ -240,20 +240,20 @@ void EllipseActor::SetRadius(const Vec2& radius)
PolygonActor::PolygonActor() {} PolygonActor::PolygonActor() {}
PolygonActor::PolygonActor(const Vector<Point>& points) PolygonActor::PolygonActor(const Vector<Point>& vertices)
{ {
SetVertices(points); SetVertices(vertices);
} }
PolygonActor::~PolygonActor() {} PolygonActor::~PolygonActor() {}
void PolygonActor::SetVertices(const Vector<Point>& points) void PolygonActor::SetVertices(const Vector<Point>& vertices)
{ {
if (points.size() > 1) if (vertices.size() > 1)
{ {
ShapeMaker maker; ShapeMaker maker;
maker.BeginPath(points[0]); maker.BeginPath(vertices[0]);
maker.AddLines(&points[1], points.size() - 1); maker.AddLines(&vertices[1], vertices.size() - 1);
maker.EndPath(true); maker.EndPath(true);
SetShape(maker.GetShape()); SetShape(maker.GetShape());

View File

@ -318,15 +318,15 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建多边形角色 /// @brief 创建多边形角色
/// @param points 多边形端点集合 /// @param vertices 多边形端点集合
PolygonActor(const Vector<Point>& points); PolygonActor(const Vector<Point>& vertices);
virtual ~PolygonActor(); virtual ~PolygonActor();
/// \~chinese /// \~chinese
/// @brief 设置多边形端点 /// @brief 设置多边形端点
/// @param points 多边形端点集合 /// @param vertices 多边形端点集合
void SetVertices(const Vector<Point>& points); void SetVertices(const Vector<Point>& vertices);
}; };

View File

@ -91,7 +91,7 @@ void Button::OnEvent(Event evt)
if (evt == Event::Clicked && clicked_cb_) if (evt == Event::Clicked && clicked_cb_)
{ {
clicked_cb_(); clicked_cb_(this);
} }
} }

View File

@ -90,6 +90,10 @@ public:
/// @brief 按钮回调函数 /// @brief 按钮回调函数
using Callback = Function<void(Button* /* self */, Event /* evt */)>; using Callback = Function<void(Button* /* self */, Event /* evt */)>;
/// \~chinese
/// @brief 按钮点击回调函数
using ClickedCallback = Function<void(Button* /* self */)>;
Button(); Button();
/// \~chinese /// \~chinese
@ -105,15 +109,15 @@ public:
/// \~chinese /// \~chinese
/// @brief 设置按钮回调函数 /// @brief 设置按钮回调函数
/// @param cb 按钮回调函数 /// @param cb 按钮回调函数
void SetCallbackOnClicked(const Function<void()>& cb); void SetCallbackOnClicked(const ClickedCallback& cb);
/// \~chinese /// \~chinese
/// @brief 按钮状态变化时 /// @brief 按钮状态变化时
void OnEvent(Event evt) override; void OnEvent(Event evt) override;
private: private:
Callback cb_; Callback cb_;
Function<void()> clicked_cb_; ClickedCallback clicked_cb_;
}; };
/** @} */ /** @} */
@ -123,7 +127,7 @@ inline void Button::SetCallback(const Button::Callback& cb)
cb_ = cb; cb_ = cb;
} }
inline void Button::SetCallbackOnClicked(const Function<void()>& cb) inline void Button::SetCallbackOnClicked(const Button::ClickedCallback& cb)
{ {
clicked_cb_ = cb; clicked_cb_ = cb;
} }

View File

@ -169,4 +169,17 @@ ShapePtr Shape::CreateEllipse(const Point& center, const Vec2& radius)
return output; return output;
} }
ShapePtr Shape::CreatePolygon(const Vector<Point>& vertices)
{
if (vertices.size() > 1)
{
ShapeMaker maker;
maker.BeginPath(vertices[0]);
maker.AddLines(&vertices[1], vertices.size() - 1);
maker.EndPath(true);
return maker.GetShape();
}
return ShapePtr();
}
} // namespace kiwano } // namespace kiwano

View File

@ -70,6 +70,11 @@ public:
/// @param radius ÍÖÔ²°ë¾¶ /// @param radius ÍÖÔ²°ë¾¶
static ShapePtr CreateEllipse(const Point& center, const Vec2& radius); static ShapePtr CreateEllipse(const Point& center, const Vec2& radius);
/// \~chinese
/// @brief 创建多边形
/// @param vertices 多边形端点集合
static ShapePtr CreatePolygon(const Vector<Point>& vertices);
Shape(); Shape();
/// \~chinese /// \~chinese