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\TextRenderer.h" />
<ClInclude Include="..\..\src\kiwano\render\Font.h" />
<ClInclude Include="..\..\src\kiwano\render\Geometry.h" />
<ClInclude Include="..\..\src\kiwano\render\GeometrySink.h" />
<ClInclude Include="..\..\src\kiwano\render\Shape.h" />
<ClInclude Include="..\..\src\kiwano\render\ShapeSink.h" />
<ClInclude Include="..\..\src\kiwano\render\GifImage.h" />
<ClInclude Include="..\..\src\kiwano\render\LayerArea.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\TextRenderer.cpp" />
<ClCompile Include="..\..\src\kiwano\render\Font.cpp" />
<ClCompile Include="..\..\src\kiwano\render\Geometry.cpp" />
<ClCompile Include="..\..\src\kiwano\render\GeometrySink.cpp" />
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp" />
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp" />
<ClCompile Include="..\..\src\kiwano\render\LayerArea.cpp" />
<ClCompile Include="..\..\src\kiwano\render\RenderContext.cpp" />

View File

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

View File

@ -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<Point> 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;
}

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/2d/Actor.h>
#include <kiwano/render/GeometrySink.h>
#include <kiwano/render/ShapeSink.h>
#include <kiwano/render/RenderContext.h>
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 圆形原点
@ -272,7 +282,7 @@ private:
float stroke_width_;
TextStyle text_style_;
StrokeStyle stroke_style_;
GeometrySink geo_sink_;
ShapeSink shape_sink_;
BrushPtr fill_brush_;
BrushPtr stroke_brush_;

View File

@ -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)

View File

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

View File

@ -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_)
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.DrawShape(*shape_, stroke_width_ * 2 /* twice width for widening */, stroke_style_);
}
if (fill_brush_)
{
ctx.SetCurrentBrush(fill_brush_);
ctx.FillGeometry(geo_);
ctx.FillShape(*shape_);
}
}
}
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<Point> 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());
}
}

View File

@ -21,8 +21,8 @@
#pragma once
#include <kiwano/2d/Actor.h>
#include <kiwano/render/Brush.h>
#include <kiwano/render/Geometry.h>
#include <kiwano/render/GeometrySink.h>
#include <kiwano/render/Shape.h>
#include <kiwano/render/ShapeSink.h>
#include <kiwano/render/StrokeStyle.h>
namespace kiwano
@ -71,7 +71,7 @@ public:
/// \~chinese
/// @brief 삿혤近榴
Geometry GetGeometry() const;
ShapePtr GetShape() const;
/// \~chinese
/// @brief 삿혤긋썹
@ -115,7 +115,7 @@ public:
/// \~chinese
/// @brief <20>零섯부近榴
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

View File

@ -29,12 +29,12 @@ namespace kiwano
//-------------------------------------------------------
ActionGroup::ActionGroup()
: sequence_(true)
: sync_(false)
{
}
ActionGroup::ActionGroup(Vector<ActionPtr> const& actions, bool sequence)
: sequence_(sequence)
ActionGroup::ActionGroup(Vector<ActionPtr> 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<ActionPtr> const& actions)
ActionPtr ActionGroup::Clone() const
{
auto group = new (std::nothrow) ActionGroup();
if (group)
Vector<ActionPtr> 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<ActionPtr> 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;
}

View File

@ -42,8 +42,8 @@ public:
/// \~chinese
/// @brief 动画组合
/// @param actions 动画集合
/// @param sequence 动画按顺序依次执行或同时执行
explicit ActionGroup(Vector<ActionPtr> const& actions, bool sequence = true);
/// @param sync 同步执行
explicit ActionGroup(Vector<ActionPtr> 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_;
};

View File

@ -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<ActionPtr> const& actions, bool sequence = true)
/// @param sync 同步执行
static inline ActionHelper Group(Vector<ActionPtr> const& actions, bool sync = false)
{
return ActionHelper(new kiwano::ActionGroup(actions, sequence));
}
/// \~chinese
/// @brief 同步动画组合
/// @param actions 动画集合
static inline ActionHelper Multiple(Vector<ActionPtr> const& actions)
{
return ActionHelper(new kiwano::ActionGroup(actions, false));
return ActionHelper(new kiwano::ActionGroup(actions, sync));
}
};

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)
{
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);

View File

@ -20,8 +20,8 @@
#pragma once
#include <kiwano/2d/action/ActionTween.h>
#include <kiwano/render/Geometry.h>
#include <kiwano/render/GeometrySink.h>
#include <kiwano/render/Shape.h>
#include <kiwano/render/ShapeSink.h>
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;
@ -84,17 +84,17 @@ private:
float end_;
float length_;
Point start_pos_;
Geometry path_;
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;
}

View File

@ -64,13 +64,14 @@
#include <kiwano/render/Color.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/LayerArea.h>
#include <kiwano/render/Renderer.h>
#include <kiwano/render/TextLayout.h>
#include <kiwano/render/Texture.h>
#include <kiwano/render/TextureCache.h>
#include <kiwano/render/Renderer.h>
//
// 2d

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/render/Geometry.h>
#include <kiwano/render/Shape.h>
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 <20>零섯부촁꿔
void SetMaskGeometry(Geometry const& mask);
void SetMaskShape(ShapePtr mask);
/// \~chinese
/// @brief <20>零섯부촁꿔긴뻣
@ -85,7 +85,7 @@ private:
private:
Rect area_;
float opacity_;
Geometry mask_;
ShapePtr mask_;
Matrix3x2 mask_transform_;
ComPtr<ID2D1Layer> 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;
}

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(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());
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();
}
@ -269,7 +269,8 @@ void RenderContext::CreateTexture(Texture& texture, math::Vec2T<uint32_t> size,
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
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))
{
@ -314,8 +315,12 @@ void RenderContext::PushLayer(LayerArea& layer)
if (layer.IsValid())
{
ComPtr<ID2D1Geometry> 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),

View File

@ -22,7 +22,7 @@
#include <kiwano/core/ObjectBase.h>
#include <kiwano/core/Time.h>
#include <kiwano/render/Brush.h>
#include <kiwano/render/Geometry.h>
#include <kiwano/render/Shape.h>
#include <kiwano/render/LayerArea.h>
#include <kiwano/render/TextLayout.h>
#include <kiwano/render/Texture.h>
@ -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 是否有效

View File

@ -21,7 +21,7 @@
#include <kiwano/core/Logger.h>
#include <kiwano/core/event/WindowEvent.h>
#include <kiwano/platform/FileSystem.h>
#include <kiwano/render/GeometrySink.h>
#include <kiwano/render/ShapeSink.h>
#include <kiwano/render/Renderer.h>
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_)

View File

@ -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 创建纹理渲染上下文

View File

@ -18,21 +18,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/render/Geometry.h>
#include <kiwano/render/GeometrySink.h>
#include <kiwano/render/Shape.h>
#include <kiwano/render/ShapeSink.h>
#include <kiwano/render/Renderer.h>
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;
}

View File

@ -19,13 +19,16 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/core/ObjectBase.h>
#include <kiwano/render/DirectX/D2DDeviceResources.h>
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<ID2D1Geometry> GetGeometry() const;
void SetGeometry(ComPtr<ID2D1Geometry> geometry);
void SetGeometry(ComPtr<ID2D1Geometry> shape);
private:
ComPtr<ID2D1Geometry> geo_;
@ -124,13 +127,14 @@ private:
/** @} */
inline ComPtr<ID2D1Geometry> Geometry::GetGeometry() const
inline ComPtr<ID2D1Geometry> Shape::GetGeometry() const
{
return geo_;
}
inline void Geometry::SetGeometry(ComPtr<ID2D1Geometry> geometry)
inline void Shape::SetGeometry(ComPtr<ID2D1Geometry> shape)
{
geo_ = geometry;
geo_ = shape;
}
} // namespace kiwano

View File

@ -18,67 +18,70 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/render/GeometrySink.h>
#include <kiwano/render/ShapeSink.h>
#include <kiwano/render/Renderer.h>
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<ID2D1Geometry> geo = input.geo_;
if (input && input->IsValid())
{
ComPtr<ID2D1Geometry> 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<Point> const& points)
ShapeSink& ShapeSink::AddLines(Vector<Point> const& points)
{
KGE_ASSERT(sink_);
sink_->AddLines(reinterpret_cast<const D2D_POINT_2F*>(&points[0]), static_cast<uint32_t>(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<const D2D_POINT_2F*>(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();

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/render/Geometry.h>
#include <kiwano/render/Shape.h>
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<Point> const& points);
ShapeSink& AddLines(Vector<Point> 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<ID2D1GeometrySink> sink);
private:
ShapePtr shape_;
ComPtr<ID2D1PathGeometry> path_geo_;
ComPtr<ID2D1GeometrySink> sink_;
};
/** @} */
inline ComPtr<ID2D1PathGeometry> GeometrySink::GetPathGeometry() const
inline ComPtr<ID2D1PathGeometry> ShapeSink::GetPathGeometry() const
{
return path_geo_;
}
inline void GeometrySink::SetPathGeometry(ComPtr<ID2D1PathGeometry> path)
inline void ShapeSink::SetPathGeometry(ComPtr<ID2D1PathGeometry> path)
{
path_geo_ = path;
}
inline ComPtr<ID2D1GeometrySink> GeometrySink::GetGeometrySink() const
inline ComPtr<ID2D1GeometrySink> ShapeSink::GetGeometrySink() const
{
return sink_;
}
inline void GeometrySink::SetGeometrySink(ComPtr<ID2D1GeometrySink> sink)
inline void ShapeSink::SetGeometrySink(ComPtr<ID2D1GeometrySink> sink)
{
sink_ = sink;
}