22#include <kiwano/2d/Actor.h>
23#include <kiwano/2d/SpriteFrame.h>
24#include <kiwano/render/ShapeMaker.h>
25#include <kiwano/render/RenderContext.h>
29class CanvasRenderContext;
61 void ResizeAndClear(
const PixelSize& size);
101 void DrawLine(
const Point& begin,
const Point& end);
107 void DrawCircle(
const Point& center,
float radius);
113 void DrawEllipse(
const Point& center,
const Vec2& radius);
118 void DrawRect(
const Rect& rect);
124 void DrawRoundedRect(
const Rect& rect,
const Vec2& radius);
135 void FillCircle(
const Point& center,
float radius);
141 void FillEllipse(
const Point& center,
const Vec2& radius);
146 void FillRect(
const Rect& rect);
152 void FillRoundedRect(
const Rect& rect,
const Vec2& radius);
202 void Clear(
const Color& clear_color);
207 void SetFillColor(
const Color& color);
221 void SetStrokeColor(
const Color& color);
244 void PushClipRect(
const Rect& clip_rect);
261 Size GetSize()
const;
265 void SetTransform(
const Matrix3x2& matrix);
269 void SetAntialiasMode(
bool enabled);
293 return texture_cached_;
313 actor->OnRender(*ctx_);
322 ctx_->SetCurrentBrush(stroke_brush_);
323 ctx_->SetCurrentStrokeStyle(stroke_style_);
324 ctx_->DrawShape(*shape);
332 ctx_->SetCurrentBrush(stroke_brush_);
333 ctx_->SetCurrentStrokeStyle(stroke_style_);
334 ctx_->DrawLine(begin, end);
341 ctx_->SetCurrentBrush(stroke_brush_);
342 ctx_->SetCurrentStrokeStyle(stroke_style_);
343 ctx_->DrawCircle(center, radius);
350 ctx_->SetCurrentBrush(stroke_brush_);
351 ctx_->SetCurrentStrokeStyle(stroke_style_);
352 ctx_->DrawEllipse(center, radius);
359 ctx_->SetCurrentBrush(stroke_brush_);
360 ctx_->SetCurrentStrokeStyle(stroke_style_);
361 ctx_->DrawRectangle(rect);
368 ctx_->SetCurrentBrush(stroke_brush_);
369 ctx_->SetCurrentStrokeStyle(stroke_style_);
370 ctx_->DrawRoundedRectangle(rect, radius);
378 ctx_->SetCurrentBrush(fill_brush_);
379 ctx_->FillShape(*shape);
387 ctx_->SetCurrentBrush(fill_brush_);
388 ctx_->FillCircle(center, radius);
395 ctx_->SetCurrentBrush(fill_brush_);
396 ctx_->FillEllipse(center, radius);
403 ctx_->SetCurrentBrush(fill_brush_);
404 ctx_->FillRectangle(rect);
411 ctx_->SetCurrentBrush(fill_brush_);
412 ctx_->FillRoundedRectangle(rect, radius);
419 this->
DrawTexture(texture, pos, texture->GetSize(), crop_rect);
424 const Rect* crop_rect)
430 Rect dest_rect(pos, pos + size);
431 ctx_->DrawTexture(*texture, crop_rect, &dest_rect);
456 ctx_->SetCurrentBrush(fill_brush_);
457 ctx_->SetCurrentStrokeStyle(stroke_style_);
458 ctx_->DrawTextLayout(*layout, point, stroke_brush_);
471 ctx_->Clear(clear_color);
478 fill_brush_ = MakePtr<Brush>();
480 fill_brush_->SetColor(color);
495 stroke_brush_ = brush;
502 stroke_brush_ = MakePtr<Brush>();
504 stroke_brush_->SetColor(color);
509 return stroke_brush_;
514 stroke_style_ = stroke_style;
519 return stroke_style_;
525 ctx_->PushClipRect(clip_rect);
539 ctx_->PushLayer(*layer);
552 return ctx_->GetSize();
558 ctx_->SetTransform(matrix);
564 ctx_->SetAntialiasMode(enabled);
570 ctx_->SetTextAntialiasMode(mode);
画布渲染上下文
Definition: Canvas.h:77
void DrawEllipse(const Point ¢er, const Vec2 &radius)
画椭圆形边框
Definition: Canvas.h:346
void SetStrokeBrush(RefPtr< Brush > brush)
设置轮廓画刷
Definition: Canvas.h:493
void FillEllipse(const Point ¢er, const Vec2 &radius)
填充椭圆形
Definition: Canvas.h:391
void FillRoundedRect(const Rect &rect, const Vec2 &radius)
填充圆角矩形
Definition: Canvas.h:407
void PushLayer(RefPtr< Layer > layer)
添加一个图层
Definition: Canvas.h:534
void DrawCircle(const Point ¢er, float radius)
画圆形边框
Definition: Canvas.h:337
void FillRect(const Rect &rect)
填充矩形
Definition: Canvas.h:399
Size GetSize() const
获取画布大小
Definition: Canvas.h:549
void SetFillBrush(RefPtr< Brush > brush)
设置填充画刷
Definition: Canvas.h:483
void DrawShape(RefPtr< Shape > shape)
画形状轮廓
Definition: Canvas.h:317
void PopLayer()
删除最近添加的图层
Definition: Canvas.h:543
void DrawActor(RefPtr< Actor > actor)
画角色
Definition: Canvas.h:308
void DrawLine(const Point &begin, const Point &end)
画线段
Definition: Canvas.h:328
void FillCircle(const Point ¢er, float radius)
填充圆形
Definition: Canvas.h:383
void SetAntialiasMode(bool enabled)
设置抗锯齿模式
Definition: Canvas.h:561
void DrawSpriteFrame(const SpriteFrame &frame, const Point &pos)
绘制精灵帧
Definition: Canvas.h:435
void PopClipRect()
删除最近添加的裁剪区域
Definition: Canvas.h:528
void Clear()
清空画布
Definition: Canvas.h:462
RefPtr< Brush > GetStrokeBrush() const
获取轮廓画刷
Definition: Canvas.h:507
void DrawRoundedRect(const Rect &rect, const Vec2 &radius)
画圆角矩形边框
Definition: Canvas.h:364
void EndDraw()
结束渲染
Definition: Canvas.h:302
void SetFillColor(const Color &color)
设置填充颜色
Definition: Canvas.h:474
void SetTextAntialiasMode(TextAntialiasMode mode)
设置文字抗锯齿模式
Definition: Canvas.h:567
RefPtr< StrokeStyle > GetStrokeStyle() const
获取轮廓样式
Definition: Canvas.h:517
void DrawTexture(RefPtr< Texture > texture, const Point &pos, const Rect *crop_rect=nullptr)
绘制纹理
Definition: Canvas.h:415
RefPtr< Brush > GetFillBrush() const
获取填充画刷
Definition: Canvas.h:488
void SetStrokeColor(const Color &color)
设置轮廓颜色
Definition: Canvas.h:498
void DrawRect(const Rect &rect)
画矩形边框
Definition: Canvas.h:355
void SetStrokeStyle(RefPtr< StrokeStyle > stroke_style)
设置轮廓样式
Definition: Canvas.h:512
void PushClipRect(const Rect &clip_rect)
添加一个裁剪区域
Definition: Canvas.h:522
void SetTransform(const Matrix3x2 &matrix)
设置渲染上下文的二维变换矩阵
Definition: Canvas.h:555
void BeginDraw()
开始渲染
Definition: Canvas.h:296
void DrawTextLayout(StringView text, const TextStyle &style, const Point &point)
绘制文字布局
Definition: Canvas.h:445
void FillShape(RefPtr< Shape > shape)
填充形状
Definition: Canvas.h:373
画布
Definition: Canvas.h:42
RefPtr< Texture > GetTexture() const
导出纹理
Definition: Canvas.h:291
基础对象
Definition: ObjectBase.h:138
引用计数智能指针
Definition: RefBasePtr.hpp:35
渲染上下文
Definition: RenderContext.h:62
精灵帧
Definition: SpriteFrame.h:34
RefPtr< Texture > GetTexture() const
获取纹理
Definition: SpriteFrame.h:131
const Rect & GetCropRect() const
获取裁剪矩形
Definition: SpriteFrame.h:126
文本样式
Definition: TextStyle.h:51
TextAntialiasMode
文字抗锯齿模式
Definition: RenderContext.h:40