aboutsummaryrefslogtreecommitdiff
path: root/src/osx/graphics/quartz/Brush.cpp
blob: 41e9d2c54cd92cf75199e985acadfcac013b8b5b (plain)
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
#include "cru/osx/graphics/quartz/Brush.hpp"

namespace cru::platform::graphics::osx::quartz {
QuartzSolidColorBrush::QuartzSolidColorBrush(IGraphicsFactory* graphics_factory,
                                             const Color& color)
    : QuartzBrush(graphics_factory), color_(color) {
  cg_color_ =
      CGColorCreateGenericRGB(color.GetFloatRed(), color.GetFloatGreen(),
                              color.GetFloatBlue(), color.GetFloatAlpha());
}

QuartzSolidColorBrush::~QuartzSolidColorBrush() { CGColorRelease(cg_color_); }

void QuartzSolidColorBrush::SetColor(const Color& color) {
  color_ = color;
  CGColorRelease(cg_color_);
  cg_color_ =
      CGColorCreateGenericRGB(color.GetFloatRed(), color.GetFloatGreen(),
                              color.GetFloatBlue(), color.GetFloatAlpha());
}

void QuartzSolidColorBrush::Select(CGContextRef context) {
  CGContextSaveGState(context);

  CGContextSetStrokeColorWithColor(context, cg_color_);
  CGContextSetFillColorWithColor(context, cg_color_);

  CGContextRestoreGState(context);
}
}  // namespace cru::platform::graphics::osx::quartz