diff options
author | crupest <crupest@outlook.com> | 2023-10-12 21:44:26 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-10-12 21:44:26 +0800 |
commit | 2025756fab9103a3baa8999445e61628cfb9b392 (patch) | |
tree | f076e51fb4580e77c50579743128176ba4c0e86c /src/platform/graphics/web_canvas/Geometry.cpp | |
parent | 3c5aa6583d7ab2533ff721282d1efd52d07281c7 (diff) | |
download | cru-2025756fab9103a3baa8999445e61628cfb9b392.tar.gz cru-2025756fab9103a3baa8999445e61628cfb9b392.tar.bz2 cru-2025756fab9103a3baa8999445e61628cfb9b392.zip |
...
Diffstat (limited to 'src/platform/graphics/web_canvas/Geometry.cpp')
-rw-r--r-- | src/platform/graphics/web_canvas/Geometry.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
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 |