From 1907d4fffd24e6d6bd1b7db7d903da60e53888dc Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 8 Oct 2023 12:23:17 +0800 Subject: ... --- src/platform/graphics/web_canvas/Painter.cpp | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/platform/graphics/web_canvas') diff --git a/src/platform/graphics/web_canvas/Painter.cpp b/src/platform/graphics/web_canvas/Painter.cpp index fd196256..cd04a725 100644 --- a/src/platform/graphics/web_canvas/Painter.cpp +++ b/src/platform/graphics/web_canvas/Painter.cpp @@ -1 +1,33 @@ +#include "cru/platform/graphics/web_canvas/WebCanvasGraphicsFactory.h" #include "cru/platform/graphics/web_canvas/WebCanvasPainter.h" +#include "cru/platform/graphics/web_canvas/WebCanvasResource.h" + +#include + +namespace cru::platform::graphics::web_canvas { + +namespace { +void contextSetTransform(emscripten::val context, const Matrix& matrix) { + context.call("setTransform", matrix.m11, matrix.m12, matrix.m21, + matrix.m22, matrix.m31, matrix.m32); +} +} // namespace + +WebCanvasPainter::WebCanvasPainter(WebCanvasGraphicsFactory* factory, + emscripten::val context, + std::optional current_transform) + : WebCanvasResource(factory), + context_(context), + current_transform_(current_transform.value_or(Matrix::Identity())) { + contextSetTransform(context_, current_transform_); +} + +WebCanvasPainter::~WebCanvasPainter() {} + +Matrix WebCanvasPainter::GetTransform() { return current_transform_; } + +void WebCanvasPainter::SetTransform(const Matrix& transform) { + current_transform_ = transform; + contextSetTransform(context_, transform); +} +} // namespace cru::platform::graphics::web_canvas -- cgit v1.2.3