diff options
Diffstat (limited to 'src/platform/graphics/web_canvas')
-rw-r--r-- | src/platform/graphics/web_canvas/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/platform/graphics/web_canvas/Geometry.cpp | 29 | ||||
-rw-r--r-- | src/platform/graphics/web_canvas/Matrix.cpp | 10 | ||||
-rw-r--r-- | src/platform/graphics/web_canvas/WebCanvasRef.cpp | 4 |
4 files changed, 41 insertions, 3 deletions
diff --git a/src/platform/graphics/web_canvas/CMakeLists.txt b/src/platform/graphics/web_canvas/CMakeLists.txt index d0a1a7d9..43e7f463 100644 --- a/src/platform/graphics/web_canvas/CMakeLists.txt +++ b/src/platform/graphics/web_canvas/CMakeLists.txt @@ -2,6 +2,7 @@ add_library(CruPlatformGraphicsWebCanvas Brush.cpp Factory.cpp Geometry.cpp + Matrix.cpp Painter.cpp Resource.cpp WebCanvasRef.cpp diff --git a/src/platform/graphics/web_canvas/Geometry.cpp b/src/platform/graphics/web_canvas/Geometry.cpp index 0f2f5a16..42669d88 100644 --- a/src/platform/graphics/web_canvas/Geometry.cpp +++ b/src/platform/graphics/web_canvas/Geometry.cpp @@ -1,14 +1,37 @@ +#include <memory> #include "cru/platform/graphics/web_canvas/WebCanvasGeometry.h" #include "cru/platform/graphics/web_canvas/WebCanvasGraphicsFactory.h" +#include "cru/platform/graphics/web_canvas/WebCanvasMatrix.h" #include "cru/platform/graphics/web_canvas/WebCanvasResource.h" #include "cru/platform/web/Js.h" namespace cru::platform::graphics::web_canvas { -bool WebCanvasGeometry::StrokeContains(float width, const Point& point) {} +WebCanvasGeometry::WebCanvasGeometry(WebCanvasGraphicsFactory* factory, + emscripten::val canvas, + emscripten::val path2d) + : WebCanvasResource(factory), + canvas_(std::move(canvas)), + path2d_(std::move(path2d)) {} + +WebCanvasGeometry::~WebCanvasGeometry() {} + +std::unique_ptr<IGeometry> WebCanvasGeometry::Transform(const Matrix& matrix) { + auto new_path = web::js::Construct("Path2D"); + auto js_matrix = CreateDomMatrix(matrix); + new_path.call<void>("addPath", js_matrix); + return std::make_unique<WebCanvasGeometry>(GetFactory(), canvas_, + std::move(new_path)); +} WebCanvasGeometryBuilder::WebCanvasGeometryBuilder( - WebCanvasGraphicsFactory* factory) - : WebCanvasResource(factory) {} + WebCanvasGraphicsFactory* factory, emscripten::val canvas) + : WebCanvasResource(factory), canvas_(std::move(canvas)) {} WebCanvasGeometryBuilder::~WebCanvasGeometryBuilder() {} + +std::unique_ptr<IGeometry> WebCanvasGeometryBuilder::Build() { + auto new_path = web::js::Construct("Path2D", GetPathData()); + return std::make_unique<WebCanvasGeometry>(GetFactory(), canvas_, + std::move(new_path)); +} } // namespace cru::platform::graphics::web_canvas diff --git a/src/platform/graphics/web_canvas/Matrix.cpp b/src/platform/graphics/web_canvas/Matrix.cpp new file mode 100644 index 00000000..6c20062e --- /dev/null +++ b/src/platform/graphics/web_canvas/Matrix.cpp @@ -0,0 +1,10 @@ +#include "cru/platform/graphics/web_canvas/WebCanvasMatrix.h" +#include "cru/platform/web/Js.h" + +namespace cru::platform::graphics::web_canvas { +emscripten::val CreateDomMatrix(const Matrix &matrix) { + return web::js::Construct( + "DOMMatrix", std::vector<float>{matrix.m11, matrix.m12, matrix.m21, + matrix.m22, matrix.m31, matrix.m32}); +} +} // namespace cru::platform::graphics::web_canvas diff --git a/src/platform/graphics/web_canvas/WebCanvasRef.cpp b/src/platform/graphics/web_canvas/WebCanvasRef.cpp index 886131f6..c4ad9b17 100644 --- a/src/platform/graphics/web_canvas/WebCanvasRef.cpp +++ b/src/platform/graphics/web_canvas/WebCanvasRef.cpp @@ -13,4 +13,8 @@ WebCanvasRef::WebCanvasRef(emscripten::val canvas_val) int WebCanvasRef::GetWidth() const { return val_["width"].as<int>(); } int WebCanvasRef::GetHeight() const { return val_["height"].as<int>(); } + +void WebCanvasRef::Save() const { val_.call<void>("save"); } + +void WebCanvasRef::Restore() const { val_.call<void>("restore"); } } // namespace cru::platform::graphics::web_canvas |