rename Geometry to Shape

This commit is contained in:
Nomango 2020-02-05 19:56:22 +08:00
parent 9ea6781f0e
commit 92f738a14d
23 changed files with 283 additions and 249 deletions

View File

@ -73,8 +73,8 @@
<ClInclude Include="..\..\src\kiwano\render\DirectX\helper.h" /> <ClInclude Include="..\..\src\kiwano\render\DirectX\helper.h" />
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h" /> <ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h" />
<ClInclude Include="..\..\src\kiwano\render\Font.h" /> <ClInclude Include="..\..\src\kiwano\render\Font.h" />
<ClInclude Include="..\..\src\kiwano\render\Geometry.h" /> <ClInclude Include="..\..\src\kiwano\render\Shape.h" />
<ClInclude Include="..\..\src\kiwano\render\GeometrySink.h" /> <ClInclude Include="..\..\src\kiwano\render\ShapeSink.h" />
<ClInclude Include="..\..\src\kiwano\render\GifImage.h" /> <ClInclude Include="..\..\src\kiwano\render\GifImage.h" />
<ClInclude Include="..\..\src\kiwano\render\LayerArea.h" /> <ClInclude Include="..\..\src\kiwano\render\LayerArea.h" />
<ClInclude Include="..\..\src\kiwano\render\RenderContext.h" /> <ClInclude Include="..\..\src\kiwano\render\RenderContext.h" />
@ -142,8 +142,8 @@
<ClCompile Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.cpp" /> <ClCompile Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.cpp" />
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp" /> <ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp" />
<ClCompile Include="..\..\src\kiwano\render\Font.cpp" /> <ClCompile Include="..\..\src\kiwano\render\Font.cpp" />
<ClCompile Include="..\..\src\kiwano\render\Geometry.cpp" /> <ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
<ClCompile Include="..\..\src\kiwano\render\GeometrySink.cpp" /> <ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp" />
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp" /> <ClCompile Include="..\..\src\kiwano\render\GifImage.cpp" />
<ClCompile Include="..\..\src\kiwano\render\LayerArea.cpp" /> <ClCompile Include="..\..\src\kiwano\render\LayerArea.cpp" />
<ClCompile Include="..\..\src\kiwano\render\RenderContext.cpp" /> <ClCompile Include="..\..\src\kiwano\render\RenderContext.cpp" />

View File

@ -231,12 +231,6 @@
<ClInclude Include="..\..\src\kiwano\render\Font.h"> <ClInclude Include="..\..\src\kiwano\render\Font.h">
<Filter>render</Filter> <Filter>render</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\kiwano\render\Geometry.h">
<Filter>render</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\render\GeometrySink.h">
<Filter>render</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\render\GifImage.h"> <ClInclude Include="..\..\src\kiwano\render\GifImage.h">
<Filter>render</Filter> <Filter>render</Filter>
</ClInclude> </ClInclude>
@ -285,6 +279,12 @@
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h"> <ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h">
<Filter>render\DirectX</Filter> <Filter>render\DirectX</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\kiwano\render\Shape.h">
<Filter>render</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\render\ShapeSink.h">
<Filter>render</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp"> <ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
@ -440,12 +440,6 @@
<ClCompile Include="..\..\src\kiwano\render\Font.cpp"> <ClCompile Include="..\..\src\kiwano\render\Font.cpp">
<Filter>render</Filter> <Filter>render</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\kiwano\render\Geometry.cpp">
<Filter>render</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\render\GeometrySink.cpp">
<Filter>render</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp"> <ClCompile Include="..\..\src\kiwano\render\GifImage.cpp">
<Filter>render</Filter> <Filter>render</Filter>
</ClCompile> </ClCompile>
@ -485,5 +479,11 @@
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp"> <ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp">
<Filter>render\DirectX</Filter> <Filter>render\DirectX</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp">
<Filter>render</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp">
<Filter>render</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -106,6 +106,17 @@ void Canvas::PopClipRect()
ctx_->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) void Canvas::DrawLine(Point const& begin, Point const& end)
{ {
InitRenderTargetAndBrushs(); InitRenderTargetAndBrushs();
@ -146,6 +157,17 @@ void Canvas::DrawRoundedRect(Rect const& rect, Vec2 const& radius)
cache_expired_ = true; 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) void Canvas::FillCircle(Point const& center, float radius)
{ {
InitRenderTargetAndBrushs(); InitRenderTargetAndBrushs();
@ -207,39 +229,39 @@ void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point)
void Canvas::BeginPath(Point const& begin_pos) void Canvas::BeginPath(Point const& begin_pos)
{ {
geo_sink_.BeginPath(begin_pos); shape_sink_.BeginPath(begin_pos);
} }
void Canvas::EndPath(bool closed) void Canvas::EndPath(bool closed)
{ {
geo_sink_.EndPath(closed); shape_sink_.EndPath(closed);
} }
void Canvas::AddLine(Point const& point) void Canvas::AddLine(Point const& point)
{ {
geo_sink_.AddLine(point); shape_sink_.AddLine(point);
} }
void Canvas::AddLines(Vector<Point> const& points) void Canvas::AddLines(Vector<Point> const& points)
{ {
geo_sink_.AddLines(points); shape_sink_.AddLines(points);
} }
void Canvas::AddBezier(Point const& point1, Point const& point2, Point const& point3) 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) 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() void Canvas::StrokePath()
{ {
InitRenderTargetAndBrushs(); InitRenderTargetAndBrushs();
ctx_->SetCurrentBrush(stroke_brush_); 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; cache_expired_ = true;
} }
@ -247,7 +269,7 @@ void Canvas::FillPath()
{ {
InitRenderTargetAndBrushs(); InitRenderTargetAndBrushs();
ctx_->SetCurrentBrush(fill_brush_); ctx_->SetCurrentBrush(fill_brush_);
ctx_->FillGeometry(geo_sink_.GetGeometry()); ctx_->FillShape(*shape_sink_.GetShape());
cache_expired_ = true; cache_expired_ = true;
} }

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include <kiwano/2d/Actor.h> #include <kiwano/2d/Actor.h>
#include <kiwano/render/GeometrySink.h> #include <kiwano/render/ShapeSink.h>
#include <kiwano/render/RenderContext.h> #include <kiwano/render/RenderContext.h>
namespace kiwano namespace kiwano
@ -53,6 +53,11 @@ public:
/// @brief 结束绘图 /// @brief 结束绘图
void EndDraw(); void EndDraw();
/// \~chinese
/// @brief »­ÐÎ×´ÂÖÀª
/// @param shape ÐÎ×´
void DrawShape(ShapePtr shape);
/// \~chinese /// \~chinese
/// @brief 画线段 /// @brief 画线段
/// @param begin 线段起点 /// @param begin 线段起点
@ -82,6 +87,11 @@ public:
/// @param radius 矩形圆角半径 /// @param radius 矩形圆角半径
void DrawRoundedRect(Rect const& rect, Vec2 const& radius); void DrawRoundedRect(Rect const& rect, Vec2 const& radius);
/// \~chinese
/// @brief Ìî³äÐÎ×´
/// @param shape ÐÎ×´
void FillShape(ShapePtr shape);
/// \~chinese /// \~chinese
/// @brief 填充圆形 /// @brief 填充圆形
/// @param center 圆形原点 /// @param center 圆形原点
@ -269,12 +279,12 @@ private:
void UpdateCache() const; void UpdateCache() const;
private: private:
float stroke_width_; float stroke_width_;
TextStyle text_style_; TextStyle text_style_;
StrokeStyle stroke_style_; StrokeStyle stroke_style_;
GeometrySink geo_sink_; ShapeSink shape_sink_;
BrushPtr fill_brush_; BrushPtr fill_brush_;
BrushPtr stroke_brush_; BrushPtr stroke_brush_;
mutable bool cache_expired_; mutable bool cache_expired_;
mutable TexturePtr texture_cached_; mutable TexturePtr texture_cached_;

View File

@ -42,9 +42,9 @@ void Layer::SetOpacity(float opacity)
area_.SetOpacity(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) void Layer::SetMaskTransform(Matrix3x2 const& transform)

View File

@ -65,7 +65,7 @@ public:
/// \~chinese /// \~chinese
/// @brief <20>零섯부촁꿔 /// @brief <20>零섯부촁꿔
/// @param mask 촁꿔돨섯부近榴 /// @param mask 촁꿔돨섯부近榴
void SetMaskGeometry(Geometry const& mask); void SetMaskShape(ShapePtr mask);
/// \~chinese /// \~chinese
/// @brief <20>零섯부촁꿔돨랗郭긴뻣 /// @brief <20>零섯부촁꿔돨랗郭긴뻣

View File

@ -24,6 +24,7 @@
namespace kiwano namespace kiwano
{ {
ShapeActor::ShapeActor() ShapeActor::ShapeActor()
: stroke_width_(1.f) : stroke_width_(1.f)
, stroke_style_() , stroke_style_()
@ -39,15 +40,18 @@ Rect ShapeActor::GetBounds() const
Rect ShapeActor::GetBoundingBox() const Rect ShapeActor::GetBoundingBox() const
{ {
if (!geo_.IsValid()) if (!shape_)
return Rect{}; return Rect{};
return geo_.GetBoundingBox(GetTransformMatrix()); return shape_->GetBoundingBox(GetTransformMatrix());
} }
bool ShapeActor::ContainsPoint(const Point& point) const 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) void ShapeActor::SetStrokeWidth(float width)
@ -60,12 +64,12 @@ void ShapeActor::SetStrokeStyle(const StrokeStyle& stroke_style)
stroke_style_ = stroke_style; stroke_style_ = stroke_style;
} }
void ShapeActor::SetGeometry(Geometry const& geometry) void ShapeActor::SetShape(ShapePtr shape)
{ {
geo_ = geometry; shape_ = shape;
if (geo_.IsValid()) if (shape_)
{ {
bounds_ = geo_.GetBoundingBox(); bounds_ = shape_->GetBoundingBox();
SetSize(bounds_.GetSize()); SetSize(bounds_.GetSize());
} }
else else
@ -77,29 +81,25 @@ void ShapeActor::SetGeometry(Geometry const& geometry)
void ShapeActor::OnRender(RenderContext& ctx) void ShapeActor::OnRender(RenderContext& ctx)
{ {
// Create default brush if (shape_)
if (!fill_brush_)
{ {
fill_brush_ = new Brush; if (stroke_brush_)
fill_brush_->SetColor(Color::White); {
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 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; begin_ = begin;
end_ = end; 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_) if (size != rect_size_)
{ {
rect_size_ = 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; rect_size_ = size;
radius_ = radius; 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) if (radius_ != radius)
{ {
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) if (radius_ != radius)
{ {
radius_ = radius; radius_ = radius;
SetGeometry(Geometry::CreateEllipse(radius, radius)); SetShape(Shape::CreateEllipse(radius, radius));
} }
} }
@ -214,8 +214,7 @@ void PolygonActor::SetVertices(Vector<Point> const& points)
{ {
if (points.size() > 1) if (points.size() > 1)
{ {
SetGeometry( SetShape(ShapeSink().BeginPath(points[0]).AddLines(&points[1], points.size() - 1).EndPath(true).GetShape());
GeometrySink().BeginPath(points[0]).AddLines(&points[1], points.size() - 1).EndPath(true).GetGeometry());
} }
} }

View File

@ -21,8 +21,8 @@
#pragma once #pragma once
#include <kiwano/2d/Actor.h> #include <kiwano/2d/Actor.h>
#include <kiwano/render/Brush.h> #include <kiwano/render/Brush.h>
#include <kiwano/render/Geometry.h> #include <kiwano/render/Shape.h>
#include <kiwano/render/GeometrySink.h> #include <kiwano/render/ShapeSink.h>
#include <kiwano/render/StrokeStyle.h> #include <kiwano/render/StrokeStyle.h>
namespace kiwano namespace kiwano
@ -71,7 +71,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 삿혤近榴 /// @brief 삿혤近榴
Geometry GetGeometry() const; ShapePtr GetShape() const;
/// \~chinese /// \~chinese
/// @brief 삿혤긋썹 /// @brief 삿혤긋썹
@ -115,7 +115,7 @@ public:
/// \~chinese /// \~chinese
/// @brief <20>零섯부近榴 /// @brief <20>零섯부近榴
void SetGeometry(Geometry const& geometry); void SetShape(ShapePtr shape);
void OnRender(RenderContext& ctx) override; void OnRender(RenderContext& ctx) override;
@ -128,7 +128,7 @@ private:
float stroke_width_; float stroke_width_;
StrokeStyle stroke_style_; StrokeStyle stroke_style_;
Rect bounds_; Rect bounds_;
Geometry geo_; ShapePtr shape_;
}; };
/// \~chinese /// \~chinese
@ -333,9 +333,9 @@ inline const StrokeStyle& ShapeActor::GetStrokeStyle() const
{ {
return stroke_style_; return stroke_style_;
} }
inline Geometry ShapeActor::GetGeometry() const inline ShapePtr ShapeActor::GetShape() const
{ {
return geo_; return shape_;
} }
inline Point const& LineActor::GetBeginPoint() const inline Point const& LineActor::GetBeginPoint() const

View File

@ -29,12 +29,12 @@ namespace kiwano
//------------------------------------------------------- //-------------------------------------------------------
ActionGroup::ActionGroup() ActionGroup::ActionGroup()
: sequence_(true) : sync_(false)
{ {
} }
ActionGroup::ActionGroup(Vector<ActionPtr> const& actions, bool sequence) ActionGroup::ActionGroup(Vector<ActionPtr> const& actions, bool sync)
: sequence_(sequence) : sync_(sync)
{ {
this->Add(actions); this->Add(actions);
} }
@ -52,7 +52,7 @@ void ActionGroup::Init(Actor* target)
current_ = actions_.first_item(); current_ = actions_.first_item();
current_->Restart(target); // init first action current_->Restart(target); // init first action
if (!sequence_) if (sync_)
{ {
// init all actions // init all actions
for (; current_; current_ = current_->next_item()) for (; current_; current_ = current_->next_item())
@ -64,7 +64,7 @@ void ActionGroup::Init(Actor* target)
void ActionGroup::Update(Actor* target, Duration dt) void ActionGroup::Update(Actor* target, Duration dt)
{ {
if (sequence_) if (!sync_)
{ {
if (current_) if (current_)
{ {
@ -116,30 +116,29 @@ void ActionGroup::Add(Vector<ActionPtr> const& actions)
ActionPtr ActionGroup::Clone() const ActionPtr ActionGroup::Clone() const
{ {
auto group = new (std::nothrow) ActionGroup(); Vector<ActionPtr> actions;
if (group) 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) actions.push_back(action->Clone());
{
group->Add(action->Clone());
}
} }
} }
ActionPtr group = new (std::nothrow) ActionGroup(actions, sync_);
return group; return group;
} }
ActionPtr ActionGroup::Reverse() const ActionPtr ActionGroup::Reverse() const
{ {
auto group = new (std::nothrow) ActionGroup(); Vector<ActionPtr> actions;
if (group && !actions_.empty()) if (!actions_.empty())
{ {
for (auto action = actions_.last_item(); action; action = action->prev_item()) 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; return group;
} }

View File

@ -42,8 +42,8 @@ public:
/// \~chinese /// \~chinese
/// @brief 动画组合 /// @brief 动画组合
/// @param actions 动画集合 /// @param actions 动画集合
/// @param sequence 动画按顺序依次执行或同时执行 /// @param sync 同步执行
explicit ActionGroup(Vector<ActionPtr> const& actions, bool sequence = true); explicit ActionGroup(Vector<ActionPtr> const& actions, bool sync = false);
virtual ~ActionGroup(); virtual ~ActionGroup();
@ -75,7 +75,7 @@ protected:
void Update(Actor* target, Duration dt) override; void Update(Actor* target, Duration dt) override;
private: private:
bool sequence_; bool sync_;
ActionPtr current_; ActionPtr current_;
ActionList actions_; ActionList actions_;
}; };

View File

@ -318,7 +318,7 @@ public:
/// @param rotating 是否沿路径切线方向旋转 /// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比) /// @param start 路径起点(百分比)
/// @param end 路径终点(百分比) /// @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) float end = 1.f)
{ {
return TweenHelper(new kiwano::ActionWalk(duration, path, rotating, start, end)); return TweenHelper(new kiwano::ActionWalk(duration, path, rotating, start, end));
@ -353,18 +353,10 @@ public:
/// \~chinese /// \~chinese
/// @brief 动画组合 /// @brief 动画组合
/// @param actions 动画集合 /// @param actions 动画集合
/// @param sequence 动画按顺序依次执行或同时执行 /// @param sync 同步执行
static inline ActionHelper Group(Vector<ActionPtr> const& actions, bool sequence = true) static inline ActionHelper Group(Vector<ActionPtr> const& actions, bool sync = false)
{ {
return ActionHelper(new kiwano::ActionGroup(actions, sequence)); return ActionHelper(new kiwano::ActionGroup(actions, sync));
}
/// \~chinese
/// @brief 同步动画组合
/// @param actions 动画集合
static inline ActionHelper Multiple(Vector<ActionPtr> const& actions)
{
return ActionHelper(new kiwano::ActionGroup(actions, false));
} }
}; };

View File

@ -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) : ActionWalk(duration, rotating, start, end, func)
{ {
path_ = path; path_ = path;
@ -60,14 +60,14 @@ ActionPtr ActionWalk::Reverse() const
void ActionWalk::Init(Actor* target) void ActionWalk::Init(Actor* target)
{ {
if (!path_.IsValid()) if (!path_ || !path_->IsValid())
{ {
Done(); Done();
return; return;
} }
start_pos_ = target->GetPosition(); start_pos_ = target->GetPosition();
length_ = path_.GetLength(); length_ = path_->GetLength();
} }
void ActionWalk::UpdateTween(Actor* target, float percent) 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); float distance = length_ * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f);
Point point, tangent; Point point, tangent;
if (path_.ComputePointAtLength(distance, point, tangent)) if (path_->ComputePointAtLength(distance, point, tangent))
{ {
target->SetPosition(start_pos_ + point); target->SetPosition(start_pos_ + point);

View File

@ -20,8 +20,8 @@
#pragma once #pragma once
#include <kiwano/2d/action/ActionTween.h> #include <kiwano/2d/action/ActionTween.h>
#include <kiwano/render/Geometry.h> #include <kiwano/render/Shape.h>
#include <kiwano/render/GeometrySink.h> #include <kiwano/render/ShapeSink.h>
namespace kiwano namespace kiwano
{ {
@ -49,12 +49,12 @@ public:
/// \~chinese /// \~chinese
/// @brief 构造路径行走动画 /// @brief 构造路径行走动画
/// @param duration 持续时长 /// @param duration 持续时长
/// @param path ·¾¶¼¸ºÎÐÎ×´ /// @param path ·¾¶ÐÎ×´
/// @param rotating 是否沿路径切线方向旋转 /// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比) /// @param start 路径起点(百分比)
/// @param end 路径终点(百分比) /// @param end 路径终点(百分比)
/// @param func 动画速度缓动函数 /// @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); EaseFunc func = nullptr);
/// \~chinese /// \~chinese
@ -67,11 +67,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取路线 /// @brief 获取路线
Geometry const& GetPath() const; ShapePtr const& GetPath() const;
/// \~chinese /// \~chinese
/// @brief 设置路径几何形状 /// @brief 设置路径几何形状
void SetPath(Geometry const& path); void SetPath(ShapePtr path);
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;
@ -79,22 +79,22 @@ protected:
void UpdateTween(Actor* target, float percent) override; void UpdateTween(Actor* target, float percent) override;
private: private:
bool rotating_; bool rotating_;
float start_; float start_;
float end_; float end_;
float length_; float length_;
Point start_pos_; Point start_pos_;
Geometry path_; ShapePtr path_;
}; };
/** @} */ /** @} */
inline Geometry const& ActionWalk::GetPath() const inline ShapePtr const& ActionWalk::GetPath() const
{ {
return path_; return path_;
} }
inline void ActionWalk::SetPath(Geometry const& path) inline void ActionWalk::SetPath(ShapePtr path)
{ {
path_ = path; path_ = path;
} }

View File

@ -64,13 +64,14 @@
#include <kiwano/render/Color.h> #include <kiwano/render/Color.h>
#include <kiwano/render/Font.h> #include <kiwano/render/Font.h>
#include <kiwano/render/Geometry.h> #include <kiwano/render/Shape.h>
#include <kiwano/render/ShapeSink.h>
#include <kiwano/render/Texture.h>
#include <kiwano/render/GifImage.h> #include <kiwano/render/GifImage.h>
#include <kiwano/render/LayerArea.h> #include <kiwano/render/LayerArea.h>
#include <kiwano/render/Renderer.h>
#include <kiwano/render/TextLayout.h> #include <kiwano/render/TextLayout.h>
#include <kiwano/render/Texture.h>
#include <kiwano/render/TextureCache.h> #include <kiwano/render/TextureCache.h>
#include <kiwano/render/Renderer.h>
// //
// 2d // 2d

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/render/Geometry.h> #include <kiwano/render/Shape.h>
namespace kiwano namespace kiwano
{ {
@ -55,7 +55,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 삿혤섯부촁꿔 /// @brief 삿혤섯부촁꿔
Geometry const& GetMaskGeometry() const; ShapePtr GetMaskShape() const;
/// \~chinese /// \~chinese
/// @brief 삿혤섯부촁꿔긴뻣 /// @brief 삿혤섯부촁꿔긴뻣
@ -71,7 +71,7 @@ public:
/// \~chinese /// \~chinese
/// @brief <20>零섯부촁꿔 /// @brief <20>零섯부촁꿔
void SetMaskGeometry(Geometry const& mask); void SetMaskShape(ShapePtr mask);
/// \~chinese /// \~chinese
/// @brief <20>零섯부촁꿔긴뻣 /// @brief <20>零섯부촁꿔긴뻣
@ -85,7 +85,7 @@ private:
private: private:
Rect area_; Rect area_;
float opacity_; float opacity_;
Geometry mask_; ShapePtr mask_;
Matrix3x2 mask_transform_; Matrix3x2 mask_transform_;
ComPtr<ID2D1Layer> layer_; ComPtr<ID2D1Layer> layer_;
}; };
@ -107,7 +107,7 @@ inline float LayerArea::GetOpacity() const
return opacity_; return opacity_;
} }
inline Geometry const& LayerArea::GetMaskGeometry() const inline ShapePtr LayerArea::GetMaskShape() const
{ {
return mask_; return mask_;
} }
@ -127,7 +127,7 @@ inline void LayerArea::SetOpacity(float opacity)
opacity_ = opacity; opacity_ = opacity;
} }
inline void LayerArea::SetMaskGeometry(Geometry const& mask) inline void LayerArea::SetMaskShape(ShapePtr mask)
{ {
mask_ = mask; mask_ = mask;
} }

View File

@ -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(render_target_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); 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, render_target_->DrawGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width,
stroke.GetStrokeStyle().get()); stroke.GetStrokeStyle().get());
IncreasePrimitivesCount(); 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(render_target_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); 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(); 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(render_target_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); 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(), render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2),
stroke_width, stroke.GetStrokeStyle().get()); current_brush_->GetBrush().get(), stroke_width, stroke.GetStrokeStyle().get());
IncreasePrimitivesCount(); 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!"); 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, render_target_->DrawRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get(), stroke_width,
stroke.GetStrokeStyle().get()); stroke.GetStrokeStyle().get());
IncreasePrimitivesCount(); 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!"); 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), 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(); 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!"); 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), render_target_->FillRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y),
current_brush_->GetBrush().get()); current_brush_->GetBrush().get());
IncreasePrimitivesCount(); 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!"); 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), 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(); 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!"); 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), render_target_->FillEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y),
current_brush_->GetBrush().get()); current_brush_->GetBrush().get());
IncreasePrimitivesCount(); IncreasePrimitivesCount();
} }
@ -221,7 +221,7 @@ void RenderContext::DrawTexture(Texture const& texture, const Rect* src_rect, co
: D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR; : D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR;
render_target_->DrawBitmap(texture.GetBitmap().get(), dest_rect ? &DX::ConvertToRectF(*dest_rect) : nullptr, 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(); IncreasePrimitivesCount();
} }
@ -269,7 +269,8 @@ void RenderContext::CreateTexture(Texture& texture, math::Vec2T<uint32_t> size,
KGE_ASSERT(render_target_ && "Render target has not been initialized!"); KGE_ASSERT(render_target_ && "Render target has not been initialized!");
ComPtr<ID2D1Bitmap> saved_bitmap; ComPtr<ID2D1Bitmap> 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)) if (SUCCEEDED(hr))
{ {
@ -285,7 +286,7 @@ void RenderContext::PushClipRect(Rect const& clip_rect)
{ {
KGE_ASSERT(render_target_ && "Render target has not been initialized!"); KGE_ASSERT(render_target_ && "Render target has not been initialized!");
render_target_->PushAxisAlignedClip(DX::ConvertToRectF(clip_rect), 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() void RenderContext::PopClipRect()
@ -314,8 +315,12 @@ void RenderContext::PushLayer(LayerArea& layer)
if (layer.IsValid()) if (layer.IsValid())
{ {
ComPtr<ID2D1Geometry> mask;
if (layer.GetMaskShape())
mask = layer.GetMaskShape()->GetGeometry();
render_target_->PushLayer( 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, antialias_ ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED,
DX::ConvertToMatrix3x2F(layer.GetMaskTransform()), layer.GetOpacity(), nullptr, DX::ConvertToMatrix3x2F(layer.GetMaskTransform()), layer.GetOpacity(), nullptr,
D2D1_LAYER_OPTIONS_NONE), D2D1_LAYER_OPTIONS_NONE),

View File

@ -22,7 +22,7 @@
#include <kiwano/core/ObjectBase.h> #include <kiwano/core/ObjectBase.h>
#include <kiwano/core/Time.h> #include <kiwano/core/Time.h>
#include <kiwano/render/Brush.h> #include <kiwano/render/Brush.h>
#include <kiwano/render/Geometry.h> #include <kiwano/render/Shape.h>
#include <kiwano/render/LayerArea.h> #include <kiwano/render/LayerArea.h>
#include <kiwano/render/TextLayout.h> #include <kiwano/render/TextLayout.h>
#include <kiwano/render/Texture.h> #include <kiwano/render/Texture.h>
@ -73,11 +73,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 是否有效 /// @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 /// \~chinese
/// @brief 是否有效 /// @brief 是否有效
void FillGeometry(Geometry const& geometry); void FillShape(Shape const& shape);
/// \~chinese /// \~chinese
/// @brief 是否有效 /// @brief 是否有效

View File

@ -21,7 +21,7 @@
#include <kiwano/core/Logger.h> #include <kiwano/core/Logger.h>
#include <kiwano/core/event/WindowEvent.h> #include <kiwano/core/event/WindowEvent.h>
#include <kiwano/platform/FileSystem.h> #include <kiwano/platform/FileSystem.h>
#include <kiwano/render/GeometrySink.h> #include <kiwano/render/ShapeSink.h>
#include <kiwano/render/Renderer.h> #include <kiwano/render/Renderer.h>
namespace kiwano namespace kiwano
@ -629,7 +629,7 @@ void Renderer::CreateTextLayout(TextLayout& layout)
win32::ThrowIfFailed(hr); 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; HRESULT hr = S_OK;
if (!d2d_res_) if (!d2d_res_)
@ -659,13 +659,13 @@ void Renderer::CreateLineGeometry(Geometry& geo, Point const& begin_pos, Point c
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
geo.SetGeometry(path_geo); shape.SetGeometry(path_geo);
} }
win32::ThrowIfFailed(hr); win32::ThrowIfFailed(hr);
} }
void Renderer::CreateRectGeometry(Geometry& geo, Rect const& rect) void Renderer::CreateRectShape(Shape& shape, Rect const& rect)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (!d2d_res_) if (!d2d_res_)
@ -681,13 +681,13 @@ void Renderer::CreateRectGeometry(Geometry& geo, Rect const& rect)
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
geo.SetGeometry(output); shape.SetGeometry(output);
} }
win32::ThrowIfFailed(hr); 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; HRESULT hr = S_OK;
if (!d2d_res_) if (!d2d_res_)
@ -704,13 +704,13 @@ void Renderer::CreateRoundedRectGeometry(Geometry& geo, Rect const& rect, Vec2 c
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
geo.SetGeometry(output); shape.SetGeometry(output);
} }
win32::ThrowIfFailed(hr); 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; HRESULT hr = S_OK;
if (!d2d_res_) if (!d2d_res_)
@ -727,13 +727,13 @@ void Renderer::CreateEllipseGeometry(Geometry& geo, Point const& center, Vec2 co
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
geo.SetGeometry(output); shape.SetGeometry(output);
} }
win32::ThrowIfFailed(hr); win32::ThrowIfFailed(hr);
} }
void Renderer::CreateGeometrySink(GeometrySink& sink) void Renderer::CreateShapeSink(ShapeSink& sink)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (!d2d_res_) if (!d2d_res_)

View File

@ -137,32 +137,32 @@ public:
/// @param[out] geo 形状 /// @param[out] geo 形状
/// @param[in] begin_pos 线段起点 /// @param[in] begin_pos 线段起点
/// @param[in] end_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 /// \~chinese
/// @brief 创建矩形形状 /// @brief 创建矩形形状
/// @param[out] geo 形状 /// @param[out] geo 形状
/// @param[in] rect 矩形大小 /// @param[in] rect 矩形大小
void CreateRectGeometry(Geometry& geo, Rect const& rect); void CreateRectShape(Shape& shape, Rect const& rect);
/// \~chinese /// \~chinese
/// @brief 创建圆角矩形形状 /// @brief 创建圆角矩形形状
/// @param[out] geo 形状 /// @param[out] geo 形状
/// @param[in] rect 矩形大小 /// @param[in] rect 矩形大小
/// @param[in] radius 圆角半径 /// @param[in] radius 圆角半径
void CreateRoundedRectGeometry(Geometry& geo, Rect const& rect, Vec2 const& radius); void CreateRoundedRectShape(Shape& shape, Rect const& rect, Vec2 const& radius);
/// \~chinese /// \~chinese
/// @brief 创建椭圆形状 /// @brief 创建椭圆形状
/// @param[out] geo 形状 /// @param[out] geo 形状
/// @param[in] center 椭圆圆心 /// @param[in] center 椭圆圆心
/// @param[in] radius 椭圆半径 /// @param[in] radius 椭圆半径
void CreateEllipseGeometry(Geometry& geo, Point const& center, Vec2 const& radius); void CreateEllipseShape(Shape& shape, Point const& center, Vec2 const& radius);
/// \~chinese /// \~chinese
/// @brief 创建几何图形生成器 /// @brief 创建几何图形生成器
/// @param[out] sink 形状生成器 /// @param[out] sink 形状生成器
void CreateGeometrySink(GeometrySink& sink); void CreateShapeSink(ShapeSink& sink);
/// \~chinese /// \~chinese
/// @brief 创建纹理渲染上下文 /// @brief 创建纹理渲染上下文

View File

@ -18,21 +18,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#include <kiwano/render/Geometry.h> #include <kiwano/render/Shape.h>
#include <kiwano/render/GeometrySink.h> #include <kiwano/render/ShapeSink.h>
#include <kiwano/render/Renderer.h> #include <kiwano/render/Renderer.h>
namespace kiwano namespace kiwano
{ {
Geometry::Geometry() {} Shape::Shape() {}
bool Geometry::IsValid() const bool Shape::IsValid() const
{ {
return geo_ != nullptr; return geo_ != nullptr;
} }
Rect Geometry::GetBoundingBox() const Rect Shape::GetBoundingBox() const
{ {
Rect bounds; Rect bounds;
if (geo_) if (geo_)
@ -43,7 +43,7 @@ Rect Geometry::GetBoundingBox() const
return bounds; return bounds;
} }
Rect Geometry::GetBoundingBox(Matrix3x2 const& transform) const Rect Shape::GetBoundingBox(Matrix3x2 const& transform) const
{ {
Rect bounds; Rect bounds;
if (geo_) if (geo_)
@ -54,7 +54,7 @@ Rect Geometry::GetBoundingBox(Matrix3x2 const& transform) const
return bounds; return bounds;
} }
float Geometry::GetLength() const float Shape::GetLength() const
{ {
float length = 0.f; float length = 0.f;
if (geo_) if (geo_)
@ -65,7 +65,7 @@ float Geometry::GetLength() const
return length; return length;
} }
bool Geometry::ComputePointAtLength(float length, Point& point, Vec2& tangent) const bool Shape::ComputePointAtLength(float length, Point& point, Vec2& tangent) const
{ {
if (geo_) if (geo_)
{ {
@ -77,12 +77,12 @@ bool Geometry::ComputePointAtLength(float length, Point& point, Vec2& tangent) c
return false; return false;
} }
void Geometry::Clear() void Shape::Clear()
{ {
geo_.reset(); geo_.reset();
} }
float Geometry::ComputeArea() const float Shape::ComputeArea() const
{ {
if (!geo_) if (!geo_)
return 0.f; return 0.f;
@ -93,7 +93,7 @@ float Geometry::ComputeArea() const
return area; return area;
} }
bool Geometry::ContainsPoint(Point const& point, const Matrix3x2* transform) const bool Shape::ContainsPoint(Point const& point, const Matrix3x2* transform) const
{ {
if (!geo_) if (!geo_)
return false; return false;
@ -105,38 +105,38 @@ bool Geometry::ContainsPoint(Point const& point, const Matrix3x2* transform) con
return !!ret; return !!ret;
} }
Geometry Geometry::CreateLine(Point const& begin, Point const& end) ShapePtr Shape::CreateLine(Point const& begin, Point const& end)
{ {
Geometry output; ShapePtr output = new Shape;
Renderer::Instance().CreateLineGeometry(output, begin, end); Renderer::Instance().CreateLineShape(*output, begin, end);
return output; return output;
} }
Geometry Geometry::CreateRect(Rect const& rect) ShapePtr Shape::CreateRect(Rect const& rect)
{ {
Geometry output; ShapePtr output = new Shape;
Renderer::Instance().CreateRectGeometry(output, rect); Renderer::Instance().CreateRectShape(*output, rect);
return output; return output;
} }
Geometry Geometry::CreateRoundedRect(Rect const& rect, Vec2 const& radius) ShapePtr Shape::CreateRoundedRect(Rect const& rect, Vec2 const& radius)
{ {
Geometry output; ShapePtr output = new Shape;
Renderer::Instance().CreateRoundedRectGeometry(output, rect, radius); Renderer::Instance().CreateRoundedRectShape(*output, rect, radius);
return output; return output;
} }
Geometry Geometry::CreateCircle(Point const& center, float radius) ShapePtr Shape::CreateCircle(Point const& center, float radius)
{ {
Geometry output; ShapePtr output = new Shape;
Renderer::Instance().CreateEllipseGeometry(output, center, Vec2{ radius, radius }); Renderer::Instance().CreateEllipseShape(*output, center, Vec2{ radius, radius });
return output; return output;
} }
Geometry Geometry::CreateEllipse(Point const& center, Vec2 const& radius) ShapePtr Shape::CreateEllipse(Point const& center, Vec2 const& radius)
{ {
Geometry output; ShapePtr output = new Shape;
Renderer::Instance().CreateEllipseGeometry(output, center, radius); Renderer::Instance().CreateEllipseShape(*output, center, radius);
return output; return output;
} }

View File

@ -19,13 +19,16 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/core/ObjectBase.h>
#include <kiwano/render/DirectX/D2DDeviceResources.h> #include <kiwano/render/DirectX/D2DDeviceResources.h>
namespace kiwano namespace kiwano
{ {
class RenderContext; class RenderContext;
class Renderer; class Renderer;
class GeometrySink; class ShapeSink;
KGE_DECLARE_SMART_PTR(Shape);
/** /**
* \addtogroup Render * \addtogroup Render
@ -36,14 +39,14 @@ class GeometrySink;
* \~chinese * \~chinese
* @brief * @brief
*/ */
class KGE_API Geometry class KGE_API Shape : public virtual ObjectBase
{ {
friend class RenderContext; friend class RenderContext;
friend class Renderer; friend class Renderer;
friend class GeometrySink; friend class ShapeSink;
public: public:
Geometry(); Shape();
/// \~chinese /// \~chinese
/// @brief 是否有效 /// @brief 是否有效
@ -88,35 +91,35 @@ public:
/// @brief 创建线段 /// @brief 创建线段
/// @param begin 线段起点 /// @param begin 线段起点
/// @param end 线段终点 /// @param end 线段终点
static Geometry CreateLine(Point const& begin, Point const& end); static ShapePtr CreateLine(Point const& begin, Point const& end);
/// \~chinese /// \~chinese
/// @brief 创建矩形 /// @brief 创建矩形
/// @param rect 矩形 /// @param rect 矩形
static Geometry CreateRect(Rect const& rect); static ShapePtr CreateRect(Rect const& rect);
/// \~chinese /// \~chinese
/// @brief 创建圆角矩形 /// @brief 创建圆角矩形
/// @param rect 矩形 /// @param rect 矩形
/// @param radius 矩形圆角半径 /// @param radius 矩形圆角半径
static Geometry CreateRoundedRect(Rect const& rect, Vec2 const& radius); static ShapePtr CreateRoundedRect(Rect const& rect, Vec2 const& radius);
/// \~chinese /// \~chinese
/// @brief 创建圆形 /// @brief 创建圆形
/// @param center 圆形原点 /// @param center 圆形原点
/// @param radius 圆形半径 /// @param radius 圆形半径
static Geometry CreateCircle(Point const& center, float radius); static ShapePtr CreateCircle(Point const& center, float radius);
/// \~chinese /// \~chinese
/// @brief 创建椭圆形 /// @brief 创建椭圆形
/// @param center 椭圆原点 /// @param center 椭圆原点
/// @param radius 椭圆半径 /// @param radius 椭圆半径
static Geometry CreateEllipse(Point const& center, Vec2 const& radius); static ShapePtr CreateEllipse(Point const& center, Vec2 const& radius);
private: private:
ComPtr<ID2D1Geometry> GetGeometry() const; ComPtr<ID2D1Geometry> GetGeometry() const;
void SetGeometry(ComPtr<ID2D1Geometry> geometry); void SetGeometry(ComPtr<ID2D1Geometry> shape);
private: private:
ComPtr<ID2D1Geometry> geo_; ComPtr<ID2D1Geometry> geo_;
@ -124,13 +127,14 @@ private:
/** @} */ /** @} */
inline ComPtr<ID2D1Geometry> Geometry::GetGeometry() const inline ComPtr<ID2D1Geometry> Shape::GetGeometry() const
{ {
return geo_; return geo_;
} }
inline void Geometry::SetGeometry(ComPtr<ID2D1Geometry> geometry) inline void Shape::SetGeometry(ComPtr<ID2D1Geometry> shape)
{ {
geo_ = geometry; geo_ = shape;
} }
} // namespace kiwano } // namespace kiwano

View File

@ -18,67 +18,70 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#include <kiwano/render/GeometrySink.h> #include <kiwano/render/ShapeSink.h>
#include <kiwano/render/Renderer.h> #include <kiwano/render/Renderer.h>
namespace kiwano namespace kiwano
{ {
GeometrySink::GeometrySink() {} ShapeSink::ShapeSink() {}
GeometrySink::~GeometrySink() ShapeSink::~ShapeSink()
{ {
Close(); Close();
} }
void GeometrySink::Open() void ShapeSink::Open()
{ {
if (!IsOpened()) if (!IsOpened())
{ {
path_geo_.reset(); path_geo_.reset();
Renderer::Instance().CreateGeometrySink(*this); Renderer::Instance().CreateShapeSink(*this);
win32::ThrowIfFailed(path_geo_->Open(&sink_)); win32::ThrowIfFailed(path_geo_->Open(&sink_));
} }
} }
void GeometrySink::Close() void ShapeSink::Close()
{ {
if (IsOpened()) if (IsOpened())
{ {
win32::ThrowIfFailed(sink_->Close()); win32::ThrowIfFailed(sink_->Close());
sink_.reset(); sink_.reset();
} }
shape_ = new Shape;
shape_->SetGeometry(path_geo_);
} }
bool GeometrySink::IsOpened() const bool ShapeSink::IsOpened() const
{ {
return sink_ != nullptr; return sink_ != nullptr;
} }
Geometry GeometrySink::GetGeometry() ShapePtr ShapeSink::GetShape()
{ {
Close(); Close();
return shape_;
Geometry geo;
geo.SetGeometry(path_geo_);
return geo;
} }
GeometrySink& GeometrySink::AddGeometry(Geometry const& input, const Matrix3x2* input_matrix) ShapeSink& ShapeSink::AddShape(ShapePtr input, const Matrix3x2* input_matrix)
{ {
if (!IsOpened()) if (!IsOpened())
{ {
Open(); Open();
} }
ComPtr<ID2D1Geometry> geo = input.geo_; if (input && input->IsValid())
win32::ThrowIfFailed( {
geo->Outline(DX::ConvertToMatrix3x2F(input_matrix), D2D1_DEFAULT_FLATTENING_TOLERANCE, sink_.get())); ComPtr<ID2D1Geometry> geo = input->GetGeometry();
win32::ThrowIfFailed(
geo->Outline(DX::ConvertToMatrix3x2F(input_matrix), D2D1_DEFAULT_FLATTENING_TOLERANCE, sink_.get()));
}
return (*this); return (*this);
} }
GeometrySink& GeometrySink::BeginPath(Point const& begin_pos) ShapeSink& ShapeSink::BeginPath(Point const& begin_pos)
{ {
if (!IsOpened()) if (!IsOpened())
{ {
@ -89,35 +92,35 @@ GeometrySink& GeometrySink::BeginPath(Point const& begin_pos)
return (*this); return (*this);
} }
GeometrySink& GeometrySink::EndPath(bool closed) ShapeSink& ShapeSink::EndPath(bool closed)
{ {
KGE_ASSERT(sink_); KGE_ASSERT(sink_);
sink_->EndFigure(closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN); sink_->EndFigure(closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN);
return (*this); return (*this);
} }
GeometrySink& GeometrySink::AddLine(Point const& point) ShapeSink& ShapeSink::AddLine(Point const& point)
{ {
KGE_ASSERT(sink_); KGE_ASSERT(sink_);
sink_->AddLine(DX::ConvertToPoint2F(point)); sink_->AddLine(DX::ConvertToPoint2F(point));
return (*this); return (*this);
} }
GeometrySink& GeometrySink::AddLines(Vector<Point> const& points) ShapeSink& ShapeSink::AddLines(Vector<Point> const& points)
{ {
KGE_ASSERT(sink_); KGE_ASSERT(sink_);
sink_->AddLines(reinterpret_cast<const D2D_POINT_2F*>(&points[0]), static_cast<uint32_t>(points.size())); sink_->AddLines(reinterpret_cast<const D2D_POINT_2F*>(&points[0]), static_cast<uint32_t>(points.size()));
return (*this); 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_); KGE_ASSERT(sink_);
sink_->AddLines(reinterpret_cast<const D2D_POINT_2F*>(points), UINT32(count)); sink_->AddLines(reinterpret_cast<const D2D_POINT_2F*>(points), UINT32(count));
return (*this); 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_); KGE_ASSERT(sink_);
sink_->AddBezier( sink_->AddBezier(
@ -125,8 +128,7 @@ GeometrySink& GeometrySink::AddBezier(Point const& point1, Point const& point2,
return (*this); return (*this);
} }
GeometrySink& GeometrySink::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, ShapeSink& ShapeSink::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small)
bool is_small)
{ {
KGE_ASSERT(sink_); KGE_ASSERT(sink_);
sink_->AddArc(D2D1::ArcSegment(DX::ConvertToPoint2F(point), DX::ConvertToSizeF(radius), rotation, 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); return (*this);
} }
GeometrySink& GeometrySink::Combine(Geometry const& geo_a, Geometry const& geo_b, CombineMode mode, ShapeSink& ShapeSink::Combine(Shape const& geo_a, Shape const& geo_b, CombineMode mode, const Matrix3x2* matrix)
const Matrix3x2* matrix)
{ {
if (!IsOpened()) if (!IsOpened())
{ {
@ -150,7 +151,7 @@ GeometrySink& GeometrySink::Combine(Geometry const& geo_a, Geometry const& geo_b
return (*this); return (*this);
} }
void GeometrySink::Clear() void ShapeSink::Clear()
{ {
Close(); Close();

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/render/Geometry.h> #include <kiwano/render/Shape.h>
namespace kiwano namespace kiwano
{ {
@ -43,14 +43,14 @@ enum class CombineMode
/// \~chinese /// \~chinese
/// @brief 几何形状生成器 /// @brief 几何形状生成器
class KGE_API GeometrySink : protected Noncopyable class KGE_API ShapeSink : protected Noncopyable
{ {
friend class Renderer; friend class Renderer;
public: public:
GeometrySink(); ShapeSink();
~GeometrySink(); ~ShapeSink();
/// \~chinese /// \~chinese
/// @brief 打开输入流 /// @brief 打开输入流
@ -68,48 +68,48 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取生成的几何形状 /// @brief 获取生成的几何形状
/// @note 若还未关闭输入流,则自动关闭 /// @note 若还未关闭输入流,则自动关闭
Geometry GetGeometry(); ShapePtr GetShape();
/// \~chinese /// \~chinese
/// @brief 添加几何形状的轮廓 /// @brief 添加几何形状的轮廓
/// @param input 输入的形状 /// @param input 输入的形状
/// @param input_matrix 应用到输入形状上的二维变换 /// @param input_matrix 应用到输入形状上的二维变换
/// @note 若还未打开输入流,则自动打开 /// @note 若还未打开输入流,则自动打开
GeometrySink& AddGeometry(Geometry const& input, const Matrix3x2* input_matrix = nullptr); ShapeSink& AddShape(ShapePtr input, const Matrix3x2* input_matrix = nullptr);
/// \~chinese /// \~chinese
/// @brief 开始添加路径 /// @brief 开始添加路径
/// @param begin_pos 路径起始点 /// @param begin_pos 路径起始点
/// @note 若还未打开输入流,则自动打开 /// @note 若还未打开输入流,则自动打开
GeometrySink& BeginPath(Point const& begin_pos = Point()); ShapeSink& BeginPath(Point const& begin_pos = Point());
/// \~chinese /// \~chinese
/// @brief 结束路径 /// @brief 结束路径
/// @param closed 路径是否闭合 /// @param closed 路径是否闭合
GeometrySink& EndPath(bool closed = false); ShapeSink& EndPath(bool closed = false);
/// \~chinese /// \~chinese
/// @brief 添加一条线段 /// @brief 添加一条线段
/// @param point 端点 /// @param point 端点
GeometrySink& AddLine(Point const& point); ShapeSink& AddLine(Point const& point);
/// \~chinese /// \~chinese
/// @brief 添加多条线段 /// @brief 添加多条线段
/// @param points 端点集合 /// @param points 端点集合
GeometrySink& AddLines(Vector<Point> const& points); ShapeSink& AddLines(Vector<Point> const& points);
/// \~chinese /// \~chinese
/// @brief 添加多条线段 /// @brief 添加多条线段
/// @param points 端点数组 /// @param points 端点数组
/// @param count 端点数量 /// @param count 端点数量
GeometrySink& AddLines(const Point* points, size_t count); ShapeSink& AddLines(const Point* points, size_t count);
/// \~chinese /// \~chinese
/// @brief 添加一条三次方贝塞尔曲线 /// @brief 添加一条三次方贝塞尔曲线
/// @param point1 贝塞尔曲线的第一个控制点 /// @param point1 贝塞尔曲线的第一个控制点
/// @param point2 贝塞尔曲线的第二个控制点 /// @param point2 贝塞尔曲线的第二个控制点
/// @param point3 贝塞尔曲线的终点 /// @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 /// \~chinese
/// @brief 添加弧线 /// @brief 添加弧线
@ -118,7 +118,7 @@ public:
/// @param rotation 椭圆旋转角度 /// @param rotation 椭圆旋转角度
/// @param clockwise 顺时针 or 逆时针 /// @param clockwise 顺时针 or 逆时针
/// @param is_small 是否取小于 180° 的弧 /// @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); bool is_small = true);
/// \~chinese /// \~chinese
@ -128,7 +128,7 @@ public:
/// @param mode 组合方式 /// @param mode 组合方式
/// @param matrix 应用到输入形状B上的二维变换 /// @param matrix 应用到输入形状B上的二维变换
/// @note 若还未打开输入流,则自动打开 /// @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); const Matrix3x2* matrix = nullptr);
/// \~chinese /// \~chinese
@ -145,28 +145,29 @@ private:
void SetGeometrySink(ComPtr<ID2D1GeometrySink> sink); void SetGeometrySink(ComPtr<ID2D1GeometrySink> sink);
private: private:
ShapePtr shape_;
ComPtr<ID2D1PathGeometry> path_geo_; ComPtr<ID2D1PathGeometry> path_geo_;
ComPtr<ID2D1GeometrySink> sink_; ComPtr<ID2D1GeometrySink> sink_;
}; };
/** @} */ /** @} */
inline ComPtr<ID2D1PathGeometry> GeometrySink::GetPathGeometry() const inline ComPtr<ID2D1PathGeometry> ShapeSink::GetPathGeometry() const
{ {
return path_geo_; return path_geo_;
} }
inline void GeometrySink::SetPathGeometry(ComPtr<ID2D1PathGeometry> path) inline void ShapeSink::SetPathGeometry(ComPtr<ID2D1PathGeometry> path)
{ {
path_geo_ = path; path_geo_ = path;
} }
inline ComPtr<ID2D1GeometrySink> GeometrySink::GetGeometrySink() const inline ComPtr<ID2D1GeometrySink> ShapeSink::GetGeometrySink() const
{ {
return sink_; return sink_;
} }
inline void GeometrySink::SetGeometrySink(ComPtr<ID2D1GeometrySink> sink) inline void ShapeSink::SetGeometrySink(ComPtr<ID2D1GeometrySink> sink)
{ {
sink_ = sink; sink_ = sink;
} }