From fdafa45b7d28a191439b0c0deabff94b0d1a7094 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 24 Aug 2021 00:58:57 +0800 Subject: ... --- src/osx/graphics/quartz/Convert.cpp | 14 +++++++++- src/osx/graphics/quartz/Painter.cpp | 53 ++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 11 deletions(-) (limited to 'src/osx') diff --git a/src/osx/graphics/quartz/Convert.cpp b/src/osx/graphics/quartz/Convert.cpp index 95923083..c1177a41 100644 --- a/src/osx/graphics/quartz/Convert.cpp +++ b/src/osx/graphics/quartz/Convert.cpp @@ -2,10 +2,22 @@ namespace cru::platform::graphics::osx::quartz { CGAffineTransform Convert(const Matrix& matrix) { - return CGAffineTransformMake(matrix.m11, matrix.m12, matrix.m21, matrix.m22, matrix.m31, matrix.m32); + return CGAffineTransformMake(matrix.m11, matrix.m12, matrix.m21, matrix.m22, + matrix.m31, matrix.m32); } Matrix Convert(const CGAffineTransform& matrix) { return Matrix(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty); } + +CGRect Convert(const Rect& rect) { + return CGRect{CGPoint{rect.left, rect.top}, CGSize{rect.width, rect.height}}; +} + +Rect Convert(const CGRect& rect) { + return Rect{static_cast(rect.origin.x), + static_cast(rect.origin.y), + static_cast(rect.size.width), + static_cast(rect.size.height)}; +} } // namespace cru::platform::graphics::osx::quartz diff --git a/src/osx/graphics/quartz/Painter.cpp b/src/osx/graphics/quartz/Painter.cpp index 65cf9154..42f6f1b7 100644 --- a/src/osx/graphics/quartz/Painter.cpp +++ b/src/osx/graphics/quartz/Painter.cpp @@ -1,16 +1,49 @@ #include "cru/osx/graphics/quartz/Painter.hpp" +#include "cru/osx/graphics/quartz/Brush.hpp" #include "cru/osx/graphics/quartz/Convert.hpp" +#include "cru/platform/Check.hpp" namespace cru::platform::graphics::osx::quartz { - Matrix QuartzCGContextPainter::GetTransform() { - return Convert(CGContextGetCTM(cg_context_)); - } - - void QuartzCGContextPainter::SetTransform(const Matrix& matrix) { - auto old = CGContextGetCTM(cg_context_); - old = CGAffineTransformInvert(old); - CGContextConcatCTM(cg_context_, old); - CGContextConcatCTM(cg_context_, Convert(matrix)); - } +Matrix QuartzCGContextPainter::GetTransform() { + return Convert(CGContextGetCTM(cg_context_)); } + +void QuartzCGContextPainter::SetTransform(const Matrix& matrix) { + auto old = CGContextGetCTM(cg_context_); + old = CGAffineTransformInvert(old); + CGContextConcatCTM(cg_context_, old); + CGContextConcatCTM(cg_context_, Convert(matrix)); +} + +void QuartzCGContextPainter::Clear(const Color& color) { + // TODO: +} + +void QuartzCGContextPainter::DrawLine(const Point& start, const Point& end, + IBrush* brush, float width) { + CGContextBeginPath(cg_context_); + CGContextMoveToPoint(cg_context_, start.x, start.y); + CGContextAddLineToPoint(cg_context_, end.x, end.y); + + QuartzBrush* b = CheckPlatform(brush, GetPlatformId()); + b->Select(cg_context_); + CGContextSetLineWidth(cg_context_, width); + CGContextStrokePath(cg_context_); +} + +void QuartzCGContextPainter::StrokeRectangle(const Rect& rectangle, + IBrush* brush, float width) { + QuartzBrush* b = CheckPlatform(brush, GetPlatformId()); + b->Select(cg_context_); + CGContextStrokeRectWithWidth(cg_context_, Convert(rectangle), width); +} + +void QuartzCGContextPainter::FillRectangle(const Rect& rectangle, + IBrush* brush) { + QuartzBrush* b = CheckPlatform(brush, GetPlatformId()); + b->Select(cg_context_); + CGContextFillRect(cg_context_, Convert(rectangle)); +} + +} // namespace cru::platform::graphics::osx::quartz -- cgit v1.2.3