diff options
author | crupest <crupest@outlook.com> | 2023-10-08 12:23:17 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-10-08 12:23:17 +0800 |
commit | 1907d4fffd24e6d6bd1b7db7d903da60e53888dc (patch) | |
tree | 5c5575e7e2584b901e554d736c37f61e6263b904 /src/platform/graphics/web_canvas | |
parent | c216f37a9dd3c360d390a3e134881539731186d1 (diff) | |
download | cru-1907d4fffd24e6d6bd1b7db7d903da60e53888dc.tar.gz cru-1907d4fffd24e6d6bd1b7db7d903da60e53888dc.tar.bz2 cru-1907d4fffd24e6d6bd1b7db7d903da60e53888dc.zip |
...
Diffstat (limited to 'src/platform/graphics/web_canvas')
-rw-r--r-- | src/platform/graphics/web_canvas/Painter.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
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 <optional> + +namespace cru::platform::graphics::web_canvas { + +namespace { +void contextSetTransform(emscripten::val context, const Matrix& matrix) { + context.call<void>("setTransform", matrix.m11, matrix.m12, matrix.m21, + matrix.m22, matrix.m31, matrix.m32); +} +} // namespace + +WebCanvasPainter::WebCanvasPainter(WebCanvasGraphicsFactory* factory, + emscripten::val context, + std::optional<Matrix> 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 |