aboutsummaryrefslogtreecommitdiff
path: root/src/osx/graphics/quartz/Painter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osx/graphics/quartz/Painter.cpp')
-rw-r--r--src/osx/graphics/quartz/Painter.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/osx/graphics/quartz/Painter.cpp b/src/osx/graphics/quartz/Painter.cpp
index be29310c..6effe9f9 100644
--- a/src/osx/graphics/quartz/Painter.cpp
+++ b/src/osx/graphics/quartz/Painter.cpp
@@ -4,6 +4,7 @@
#include "cru/osx/graphics/quartz/Convert.hpp"
#include "cru/osx/graphics/quartz/Geometry.hpp"
#include "cru/platform/Check.hpp"
+#include "cru/platform/Exception.hpp"
namespace cru::platform::graphics::osx::quartz {
Matrix QuartzCGContextPainter::GetTransform() {
@@ -18,11 +19,21 @@ void QuartzCGContextPainter::SetTransform(const Matrix& matrix) {
}
void QuartzCGContextPainter::Clear(const Color& color) {
- // TODO:
+ Validate();
+
+ CGColorRef c =
+ CGColorCreateGenericRGB(color.GetFloatRed(), color.GetFloatGreen(),
+ color.GetFloatBlue(), color.GetFloatAlpha());
+ CGContextSetFillColorWithColor(cg_context_, c);
+ CGColorRelease(c);
+
+ CGContextFillRect(cg_context_, Convert(Rect{Point{}, size_}));
}
void QuartzCGContextPainter::DrawLine(const Point& start, const Point& end,
IBrush* brush, float width) {
+ Validate();
+
CGContextBeginPath(cg_context_);
CGContextMoveToPoint(cg_context_, start.x, start.y);
CGContextAddLineToPoint(cg_context_, end.x, end.y);
@@ -35,6 +46,8 @@ void QuartzCGContextPainter::DrawLine(const Point& start, const Point& end,
void QuartzCGContextPainter::StrokeRectangle(const Rect& rectangle,
IBrush* brush, float width) {
+ Validate();
+
QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextStrokeRectWithWidth(cg_context_, Convert(rectangle), width);
@@ -42,6 +55,8 @@ void QuartzCGContextPainter::StrokeRectangle(const Rect& rectangle,
void QuartzCGContextPainter::FillRectangle(const Rect& rectangle,
IBrush* brush) {
+ Validate();
+
QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextFillRect(cg_context_, Convert(rectangle));
@@ -49,6 +64,8 @@ void QuartzCGContextPainter::FillRectangle(const Rect& rectangle,
void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
+ Validate();
+
QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId());
QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
@@ -60,6 +77,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
}
void QuartzCGContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
+ Validate();
+
QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId());
QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
@@ -68,4 +87,28 @@ void QuartzCGContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
CGContextAddPath(cg_context_, g->GetCGPath());
CGContextFillPath(cg_context_);
}
+
+void QuartzCGContextPainter::DrawText(const Point& offset,
+ ITextLayout* text_layout, IBrush* brush) {
+ // TODO: Implement this.
+}
+
+void QuartzCGContextPainter::PushLayer(const Rect& bounds) {
+ // TODO: Implement this.
+}
+
+void QuartzCGContextPainter::PopLayer() {
+ // TODO: Implement this.
+}
+
+void QuartzCGContextPainter::EndDraw() {
+ CGContextRelease(cg_context_);
+ CGContextFlush(cg_context_);
+ cg_context_ = nullptr;
+}
+
+void QuartzCGContextPainter::Validate() {
+ if (cg_context_ == nullptr)
+ throw ReuseException(u"QuartzCGContextPainter has already be released.");
+}
} // namespace cru::platform::graphics::osx::quartz