aboutsummaryrefslogtreecommitdiff
path: root/src/osx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-08-31 00:54:12 +0800
committercrupest <crupest@outlook.com>2021-08-31 00:54:12 +0800
commit312bfa625dd02b59ceb5d1a9f9e5c5189446781b (patch)
treef10e7c00f98d9f4cdd77941642e9a362f17e360c /src/osx
parent45ecfd5699e4949952cc71178521d1a238736ac6 (diff)
downloadcru-312bfa625dd02b59ceb5d1a9f9e5c5189446781b.tar.gz
cru-312bfa625dd02b59ceb5d1a9f9e5c5189446781b.tar.bz2
cru-312bfa625dd02b59ceb5d1a9f9e5c5189446781b.zip
...
Diffstat (limited to 'src/osx')
-rw-r--r--src/osx/graphics/quartz/Geometry.cpp68
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