From 767f619a8f436d81c0961f55469468b9914fa9b3 Mon Sep 17 00:00:00 2001 From: Nomango Date: Sun, 4 Oct 2020 04:47:49 +0800 Subject: [PATCH] [deploy] Add Shape::CreatePolygon --- src/kiwano/2d/ShapeActor.cpp | 12 ++++++------ src/kiwano/2d/ShapeActor.h | 8 ++++---- src/kiwano/base/component/Button.cpp | 2 +- src/kiwano/base/component/Button.h | 12 ++++++++---- src/kiwano/render/Shape.cpp | 13 +++++++++++++ src/kiwano/render/Shape.h | 5 +++++ 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/kiwano/2d/ShapeActor.cpp b/src/kiwano/2d/ShapeActor.cpp index ba80091e..f00fc4ec 100644 --- a/src/kiwano/2d/ShapeActor.cpp +++ b/src/kiwano/2d/ShapeActor.cpp @@ -240,20 +240,20 @@ void EllipseActor::SetRadius(const Vec2& radius) PolygonActor::PolygonActor() {} -PolygonActor::PolygonActor(const Vector& points) +PolygonActor::PolygonActor(const Vector& vertices) { - SetVertices(points); + SetVertices(vertices); } PolygonActor::~PolygonActor() {} -void PolygonActor::SetVertices(const Vector& points) +void PolygonActor::SetVertices(const Vector& 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()); diff --git a/src/kiwano/2d/ShapeActor.h b/src/kiwano/2d/ShapeActor.h index 480bd056..49141c87 100644 --- a/src/kiwano/2d/ShapeActor.h +++ b/src/kiwano/2d/ShapeActor.h @@ -318,15 +318,15 @@ public: /// \~chinese /// @brief 创建多边形角色 - /// @param points 多边形端点集合 - PolygonActor(const Vector& points); + /// @param vertices 多边形端点集合 + PolygonActor(const Vector& vertices); virtual ~PolygonActor(); /// \~chinese /// @brief 设置多边形端点 - /// @param points 多边形端点集合 - void SetVertices(const Vector& points); + /// @param vertices 多边形端点集合 + void SetVertices(const Vector& vertices); }; diff --git a/src/kiwano/base/component/Button.cpp b/src/kiwano/base/component/Button.cpp index 13ad89a0..d7f803f4 100644 --- a/src/kiwano/base/component/Button.cpp +++ b/src/kiwano/base/component/Button.cpp @@ -91,7 +91,7 @@ void Button::OnEvent(Event evt) if (evt == Event::Clicked && clicked_cb_) { - clicked_cb_(); + clicked_cb_(this); } } diff --git a/src/kiwano/base/component/Button.h b/src/kiwano/base/component/Button.h index 633593c7..8adebf37 100644 --- a/src/kiwano/base/component/Button.h +++ b/src/kiwano/base/component/Button.h @@ -90,6 +90,10 @@ public: /// @brief 按钮回调函数 using Callback = Function; + /// \~chinese + /// @brief 按钮点击回调函数 + using ClickedCallback = Function; + Button(); /// \~chinese @@ -105,15 +109,15 @@ public: /// \~chinese /// @brief 设置按钮回调函数 /// @param cb 按钮回调函数 - void SetCallbackOnClicked(const Function& cb); + void SetCallbackOnClicked(const ClickedCallback& cb); /// \~chinese /// @brief 按钮状态变化时 void OnEvent(Event evt) override; private: - Callback cb_; - Function clicked_cb_; + Callback cb_; + ClickedCallback clicked_cb_; }; /** @} */ @@ -123,7 +127,7 @@ inline void Button::SetCallback(const Button::Callback& cb) cb_ = cb; } -inline void Button::SetCallbackOnClicked(const Function& cb) +inline void Button::SetCallbackOnClicked(const Button::ClickedCallback& cb) { clicked_cb_ = cb; } diff --git a/src/kiwano/render/Shape.cpp b/src/kiwano/render/Shape.cpp index f95038d5..c20d7dbf 100644 --- a/src/kiwano/render/Shape.cpp +++ b/src/kiwano/render/Shape.cpp @@ -169,4 +169,17 @@ ShapePtr Shape::CreateEllipse(const Point& center, const Vec2& radius) return output; } +ShapePtr Shape::CreatePolygon(const Vector& 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 diff --git a/src/kiwano/render/Shape.h b/src/kiwano/render/Shape.h index 8bf40be8..ce9f58fc 100644 --- a/src/kiwano/render/Shape.h +++ b/src/kiwano/render/Shape.h @@ -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& vertices); + Shape(); /// \~chinese