diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj
index 06c49d61..f8ae48e0 100644
--- a/projects/kiwano/kiwano.vcxproj
+++ b/projects/kiwano/kiwano.vcxproj
@@ -11,7 +11,6 @@
-
@@ -39,7 +38,6 @@
-
@@ -86,6 +84,8 @@
+
+
@@ -114,8 +114,6 @@
-
-
@@ -160,6 +158,8 @@
+
+
diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters
index 034a860a..86b3cb0b 100644
--- a/projects/kiwano/kiwano.vcxproj.filters
+++ b/projects/kiwano/kiwano.vcxproj.filters
@@ -84,9 +84,6 @@
2d
-
- 2d
-
2d\action
@@ -108,9 +105,6 @@
utils
-
- 2d
-
2d
@@ -327,6 +321,12 @@
core
+
+ render
+
+
+ render
+
@@ -365,9 +365,6 @@
2d
-
- 2d
-
2d\action
@@ -386,9 +383,6 @@
utils
-
- 2d
-
2d
@@ -539,6 +533,12 @@
core
+
+ render
+
+
+ render
+
diff --git a/src/kiwano-physics/PhysicWorld.cpp b/src/kiwano-physics/PhysicWorld.cpp
index afe7406e..e97384b7 100644
--- a/src/kiwano-physics/PhysicWorld.cpp
+++ b/src/kiwano-physics/PhysicWorld.cpp
@@ -32,25 +32,23 @@ public:
DebugDrawer(const Size& size)
{
canvas_ = Canvas::Create(size);
+ ctx_ = canvas_->GetContext2D();
fill_brush_ = Brush::Create(Color::White);
line_brush_ = Brush::Create(Color::White);
- canvas_->SetFillBrush(fill_brush_);
- canvas_->SetStrokeBrush(line_brush_);
-
b2Draw::SetFlags(b2Draw::e_shapeBit | b2Draw::e_jointBit | b2Draw::e_jointBit | b2Draw::e_centerOfMassBit);
}
void BeginDraw()
{
- canvas_->BeginDraw();
- canvas_->Clear();
+ ctx_->BeginDraw();
+ ctx_->Clear();
}
void EndDraw()
{
- canvas_->EndDraw();
+ ctx_->EndDraw();
}
void Render(RenderContext& ctx)
@@ -61,11 +59,13 @@ public:
void SetFillColor(const b2Color& color)
{
fill_brush_->SetColor(reinterpret_cast(color));
+ ctx_->SetCurrentBrush(fill_brush_);
}
void SetLineColor(const b2Color& color)
{
line_brush_->SetColor(reinterpret_cast(color));
+ ctx_->SetCurrentBrush(line_brush_);
}
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override
@@ -76,7 +76,7 @@ public:
for (int32 i = 0; i < vertexCount; ++i)
{
b2Vec2 p2 = vertices[i];
- canvas_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
+ ctx_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
p1 = p2;
}
}
@@ -92,25 +92,25 @@ public:
maker.EndPath(true);
SetFillColor(color);
- canvas_->FillShape(maker.GetShape());
+ ctx_->FillShape(*maker.GetShape());
}
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) override
{
SetLineColor(color);
- canvas_->DrawCircle(global::WorldToLocal(center), global::WorldToLocal(radius));
+ ctx_->DrawCircle(global::WorldToLocal(center), global::WorldToLocal(radius));
}
void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) override
{
SetFillColor(color);
- canvas_->FillCircle(global::WorldToLocal(center), global::WorldToLocal(radius));
+ ctx_->FillCircle(global::WorldToLocal(center), global::WorldToLocal(radius));
}
void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) override
{
SetLineColor(color);
- canvas_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
+ ctx_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
}
void DrawTransform(const b2Transform& xf) override
@@ -124,24 +124,25 @@ public:
p2 = p1 + k_axisScale * xf.q.GetXAxis();
SetLineColor(red);
- canvas_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
+ ctx_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
p2 = p1 + k_axisScale * xf.q.GetYAxis();
SetLineColor(green);
- canvas_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
+ ctx_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
}
void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color) override
{
SetFillColor(color);
- canvas_->FillCircle(global::WorldToLocal(p), global::WorldToLocal(size));
+ ctx_->FillCircle(global::WorldToLocal(p), global::WorldToLocal(size));
}
private:
- CanvasPtr canvas_;
- BrushPtr fill_brush_;
- BrushPtr line_brush_;
+ CanvasPtr canvas_;
+ RenderContextPtr ctx_;
+ BrushPtr fill_brush_;
+ BrushPtr line_brush_;
};
class DestructionListener : public b2DestructionListener
diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp
index 661c4e60..0a272d3e 100644
--- a/src/kiwano/2d/Canvas.cpp
+++ b/src/kiwano/2d/Canvas.cpp
@@ -42,20 +42,11 @@ CanvasPtr Canvas::Create(const Size& size)
return ptr;
}
-Canvas::Canvas()
-{
-}
+Canvas::Canvas() {}
-void Canvas::BeginDraw()
+RenderContextPtr Canvas::GetContext2D() const
{
- KGE_ASSERT(render_ctx_);
- render_ctx_->BeginDraw();
-}
-
-void Canvas::EndDraw()
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->EndDraw();
+ return render_ctx_;
}
void Canvas::OnRender(RenderContext& ctx)
@@ -66,232 +57,6 @@ void Canvas::OnRender(RenderContext& ctx)
}
}
-void Canvas::SetBrush(BrushPtr brush)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(brush);
-}
-
-void Canvas::SetBrushTransform(const Transform& transform)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetTransform(transform.ToMatrix());
-}
-
-void Canvas::SetBrushTransform(const Matrix3x2& transform)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetTransform(transform);
-}
-
-void Canvas::PushLayer(LayerPtr layer)
-{
- KGE_ASSERT(render_ctx_);
- if (layer)
- {
- render_ctx_->PushLayer(*layer);
- }
-}
-
-void Canvas::PopLayer()
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->PopLayer();
-}
-
-void Canvas::PushClipRect(const Rect& clip_rect)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->PushClipRect(clip_rect);
-}
-
-void Canvas::PopClipRect()
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->PopClipRect();
-}
-
-void Canvas::DrawShape(ShapePtr shape)
-{
- KGE_ASSERT(render_ctx_);
- if (shape)
- {
- render_ctx_->SetCurrentBrush(stroke_brush_);
- render_ctx_->SetCurrentStrokeStyle(stroke_style_);
- render_ctx_->DrawShape(*shape);
- }
-}
-
-void Canvas::DrawLine(const Point& begin, const Point& end)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(stroke_brush_);
- render_ctx_->SetCurrentStrokeStyle(stroke_style_);
- render_ctx_->DrawLine(begin, end);
-}
-
-void Canvas::DrawCircle(const Point& center, float radius)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(stroke_brush_);
- render_ctx_->SetCurrentStrokeStyle(stroke_style_);
- render_ctx_->DrawEllipse(center, Vec2(radius, radius));
-}
-
-void Canvas::DrawEllipse(const Point& center, const Vec2& radius)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(stroke_brush_);
- render_ctx_->SetCurrentStrokeStyle(stroke_style_);
- render_ctx_->DrawEllipse(center, radius);
-}
-
-void Canvas::DrawRect(const Rect& rect)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(stroke_brush_);
- render_ctx_->SetCurrentStrokeStyle(stroke_style_);
- render_ctx_->DrawRectangle(rect);
-}
-
-void Canvas::DrawRoundedRect(const Rect& rect, const Vec2& radius)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(stroke_brush_);
- render_ctx_->SetCurrentStrokeStyle(stroke_style_);
- render_ctx_->DrawRoundedRectangle(rect, radius);
-}
-
-void Canvas::FillShape(ShapePtr shape)
-{
- KGE_ASSERT(render_ctx_);
- if (shape)
- {
- render_ctx_->SetCurrentBrush(fill_brush_);
- render_ctx_->FillShape(*shape);
- }
-}
-
-void Canvas::FillCircle(const Point& center, float radius)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(fill_brush_);
- render_ctx_->FillEllipse(center, Vec2(radius, radius));
-}
-
-void Canvas::FillEllipse(const Point& center, const Vec2& radius)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(fill_brush_);
- render_ctx_->FillEllipse(center, radius);
-}
-
-void Canvas::FillRect(const Rect& rect)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(fill_brush_);
- render_ctx_->FillRectangle(rect);
-}
-
-void Canvas::FillRoundedRect(const Rect& rect, const Vec2& radius)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(fill_brush_);
- render_ctx_->FillRoundedRectangle(rect, radius);
-}
-
-void Canvas::DrawFrame(FramePtr frame, const Point& pos)
-{
- KGE_ASSERT(render_ctx_);
- if (frame && frame->IsValid())
- {
- render_ctx_->DrawTexture(*frame->GetTexture(), &frame->GetCropRect(), &Rect(pos, frame->GetSize()));
- }
-}
-
-void Canvas::DrawFrame(FramePtr frame, const Point& pos, const Size& size)
-{
- KGE_ASSERT(render_ctx_);
- if (frame && frame->IsValid())
- {
- render_ctx_->DrawTexture(*frame->GetTexture(), &frame->GetCropRect(), &Rect(pos, size));
- }
-}
-
-void Canvas::DrawTextLayout(const String& text, const TextStyle& style, const Point& point)
-{
- if (text.empty())
- return;
-
- DrawTextLayout(TextLayout::Create(text, style), point);
-}
-
-void Canvas::DrawTextLayout(TextLayoutPtr layout, const Point& point)
-{
- KGE_ASSERT(render_ctx_);
- if (layout)
- {
- render_ctx_->DrawTextLayout(*layout, point);
- }
-}
-
-void Canvas::BeginPath(const Point& begin_pos)
-{
- shape_maker_.BeginPath(begin_pos);
-}
-
-void Canvas::EndPath(bool closed)
-{
- shape_maker_.EndPath(closed);
-}
-
-void Canvas::AddLine(const Point& point)
-{
- shape_maker_.AddLine(point);
-}
-
-void Canvas::AddLines(const Vector& points)
-{
- shape_maker_.AddLines(points);
-}
-
-void Canvas::AddBezier(const Point& point1, const Point& point2, const Point& point3)
-{
- shape_maker_.AddBezier(point1, point2, point3);
-}
-
-void Canvas::AddArc(const Point& point, const Size& radius, float rotation, bool clockwise, bool is_small)
-{
- shape_maker_.AddArc(point, radius, rotation, clockwise, is_small);
-}
-
-void Canvas::StrokePath()
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(stroke_brush_);
- render_ctx_->SetCurrentStrokeStyle(stroke_style_);
- render_ctx_->DrawShape(*shape_maker_.GetShape());
-}
-
-void Canvas::FillPath()
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->SetCurrentBrush(fill_brush_);
- render_ctx_->FillShape(*shape_maker_.GetShape());
-}
-
-void Canvas::Clear()
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->Clear();
-}
-
-void Canvas::Clear(const Color& clear_color)
-{
- KGE_ASSERT(render_ctx_);
- render_ctx_->Clear(clear_color);
-}
-
void Canvas::ResizeAndClear(Size size)
{
texture_cached_ = memory::New();
diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h
index 2c8b46b2..f0f147f0 100644
--- a/src/kiwano/2d/Canvas.h
+++ b/src/kiwano/2d/Canvas.h
@@ -20,7 +20,7 @@
#pragma once
#include
-#include
+#include
#include
#include
@@ -48,222 +48,12 @@ public:
static CanvasPtr Create(const Size& size);
/// \~chinese
- /// @brief 开始绘图
- void BeginDraw();
-
- /// \~chinese
- /// @brief 结束绘图
- void EndDraw();
-
- /// \~chinese
- /// @brief 画形状轮廓
- /// @param shape 形状
- void DrawShape(ShapePtr shape);
-
- /// \~chinese
- /// @brief 画线段
- /// @param begin 线段起点
- /// @param end 线段终点
- void DrawLine(const Point& begin, const Point& end);
-
- /// \~chinese
- /// @brief 画圆形边框
- /// @param center 圆形原点
- /// @param radius 圆形半径
- void DrawCircle(const Point& center, float radius);
-
- /// \~chinese
- /// @brief 画椭圆形边框
- /// @param center 椭圆原点
- /// @param radius 椭圆半径
- void DrawEllipse(const Point& center, const Vec2& radius);
-
- /// \~chinese
- /// @brief 画矩形边框
- /// @param rect 矩形
- void DrawRect(const Rect& rect);
-
- /// \~chinese
- /// @brief 画圆角矩形边框
- /// @param rect 矩形
- /// @param radius 矩形圆角半径
- void DrawRoundedRect(const Rect& rect, const Vec2& radius);
-
- /// \~chinese
- /// @brief 填充形状
- /// @param shape 形状
- void FillShape(ShapePtr shape);
-
- /// \~chinese
- /// @brief 填充圆形
- /// @param center 圆形原点
- /// @param radius 圆形半径
- void FillCircle(const Point& center, float radius);
-
- /// \~chinese
- /// @brief 填充椭圆形
- /// @param center 椭圆原点
- /// @param radius 椭圆半径
- void FillEllipse(const Point& center, const Vec2& radius);
-
- /// \~chinese
- /// @brief 填充矩形
- /// @param rect 矩形
- void FillRect(const Rect& rect);
-
- /// \~chinese
- /// @brief 填充圆角矩形
- /// @param rect 矩形
- /// @param radius 矩形圆角半径
- void FillRoundedRect(const Rect& rect, const Vec2& radius);
-
- /// \~chinese
- /// @brief 绘制图像帧
- /// @param frame 图像帧
- /// @param pos 绘制图像的位置
- void DrawFrame(FramePtr frame, const Point& pos);
-
- /// \~chinese
- /// @brief 绘制图像帧
- /// @param frame 图像帧
- /// @param pos 绘制图像的位置
- /// @param size 渲染的图像大小
- void DrawFrame(FramePtr frame, const Point& pos, const Size& size);
-
- /// \~chinese
- /// @brief 绘制文字布局
- /// @param text 文字
- /// @param style 文字样式
- /// @param point 绘制文字的位置
- void DrawTextLayout(const String& text, const TextStyle& style, const Point& point);
-
- /// \~chinese
- /// @brief 绘制文字布局
- /// @param layout 文字布局
- /// @param point 绘制布局的位置
- void DrawTextLayout(TextLayoutPtr layout, const Point& point);
-
- /// \~chinese
- /// @brief 开始绘制路径
- /// @param begin_pos 路径起始点
- void BeginPath(const Point& begin_pos);
-
- /// \~chinese
- /// @brief 结束路径
- /// @param closed 路径是否闭合
- void EndPath(bool closed = false);
-
- /// \~chinese
- /// @brief 添加一条线段
- /// @param point 端点
- void AddLine(const Point& point);
-
- /// \~chinese
- /// @brief 添加多条线段
- /// @param points 端点集合
- void AddLines(const Vector& points);
-
- /// \~chinese
- /// @brief 添加一条三次方贝塞尔曲线
- /// @param point1 贝塞尔曲线的第一个控制点
- /// @param point2 贝塞尔曲线的第二个控制点
- /// @param point3 贝塞尔曲线的终点
- void AddBezier(const Point& point1, const Point& point2, const Point& point3);
-
- /// \~chinese
- /// @brief 添加弧线
- /// @param point 终点
- /// @param radius 椭圆半径
- /// @param rotation 椭圆旋转角度
- /// @param clockwise 顺时针 or 逆时针
- /// @param is_small 是否取小于 180° 的弧
- void AddArc(const Point& point, const Size& radius, float rotation, bool clockwise = true, bool is_small = true);
-
- /// \~chinese
- /// @brief 以描边的方式绘制路径
- void StrokePath();
-
- /// \~chinese
- /// @brief 以填充的方式绘制路径
- void FillPath();
-
- /// \~chinese
- /// @brief 清空画布
- void Clear();
-
- /// \~chinese
- /// @brief 清空画布
- /// @param clear_color 清空颜色
- void Clear(const Color& clear_color);
-
- /// \~chinese
- /// @brief 设置填充颜色
- /// @param color 填充颜色
- void SetFillColor(const Color& color);
-
- /// \~chinese
- /// @brief 设置填充画刷
- /// @param[in] brush 填充画刷
- void SetFillBrush(BrushPtr brush);
-
- /// \~chinese
- /// @brief 设置轮廓颜色
- /// @param color 轮廓颜色
- void SetStrokeColor(const Color& color);
-
- /// \~chinese
- /// @brief 设置轮廓画刷
- /// @param[in] brush 轮廓画刷
- void SetStrokeBrush(BrushPtr brush);
-
- /// \~chinese
- /// @brief 设置轮廓样式
- /// @param stroke_style 轮廓样式
- void SetStrokeStyle(StrokeStylePtr stroke_style);
-
- /// \~chinese
- /// @brief 设置画刷
- /// @param[in] brush 画刷
- void SetBrush(BrushPtr brush);
-
- /// \~chinese
- /// @brief 设置画刷二维变换
- /// @param transform 二维变换
- void SetBrushTransform(const Transform& transform);
-
- /// \~chinese
- /// @brief 设置画刷二维变换矩阵
- /// @param transform 二维变换矩阵
- void SetBrushTransform(const Matrix3x2& transform);
-
- /// \~chinese
- /// @brief 添加一个图层
- /// @param layer 图层
- void PushLayer(LayerPtr layer);
-
- /// \~chinese
- /// @brief 删除最近添加的图层
- void PopLayer();
-
- /// \~chinese
- /// @brief 添加一个裁剪区域
- /// @param clip_rect 裁剪矩形
- void PushClipRect(const Rect& clip_rect);
-
- /// \~chinese
- /// @brief 删除最近添加的裁剪区域
- void PopClipRect();
-
- /// \~chinese
- /// @brief 获取填充画刷
- BrushPtr GetFillBrush() const;
-
- /// \~chinese
- /// @brief 获取轮廓画刷
- BrushPtr GetStrokeBrush() const;
+ /// @brief 获取2D绘图上下文
+ RenderContextPtr GetContext2D() const;
/// \~chinese
/// @brief 清空画布大小并重设画布大小
+ /// @warning 该函数会导致原绘图上下文失效
void ResizeAndClear(Size size);
/// \~chinese
@@ -276,57 +66,10 @@ private:
Canvas();
private:
- StrokeStylePtr stroke_style_;
- ShapeMaker shape_maker_;
- BrushPtr fill_brush_;
- BrushPtr stroke_brush_;
TexturePtr texture_cached_;
RenderContextPtr render_ctx_;
};
/** @} */
-inline void Canvas::SetStrokeStyle(StrokeStylePtr stroke_style)
-{
- stroke_style_ = stroke_style;
-}
-
-inline void Canvas::SetStrokeColor(const Color& color)
-{
- if (!stroke_brush_)
- {
- stroke_brush_ = memory::New();
- }
- stroke_brush_->SetColor(color);
-}
-
-inline void Canvas::SetFillColor(const Color& color)
-{
- if (!fill_brush_)
- {
- fill_brush_ = memory::New();
- }
- fill_brush_->SetColor(color);
-}
-
-inline void Canvas::SetFillBrush(BrushPtr brush)
-{
- fill_brush_ = brush;
-}
-
-inline void Canvas::SetStrokeBrush(BrushPtr brush)
-{
- stroke_brush_ = brush;
-}
-
-inline BrushPtr Canvas::GetFillBrush() const
-{
- return fill_brush_;
-}
-
-inline BrushPtr Canvas::GetStrokeBrush() const
-{
- return stroke_brush_;
-}
-
} // namespace kiwano
diff --git a/src/kiwano/2d/Sprite.h b/src/kiwano/2d/Sprite.h
index dbadbc6f..934abbac 100644
--- a/src/kiwano/2d/Sprite.h
+++ b/src/kiwano/2d/Sprite.h
@@ -20,7 +20,7 @@
#pragma once
#include
-#include
+#include
namespace kiwano
{
diff --git a/src/kiwano/2d/action/Animation.cpp b/src/kiwano/2d/action/Animation.cpp
index 1abdaae1..bb52344a 100644
--- a/src/kiwano/2d/action/Animation.cpp
+++ b/src/kiwano/2d/action/Animation.cpp
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
+#include
#include
#include
diff --git a/src/kiwano/2d/action/Animation.h b/src/kiwano/2d/action/Animation.h
index 769b7386..7e991c72 100644
--- a/src/kiwano/2d/action/Animation.h
+++ b/src/kiwano/2d/action/Animation.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
#include
namespace kiwano
diff --git a/src/kiwano/kiwano.h b/src/kiwano/kiwano.h
index cc1877cf..f63b0ea0 100644
--- a/src/kiwano/kiwano.h
+++ b/src/kiwano/kiwano.h
@@ -68,6 +68,8 @@
#include
#include
#include
+#include
+#include
#include
#include
#include
@@ -82,8 +84,6 @@
#include
#include
#include
-#include
-#include
#include
#include
#include
diff --git a/src/kiwano/2d/Frame.cpp b/src/kiwano/render/Frame.cpp
similarity index 98%
rename from src/kiwano/2d/Frame.cpp
rename to src/kiwano/render/Frame.cpp
index 9e9f95be..2c42cd7c 100644
--- a/src/kiwano/2d/Frame.cpp
+++ b/src/kiwano/render/Frame.cpp
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
+#include
#include
namespace kiwano
diff --git a/src/kiwano/2d/Frame.h b/src/kiwano/render/Frame.h
similarity index 100%
rename from src/kiwano/2d/Frame.h
rename to src/kiwano/render/Frame.h
diff --git a/src/kiwano/2d/FrameSequence.cpp b/src/kiwano/render/FrameSequence.cpp
similarity index 99%
rename from src/kiwano/2d/FrameSequence.cpp
rename to src/kiwano/render/FrameSequence.cpp
index 008517fe..a5ce48fa 100644
--- a/src/kiwano/2d/FrameSequence.cpp
+++ b/src/kiwano/render/FrameSequence.cpp
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
+#include
#include
namespace kiwano
diff --git a/src/kiwano/2d/FrameSequence.h b/src/kiwano/render/FrameSequence.h
similarity index 99%
rename from src/kiwano/2d/FrameSequence.h
rename to src/kiwano/render/FrameSequence.h
index 681ecfd2..904eba8d 100644
--- a/src/kiwano/2d/FrameSequence.h
+++ b/src/kiwano/render/FrameSequence.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
#include
#include
diff --git a/src/kiwano/render/RenderContext.cpp b/src/kiwano/render/RenderContext.cpp
index fcb281d2..0bd36a47 100644
--- a/src/kiwano/render/RenderContext.cpp
+++ b/src/kiwano/render/RenderContext.cpp
@@ -60,6 +60,22 @@ void RenderContext::EndDraw()
}
}
+void RenderContext::DrawFrame(FramePtr frame, const Point& dest_pos)
+{
+ if (frame)
+ {
+ this->DrawTexture(*frame->GetTexture(), &frame->GetCropRect(), &Rect(dest_pos, frame->GetSize()));
+ }
+}
+
+void RenderContext::DrawFrame(FramePtr frame, const Rect& dest_rect)
+{
+ if (frame)
+ {
+ this->DrawTexture(*frame->GetTexture(), &frame->GetCropRect(), &dest_rect);
+ }
+}
+
void RenderContext::SetGlobalTransform(const Matrix3x2* matrix)
{
if (matrix)
@@ -121,4 +137,14 @@ void RenderContext::SetCurrentStrokeStyle(StrokeStylePtr stroke)
current_stroke_ = stroke;
}
+void RenderContext::DrawCircle(const Point& center, float radius)
+{
+ this->DrawEllipse(center, Vec2(radius, radius));
+}
+
+void RenderContext::FillCircle(const Point& center, float radius)
+{
+ this->FillEllipse(center, Vec2(radius, radius));
+}
+
} // namespace kiwano
diff --git a/src/kiwano/render/RenderContext.h b/src/kiwano/render/RenderContext.h
index 8bafec7c..6f2199a0 100644
--- a/src/kiwano/render/RenderContext.h
+++ b/src/kiwano/render/RenderContext.h
@@ -25,6 +25,7 @@
#include
#include
#include
+#include
namespace kiwano
{
@@ -79,6 +80,18 @@ public:
virtual void DrawTexture(const Texture& texture, const Rect* src_rect = nullptr,
const Rect* dest_rect = nullptr) = 0;
+ /// \~chinese
+ /// @brief 绘制图像帧
+ /// @param frame 图像帧
+ /// @param dest_pos 绘制图像的位置
+ virtual void DrawFrame(FramePtr frame, const Point& dest_pos);
+
+ /// \~chinese
+ /// @brief 绘制图像帧
+ /// @param frame 图像帧
+ /// @param dest_rect 绘制的目标区域
+ virtual void DrawFrame(FramePtr frame, const Rect& dest_rect);
+
/// \~chinese
/// @brief 绘制文本布局
/// @param layout 文本布局
@@ -107,6 +120,12 @@ public:
/// @param radius 圆角半径
virtual void DrawRoundedRectangle(const Rect& rect, const Vec2& radius) = 0;
+ /// \~chinese
+ /// @brief 绘制圆形边框
+ /// @param center 圆心
+ /// @param radius 椭圆半径
+ virtual void DrawCircle(const Point& center, float radius);
+
/// \~chinese
/// @brief 绘制椭圆边框
/// @param center 圆心
@@ -129,6 +148,12 @@ public:
/// @param radius 圆角半径
virtual void FillRoundedRectangle(const Rect& rect, const Vec2& radius) = 0;
+ /// \~chinese
+ /// @brief 填充圆形
+ /// @param center 圆心
+ /// @param radius 椭圆半径
+ virtual void FillCircle(const Point& center, float radius);
+
/// \~chinese
/// @brief 填充椭圆
/// @param center 圆心
diff --git a/src/kiwano/utils/ResourceCache.h b/src/kiwano/utils/ResourceCache.h
index 7917f30f..6c40b938 100644
--- a/src/kiwano/utils/ResourceCache.h
+++ b/src/kiwano/utils/ResourceCache.h
@@ -19,8 +19,8 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
+#include
+#include
#include
#include
#include