From 312bfa625dd02b59ceb5d1a9f9e5c5189446781b Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 31 Aug 2021 00:54:12 +0800 Subject: ... --- src/osx/graphics/quartz/Geometry.cpp | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'src/osx/graphics/quartz/Geometry.cpp') diff --git a/src/osx/graphics/quartz/Geometry.cpp b/src/osx/graphics/quartz/Geometry.cpp index 428b24ab..79e6fbb1 100644 --- a/src/osx/graphics/quartz/Geometry.cpp +++ b/src/osx/graphics/quartz/Geometry.cpp @@ -3,46 +3,46 @@ #include namespace cru::platform::graphics::osx::quartz { -QuartzGeometry::QuartzGeometry(IGraphFactory* graphics_factory, - CGContextRef cg_context, CGPathRef cg_path) - : OsxQuartzResource(graphics_factory), - cg_context_(cg_context), - cg_path_(cg_path) {} +QuartzGeometry::QuartzGeometry(IGraphFactory *graphics_factory, + CGPathRef cg_path) + : OsxQuartzResource(graphics_factory), cg_path_(cg_path) {} QuartzGeometry::~QuartzGeometry() { CGPathRelease(cg_path_); } -bool QuartzGeometry::FillContains(const Point& point) { - CGContextBeginPath(cg_context_); - CGContextAddPath(cg_context_, cg_path_); - return CGContextPathContainsPoint(cg_context_, CGPoint{point.x, point.y}, - kCGPathFill); +bool QuartzGeometry::FillContains(const Point &point) { + return CGPathContainsPoint(cg_path_, nullptr, CGPoint{point.x, point.y}, + kCGPathFill); } -QuartzGeometryBuilder::QuartzGeometryBuilder(IGraphFactory* graphics_factory, - CGContextRef cg_context) - : OsxQuartzResource(graphics_factory), cg_context_(cg_context) {} +QuartzGeometryBuilder::QuartzGeometryBuilder(IGraphFactory *graphics_factory) + : OsxQuartzResource(graphics_factory) { + cg_mutable_path_ = CGPathCreateMutable(); +} + +QuartzGeometryBuilder::~QuartzGeometryBuilder() { + CGPathRelease(cg_mutable_path_); +} + +void QuartzGeometryBuilder::BeginFigure(const Point &point) { + CGPathMoveToPoint(cg_mutable_path_, nullptr, point.x, point.y); +} + +void QuartzGeometryBuilder::CloseFigure(bool close) { + if (close) CGPathCloseSubpath(cg_mutable_path_); +} + +void QuartzGeometryBuilder::LineTo(const Point &point) { + CGPathAddLineToPoint(cg_mutable_path_, nullptr, point.x, point.y); +} + +void QuartzGeometryBuilder::QuadraticBezierTo(const Point &control_point, + const Point &end_point) { + CGPathAddQuadCurveToPoint(cg_mutable_path_, nullptr, control_point.x, + control_point.y, end_point.x, end_point.y); +} std::unique_ptr QuartzGeometryBuilder::Build() { - CGContextBeginPath(cg_context_); - - for (const auto& action : actions_) { - Object* o = action.get(); - - if (auto a = dynamic_cast(o)) { - CGContextMoveToPoint(cg_context_, a->point.x, a->point.y); - } else if (auto a = dynamic_cast(o)) { - if (a->close) CGContextClosePath(cg_context_); - } else if (auto a = dynamic_cast(o)) { - CGContextAddLineToPoint(cg_context_, a->point.x, a->point.y); - } else if (auto a = - dynamic_cast(o)) { - CGContextAddQuadCurveToPoint(cg_context_, a->control_point.x, - a->control_point.y, a->end_point.x, - a->end_point.y); - } - } - - return std::make_unique(GetGraphFactory(), cg_context_, - CGContextCopyPath(cg_context_)); + return std::make_unique(GetGraphFactory(), + CGPathCreateCopy(cg_mutable_path_)); } } // namespace cru::platform::graphics::osx::quartz -- cgit v1.2.3