[deploy] Use Canvas::GetContext2D() instead of drawing functions
This commit is contained in:
parent
8331126bbc
commit
b790bb7315
|
|
@ -11,7 +11,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\action\Animation.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\action\Animation.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Button.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\Button.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Component.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\Component.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Frame.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Allocator.h" />
|
<ClInclude Include="..\..\src\kiwano\core\Allocator.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Any.h" />
|
<ClInclude Include="..\..\src\kiwano\core\Any.h" />
|
||||||
|
|
@ -39,7 +38,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\macros.h" />
|
<ClInclude Include="..\..\src\kiwano\macros.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\ShapeActor.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\ShapeActor.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\LayerActor.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\LayerActor.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Actor.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\Actor.h" />
|
||||||
|
|
@ -86,6 +84,8 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\RendererImpl.h" />
|
<ClInclude Include="..\..\src\kiwano\render\DirectX\RendererImpl.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\Frame.h" />
|
||||||
|
<ClInclude Include="..\..\src\kiwano\render\FrameSequence.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\NativeObject.h" />
|
<ClInclude Include="..\..\src\kiwano\render\NativeObject.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\Shape.h" />
|
<ClInclude Include="..\..\src\kiwano\render\Shape.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\ShapeMaker.h" />
|
<ClInclude Include="..\..\src\kiwano\render\ShapeMaker.h" />
|
||||||
|
|
@ -114,8 +114,6 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Component.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\Component.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\DebugActor.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\DebugActor.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Frame.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\FrameSequence.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\ShapeActor.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\ShapeActor.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\GifSprite.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\GifSprite.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\LayerActor.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\LayerActor.cpp" />
|
||||||
|
|
@ -160,6 +158,8 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\RendererImpl.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\DirectX\RendererImpl.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\Frame.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\kiwano\render\FrameSequence.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\ShapeMaker.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\ShapeMaker.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Stage.h">
|
<ClInclude Include="..\..\src\kiwano\2d\Stage.h">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Frame.h">
|
|
||||||
<Filter>2d</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\action\Action.h">
|
<ClInclude Include="..\..\src\kiwano\2d\action\Action.h">
|
||||||
<Filter>2d\action</Filter>
|
<Filter>2d\action</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -108,9 +105,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h">
|
<ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h">
|
|
||||||
<Filter>2d</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h">
|
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -327,6 +321,12 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Serializable.h">
|
<ClInclude Include="..\..\src\kiwano\core\Serializable.h">
|
||||||
<Filter>core</Filter>
|
<Filter>core</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kiwano\render\Frame.h">
|
||||||
|
<Filter>render</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kiwano\render\FrameSequence.h">
|
||||||
|
<Filter>render</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
||||||
|
|
@ -365,9 +365,6 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp">
|
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Frame.cpp">
|
|
||||||
<Filter>2d</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\action\Action.cpp">
|
<ClCompile Include="..\..\src\kiwano\2d\action\Action.cpp">
|
||||||
<Filter>2d\action</Filter>
|
<Filter>2d\action</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -386,9 +383,6 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp">
|
<ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\FrameSequence.cpp">
|
|
||||||
<Filter>2d</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\DebugActor.cpp">
|
<ClCompile Include="..\..\src\kiwano\2d\DebugActor.cpp">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -539,6 +533,12 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\core\Allocator.cpp">
|
<ClCompile Include="..\..\src\kiwano\core\Allocator.cpp">
|
||||||
<Filter>core</Filter>
|
<Filter>core</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\kiwano\render\Frame.cpp">
|
||||||
|
<Filter>render</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\kiwano\render\FrameSequence.cpp">
|
||||||
|
<Filter>render</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="cpp.hint" />
|
<None Include="cpp.hint" />
|
||||||
|
|
|
||||||
|
|
@ -32,25 +32,23 @@ public:
|
||||||
DebugDrawer(const Size& size)
|
DebugDrawer(const Size& size)
|
||||||
{
|
{
|
||||||
canvas_ = Canvas::Create(size);
|
canvas_ = Canvas::Create(size);
|
||||||
|
ctx_ = canvas_->GetContext2D();
|
||||||
|
|
||||||
fill_brush_ = Brush::Create(Color::White);
|
fill_brush_ = Brush::Create(Color::White);
|
||||||
line_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);
|
b2Draw::SetFlags(b2Draw::e_shapeBit | b2Draw::e_jointBit | b2Draw::e_jointBit | b2Draw::e_centerOfMassBit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeginDraw()
|
void BeginDraw()
|
||||||
{
|
{
|
||||||
canvas_->BeginDraw();
|
ctx_->BeginDraw();
|
||||||
canvas_->Clear();
|
ctx_->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndDraw()
|
void EndDraw()
|
||||||
{
|
{
|
||||||
canvas_->EndDraw();
|
ctx_->EndDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render(RenderContext& ctx)
|
void Render(RenderContext& ctx)
|
||||||
|
|
@ -61,11 +59,13 @@ public:
|
||||||
void SetFillColor(const b2Color& color)
|
void SetFillColor(const b2Color& color)
|
||||||
{
|
{
|
||||||
fill_brush_->SetColor(reinterpret_cast<const Color&>(color));
|
fill_brush_->SetColor(reinterpret_cast<const Color&>(color));
|
||||||
|
ctx_->SetCurrentBrush(fill_brush_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetLineColor(const b2Color& color)
|
void SetLineColor(const b2Color& color)
|
||||||
{
|
{
|
||||||
line_brush_->SetColor(reinterpret_cast<const Color&>(color));
|
line_brush_->SetColor(reinterpret_cast<const Color&>(color));
|
||||||
|
ctx_->SetCurrentBrush(line_brush_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override
|
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override
|
||||||
|
|
@ -76,7 +76,7 @@ public:
|
||||||
for (int32 i = 0; i < vertexCount; ++i)
|
for (int32 i = 0; i < vertexCount; ++i)
|
||||||
{
|
{
|
||||||
b2Vec2 p2 = vertices[i];
|
b2Vec2 p2 = vertices[i];
|
||||||
canvas_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
|
ctx_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
|
||||||
p1 = p2;
|
p1 = p2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,25 +92,25 @@ public:
|
||||||
maker.EndPath(true);
|
maker.EndPath(true);
|
||||||
|
|
||||||
SetFillColor(color);
|
SetFillColor(color);
|
||||||
canvas_->FillShape(maker.GetShape());
|
ctx_->FillShape(*maker.GetShape());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) override
|
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) override
|
||||||
{
|
{
|
||||||
SetLineColor(color);
|
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
|
void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) override
|
||||||
{
|
{
|
||||||
SetFillColor(color);
|
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
|
void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) override
|
||||||
{
|
{
|
||||||
SetLineColor(color);
|
SetLineColor(color);
|
||||||
canvas_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
|
ctx_->DrawLine(global::WorldToLocal(p1), global::WorldToLocal(p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTransform(const b2Transform& xf) override
|
void DrawTransform(const b2Transform& xf) override
|
||||||
|
|
@ -124,22 +124,23 @@ public:
|
||||||
p2 = p1 + k_axisScale * xf.q.GetXAxis();
|
p2 = p1 + k_axisScale * xf.q.GetXAxis();
|
||||||
|
|
||||||
SetLineColor(red);
|
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();
|
p2 = p1 + k_axisScale * xf.q.GetYAxis();
|
||||||
|
|
||||||
SetLineColor(green);
|
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
|
void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color) override
|
||||||
{
|
{
|
||||||
SetFillColor(color);
|
SetFillColor(color);
|
||||||
canvas_->FillCircle(global::WorldToLocal(p), global::WorldToLocal(size));
|
ctx_->FillCircle(global::WorldToLocal(p), global::WorldToLocal(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CanvasPtr canvas_;
|
CanvasPtr canvas_;
|
||||||
|
RenderContextPtr ctx_;
|
||||||
BrushPtr fill_brush_;
|
BrushPtr fill_brush_;
|
||||||
BrushPtr line_brush_;
|
BrushPtr line_brush_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -42,20 +42,11 @@ CanvasPtr Canvas::Create(const Size& size)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas::Canvas()
|
Canvas::Canvas() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::BeginDraw()
|
RenderContextPtr Canvas::GetContext2D() const
|
||||||
{
|
{
|
||||||
KGE_ASSERT(render_ctx_);
|
return render_ctx_;
|
||||||
render_ctx_->BeginDraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::EndDraw()
|
|
||||||
{
|
|
||||||
KGE_ASSERT(render_ctx_);
|
|
||||||
render_ctx_->EndDraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnRender(RenderContext& 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<Point>& 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)
|
void Canvas::ResizeAndClear(Size size)
|
||||||
{
|
{
|
||||||
texture_cached_ = memory::New<Texture>();
|
texture_cached_ = memory::New<Texture>();
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Actor.h>
|
#include <kiwano/2d/Actor.h>
|
||||||
#include <kiwano/2d/Frame.h>
|
#include <kiwano/render/Frame.h>
|
||||||
#include <kiwano/render/ShapeMaker.h>
|
#include <kiwano/render/ShapeMaker.h>
|
||||||
#include <kiwano/render/RenderContext.h>
|
#include <kiwano/render/RenderContext.h>
|
||||||
|
|
||||||
|
|
@ -48,222 +48,12 @@ public:
|
||||||
static CanvasPtr Create(const Size& size);
|
static CanvasPtr Create(const Size& size);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 开始绘图
|
/// @brief 获取2D绘图上下文
|
||||||
void BeginDraw();
|
RenderContextPtr GetContext2D() const;
|
||||||
|
|
||||||
/// \~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<Point>& 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;
|
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 清空画布大小并重设画布大小
|
/// @brief 清空画布大小并重设画布大小
|
||||||
|
/// @warning 该函数会导致原绘图上下文失效
|
||||||
void ResizeAndClear(Size size);
|
void ResizeAndClear(Size size);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
@ -276,57 +66,10 @@ private:
|
||||||
Canvas();
|
Canvas();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StrokeStylePtr stroke_style_;
|
|
||||||
ShapeMaker shape_maker_;
|
|
||||||
BrushPtr fill_brush_;
|
|
||||||
BrushPtr stroke_brush_;
|
|
||||||
TexturePtr texture_cached_;
|
TexturePtr texture_cached_;
|
||||||
RenderContextPtr render_ctx_;
|
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<Brush>();
|
|
||||||
}
|
|
||||||
stroke_brush_->SetColor(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Canvas::SetFillColor(const Color& color)
|
|
||||||
{
|
|
||||||
if (!fill_brush_)
|
|
||||||
{
|
|
||||||
fill_brush_ = memory::New<Brush>();
|
|
||||||
}
|
|
||||||
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
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Actor.h>
|
#include <kiwano/2d/Actor.h>
|
||||||
#include <kiwano/2d/Frame.h>
|
#include <kiwano/render/Frame.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
// 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/2d/FrameSequence.h>
|
#include <kiwano/render/FrameSequence.h>
|
||||||
#include <kiwano/2d/Sprite.h>
|
#include <kiwano/2d/Sprite.h>
|
||||||
#include <kiwano/2d/action/Animation.h>
|
#include <kiwano/2d/action/Animation.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/FrameSequence.h>
|
#include <kiwano/render/FrameSequence.h>
|
||||||
#include <kiwano/2d/action/ActionTween.h>
|
#include <kiwano/2d/action/ActionTween.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@
|
||||||
#include <kiwano/render/Shape.h>
|
#include <kiwano/render/Shape.h>
|
||||||
#include <kiwano/render/ShapeMaker.h>
|
#include <kiwano/render/ShapeMaker.h>
|
||||||
#include <kiwano/render/Texture.h>
|
#include <kiwano/render/Texture.h>
|
||||||
|
#include <kiwano/render/Frame.h>
|
||||||
|
#include <kiwano/render/FrameSequence.h>
|
||||||
#include <kiwano/render/GifImage.h>
|
#include <kiwano/render/GifImage.h>
|
||||||
#include <kiwano/render/Layer.h>
|
#include <kiwano/render/Layer.h>
|
||||||
#include <kiwano/render/TextLayout.h>
|
#include <kiwano/render/TextLayout.h>
|
||||||
|
|
@ -82,8 +84,6 @@
|
||||||
#include <kiwano/2d/Button.h>
|
#include <kiwano/2d/Button.h>
|
||||||
#include <kiwano/2d/Canvas.h>
|
#include <kiwano/2d/Canvas.h>
|
||||||
#include <kiwano/2d/DebugActor.h>
|
#include <kiwano/2d/DebugActor.h>
|
||||||
#include <kiwano/2d/Frame.h>
|
|
||||||
#include <kiwano/2d/FrameSequence.h>
|
|
||||||
#include <kiwano/2d/GifSprite.h>
|
#include <kiwano/2d/GifSprite.h>
|
||||||
#include <kiwano/2d/LayerActor.h>
|
#include <kiwano/2d/LayerActor.h>
|
||||||
#include <kiwano/2d/ShapeActor.h>
|
#include <kiwano/2d/ShapeActor.h>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
// 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/2d/Frame.h>
|
#include <kiwano/render/Frame.h>
|
||||||
#include <kiwano/render/TextureCache.h>
|
#include <kiwano/render/TextureCache.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
// 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/2d/FrameSequence.h>
|
#include <kiwano/render/FrameSequence.h>
|
||||||
#include <kiwano/core/Logger.h>
|
#include <kiwano/core/Logger.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Frame.h>
|
#include <kiwano/render/Frame.h>
|
||||||
#include <kiwano/core/Common.h>
|
#include <kiwano/core/Common.h>
|
||||||
#include <kiwano/core/Time.h>
|
#include <kiwano/core/Time.h>
|
||||||
|
|
||||||
|
|
@ -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)
|
void RenderContext::SetGlobalTransform(const Matrix3x2* matrix)
|
||||||
{
|
{
|
||||||
if (matrix)
|
if (matrix)
|
||||||
|
|
@ -121,4 +137,14 @@ void RenderContext::SetCurrentStrokeStyle(StrokeStylePtr stroke)
|
||||||
current_stroke_ = 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
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include <kiwano/render/Layer.h>
|
#include <kiwano/render/Layer.h>
|
||||||
#include <kiwano/render/TextLayout.h>
|
#include <kiwano/render/TextLayout.h>
|
||||||
#include <kiwano/render/Texture.h>
|
#include <kiwano/render/Texture.h>
|
||||||
|
#include <kiwano/render/Frame.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -79,6 +80,18 @@ public:
|
||||||
virtual void DrawTexture(const Texture& texture, const Rect* src_rect = nullptr,
|
virtual void DrawTexture(const Texture& texture, const Rect* src_rect = nullptr,
|
||||||
const Rect* dest_rect = nullptr) = 0;
|
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
|
/// \~chinese
|
||||||
/// @brief 绘制文本布局
|
/// @brief 绘制文本布局
|
||||||
/// @param layout 文本布局
|
/// @param layout 文本布局
|
||||||
|
|
@ -107,6 +120,12 @@ public:
|
||||||
/// @param radius 圆角半径
|
/// @param radius 圆角半径
|
||||||
virtual void DrawRoundedRectangle(const Rect& rect, const Vec2& radius) = 0;
|
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
|
/// \~chinese
|
||||||
/// @brief 绘制椭圆边框
|
/// @brief 绘制椭圆边框
|
||||||
/// @param center 圆心
|
/// @param center 圆心
|
||||||
|
|
@ -129,6 +148,12 @@ public:
|
||||||
/// @param radius 圆角半径
|
/// @param radius 圆角半径
|
||||||
virtual void FillRoundedRectangle(const Rect& rect, const Vec2& radius) = 0;
|
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
|
/// \~chinese
|
||||||
/// @brief 填充椭圆
|
/// @brief 填充椭圆
|
||||||
/// @param center 圆心
|
/// @param center 圆心
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Frame.h>
|
#include <kiwano/render/Frame.h>
|
||||||
#include <kiwano/2d/FrameSequence.h>
|
#include <kiwano/render/FrameSequence.h>
|
||||||
#include <kiwano/core/Resource.h>
|
#include <kiwano/core/Resource.h>
|
||||||
#include <kiwano/core/Json.h>
|
#include <kiwano/core/Json.h>
|
||||||
#include <kiwano/core/Xml.h>
|
#include <kiwano/core/Xml.h>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue