diff options
author | crupest <crupest@outlook.com> | 2021-08-24 00:58:57 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-08-24 00:58:57 +0800 |
commit | fdafa45b7d28a191439b0c0deabff94b0d1a7094 (patch) | |
tree | d7ebe04d5ce304ed99d13fdff55d94b5a4ef014b /src/osx/graphics/quartz/Painter.cpp | |
parent | 100c2ae5cd7b815dc9accca0fa9ceaca2f5d1020 (diff) | |
download | cru-fdafa45b7d28a191439b0c0deabff94b0d1a7094.tar.gz cru-fdafa45b7d28a191439b0c0deabff94b0d1a7094.tar.bz2 cru-fdafa45b7d28a191439b0c0deabff94b0d1a7094.zip |
...
Diffstat (limited to 'src/osx/graphics/quartz/Painter.cpp')
-rw-r--r-- | src/osx/graphics/quartz/Painter.cpp | 53 |
1 files changed, 43 insertions, 10 deletions
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<QuartzBrush>(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<QuartzBrush>(brush, GetPlatformId()); + b->Select(cg_context_); + CGContextStrokeRectWithWidth(cg_context_, Convert(rectangle), width); +} + +void QuartzCGContextPainter::FillRectangle(const Rect& rectangle, + IBrush* brush) { + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + b->Select(cg_context_); + CGContextFillRect(cg_context_, Convert(rectangle)); +} + +} // namespace cru::platform::graphics::osx::quartz |