diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj
index a9cdfe46..505cc43b 100644
--- a/projects/kiwano/kiwano.vcxproj
+++ b/projects/kiwano/kiwano.vcxproj
@@ -73,8 +73,8 @@
-
-
+
+
@@ -142,8 +142,8 @@
-
-
+
+
diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters
index 4281032d..6b3c7859 100644
--- a/projects/kiwano/kiwano.vcxproj.filters
+++ b/projects/kiwano/kiwano.vcxproj.filters
@@ -231,12 +231,6 @@
render
-
- render
-
-
- render
-
render
@@ -285,6 +279,12 @@
render\DirectX
+
+ render
+
+
+ render
+
@@ -440,12 +440,6 @@
render
-
- render
-
-
- render
-
render
@@ -485,5 +479,11 @@
render\DirectX
+
+ render
+
+
+ render
+
\ No newline at end of file
diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp
index e2f1fc44..23693168 100644
--- a/src/kiwano/2d/Canvas.cpp
+++ b/src/kiwano/2d/Canvas.cpp
@@ -106,6 +106,17 @@ void Canvas::PopClipRect()
ctx_->PopClipRect();
}
+void Canvas::DrawShape(ShapePtr shape)
+{
+ if (!shape)
+ return;
+
+ InitRenderTargetAndBrushs();
+ ctx_->SetCurrentBrush(stroke_brush_);
+ ctx_->DrawShape(*shape, stroke_width_, stroke_style_);
+ cache_expired_ = true;
+}
+
void Canvas::DrawLine(Point const& begin, Point const& end)
{
InitRenderTargetAndBrushs();
@@ -146,6 +157,17 @@ void Canvas::DrawRoundedRect(Rect const& rect, Vec2 const& radius)
cache_expired_ = true;
}
+void Canvas::FillShape(ShapePtr shape)
+{
+ if (!shape)
+ return;
+
+ InitRenderTargetAndBrushs();
+ ctx_->SetCurrentBrush(fill_brush_);
+ ctx_->FillShape(*shape);
+ cache_expired_ = true;
+}
+
void Canvas::FillCircle(Point const& center, float radius)
{
InitRenderTargetAndBrushs();
@@ -207,39 +229,39 @@ void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point)
void Canvas::BeginPath(Point const& begin_pos)
{
- geo_sink_.BeginPath(begin_pos);
+ shape_sink_.BeginPath(begin_pos);
}
void Canvas::EndPath(bool closed)
{
- geo_sink_.EndPath(closed);
+ shape_sink_.EndPath(closed);
}
void Canvas::AddLine(Point const& point)
{
- geo_sink_.AddLine(point);
+ shape_sink_.AddLine(point);
}
void Canvas::AddLines(Vector const& points)
{
- geo_sink_.AddLines(points);
+ shape_sink_.AddLines(points);
}
void Canvas::AddBezier(Point const& point1, Point const& point2, Point const& point3)
{
- geo_sink_.AddBezier(point1, point2, point3);
+ shape_sink_.AddBezier(point1, point2, point3);
}
void Canvas::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small)
{
- geo_sink_.AddArc(point, radius, rotation, clockwise, is_small);
+ shape_sink_.AddArc(point, radius, rotation, clockwise, is_small);
}
void Canvas::StrokePath()
{
InitRenderTargetAndBrushs();
ctx_->SetCurrentBrush(stroke_brush_);
- ctx_->DrawGeometry(geo_sink_.GetGeometry(), stroke_width_, stroke_style_);
+ ctx_->DrawShape(*shape_sink_.GetShape(), stroke_width_, stroke_style_);
cache_expired_ = true;
}
@@ -247,7 +269,7 @@ void Canvas::FillPath()
{
InitRenderTargetAndBrushs();
ctx_->SetCurrentBrush(fill_brush_);
- ctx_->FillGeometry(geo_sink_.GetGeometry());
+ ctx_->FillShape(*shape_sink_.GetShape());
cache_expired_ = true;
}
diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h
index 064b4b3d..9bafaa47 100644
--- a/src/kiwano/2d/Canvas.h
+++ b/src/kiwano/2d/Canvas.h
@@ -20,7 +20,7 @@
#pragma once
#include
-#include
+#include
#include
namespace kiwano
@@ -53,6 +53,11 @@ public:
/// @brief 结束绘图
void EndDraw();
+ /// \~chinese
+ /// @brief 画形状轮廓
+ /// @param shape 形状
+ void DrawShape(ShapePtr shape);
+
/// \~chinese
/// @brief 画线段
/// @param begin 线段起点
@@ -82,6 +87,11 @@ public:
/// @param radius 矩形圆角半径
void DrawRoundedRect(Rect const& rect, Vec2 const& radius);
+ /// \~chinese
+ /// @brief 填充形状
+ /// @param shape 形状
+ void FillShape(ShapePtr shape);
+
/// \~chinese
/// @brief 填充圆形
/// @param center 圆形原点
@@ -269,12 +279,12 @@ private:
void UpdateCache() const;
private:
- float stroke_width_;
- TextStyle text_style_;
- StrokeStyle stroke_style_;
- GeometrySink geo_sink_;
- BrushPtr fill_brush_;
- BrushPtr stroke_brush_;
+ float stroke_width_;
+ TextStyle text_style_;
+ StrokeStyle stroke_style_;
+ ShapeSink shape_sink_;
+ BrushPtr fill_brush_;
+ BrushPtr stroke_brush_;
mutable bool cache_expired_;
mutable TexturePtr texture_cached_;
diff --git a/src/kiwano/2d/Layer.cpp b/src/kiwano/2d/Layer.cpp
index dc87e891..827da390 100644
--- a/src/kiwano/2d/Layer.cpp
+++ b/src/kiwano/2d/Layer.cpp
@@ -42,9 +42,9 @@ void Layer::SetOpacity(float opacity)
area_.SetOpacity(opacity);
}
-void Layer::SetMaskGeometry(Geometry const& mask)
+void Layer::SetMaskShape(ShapePtr mask)
{
- area_.SetMaskGeometry(mask);
+ area_.SetMaskShape(mask);
}
void Layer::SetMaskTransform(Matrix3x2 const& transform)
diff --git a/src/kiwano/2d/Layer.h b/src/kiwano/2d/Layer.h
index 5c9224d2..57db29d2 100644
--- a/src/kiwano/2d/Layer.h
+++ b/src/kiwano/2d/Layer.h
@@ -65,7 +65,7 @@ public:
/// \~chinese
/// @brief 设置几何蒙层
/// @param mask 蒙层的几何形状
- void SetMaskGeometry(Geometry const& mask);
+ void SetMaskShape(ShapePtr mask);
/// \~chinese
/// @brief 设置几何蒙层的二维变换
diff --git a/src/kiwano/2d/ShapeActor.cpp b/src/kiwano/2d/ShapeActor.cpp
index 53850bb7..a69de2fd 100644
--- a/src/kiwano/2d/ShapeActor.cpp
+++ b/src/kiwano/2d/ShapeActor.cpp
@@ -24,6 +24,7 @@
namespace kiwano
{
+
ShapeActor::ShapeActor()
: stroke_width_(1.f)
, stroke_style_()
@@ -39,15 +40,18 @@ Rect ShapeActor::GetBounds() const
Rect ShapeActor::GetBoundingBox() const
{
- if (!geo_.IsValid())
+ if (!shape_)
return Rect{};
- return geo_.GetBoundingBox(GetTransformMatrix());
+ return shape_->GetBoundingBox(GetTransformMatrix());
}
bool ShapeActor::ContainsPoint(const Point& point) const
{
- return geo_.ContainsPoint(point, &GetTransformMatrix());
+ if (!shape_)
+ return false;
+
+ return shape_->ContainsPoint(point, &GetTransformMatrix());
}
void ShapeActor::SetStrokeWidth(float width)
@@ -60,12 +64,12 @@ void ShapeActor::SetStrokeStyle(const StrokeStyle& stroke_style)
stroke_style_ = stroke_style;
}
-void ShapeActor::SetGeometry(Geometry const& geometry)
+void ShapeActor::SetShape(ShapePtr shape)
{
- geo_ = geometry;
- if (geo_.IsValid())
+ shape_ = shape;
+ if (shape_)
{
- bounds_ = geo_.GetBoundingBox();
+ bounds_ = shape_->GetBoundingBox();
SetSize(bounds_.GetSize());
}
else
@@ -77,29 +81,25 @@ void ShapeActor::SetGeometry(Geometry const& geometry)
void ShapeActor::OnRender(RenderContext& ctx)
{
- // Create default brush
- if (!fill_brush_)
+ if (shape_)
{
- fill_brush_ = new Brush;
- fill_brush_->SetColor(Color::White);
+ if (stroke_brush_)
+ {
+ ctx.SetCurrentBrush(stroke_brush_);
+ ctx.DrawShape(*shape_, stroke_width_ * 2 /* twice width for widening */, stroke_style_);
+ }
+
+ if (fill_brush_)
+ {
+ ctx.SetCurrentBrush(fill_brush_);
+ ctx.FillShape(*shape_);
+ }
}
-
- if (!stroke_brush_)
- {
- stroke_brush_ = new Brush;
- stroke_brush_->SetColor(Color::Transparent);
- }
-
- ctx.SetCurrentBrush(stroke_brush_);
- ctx.DrawGeometry(geo_, stroke_width_ * 2 /* twice width for widening */, stroke_style_);
-
- ctx.SetCurrentBrush(fill_brush_);
- ctx.FillGeometry(geo_);
}
bool ShapeActor::CheckVisibility(RenderContext& ctx) const
{
- return geo_.IsValid() && Actor::CheckVisibility(ctx);
+ return shape_ && Actor::CheckVisibility(ctx);
}
//-------------------------------------------------------
@@ -116,7 +116,7 @@ void LineActor::SetLine(Point const& begin, Point const& end)
{
begin_ = begin;
end_ = end;
- SetGeometry(Geometry::CreateLine(begin, end));
+ SetShape(Shape::CreateLine(begin, end));
}
}
@@ -133,7 +133,7 @@ void RectActor::SetRectSize(Size const& size)
if (size != rect_size_)
{
rect_size_ = size;
- SetGeometry(Geometry::CreateRect(Rect{ Point{}, size }));
+ SetShape(Shape::CreateRect(Rect{ Point{}, size }));
}
}
@@ -161,7 +161,7 @@ void RoundRectActor::SetRoundedRect(Size const& size, Vec2 const& radius)
{
rect_size_ = size;
radius_ = radius;
- SetGeometry(Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius));
+ SetShape(Shape::CreateRoundedRect(Rect{ Point{}, size }, radius));
}
}
@@ -181,7 +181,7 @@ void CircleActor::SetRadius(float radius)
if (radius_ != radius)
{
radius_ = radius;
- SetGeometry(Geometry::CreateCircle(Point{ radius, radius }, radius));
+ SetShape(Shape::CreateCircle(Point{ radius, radius }, radius));
}
}
@@ -198,7 +198,7 @@ void EllipseActor::SetRadius(Vec2 const& radius)
if (radius_ != radius)
{
radius_ = radius;
- SetGeometry(Geometry::CreateEllipse(radius, radius));
+ SetShape(Shape::CreateEllipse(radius, radius));
}
}
@@ -214,8 +214,7 @@ void PolygonActor::SetVertices(Vector const& points)
{
if (points.size() > 1)
{
- SetGeometry(
- GeometrySink().BeginPath(points[0]).AddLines(&points[1], points.size() - 1).EndPath(true).GetGeometry());
+ SetShape(ShapeSink().BeginPath(points[0]).AddLines(&points[1], points.size() - 1).EndPath(true).GetShape());
}
}
diff --git a/src/kiwano/2d/ShapeActor.h b/src/kiwano/2d/ShapeActor.h
index 0f21b922..40402c96 100644
--- a/src/kiwano/2d/ShapeActor.h
+++ b/src/kiwano/2d/ShapeActor.h
@@ -21,8 +21,8 @@
#pragma once
#include
#include
-#include
-#include
+#include
+#include
#include
namespace kiwano
@@ -71,7 +71,7 @@ public:
/// \~chinese
/// @brief 获取形状
- Geometry GetGeometry() const;
+ ShapePtr GetShape() const;
/// \~chinese
/// @brief 获取边界
@@ -115,7 +115,7 @@ public:
/// \~chinese
/// @brief 设置几何形状
- void SetGeometry(Geometry const& geometry);
+ void SetShape(ShapePtr shape);
void OnRender(RenderContext& ctx) override;
@@ -128,7 +128,7 @@ private:
float stroke_width_;
StrokeStyle stroke_style_;
Rect bounds_;
- Geometry geo_;
+ ShapePtr shape_;
};
/// \~chinese
@@ -333,9 +333,9 @@ inline const StrokeStyle& ShapeActor::GetStrokeStyle() const
{
return stroke_style_;
}
-inline Geometry ShapeActor::GetGeometry() const
+inline ShapePtr ShapeActor::GetShape() const
{
- return geo_;
+ return shape_;
}
inline Point const& LineActor::GetBeginPoint() const
diff --git a/src/kiwano/2d/action/ActionGroup.cpp b/src/kiwano/2d/action/ActionGroup.cpp
index 1632c318..e52325bf 100644
--- a/src/kiwano/2d/action/ActionGroup.cpp
+++ b/src/kiwano/2d/action/ActionGroup.cpp
@@ -29,12 +29,12 @@ namespace kiwano
//-------------------------------------------------------
ActionGroup::ActionGroup()
- : sequence_(true)
+ : sync_(false)
{
}
-ActionGroup::ActionGroup(Vector const& actions, bool sequence)
- : sequence_(sequence)
+ActionGroup::ActionGroup(Vector const& actions, bool sync)
+ : sync_(sync)
{
this->Add(actions);
}
@@ -52,7 +52,7 @@ void ActionGroup::Init(Actor* target)
current_ = actions_.first_item();
current_->Restart(target); // init first action
- if (!sequence_)
+ if (sync_)
{
// init all actions
for (; current_; current_ = current_->next_item())
@@ -64,7 +64,7 @@ void ActionGroup::Init(Actor* target)
void ActionGroup::Update(Actor* target, Duration dt)
{
- if (sequence_)
+ if (!sync_)
{
if (current_)
{
@@ -116,30 +116,29 @@ void ActionGroup::Add(Vector const& actions)
ActionPtr ActionGroup::Clone() const
{
- auto group = new (std::nothrow) ActionGroup();
- if (group)
+ Vector actions;
+ if (!actions_.empty())
{
- for (auto action = actions_.first_item(); action; action = action->next_item())
+ for (auto action = actions_.last_item(); action; action = action->prev_item())
{
- if (action)
- {
- group->Add(action->Clone());
- }
+ actions.push_back(action->Clone());
}
}
+ ActionPtr group = new (std::nothrow) ActionGroup(actions, sync_);
return group;
}
ActionPtr ActionGroup::Reverse() const
{
- auto group = new (std::nothrow) ActionGroup();
- if (group && !actions_.empty())
+ Vector actions;
+ if (!actions_.empty())
{
for (auto action = actions_.last_item(); action; action = action->prev_item())
{
- group->Add(action->Reverse());
+ actions.push_back(action->Reverse());
}
}
+ ActionPtr group = new (std::nothrow) ActionGroup(actions, sync_);
return group;
}
diff --git a/src/kiwano/2d/action/ActionGroup.h b/src/kiwano/2d/action/ActionGroup.h
index ef5542a4..8ff0a964 100644
--- a/src/kiwano/2d/action/ActionGroup.h
+++ b/src/kiwano/2d/action/ActionGroup.h
@@ -42,8 +42,8 @@ public:
/// \~chinese
/// @brief 动画组合
/// @param actions 动画集合
- /// @param sequence 动画按顺序依次执行或同时执行
- explicit ActionGroup(Vector const& actions, bool sequence = true);
+ /// @param sync 同步执行
+ explicit ActionGroup(Vector const& actions, bool sync = false);
virtual ~ActionGroup();
@@ -75,7 +75,7 @@ protected:
void Update(Actor* target, Duration dt) override;
private:
- bool sequence_;
+ bool sync_;
ActionPtr current_;
ActionList actions_;
};
diff --git a/src/kiwano/2d/action/ActionHelper.h b/src/kiwano/2d/action/ActionHelper.h
index 30ad8d48..855b7c7d 100644
--- a/src/kiwano/2d/action/ActionHelper.h
+++ b/src/kiwano/2d/action/ActionHelper.h
@@ -318,7 +318,7 @@ public:
/// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比)
/// @param end 路径终点(百分比)
- static inline TweenHelper Walk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f,
+ static inline TweenHelper Walk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f,
float end = 1.f)
{
return TweenHelper(new kiwano::ActionWalk(duration, path, rotating, start, end));
@@ -353,18 +353,10 @@ public:
/// \~chinese
/// @brief 动画组合
/// @param actions 动画集合
- /// @param sequence 动画按顺序依次执行或同时执行
- static inline ActionHelper Group(Vector const& actions, bool sequence = true)
+ /// @param sync 同步执行
+ static inline ActionHelper Group(Vector const& actions, bool sync = false)
{
- return ActionHelper(new kiwano::ActionGroup(actions, sequence));
- }
-
- /// \~chinese
- /// @brief 同步动画组合
- /// @param actions 动画集合
- static inline ActionHelper Multiple(Vector const& actions)
- {
- return ActionHelper(new kiwano::ActionGroup(actions, false));
+ return ActionHelper(new kiwano::ActionGroup(actions, sync));
}
};
diff --git a/src/kiwano/2d/action/ActionWalk.cpp b/src/kiwano/2d/action/ActionWalk.cpp
index 1041f376..41833b1b 100644
--- a/src/kiwano/2d/action/ActionWalk.cpp
+++ b/src/kiwano/2d/action/ActionWalk.cpp
@@ -32,7 +32,7 @@ ActionWalk::ActionWalk(Duration duration, bool rotating, float start, float end,
{
}
-ActionWalk::ActionWalk(Duration duration, Geometry const& path, bool rotating, float start, float end, EaseFunc func)
+ActionWalk::ActionWalk(Duration duration, ShapePtr path, bool rotating, float start, float end, EaseFunc func)
: ActionWalk(duration, rotating, start, end, func)
{
path_ = path;
@@ -60,14 +60,14 @@ ActionPtr ActionWalk::Reverse() const
void ActionWalk::Init(Actor* target)
{
- if (!path_.IsValid())
+ if (!path_ || !path_->IsValid())
{
Done();
return;
}
start_pos_ = target->GetPosition();
- length_ = path_.GetLength();
+ length_ = path_->GetLength();
}
void ActionWalk::UpdateTween(Actor* target, float percent)
@@ -75,7 +75,7 @@ void ActionWalk::UpdateTween(Actor* target, float percent)
float distance = length_ * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f);
Point point, tangent;
- if (path_.ComputePointAtLength(distance, point, tangent))
+ if (path_->ComputePointAtLength(distance, point, tangent))
{
target->SetPosition(start_pos_ + point);
diff --git a/src/kiwano/2d/action/ActionWalk.h b/src/kiwano/2d/action/ActionWalk.h
index ddfe18d6..e8856a3d 100644
--- a/src/kiwano/2d/action/ActionWalk.h
+++ b/src/kiwano/2d/action/ActionWalk.h
@@ -20,8 +20,8 @@
#pragma once
#include
-#include
-#include
+#include
+#include
namespace kiwano
{
@@ -49,12 +49,12 @@ public:
/// \~chinese
/// @brief 构造路径行走动画
/// @param duration 持续时长
- /// @param path 路径几何形状
+ /// @param path 路径形状
/// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比)
/// @param end 路径终点(百分比)
/// @param func 动画速度缓动函数
- ActionWalk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f, float end = 1.f,
+ ActionWalk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f, float end = 1.f,
EaseFunc func = nullptr);
/// \~chinese
@@ -67,11 +67,11 @@ public:
/// \~chinese
/// @brief 获取路线
- Geometry const& GetPath() const;
+ ShapePtr const& GetPath() const;
/// \~chinese
/// @brief 设置路径几何形状
- void SetPath(Geometry const& path);
+ void SetPath(ShapePtr path);
protected:
void Init(Actor* target) override;
@@ -79,22 +79,22 @@ protected:
void UpdateTween(Actor* target, float percent) override;
private:
- bool rotating_;
- float start_;
- float end_;
- float length_;
- Point start_pos_;
- Geometry path_;
+ bool rotating_;
+ float start_;
+ float end_;
+ float length_;
+ Point start_pos_;
+ ShapePtr path_;
};
/** @} */
-inline Geometry const& ActionWalk::GetPath() const
+inline ShapePtr const& ActionWalk::GetPath() const
{
return path_;
}
-inline void ActionWalk::SetPath(Geometry const& path)
+inline void ActionWalk::SetPath(ShapePtr path)
{
path_ = path;
}
diff --git a/src/kiwano/kiwano.h b/src/kiwano/kiwano.h
index 5e008367..75c80195 100644
--- a/src/kiwano/kiwano.h
+++ b/src/kiwano/kiwano.h
@@ -64,13 +64,14 @@
#include
#include
-#include
+#include
+#include
+#include
#include
#include
-#include
#include
-#include
#include
+#include
//
// 2d
diff --git a/src/kiwano/render/LayerArea.h b/src/kiwano/render/LayerArea.h
index f8460d94..cd199339 100644
--- a/src/kiwano/render/LayerArea.h
+++ b/src/kiwano/render/LayerArea.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
namespace kiwano
{
@@ -55,7 +55,7 @@ public:
/// \~chinese
/// @brief 获取几何蒙层
- Geometry const& GetMaskGeometry() const;
+ ShapePtr GetMaskShape() const;
/// \~chinese
/// @brief 获取几何蒙层变换
@@ -71,7 +71,7 @@ public:
/// \~chinese
/// @brief 设置几何蒙层
- void SetMaskGeometry(Geometry const& mask);
+ void SetMaskShape(ShapePtr mask);
/// \~chinese
/// @brief 设置几何蒙层变换
@@ -85,7 +85,7 @@ private:
private:
Rect area_;
float opacity_;
- Geometry mask_;
+ ShapePtr mask_;
Matrix3x2 mask_transform_;
ComPtr layer_;
};
@@ -107,7 +107,7 @@ inline float LayerArea::GetOpacity() const
return opacity_;
}
-inline Geometry const& LayerArea::GetMaskGeometry() const
+inline ShapePtr LayerArea::GetMaskShape() const
{
return mask_;
}
@@ -127,7 +127,7 @@ inline void LayerArea::SetOpacity(float opacity)
opacity_ = opacity;
}
-inline void LayerArea::SetMaskGeometry(Geometry const& mask)
+inline void LayerArea::SetMaskShape(ShapePtr mask)
{
mask_ = mask;
}
diff --git a/src/kiwano/render/RenderContext.cpp b/src/kiwano/render/RenderContext.cpp
index db4e26af..a4c2c938 100644
--- a/src/kiwano/render/RenderContext.cpp
+++ b/src/kiwano/render/RenderContext.cpp
@@ -101,28 +101,28 @@ void RenderContext::EndDraw()
}
}
-void RenderContext::DrawGeometry(Geometry const& geometry, float stroke_width, const StrokeStyle& stroke)
+void RenderContext::DrawShape(Shape const& shape, float stroke_width, const StrokeStyle& stroke)
{
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- if (geometry.IsValid())
+ if (shape.IsValid())
{
- render_target_->DrawGeometry(geometry.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width,
- stroke.GetStrokeStyle().get());
+ render_target_->DrawGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width,
+ stroke.GetStrokeStyle().get());
IncreasePrimitivesCount();
}
}
-void RenderContext::FillGeometry(Geometry const& geometry)
+void RenderContext::FillShape(Shape const& shape)
{
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- if (geometry.IsValid())
+ if (shape.IsValid())
{
- render_target_->FillGeometry(geometry.GetGeometry().get(), current_brush_->GetBrush().get());
+ render_target_->FillGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get());
IncreasePrimitivesCount();
}
@@ -133,8 +133,8 @@ void RenderContext::DrawLine(Point const& point1, Point const& point2, float str
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), current_brush_->GetBrush().get(),
- stroke_width, stroke.GetStrokeStyle().get());
+ render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2),
+ current_brush_->GetBrush().get(), stroke_width, stroke.GetStrokeStyle().get());
IncreasePrimitivesCount();
}
@@ -145,7 +145,7 @@ void RenderContext::DrawRectangle(Rect const& rect, float stroke_width, const St
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
render_target_->DrawRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get(), stroke_width,
- stroke.GetStrokeStyle().get());
+ stroke.GetStrokeStyle().get());
IncreasePrimitivesCount();
}
@@ -167,7 +167,7 @@ void RenderContext::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, f
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
render_target_->DrawRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y),
- current_brush_->GetBrush().get(), stroke_width, stroke.GetStrokeStyle().get());
+ current_brush_->GetBrush().get(), stroke_width, stroke.GetStrokeStyle().get());
IncreasePrimitivesCount();
}
@@ -178,7 +178,7 @@ void RenderContext::FillRoundedRectangle(Rect const& rect, Vec2 const& radius)
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
render_target_->FillRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y),
- current_brush_->GetBrush().get());
+ current_brush_->GetBrush().get());
IncreasePrimitivesCount();
}
@@ -189,7 +189,7 @@ void RenderContext::DrawEllipse(Point const& center, Vec2 const& radius, float s
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
render_target_->DrawEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y),
- current_brush_->GetBrush().get(), stroke_width, stroke.GetStrokeStyle().get());
+ current_brush_->GetBrush().get(), stroke_width, stroke.GetStrokeStyle().get());
IncreasePrimitivesCount();
}
@@ -200,7 +200,7 @@ void RenderContext::FillEllipse(Point const& center, Vec2 const& radius)
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
render_target_->FillEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y),
- current_brush_->GetBrush().get());
+ current_brush_->GetBrush().get());
IncreasePrimitivesCount();
}
@@ -221,7 +221,7 @@ void RenderContext::DrawTexture(Texture const& texture, const Rect* src_rect, co
: D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR;
render_target_->DrawBitmap(texture.GetBitmap().get(), dest_rect ? &DX::ConvertToRectF(*dest_rect) : nullptr,
- brush_opacity_, mode, src_rect ? &DX::ConvertToRectF(*src_rect) : nullptr);
+ brush_opacity_, mode, src_rect ? &DX::ConvertToRectF(*src_rect) : nullptr);
IncreasePrimitivesCount();
}
@@ -269,7 +269,8 @@ void RenderContext::CreateTexture(Texture& texture, math::Vec2T size,
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
ComPtr saved_bitmap;
- HRESULT hr = render_target_->CreateBitmap(D2D1::SizeU(size.x, size.y), D2D1::BitmapProperties(format), &saved_bitmap);
+ HRESULT hr =
+ render_target_->CreateBitmap(D2D1::SizeU(size.x, size.y), D2D1::BitmapProperties(format), &saved_bitmap);
if (SUCCEEDED(hr))
{
@@ -285,7 +286,7 @@ void RenderContext::PushClipRect(Rect const& clip_rect)
{
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
render_target_->PushAxisAlignedClip(DX::ConvertToRectF(clip_rect),
- antialias_ ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED);
+ antialias_ ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED);
}
void RenderContext::PopClipRect()
@@ -314,8 +315,12 @@ void RenderContext::PushLayer(LayerArea& layer)
if (layer.IsValid())
{
+ ComPtr mask;
+ if (layer.GetMaskShape())
+ mask = layer.GetMaskShape()->GetGeometry();
+
render_target_->PushLayer(
- D2D1::LayerParameters(DX::ConvertToRectF(layer.GetAreaRect()), layer.GetMaskGeometry().GetGeometry().get(),
+ D2D1::LayerParameters(DX::ConvertToRectF(layer.GetAreaRect()), mask.get(),
antialias_ ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED,
DX::ConvertToMatrix3x2F(layer.GetMaskTransform()), layer.GetOpacity(), nullptr,
D2D1_LAYER_OPTIONS_NONE),
diff --git a/src/kiwano/render/RenderContext.h b/src/kiwano/render/RenderContext.h
index d7ec1e92..379c7ad1 100644
--- a/src/kiwano/render/RenderContext.h
+++ b/src/kiwano/render/RenderContext.h
@@ -22,7 +22,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -73,11 +73,11 @@ public:
/// \~chinese
/// @brief 是否有效
- void DrawGeometry(Geometry const& geometry, float stroke_width, const StrokeStyle& stroke = StrokeStyle());
+ void DrawShape(Shape const& shape, float stroke_width, const StrokeStyle& stroke = StrokeStyle());
/// \~chinese
/// @brief 是否有效
- void FillGeometry(Geometry const& geometry);
+ void FillShape(Shape const& shape);
/// \~chinese
/// @brief 是否有效
diff --git a/src/kiwano/render/Renderer.cpp b/src/kiwano/render/Renderer.cpp
index c6cf4695..f387fd82 100644
--- a/src/kiwano/render/Renderer.cpp
+++ b/src/kiwano/render/Renderer.cpp
@@ -21,7 +21,7 @@
#include
#include
#include
-#include
+#include
#include
namespace kiwano
@@ -629,7 +629,7 @@ void Renderer::CreateTextLayout(TextLayout& layout)
win32::ThrowIfFailed(hr);
}
-void Renderer::CreateLineGeometry(Geometry& geo, Point const& begin_pos, Point const& end_pos)
+void Renderer::CreateLineShape(Shape& shape, Point const& begin_pos, Point const& end_pos)
{
HRESULT hr = S_OK;
if (!d2d_res_)
@@ -659,13 +659,13 @@ void Renderer::CreateLineGeometry(Geometry& geo, Point const& begin_pos, Point c
if (SUCCEEDED(hr))
{
- geo.SetGeometry(path_geo);
+ shape.SetGeometry(path_geo);
}
win32::ThrowIfFailed(hr);
}
-void Renderer::CreateRectGeometry(Geometry& geo, Rect const& rect)
+void Renderer::CreateRectShape(Shape& shape, Rect const& rect)
{
HRESULT hr = S_OK;
if (!d2d_res_)
@@ -681,13 +681,13 @@ void Renderer::CreateRectGeometry(Geometry& geo, Rect const& rect)
if (SUCCEEDED(hr))
{
- geo.SetGeometry(output);
+ shape.SetGeometry(output);
}
win32::ThrowIfFailed(hr);
}
-void Renderer::CreateRoundedRectGeometry(Geometry& geo, Rect const& rect, Vec2 const& radius)
+void Renderer::CreateRoundedRectShape(Shape& shape, Rect const& rect, Vec2 const& radius)
{
HRESULT hr = S_OK;
if (!d2d_res_)
@@ -704,13 +704,13 @@ void Renderer::CreateRoundedRectGeometry(Geometry& geo, Rect const& rect, Vec2 c
if (SUCCEEDED(hr))
{
- geo.SetGeometry(output);
+ shape.SetGeometry(output);
}
win32::ThrowIfFailed(hr);
}
-void Renderer::CreateEllipseGeometry(Geometry& geo, Point const& center, Vec2 const& radius)
+void Renderer::CreateEllipseShape(Shape& shape, Point const& center, Vec2 const& radius)
{
HRESULT hr = S_OK;
if (!d2d_res_)
@@ -727,13 +727,13 @@ void Renderer::CreateEllipseGeometry(Geometry& geo, Point const& center, Vec2 co
if (SUCCEEDED(hr))
{
- geo.SetGeometry(output);
+ shape.SetGeometry(output);
}
win32::ThrowIfFailed(hr);
}
-void Renderer::CreateGeometrySink(GeometrySink& sink)
+void Renderer::CreateShapeSink(ShapeSink& sink)
{
HRESULT hr = S_OK;
if (!d2d_res_)
diff --git a/src/kiwano/render/Renderer.h b/src/kiwano/render/Renderer.h
index 21275f84..3028fbf3 100644
--- a/src/kiwano/render/Renderer.h
+++ b/src/kiwano/render/Renderer.h
@@ -137,32 +137,32 @@ public:
/// @param[out] geo 形状
/// @param[in] begin_pos 线段起点
/// @param[in] end_pos 线段终点
- void CreateLineGeometry(Geometry& geo, Point const& begin_pos, Point const& end_pos);
+ void CreateLineShape(Shape& shape, Point const& begin_pos, Point const& end_pos);
/// \~chinese
/// @brief 创建矩形形状
/// @param[out] geo 形状
/// @param[in] rect 矩形大小
- void CreateRectGeometry(Geometry& geo, Rect const& rect);
+ void CreateRectShape(Shape& shape, Rect const& rect);
/// \~chinese
/// @brief 创建圆角矩形形状
/// @param[out] geo 形状
/// @param[in] rect 矩形大小
/// @param[in] radius 圆角半径
- void CreateRoundedRectGeometry(Geometry& geo, Rect const& rect, Vec2 const& radius);
+ void CreateRoundedRectShape(Shape& shape, Rect const& rect, Vec2 const& radius);
/// \~chinese
/// @brief 创建椭圆形状
/// @param[out] geo 形状
/// @param[in] center 椭圆圆心
/// @param[in] radius 椭圆半径
- void CreateEllipseGeometry(Geometry& geo, Point const& center, Vec2 const& radius);
+ void CreateEllipseShape(Shape& shape, Point const& center, Vec2 const& radius);
/// \~chinese
/// @brief 创建几何图形生成器
/// @param[out] sink 形状生成器
- void CreateGeometrySink(GeometrySink& sink);
+ void CreateShapeSink(ShapeSink& sink);
/// \~chinese
/// @brief 创建纹理渲染上下文
diff --git a/src/kiwano/render/Geometry.cpp b/src/kiwano/render/Shape.cpp
similarity index 67%
rename from src/kiwano/render/Geometry.cpp
rename to src/kiwano/render/Shape.cpp
index 63400f42..ed45dae6 100644
--- a/src/kiwano/render/Geometry.cpp
+++ b/src/kiwano/render/Shape.cpp
@@ -18,21 +18,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
-#include
+#include
+#include
#include
namespace kiwano
{
-Geometry::Geometry() {}
+Shape::Shape() {}
-bool Geometry::IsValid() const
+bool Shape::IsValid() const
{
return geo_ != nullptr;
}
-Rect Geometry::GetBoundingBox() const
+Rect Shape::GetBoundingBox() const
{
Rect bounds;
if (geo_)
@@ -43,7 +43,7 @@ Rect Geometry::GetBoundingBox() const
return bounds;
}
-Rect Geometry::GetBoundingBox(Matrix3x2 const& transform) const
+Rect Shape::GetBoundingBox(Matrix3x2 const& transform) const
{
Rect bounds;
if (geo_)
@@ -54,7 +54,7 @@ Rect Geometry::GetBoundingBox(Matrix3x2 const& transform) const
return bounds;
}
-float Geometry::GetLength() const
+float Shape::GetLength() const
{
float length = 0.f;
if (geo_)
@@ -65,7 +65,7 @@ float Geometry::GetLength() const
return length;
}
-bool Geometry::ComputePointAtLength(float length, Point& point, Vec2& tangent) const
+bool Shape::ComputePointAtLength(float length, Point& point, Vec2& tangent) const
{
if (geo_)
{
@@ -77,12 +77,12 @@ bool Geometry::ComputePointAtLength(float length, Point& point, Vec2& tangent) c
return false;
}
-void Geometry::Clear()
+void Shape::Clear()
{
geo_.reset();
}
-float Geometry::ComputeArea() const
+float Shape::ComputeArea() const
{
if (!geo_)
return 0.f;
@@ -93,7 +93,7 @@ float Geometry::ComputeArea() const
return area;
}
-bool Geometry::ContainsPoint(Point const& point, const Matrix3x2* transform) const
+bool Shape::ContainsPoint(Point const& point, const Matrix3x2* transform) const
{
if (!geo_)
return false;
@@ -105,38 +105,38 @@ bool Geometry::ContainsPoint(Point const& point, const Matrix3x2* transform) con
return !!ret;
}
-Geometry Geometry::CreateLine(Point const& begin, Point const& end)
+ShapePtr Shape::CreateLine(Point const& begin, Point const& end)
{
- Geometry output;
- Renderer::Instance().CreateLineGeometry(output, begin, end);
+ ShapePtr output = new Shape;
+ Renderer::Instance().CreateLineShape(*output, begin, end);
return output;
}
-Geometry Geometry::CreateRect(Rect const& rect)
+ShapePtr Shape::CreateRect(Rect const& rect)
{
- Geometry output;
- Renderer::Instance().CreateRectGeometry(output, rect);
+ ShapePtr output = new Shape;
+ Renderer::Instance().CreateRectShape(*output, rect);
return output;
}
-Geometry Geometry::CreateRoundedRect(Rect const& rect, Vec2 const& radius)
+ShapePtr Shape::CreateRoundedRect(Rect const& rect, Vec2 const& radius)
{
- Geometry output;
- Renderer::Instance().CreateRoundedRectGeometry(output, rect, radius);
+ ShapePtr output = new Shape;
+ Renderer::Instance().CreateRoundedRectShape(*output, rect, radius);
return output;
}
-Geometry Geometry::CreateCircle(Point const& center, float radius)
+ShapePtr Shape::CreateCircle(Point const& center, float radius)
{
- Geometry output;
- Renderer::Instance().CreateEllipseGeometry(output, center, Vec2{ radius, radius });
+ ShapePtr output = new Shape;
+ Renderer::Instance().CreateEllipseShape(*output, center, Vec2{ radius, radius });
return output;
}
-Geometry Geometry::CreateEllipse(Point const& center, Vec2 const& radius)
+ShapePtr Shape::CreateEllipse(Point const& center, Vec2 const& radius)
{
- Geometry output;
- Renderer::Instance().CreateEllipseGeometry(output, center, radius);
+ ShapePtr output = new Shape;
+ Renderer::Instance().CreateEllipseShape(*output, center, radius);
return output;
}
diff --git a/src/kiwano/render/Geometry.h b/src/kiwano/render/Shape.h
similarity index 82%
rename from src/kiwano/render/Geometry.h
rename to src/kiwano/render/Shape.h
index c13ecc81..1d2f3a66 100644
--- a/src/kiwano/render/Geometry.h
+++ b/src/kiwano/render/Shape.h
@@ -19,13 +19,16 @@
// THE SOFTWARE.
#pragma once
+#include
#include
namespace kiwano
{
class RenderContext;
class Renderer;
-class GeometrySink;
+class ShapeSink;
+
+KGE_DECLARE_SMART_PTR(Shape);
/**
* \addtogroup Render
@@ -36,14 +39,14 @@ class GeometrySink;
* \~chinese
* @brief 几何形状
*/
-class KGE_API Geometry
+class KGE_API Shape : public virtual ObjectBase
{
friend class RenderContext;
friend class Renderer;
- friend class GeometrySink;
+ friend class ShapeSink;
public:
- Geometry();
+ Shape();
/// \~chinese
/// @brief 是否有效
@@ -88,35 +91,35 @@ public:
/// @brief 创建线段
/// @param begin 线段起点
/// @param end 线段终点
- static Geometry CreateLine(Point const& begin, Point const& end);
+ static ShapePtr CreateLine(Point const& begin, Point const& end);
/// \~chinese
/// @brief 创建矩形
/// @param rect 矩形
- static Geometry CreateRect(Rect const& rect);
+ static ShapePtr CreateRect(Rect const& rect);
/// \~chinese
/// @brief 创建圆角矩形
/// @param rect 矩形
/// @param radius 矩形圆角半径
- static Geometry CreateRoundedRect(Rect const& rect, Vec2 const& radius);
+ static ShapePtr CreateRoundedRect(Rect const& rect, Vec2 const& radius);
/// \~chinese
/// @brief 创建圆形
/// @param center 圆形原点
/// @param radius 圆形半径
- static Geometry CreateCircle(Point const& center, float radius);
+ static ShapePtr CreateCircle(Point const& center, float radius);
/// \~chinese
/// @brief 创建椭圆形
/// @param center 椭圆原点
/// @param radius 椭圆半径
- static Geometry CreateEllipse(Point const& center, Vec2 const& radius);
+ static ShapePtr CreateEllipse(Point const& center, Vec2 const& radius);
private:
ComPtr GetGeometry() const;
- void SetGeometry(ComPtr geometry);
+ void SetGeometry(ComPtr shape);
private:
ComPtr geo_;
@@ -124,13 +127,14 @@ private:
/** @} */
-inline ComPtr Geometry::GetGeometry() const
+inline ComPtr Shape::GetGeometry() const
{
return geo_;
}
-inline void Geometry::SetGeometry(ComPtr geometry)
+inline void Shape::SetGeometry(ComPtr shape)
{
- geo_ = geometry;
+ geo_ = shape;
}
+
} // namespace kiwano
diff --git a/src/kiwano/render/GeometrySink.cpp b/src/kiwano/render/ShapeSink.cpp
similarity index 69%
rename from src/kiwano/render/GeometrySink.cpp
rename to src/kiwano/render/ShapeSink.cpp
index 3aa2059a..63918f10 100644
--- a/src/kiwano/render/GeometrySink.cpp
+++ b/src/kiwano/render/ShapeSink.cpp
@@ -18,67 +18,70 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
+#include
#include
namespace kiwano
{
-GeometrySink::GeometrySink() {}
+ShapeSink::ShapeSink() {}
-GeometrySink::~GeometrySink()
+ShapeSink::~ShapeSink()
{
Close();
}
-void GeometrySink::Open()
+void ShapeSink::Open()
{
if (!IsOpened())
{
path_geo_.reset();
- Renderer::Instance().CreateGeometrySink(*this);
+ Renderer::Instance().CreateShapeSink(*this);
win32::ThrowIfFailed(path_geo_->Open(&sink_));
}
}
-void GeometrySink::Close()
+void ShapeSink::Close()
{
if (IsOpened())
{
win32::ThrowIfFailed(sink_->Close());
sink_.reset();
}
+
+ shape_ = new Shape;
+ shape_->SetGeometry(path_geo_);
}
-bool GeometrySink::IsOpened() const
+bool ShapeSink::IsOpened() const
{
return sink_ != nullptr;
}
-Geometry GeometrySink::GetGeometry()
+ShapePtr ShapeSink::GetShape()
{
Close();
-
- Geometry geo;
- geo.SetGeometry(path_geo_);
- return geo;
+ return shape_;
}
-GeometrySink& GeometrySink::AddGeometry(Geometry const& input, const Matrix3x2* input_matrix)
+ShapeSink& ShapeSink::AddShape(ShapePtr input, const Matrix3x2* input_matrix)
{
if (!IsOpened())
{
Open();
}
- ComPtr geo = input.geo_;
- win32::ThrowIfFailed(
- geo->Outline(DX::ConvertToMatrix3x2F(input_matrix), D2D1_DEFAULT_FLATTENING_TOLERANCE, sink_.get()));
+ if (input && input->IsValid())
+ {
+ ComPtr geo = input->GetGeometry();
+ win32::ThrowIfFailed(
+ geo->Outline(DX::ConvertToMatrix3x2F(input_matrix), D2D1_DEFAULT_FLATTENING_TOLERANCE, sink_.get()));
+ }
return (*this);
}
-GeometrySink& GeometrySink::BeginPath(Point const& begin_pos)
+ShapeSink& ShapeSink::BeginPath(Point const& begin_pos)
{
if (!IsOpened())
{
@@ -89,35 +92,35 @@ GeometrySink& GeometrySink::BeginPath(Point const& begin_pos)
return (*this);
}
-GeometrySink& GeometrySink::EndPath(bool closed)
+ShapeSink& ShapeSink::EndPath(bool closed)
{
KGE_ASSERT(sink_);
sink_->EndFigure(closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN);
return (*this);
}
-GeometrySink& GeometrySink::AddLine(Point const& point)
+ShapeSink& ShapeSink::AddLine(Point const& point)
{
KGE_ASSERT(sink_);
sink_->AddLine(DX::ConvertToPoint2F(point));
return (*this);
}
-GeometrySink& GeometrySink::AddLines(Vector const& points)
+ShapeSink& ShapeSink::AddLines(Vector const& points)
{
KGE_ASSERT(sink_);
sink_->AddLines(reinterpret_cast(&points[0]), static_cast(points.size()));
return (*this);
}
-GeometrySink& kiwano::GeometrySink::AddLines(const Point* points, size_t count)
+ShapeSink& kiwano::ShapeSink::AddLines(const Point* points, size_t count)
{
KGE_ASSERT(sink_);
sink_->AddLines(reinterpret_cast(points), UINT32(count));
return (*this);
}
-GeometrySink& GeometrySink::AddBezier(Point const& point1, Point const& point2, Point const& point3)
+ShapeSink& ShapeSink::AddBezier(Point const& point1, Point const& point2, Point const& point3)
{
KGE_ASSERT(sink_);
sink_->AddBezier(
@@ -125,8 +128,7 @@ GeometrySink& GeometrySink::AddBezier(Point const& point1, Point const& point2,
return (*this);
}
-GeometrySink& GeometrySink::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise,
- bool is_small)
+ShapeSink& ShapeSink::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small)
{
KGE_ASSERT(sink_);
sink_->AddArc(D2D1::ArcSegment(DX::ConvertToPoint2F(point), DX::ConvertToSizeF(radius), rotation,
@@ -135,8 +137,7 @@ GeometrySink& GeometrySink::AddArc(Point const& point, Size const& radius, float
return (*this);
}
-GeometrySink& GeometrySink::Combine(Geometry const& geo_a, Geometry const& geo_b, CombineMode mode,
- const Matrix3x2* matrix)
+ShapeSink& ShapeSink::Combine(Shape const& geo_a, Shape const& geo_b, CombineMode mode, const Matrix3x2* matrix)
{
if (!IsOpened())
{
@@ -150,7 +151,7 @@ GeometrySink& GeometrySink::Combine(Geometry const& geo_a, Geometry const& geo_b
return (*this);
}
-void GeometrySink::Clear()
+void ShapeSink::Clear()
{
Close();
diff --git a/src/kiwano/render/GeometrySink.h b/src/kiwano/render/ShapeSink.h
similarity index 77%
rename from src/kiwano/render/GeometrySink.h
rename to src/kiwano/render/ShapeSink.h
index 2f09cdd6..29bab62e 100644
--- a/src/kiwano/render/GeometrySink.h
+++ b/src/kiwano/render/ShapeSink.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
namespace kiwano
{
@@ -43,14 +43,14 @@ enum class CombineMode
/// \~chinese
/// @brief 几何形状生成器
-class KGE_API GeometrySink : protected Noncopyable
+class KGE_API ShapeSink : protected Noncopyable
{
friend class Renderer;
public:
- GeometrySink();
+ ShapeSink();
- ~GeometrySink();
+ ~ShapeSink();
/// \~chinese
/// @brief 打开输入流
@@ -68,48 +68,48 @@ public:
/// \~chinese
/// @brief 获取生成的几何形状
/// @note 若还未关闭输入流,则自动关闭
- Geometry GetGeometry();
+ ShapePtr GetShape();
/// \~chinese
/// @brief 添加几何形状的轮廓
/// @param input 输入的形状
/// @param input_matrix 应用到输入形状上的二维变换
/// @note 若还未打开输入流,则自动打开
- GeometrySink& AddGeometry(Geometry const& input, const Matrix3x2* input_matrix = nullptr);
+ ShapeSink& AddShape(ShapePtr input, const Matrix3x2* input_matrix = nullptr);
/// \~chinese
/// @brief 开始添加路径
/// @param begin_pos 路径起始点
/// @note 若还未打开输入流,则自动打开
- GeometrySink& BeginPath(Point const& begin_pos = Point());
+ ShapeSink& BeginPath(Point const& begin_pos = Point());
/// \~chinese
/// @brief 结束路径
/// @param closed 路径是否闭合
- GeometrySink& EndPath(bool closed = false);
+ ShapeSink& EndPath(bool closed = false);
/// \~chinese
/// @brief 添加一条线段
/// @param point 端点
- GeometrySink& AddLine(Point const& point);
+ ShapeSink& AddLine(Point const& point);
/// \~chinese
/// @brief 添加多条线段
/// @param points 端点集合
- GeometrySink& AddLines(Vector const& points);
+ ShapeSink& AddLines(Vector const& points);
/// \~chinese
/// @brief 添加多条线段
/// @param points 端点数组
/// @param count 端点数量
- GeometrySink& AddLines(const Point* points, size_t count);
+ ShapeSink& AddLines(const Point* points, size_t count);
/// \~chinese
/// @brief 添加一条三次方贝塞尔曲线
/// @param point1 贝塞尔曲线的第一个控制点
/// @param point2 贝塞尔曲线的第二个控制点
/// @param point3 贝塞尔曲线的终点
- GeometrySink& AddBezier(Point const& point1, Point const& point2, Point const& point3);
+ ShapeSink& AddBezier(Point const& point1, Point const& point2, Point const& point3);
/// \~chinese
/// @brief 添加弧线
@@ -118,7 +118,7 @@ public:
/// @param rotation 椭圆旋转角度
/// @param clockwise 顺时针 or 逆时针
/// @param is_small 是否取小于 180° 的弧
- GeometrySink& AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true,
+ ShapeSink& AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true,
bool is_small = true);
/// \~chinese
@@ -128,7 +128,7 @@ public:
/// @param mode 组合方式
/// @param matrix 应用到输入形状B上的二维变换
/// @note 若还未打开输入流,则自动打开
- GeometrySink& Combine(Geometry const& geo_a, Geometry const& geo_b, CombineMode mode,
+ ShapeSink& Combine(Shape const& geo_a, Shape const& geo_b, CombineMode mode,
const Matrix3x2* matrix = nullptr);
/// \~chinese
@@ -145,28 +145,29 @@ private:
void SetGeometrySink(ComPtr sink);
private:
+ ShapePtr shape_;
ComPtr path_geo_;
ComPtr sink_;
};
/** @} */
-inline ComPtr GeometrySink::GetPathGeometry() const
+inline ComPtr ShapeSink::GetPathGeometry() const
{
return path_geo_;
}
-inline void GeometrySink::SetPathGeometry(ComPtr path)
+inline void ShapeSink::SetPathGeometry(ComPtr path)
{
path_geo_ = path;
}
-inline ComPtr GeometrySink::GetGeometrySink() const
+inline ComPtr ShapeSink::GetGeometrySink() const
{
return sink_;
}
-inline void GeometrySink::SetGeometrySink(ComPtr sink)
+inline void ShapeSink::SetGeometrySink(ComPtr sink)
{
sink_ = sink;
}