aboutsummaryrefslogtreecommitdiff
path: root/src/osx/graphics/quartz/Painter.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-10-20 17:04:27 +0800
committercrupest <crupest@outlook.com>2021-10-20 17:04:27 +0800
commit152133978872f6d6476c3fc7e0e3a5a6cc23b119 (patch)
tree374a793cb56ef5c8d1e413f4b781fec087e28678 /src/osx/graphics/quartz/Painter.cpp
parent398aadcddb8b6ed20b17f6c56cd7b49947b72136 (diff)
downloadcru-152133978872f6d6476c3fc7e0e3a5a6cc23b119.tar.gz
cru-152133978872f6d6476c3fc7e0e3a5a6cc23b119.tar.bz2
cru-152133978872f6d6476c3fc7e0e3a5a6cc23b119.zip
...
Diffstat (limited to 'src/osx/graphics/quartz/Painter.cpp')
-rw-r--r--src/osx/graphics/quartz/Painter.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/osx/graphics/quartz/Painter.cpp b/src/osx/graphics/quartz/Painter.cpp
index 0dc9e786..3f859571 100644
--- a/src/osx/graphics/quartz/Painter.cpp
+++ b/src/osx/graphics/quartz/Painter.cpp
@@ -6,6 +6,7 @@
#include "cru/osx/graphics/quartz/Geometry.hpp"
#include "cru/osx/graphics/quartz/TextLayout.hpp"
#include "cru/platform/Check.hpp"
+#include "cru/platform/Color.hpp"
#include "cru/platform/Exception.hpp"
#include "cru/platform/graphics/util/Painter.hpp"
@@ -118,20 +119,38 @@ void QuartzCGContextPainter::DrawText(const Point& offset,
Validate();
auto tl = CheckPlatform<OsxCTTextLayout>(text_layout, GetPlatformId());
- auto b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
+
+ Color color;
+
+ if (auto b = dynamic_cast<QuartzSolidColorBrush*>(brush)) {
+ color = b->GetColor();
+ } else {
+ color = colors::black;
+ }
util::WithTransform(this, Matrix::Translation(offset),
- [this, tl, b](IPainter*) {
- CTFrameDraw(tl->GetCTFrameRef(), cg_context_);
+ [this, tl, color](IPainter*) {
+ auto frame = tl->CreateFrameWithColor(color);
+ Ensures(frame);
+ CTFrameDraw(frame, cg_context_);
+ CFRelease(frame);
});
}
void QuartzCGContextPainter::PushLayer(const Rect& bounds) {
- // TODO: Implement this.
+ Validate();
+ clip_stack_.push_back(bounds);
+ CGContextClipToRect(cg_context_, Convert(bounds));
}
void QuartzCGContextPainter::PopLayer() {
- // TODO: Implement this.
+ Validate();
+ clip_stack_.pop_back();
+ if (clip_stack_.empty()) {
+ CGContextResetClip(cg_context_);
+ } else {
+ CGContextClipToRect(cg_context_, Convert(clip_stack_.back()));
+ }
}
void QuartzCGContextPainter::EndDraw() { DoEndDraw(); }