aboutsummaryrefslogtreecommitdiff
path: root/src/platform/graphics/web_canvas/Painter.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-10-09 22:25:54 +0800
committercrupest <crupest@outlook.com>2023-10-09 22:25:54 +0800
commit78760fd8a5b310ca4e8de502e510b95c9b4c880c (patch)
treed53da9e28decf583d027cc8eb023c591e02ee73f /src/platform/graphics/web_canvas/Painter.cpp
parent1907d4fffd24e6d6bd1b7db7d903da60e53888dc (diff)
downloadcru-78760fd8a5b310ca4e8de502e510b95c9b4c880c.tar.gz
cru-78760fd8a5b310ca4e8de502e510b95c9b4c880c.tar.bz2
cru-78760fd8a5b310ca4e8de502e510b95c9b4c880c.zip
...
Diffstat (limited to 'src/platform/graphics/web_canvas/Painter.cpp')
-rw-r--r--src/platform/graphics/web_canvas/Painter.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/platform/graphics/web_canvas/Painter.cpp b/src/platform/graphics/web_canvas/Painter.cpp
index cd04a725..31c4a53d 100644
--- a/src/platform/graphics/web_canvas/Painter.cpp
+++ b/src/platform/graphics/web_canvas/Painter.cpp
@@ -1,5 +1,6 @@
#include "cru/platform/graphics/web_canvas/WebCanvasGraphicsFactory.h"
#include "cru/platform/graphics/web_canvas/WebCanvasPainter.h"
+#include "cru/platform/graphics/web_canvas/WebCanvasRef.h"
#include "cru/platform/graphics/web_canvas/WebCanvasResource.h"
#include <optional>
@@ -7,9 +8,10 @@
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);
+void contextDoTransform(emscripten::val context, const char* method,
+ const Matrix& matrix) {
+ context.call<void>(method, matrix.m11, matrix.m12, matrix.m21, matrix.m22,
+ matrix.m31, matrix.m32);
}
} // namespace
@@ -19,7 +21,7 @@ WebCanvasPainter::WebCanvasPainter(WebCanvasGraphicsFactory* factory,
: WebCanvasResource(factory),
context_(context),
current_transform_(current_transform.value_or(Matrix::Identity())) {
- contextSetTransform(context_, current_transform_);
+ contextDoTransform(context_, "setTransform", current_transform_);
}
WebCanvasPainter::~WebCanvasPainter() {}
@@ -28,6 +30,17 @@ Matrix WebCanvasPainter::GetTransform() { return current_transform_; }
void WebCanvasPainter::SetTransform(const Matrix& transform) {
current_transform_ = transform;
- contextSetTransform(context_, transform);
+ contextDoTransform(context_, "setTransform", current_transform_);
+}
+
+void WebCanvasPainter::ConcatTransform(const Matrix& transform) {
+ current_transform_ *= transform;
+ contextDoTransform(context_, "transform", transform);
+}
+
+void WebCanvasPainter::Clear(const Color& color) {}
+
+WebCanvasRef WebCanvasPainter::GetCanvas() {
+ return WebCanvasRef(context_["canvas"]);
}
} // namespace cru::platform::graphics::web_canvas