aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform/graphics')
-rw-r--r--include/cru/platform/graphics/web_canvas/WebCanvasPainter.h16
-rw-r--r--include/cru/platform/graphics/web_canvas/WebCanvasRef.h24
2 files changed, 40 insertions, 0 deletions
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 <emscripten/val.h>
#include <optional>
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 <emscripten/val.h>
+
+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_;
+ };
+}