From 78760fd8a5b310ca4e8de502e510b95c9b4c880c Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 9 Oct 2023 22:25:54 +0800 Subject: ... --- .../graphics/web_canvas/WebCanvasPainter.h | 16 +++++++++++++++ .../platform/graphics/web_canvas/WebCanvasRef.h | 24 ++++++++++++++++++++++ include/cru/platform/web/JsUtility.h | 9 ++++++++ 3 files changed, 49 insertions(+) create mode 100644 include/cru/platform/graphics/web_canvas/WebCanvasRef.h create mode 100644 include/cru/platform/web/JsUtility.h (limited to 'include') diff --git a/include/cru/platform/graphics/web_canvas/WebCanvasPainter.h b/include/cru/platform/graphics/web_canvas/WebCanvasPainter.h index cd885aa4..1f7d21b6 100644 --- a/include/cru/platform/graphics/web_canvas/WebCanvasPainter.h +++ b/include/cru/platform/graphics/web_canvas/WebCanvasPainter.h @@ -1,11 +1,20 @@ #pragma once #include "../Painter.h" +#include "WebCanvasRef.h" #include "WebCanvasResource.h" #include #include namespace cru::platform::graphics::web_canvas { +/** + * Notes about Transform: + * Although there is a Matrix object now supported by browsers, it is not + * generally available in old browsers. However, now that we are using + * WebAssembly, the browsers should be quite up to date, but there is still a + * window between the two things. And it is common for a platform to not support + * getting transform and only allow you to do transformation. + */ class WebCanvasPainter : public WebCanvasResource, public virtual IPainter { public: WebCanvasPainter(WebCanvasGraphicsFactory* factory, emscripten::val context, @@ -17,6 +26,13 @@ class WebCanvasPainter : public WebCanvasResource, public virtual IPainter { Matrix GetTransform() override; void SetTransform(const Matrix& transform) override; + void ConcatTransform(const Matrix& matrix) override; + + void Clear(const Color& color) override; + + emscripten::val GetCanvas2DContext() const { return context_; } + WebCanvasRef GetCanvas(); + private: Matrix current_transform_; emscripten::val context_; diff --git a/include/cru/platform/graphics/web_canvas/WebCanvasRef.h b/include/cru/platform/graphics/web_canvas/WebCanvasRef.h new file mode 100644 index 00000000..4cb960bd --- /dev/null +++ b/include/cru/platform/graphics/web_canvas/WebCanvasRef.h @@ -0,0 +1,24 @@ +#pragma once + +#include "cru/common/Base.h" + +#include + +namespace cru::platform::graphics::web_canvas { + class WebCanvasRef { + public: + explicit WebCanvasRef(emscripten::val canvas_val); + + CRU_DEFAULT_COPY(WebCanvasRef) + CRU_DEFAULT_MOVE(WebCanvasRef) + + CRU_DEFAULT_DESTRUCTOR(WebCanvasRef) + + public: + int GetWidth() const; + int GetHeight() const; + + private: + emscripten::val val_; + }; +} diff --git a/include/cru/platform/web/JsUtility.h b/include/cru/platform/web/JsUtility.h new file mode 100644 index 00000000..37c2735d --- /dev/null +++ b/include/cru/platform/web/JsUtility.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace cru::platform::web { + bool IsNotNullAndInstanceOf(const emscripten::val& value, const emscripten::val& type); + bool IsNotNullAndInstanceOf(const emscripten::val& value, const char* global_type); +} + -- cgit v1.2.3