[deploy] Add Shape::CreatePolygon
This commit is contained in:
parent
678b47b9bd
commit
767f619a8f
|
|
@ -240,20 +240,20 @@ void EllipseActor::SetRadius(const Vec2& radius)
|
|||
|
||||
PolygonActor::PolygonActor() {}
|
||||
|
||||
PolygonActor::PolygonActor(const Vector<Point>& points)
|
||||
PolygonActor::PolygonActor(const Vector<Point>& vertices)
|
||||
{
|
||||
SetVertices(points);
|
||||
SetVertices(vertices);
|
||||
}
|
||||
|
||||
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;
|
||||
maker.BeginPath(points[0]);
|
||||
maker.AddLines(&points[1], points.size() - 1);
|
||||
maker.BeginPath(vertices[0]);
|
||||
maker.AddLines(&vertices[1], vertices.size() - 1);
|
||||
maker.EndPath(true);
|
||||
|
||||
SetShape(maker.GetShape());
|
||||
|
|
|
|||
|
|
@ -318,15 +318,15 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 创建多边形角色
|
||||
/// @param points 多边形端点集合
|
||||
PolygonActor(const Vector<Point>& points);
|
||||
/// @param vertices 多边形端点集合
|
||||
PolygonActor(const Vector<Point>& vertices);
|
||||
|
||||
virtual ~PolygonActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置多边形端点
|
||||
/// @param points 多边形端点集合
|
||||
void SetVertices(const Vector<Point>& points);
|
||||
/// @param vertices 多边形端点集合
|
||||
void SetVertices(const Vector<Point>& vertices);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ void Button::OnEvent(Event evt)
|
|||
|
||||
if (evt == Event::Clicked && clicked_cb_)
|
||||
{
|
||||
clicked_cb_();
|
||||
clicked_cb_(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,10 @@ public:
|
|||
/// @brief 按钮回调函数
|
||||
using Callback = Function<void(Button* /* self */, Event /* evt */)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 按钮点击回调函数
|
||||
using ClickedCallback = Function<void(Button* /* self */)>;
|
||||
|
||||
Button();
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -105,7 +109,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 设置按钮回调函数
|
||||
/// @param cb 按钮回调函数
|
||||
void SetCallbackOnClicked(const Function<void()>& cb);
|
||||
void SetCallbackOnClicked(const ClickedCallback& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 按钮状态变化时
|
||||
|
|
@ -113,7 +117,7 @@ public:
|
|||
|
||||
private:
|
||||
Callback cb_;
|
||||
Function<void()> clicked_cb_;
|
||||
ClickedCallback clicked_cb_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
|
@ -123,7 +127,7 @@ inline void Button::SetCallback(const Button::Callback& cb)
|
|||
cb_ = cb;
|
||||
}
|
||||
|
||||
inline void Button::SetCallbackOnClicked(const Function<void()>& cb)
|
||||
inline void Button::SetCallbackOnClicked(const Button::ClickedCallback& cb)
|
||||
{
|
||||
clicked_cb_ = cb;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,4 +169,17 @@ ShapePtr Shape::CreateEllipse(const Point& center, const Vec2& radius)
|
|||
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
|
||||
|
|
|
|||
|
|
@ -70,6 +70,11 @@ public:
|
|||
/// @param radius ÍÖÔ²°ë¾¶
|
||||
static ShapePtr CreateEllipse(const Point& center, const Vec2& radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建多边形
|
||||
/// @param vertices 多边形端点集合
|
||||
static ShapePtr CreatePolygon(const Vector<Point>& vertices);
|
||||
|
||||
Shape();
|
||||
|
||||
/// \~chinese
|
||||
|
|
|
|||
Loading…
Reference in New Issue