diff options
Diffstat (limited to 'src/osx/graphics/quartz/Geometry.cpp')
-rw-r--r-- | src/osx/graphics/quartz/Geometry.cpp | 68 |
1 files changed, 34 insertions, 34 deletions
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 <memory> 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<IGeometry> QuartzGeometryBuilder::Build() { - CGContextBeginPath(cg_context_); - - for (const auto& action : actions_) { - Object* o = action.get(); - - if (auto a = dynamic_cast<details::GeometryBeginFigureAction*>(o)) { - CGContextMoveToPoint(cg_context_, a->point.x, a->point.y); - } else if (auto a = dynamic_cast<details::GeometryCloseFigureAction*>(o)) { - if (a->close) CGContextClosePath(cg_context_); - } else if (auto a = dynamic_cast<details::GeometryLineToAction*>(o)) { - CGContextAddLineToPoint(cg_context_, a->point.x, a->point.y); - } else if (auto a = - dynamic_cast<details::GeometryQuadraticBezierToAction*>(o)) { - CGContextAddQuadCurveToPoint(cg_context_, a->control_point.x, - a->control_point.y, a->end_point.x, - a->end_point.y); - } - } - - return std::make_unique<QuartzGeometry>(GetGraphFactory(), cg_context_, - CGContextCopyPath(cg_context_)); + return std::make_unique<QuartzGeometry>(GetGraphFactory(), + CGPathCreateCopy(cg_mutable_path_)); } } // namespace cru::platform::graphics::osx::quartz |