diff options
author | crupest <crupest@outlook.com> | 2021-08-31 00:11:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-08-31 00:11:33 +0800 |
commit | 45ecfd5699e4949952cc71178521d1a238736ac6 (patch) | |
tree | 71df5be6cf2fda1e6b8d3514367ed27f1f29d78b /src | |
parent | fdafa45b7d28a191439b0c0deabff94b0d1a7094 (diff) | |
download | cru-45ecfd5699e4949952cc71178521d1a238736ac6.tar.gz cru-45ecfd5699e4949952cc71178521d1a238736ac6.tar.bz2 cru-45ecfd5699e4949952cc71178521d1a238736ac6.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/osx/graphics/quartz/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/osx/graphics/quartz/Geometry.cpp | 48 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/osx/graphics/quartz/CMakeLists.txt b/src/osx/graphics/quartz/CMakeLists.txt index fcbda648..6c978b18 100644 --- a/src/osx/graphics/quartz/CMakeLists.txt +++ b/src/osx/graphics/quartz/CMakeLists.txt @@ -4,6 +4,7 @@ add_library(cru_osx_graphics_quartz SHARED Brush.cpp Convert.cpp Factory.cpp + Geometry.cpp Painter.cpp Resource.cpp ) @@ -11,6 +12,7 @@ target_sources(cru_osx_graphics_quartz PUBLIC ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Brush.hpp ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Convert.hpp ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Factory.hpp + ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Geometry.hpp ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Painter.hpp ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Resource.hpp ) diff --git a/src/osx/graphics/quartz/Geometry.cpp b/src/osx/graphics/quartz/Geometry.cpp new file mode 100644 index 00000000..428b24ab --- /dev/null +++ b/src/osx/graphics/quartz/Geometry.cpp @@ -0,0 +1,48 @@ +#include "cru/osx/graphics/quartz/Geometry.hpp" + +#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() { 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); +} + +QuartzGeometryBuilder::QuartzGeometryBuilder(IGraphFactory* graphics_factory, + CGContextRef cg_context) + : OsxQuartzResource(graphics_factory), cg_context_(cg_context) {} + +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_)); +} +} // namespace cru::platform::graphics::osx::quartz |