From 9a077caa6d3f7eb8255ae68916dccac9b50a4333 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 12 Oct 2023 17:10:18 +0800 Subject: ... --- src/platform/graphics/web_canvas/CMakeLists.txt | 1 + src/platform/graphics/web_canvas/Geometry.cpp | 12 ++++++++++++ src/platform/graphics/web_canvas/Painter.cpp | 23 +++++++++++++++++++++++ src/platform/graphics/web_canvas/WebCanvasRef.cpp | 4 ++-- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/platform/graphics/web_canvas/Geometry.cpp (limited to 'src/platform/graphics/web_canvas') diff --git a/src/platform/graphics/web_canvas/CMakeLists.txt b/src/platform/graphics/web_canvas/CMakeLists.txt index bbf736e0..d0a1a7d9 100644 --- a/src/platform/graphics/web_canvas/CMakeLists.txt +++ b/src/platform/graphics/web_canvas/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(CruPlatformGraphicsWebCanvas Brush.cpp Factory.cpp + Geometry.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 new file mode 100644 index 00000000..eb4ce84e --- /dev/null +++ b/src/platform/graphics/web_canvas/Geometry.cpp @@ -0,0 +1,12 @@ +#include "cru/platform/graphics/web_canvas/WebCanvasGeometry.h" +#include "cru/platform/graphics/web_canvas/WebCanvasGraphicsFactory.h" +#include "cru/platform/graphics/web_canvas/WebCanvasResource.h" +#include "cru/platform/web/Js.h" + +namespace cru::platform::graphics::web_canvas { +WebCanvasGeometryBuilder::WebCanvasGeometryBuilder( + WebCanvasGraphicsFactory* factory) + : WebCanvasResource(factory) { + path2d_ = web::js::Construct("Path2D"); +} +} // namespace cru::platform::graphics::web_canvas diff --git a/src/platform/graphics/web_canvas/Painter.cpp b/src/platform/graphics/web_canvas/Painter.cpp index a78ab9f1..c9184165 100644 --- a/src/platform/graphics/web_canvas/Painter.cpp +++ b/src/platform/graphics/web_canvas/Painter.cpp @@ -59,6 +59,29 @@ void WebCanvasPainter::DrawLine(const Point& start, const Point& end, context_.call("stroke"); } +void WebCanvasPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush, + float width) { + SetStrokeStyle(brush, width); + context_.call("strokeRect", rectangle.left, rectangle.top, + rectangle.width, rectangle.height); +} + +void WebCanvasPainter::FillRectangle(const Rect& rectangle, IBrush* brush) { + SetFillStyle(brush); + context_.call("fillRect", rectangle.left, rectangle.top, + rectangle.width, rectangle.height); +} + +void WebCanvasPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush, + float width) { + SetStrokeStyle(brush); + // TODO: Need to use path. +} +void WebCanvasPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) { + SetFillStyle(brush); + // TODO: Need to use path. +} + void WebCanvasPainter::SetStrokeStyle(IBrush* brush, float width) { context_.set("strokeStyle", ConvertBrush(brush)->GetStyle()); if (width > 0) { diff --git a/src/platform/graphics/web_canvas/WebCanvasRef.cpp b/src/platform/graphics/web_canvas/WebCanvasRef.cpp index c4f75626..886131f6 100644 --- a/src/platform/graphics/web_canvas/WebCanvasRef.cpp +++ b/src/platform/graphics/web_canvas/WebCanvasRef.cpp @@ -1,5 +1,5 @@ #include "cru/platform/graphics/web_canvas/WebCanvasRef.h" -#include "cru/platform/web/JsUtility.h" +#include "cru/platform/web/Js.h" #include #include @@ -7,7 +7,7 @@ namespace cru::platform::graphics::web_canvas { WebCanvasRef::WebCanvasRef(emscripten::val canvas_val) : val_(std::move(canvas_val)) { - assert(web::IsNotNullAndInstanceOf(val_, "HTMLCanvasElement")); + assert(web::js::IsNotNullAndInstanceOf(val_, "HTMLCanvasElement")); } int WebCanvasRef::GetWidth() const { return val_["width"].as(); } -- cgit v1.2.3