diff options
author | mitchell <unknown> | 2018-05-25 17:44:28 -0400 |
---|---|---|
committer | mitchell <unknown> | 2018-05-25 17:44:28 -0400 |
commit | fba451a1d76be9b6945c9d5d7e219f7d7d1a4260 (patch) | |
tree | 0e1aa6f197c34e6c1a9782e264359c220ed014a7 /cocoa/PlatCocoa.mm | |
parent | 9f00df4e57e917035d2f939ce70ccf2ee83a9725 (diff) | |
download | scintilla-mirror-fba451a1d76be9b6945c9d5d7e219f7d7d1a4260.tar.gz |
Backport: Add GradientRectangle method to Surface to draw rectangles with vertical or horizontal gradients.
Backport of changeset 6965:90c71d69e3b6.
Diffstat (limited to 'cocoa/PlatCocoa.mm')
-rw-r--r-- | cocoa/PlatCocoa.mm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index b517a7e6a..65481c252 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -690,6 +690,50 @@ void Scintilla::SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, Colou } } +void Scintilla::SurfaceImpl::GradientRectangle(PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) { + if (!gc) { + return; + } + + CGPoint ptStart = CGPointMake(rc.left, rc.top); + CGPoint ptEnd = CGPointMake(rc.left, rc.bottom); + if (options == GradientOptions::leftToRight) { + ptEnd = CGPointMake(rc.right, rc.top); + } + + std::vector<CGFloat> components; + std::vector<CGFloat> locations; + for (const ColourStop &stop : stops) { + locations.push_back(stop.position); + components.push_back(stop.colour.GetRedComponent()); + components.push_back(stop.colour.GetGreenComponent()); + components.push_back(stop.colour.GetBlueComponent()); + components.push_back(stop.colour.GetAlphaComponent()); + } + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + if (!colorSpace) { + return; + } + + CGGradientRef gradiantRef = CGGradientCreateWithColorComponents(colorSpace, + components.data(), + locations.data(), + locations.size()); + if (gradiantRef) { + CGContextSaveGState(gc); + CGRect rect = PRectangleToCGRect(rc); + CGContextClipToRect(gc, rect); + CGContextBeginPath(gc); + CGContextAddRect(gc, rect); + CGContextClosePath(gc); + CGContextDrawLinearGradient(gc, gradiantRef, ptStart, ptEnd, 0); + CGGradientRelease(gradiantRef); + CGContextRestoreGState(gc); + } + CGColorSpaceRelease(colorSpace); +} + static void ProviderReleaseData(void *, const void *data, size_t) { const unsigned char *pixels = static_cast<const unsigned char *>(data); delete []pixels; |