blob: 42669d883548d5bcb88f31b2501bbf434f39d131 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 {
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, 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
|