| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 | #pragma once
#include "Resource.h"
#include "cru/base/Base.h"
#include "cru/platform/graphics/Base.h"
#include "cru/platform/graphics/Painter.h"
#include <CoreGraphics/CoreGraphics.h>
#include <functional>
namespace cru::platform::graphics::quartz {
class QuartzCGContextPainter : public OsxQuartzResource,
                               public virtual IPainter {
  CRU_DEFINE_CLASS_LOG_TAG("QuartzCGContextPainter")
 public:
  explicit QuartzCGContextPainter(
      IGraphicsFactory* graphics_factory, CGContextRef cg_context,
      bool auto_release, const Size& size,
      std::function<void(QuartzCGContextPainter*)> on_end_draw);
  CRU_DELETE_COPY(QuartzCGContextPainter)
  CRU_DELETE_MOVE(QuartzCGContextPainter)
  ~QuartzCGContextPainter() override;
 public:
  Matrix GetTransform() override;
  void SetTransform(const Matrix& matrix) override;
  void ConcatTransform(const Matrix& matrix) override;
  void Clear(const Color& color) override;
  void DrawLine(const Point& start, const Point& end, IBrush* brush,
                float width) override;
  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) override;
  void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) override;
  void FillGeometry(IGeometry* geometry, IBrush* brush) override;
  void DrawText(const Point& offset, ITextLayout* text_layout,
                IBrush* brush) override;
  void DrawImage(const Point& offset, IImage* image) override;
  void PushLayer(const Rect& bounds) override;
  void PopLayer() override;
  void EndDraw() override;
  void PushState() override;
  void PopState() override;
 private:
  void SetLineWidth(float width);
  void DoEndDraw();
  void Validate();
 private:
  CGContextRef cg_context_;
  bool auto_release_;
  Size size_;
  Matrix transform_;
  std::function<void(QuartzCGContextPainter*)> on_end_draw_;
  std::vector<Rect> clip_stack_;
};
}  // namespace cru::platform::graphics::quartz
 |