aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/osx/graphics/quartz/Painter.hpp6
-rw-r--r--include/cru/platform/graphics/Painter.hpp4
-rw-r--r--src/osx/graphics/quartz/Brush.cpp4
-rw-r--r--src/osx/graphics/quartz/Painter.cpp33
4 files changed, 40 insertions, 7 deletions
diff --git a/include/cru/osx/graphics/quartz/Painter.hpp b/include/cru/osx/graphics/quartz/Painter.hpp
index e9b3365d..0889d413 100644
--- a/include/cru/osx/graphics/quartz/Painter.hpp
+++ b/include/cru/osx/graphics/quartz/Painter.hpp
@@ -38,6 +38,10 @@ class QuartzCGContextPainter : public OsxQuartzResource,
void StrokeRectangle(const Rect& rectangle, IBrush* brush,
float width) override;
void FillRectangle(const Rect& rectangle, IBrush* brush) override;
+ void StrokeEllipse(const Rect& outline_rect, IBrush* brush,
+ float width) override;
+ void FillEllipse(const Rect& outline_rect, IBrush* brush,
+ float width) override;
void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) override;
void FillGeometry(IGeometry* geometry, IBrush* brush) override;
@@ -56,6 +60,8 @@ class QuartzCGContextPainter : public OsxQuartzResource,
void PopState() override;
private:
+ void SetLineWidth(float width);
+
void DoEndDraw();
void Validate();
diff --git a/include/cru/platform/graphics/Painter.hpp b/include/cru/platform/graphics/Painter.hpp
index 9bde0640..4f1724ec 100644
--- a/include/cru/platform/graphics/Painter.hpp
+++ b/include/cru/platform/graphics/Painter.hpp
@@ -16,6 +16,10 @@ struct IPainter : virtual IPlatformResource {
virtual void StrokeRectangle(const Rect& rectangle, IBrush* brush,
float width) = 0;
virtual void FillRectangle(const Rect& rectangle, IBrush* brush) = 0;
+ virtual void StrokeEllipse(const Rect& outline_rect, IBrush* brush,
+ float width) = 0;
+ virtual void FillEllipse(const Rect& outline_rect, IBrush* brush,
+ float width) = 0;
virtual void StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) = 0;
diff --git a/src/osx/graphics/quartz/Brush.cpp b/src/osx/graphics/quartz/Brush.cpp
index 41e9d2c5..9daa8e13 100644
--- a/src/osx/graphics/quartz/Brush.cpp
+++ b/src/osx/graphics/quartz/Brush.cpp
@@ -20,11 +20,7 @@ void QuartzSolidColorBrush::SetColor(const Color& color) {
}
void QuartzSolidColorBrush::Select(CGContextRef context) {
- CGContextSaveGState(context);
-
CGContextSetStrokeColorWithColor(context, cg_color_);
CGContextSetFillColorWithColor(context, cg_color_);
-
- CGContextRestoreGState(context);
}
} // namespace cru::platform::graphics::osx::quartz
diff --git a/src/osx/graphics/quartz/Painter.cpp b/src/osx/graphics/quartz/Painter.cpp
index eee175ac..ec951e6c 100644
--- a/src/osx/graphics/quartz/Painter.cpp
+++ b/src/osx/graphics/quartz/Painter.cpp
@@ -8,7 +8,6 @@
#include "cru/platform/Check.hpp"
#include "cru/platform/Color.hpp"
#include "cru/platform/Exception.hpp"
-#include "cru/platform/graphics/util/Painter.hpp"
namespace cru::platform::graphics::osx::quartz {
QuartzCGContextPainter::QuartzCGContextPainter(
@@ -75,7 +74,8 @@ void QuartzCGContextPainter::DrawLine(const Point& start, const Point& end,
QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
- CGContextSetLineWidth(cg_context_, width);
+ SetLineWidth(width);
+
CGContextStrokePath(cg_context_);
}
@@ -97,6 +97,26 @@ void QuartzCGContextPainter::FillRectangle(const Rect& rectangle,
CGContextFillRect(cg_context_, Convert(rectangle));
}
+void QuartzCGContextPainter::StrokeEllipse(const Rect& outline_rect,
+ IBrush* brush, float width) {
+ Validate();
+
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
+ b->Select(cg_context_);
+ SetLineWidth(width);
+
+ CGContextStrokeEllipseInRect(cg_context_, Convert(outline_rect));
+}
+
+void QuartzCGContextPainter::FillEllipse(const Rect& outline_rect,
+ IBrush* brush, float width) {
+ Validate();
+
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
+ b->Select(cg_context_);
+ CGContextFillEllipseInRect(cg_context_, Convert(outline_rect));
+}
+
void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
Validate();
@@ -105,7 +125,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
- CGContextSetLineWidth(cg_context_, width);
+ SetLineWidth(width);
+
CGContextBeginPath(cg_context_);
CGContextAddPath(cg_context_, g->GetCGPath());
CGContextStrokePath(cg_context_);
@@ -189,6 +210,12 @@ void QuartzCGContextPainter::PopState() {
void QuartzCGContextPainter::EndDraw() { DoEndDraw(); }
+void QuartzCGContextPainter::SetLineWidth(float width) {
+ if (cg_context_) {
+ CGContextSetLineWidth(cg_context_, width);
+ }
+}
+
void QuartzCGContextPainter::DoEndDraw() {
if (cg_context_) {
CGContextFlush(cg_context_);