diff --git a/Frameworks/CoreGraphics/CGContext.mm b/Frameworks/CoreGraphics/CGContext.mm index ddb75fb366..0bd842cfab 100644 --- a/Frameworks/CoreGraphics/CGContext.mm +++ b/Frameworks/CoreGraphics/CGContext.mm @@ -59,7 +59,7 @@ - (void)dealloc { #ifdef DEBUG_CONTEXT_COUNT TraceVerbose(TAG, L"contextCount: %d", contextCount); #endif - object_setClass((id) this, [CGNSContext class]); + object_setClass((id)this, [CGNSContext class]); scale = 1.0f; _backing = pDest->Backing()->CreateDrawingContext(this); } @@ -753,18 +753,16 @@ void CGContextAddLines(CGContextRef pContext, const CGPoint* pt, unsigned count) } /** - @Status Stub + @Status Interoperable */ void CGContextBeginTransparencyLayer(CGContextRef ctx, CFDictionaryRef auxInfo) { - UNIMPLEMENTED(); ctx->Backing()->CGContextBeginTransparencyLayer((id)auxInfo); } /** - @Status Stub + @Status Interoperable */ void CGContextEndTransparencyLayer(CGContextRef ctx) { - UNIMPLEMENTED(); ctx->Backing()->CGContextEndTransparencyLayer(); } @@ -1131,11 +1129,11 @@ void CGContextBeginPage(CGContextRef c, const CGRect* mediaBox) { } /** - @Status Stub + @Status Interoperable @Notes */ -void CGContextBeginTransparencyLayerWithRect(CGContextRef c, CGRect rect, CFDictionaryRef auxInfo) { - UNIMPLEMENTED(); +void CGContextBeginTransparencyLayerWithRect(CGContextRef ctx, CGRect rect, CFDictionaryRef auxInfo) { + ctx->Backing()->CGContextBeginTransparencyLayerWithRect(rect, (id)auxInfo); } /** diff --git a/Frameworks/CoreGraphics/CGContextCairo.mm b/Frameworks/CoreGraphics/CGContextCairo.mm index 55f04fed23..45398cd28c 100644 --- a/Frameworks/CoreGraphics/CGContextCairo.mm +++ b/Frameworks/CoreGraphics/CGContextCairo.mm @@ -1681,35 +1681,60 @@ } void CGContextCairo::CGContextBeginTransparencyLayer(id auxInfo) { - // [To future blamb, next time you comment this out, make a note as to why] + ObtainLock(); + LOCK_CAIRO(); + cairo_save(_drawContext); + CGContextSaveGState(); + // Set defaults for new group/layer + CGContextSetAlpha(1.0); + CGContextSetShadowWithColor(CGSizeMake(0, 0), 0, NULL); + CGContextSetBlendMode(kCGBlendModeNormal); + // Create group cairo_push_group(_drawContext); + UNLOCK_CAIRO(); } -void CGContextCairo::CGContextEndTransparencyLayer() { +void CGContextCairo::CGContextBeginTransparencyLayerWithRect(CGRect rect, id auxInfo) { ObtainLock(); - LOCK_CAIRO(); - cairo_pop_group_to_source(_drawContext); - cairo_save(_drawContext); + // Add rect and clip with it cairo_new_path(_drawContext); - cairo_rectangle(_drawContext, 0, 0, _imgDest->Backing()->Width(), _imgDest->Backing()->Height()); + CGContextAddRect(rect); + cairo_clip(_drawContext); + CGContextSaveGState(); + // Set defaults for new group/layer + CGContextSetAlpha(1.0); + CGContextSetShadowWithColor(CGSizeMake(0, 0), 0, NULL); + CGContextSetBlendMode(kCGBlendModeNormal); + // Create group + cairo_push_group(_drawContext); + UNLOCK_CAIRO(); +} +void CGContextCairo::CGContextEndTransparencyLayer() { + ObtainLock(); + LOCK_CAIRO(); + // Retrieve the group as a pattern + cairo_pattern_t* group = cairo_pop_group(_drawContext); + // Restore the CG state before the group was created + CGContextRestoreGState(); + // Set the transform matrix cairo_matrix_t m; float trans[6]; memcpy(trans, &curState->curTransform, sizeof(curState->curTransform)); - m.xx = trans[0]; m.yx = trans[1]; m.xy = trans[2]; m.yy = trans[3]; m.x0 = trans[4]; m.y0 = trans[5]; - cairo_set_matrix(_drawContext, &m); - cairo_fill(_drawContext); - + // Draw the group + cairo_set_source(_drawContext, group); + cairo_paint_with_alpha(_drawContext, curState->curFillColor.a); cairo_restore(_drawContext); + cairo_pattern_destroy(group); UNLOCK_CAIRO(); } diff --git a/Frameworks/CoreGraphics/CGContextImpl.mm b/Frameworks/CoreGraphics/CGContextImpl.mm index 106b5f1576..37d481790c 100644 --- a/Frameworks/CoreGraphics/CGContextImpl.mm +++ b/Frameworks/CoreGraphics/CGContextImpl.mm @@ -694,6 +694,9 @@ void CGContextImpl::CGContextBeginTransparencyLayer(id auxInfo) { } +void CGContextImpl::CGContextBeginTransparencyLayerWithRect(CGRect rect, id auxInfo) { +} + void CGContextImpl::CGContextEndTransparencyLayer() { } diff --git a/Frameworks/include/CGContextCairo.h b/Frameworks/include/CGContextCairo.h index 61b5abbbf8..8f574d4dcf 100644 --- a/Frameworks/include/CGContextCairo.h +++ b/Frameworks/include/CGContextCairo.h @@ -123,6 +123,7 @@ class CGContextCairo : public CGContextImpl { virtual void CGContextClipToRect(CGRect rect); virtual void CGContextBeginTransparencyLayer(id auxInfo); + virtual void CGContextBeginTransparencyLayerWithRect(CGRect rect, id auxInfo); virtual void CGContextEndTransparencyLayer(); virtual void CGContextSetGrayStrokeColor(float gray, float alpha); diff --git a/Frameworks/include/CGContextImpl.h b/Frameworks/include/CGContextImpl.h index 48056bff01..ca3f030eb1 100644 --- a/Frameworks/include/CGContextImpl.h +++ b/Frameworks/include/CGContextImpl.h @@ -153,6 +153,7 @@ class CGContextImpl { virtual void CGContextClipToRect(CGRect rect); virtual void CGContextBeginTransparencyLayer(id auxInfo); + virtual void CGContextBeginTransparencyLayerWithRect(CGRect rect, id auxInfo); virtual void CGContextEndTransparencyLayer(); virtual void CGContextSetGrayStrokeColor(float gray, float alpha); diff --git a/include/CoreGraphics/CGContext.h b/include/CoreGraphics/CGContext.h index 3fcd11a5d7..7029dfe730 100644 --- a/include/CoreGraphics/CGContext.h +++ b/include/CoreGraphics/CGContext.h @@ -188,9 +188,9 @@ COREGRAPHICS_EXPORT void CGContextRotateCTM(CGContextRef c, CGFloat angle); COREGRAPHICS_EXPORT void CGContextScaleCTM(CGContextRef c, CGFloat sx, CGFloat sy); COREGRAPHICS_EXPORT void CGContextTranslateCTM(CGContextRef c, CGFloat tx, CGFloat ty); -COREGRAPHICS_EXPORT void CGContextBeginTransparencyLayer(CGContextRef c, CFDictionaryRef auxiliaryInfo) STUB_METHOD; -COREGRAPHICS_EXPORT void CGContextBeginTransparencyLayerWithRect(CGContextRef c, CGRect rect, CFDictionaryRef auxInfo) STUB_METHOD; -COREGRAPHICS_EXPORT void CGContextEndTransparencyLayer(CGContextRef c) STUB_METHOD; +COREGRAPHICS_EXPORT void CGContextBeginTransparencyLayer(CGContextRef c, CFDictionaryRef auxiliaryInfo); +COREGRAPHICS_EXPORT void CGContextBeginTransparencyLayerWithRect(CGContextRef c, CGRect rect, CFDictionaryRef auxInfo); +COREGRAPHICS_EXPORT void CGContextEndTransparencyLayer(CGContextRef c); COREGRAPHICS_EXPORT void CGContextDrawTiledImage(CGContextRef c, CGRect rect, CGImageRef image); COREGRAPHICS_EXPORT void CGContextDrawImage(CGContextRef c, CGRect rect, CGImageRef image); diff --git a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems index 58a4dfd606..031831816e 100644 --- a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems +++ b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems @@ -16,6 +16,7 @@ + diff --git a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems.filters b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems.filters index 4613e52ec5..e08239cc98 100644 --- a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems.filters +++ b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-Headers-WinStore10/CGCatalog-Headers.vcxitems.filters @@ -30,6 +30,9 @@ CGCatalog\Samples + + CGCatalog\Samples + CGCatalog\Samples diff --git a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj index b05bc008ff..52db9e01c8 100644 --- a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj +++ b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj @@ -188,6 +188,7 @@ + diff --git a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj.filters b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj.filters index 2c0b133151..57a144cf76 100644 --- a/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj.filters +++ b/samples/CGCatalog/CGCatalog.vsimporter/CGCatalog-WinStore10/CGCatalog.vcxproj.filters @@ -69,6 +69,9 @@ CGCatalog + + CGCatalog\Samples + CGCatalog\Samples diff --git a/samples/CGCatalog/CGCatalog.xcodeproj/project.pbxproj b/samples/CGCatalog/CGCatalog.xcodeproj/project.pbxproj index 71de4db12c..c36a08c7a3 100644 --- a/samples/CGCatalog/CGCatalog.xcodeproj/project.pbxproj +++ b/samples/CGCatalog/CGCatalog.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ F0D21CBF1D06078D002C32EE /* CGCBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0D21CBE1D06078D002C32EE /* CGCBaseViewController.m */; }; FB10A19A1D10792E008EA8A1 /* CGCCGContextSetPatternPhase.m in Sources */ = {isa = PBXBuildFile; fileRef = FB10A1991D10792E008EA8A1 /* CGCCGContextSetPatternPhase.m */; }; FB1264921D0A0484007C907C /* CGCCGContextBeginEndTransparencyLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = FB1264911D0A0484007C907C /* CGCCGContextBeginEndTransparencyLayer.m */; }; + FB18A4BA1D1AD10A00A9555A /* CGCCGContextBeginTransparencyLayerWithRect.m in Sources */ = {isa = PBXBuildFile; fileRef = FB18A4B91D1AD10A00A9555A /* CGCCGContextBeginTransparencyLayerWithRect.m */; }; FBA3A50C1D132C9A00C3C011 /* CGCCGContextReplacePathWithStrokedPath.m in Sources */ = {isa = PBXBuildFile; fileRef = FBA3A50B1D132C9A00C3C011 /* CGCCGContextReplacePathWithStrokedPath.m */; }; /* End PBXBuildFile section */ @@ -45,6 +46,8 @@ FB10A1991D10792E008EA8A1 /* CGCCGContextSetPatternPhase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CGCCGContextSetPatternPhase.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; FB1264901D0A0484007C907C /* CGCCGContextBeginEndTransparencyLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = CGCCGContextBeginEndTransparencyLayer.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; FB1264911D0A0484007C907C /* CGCCGContextBeginEndTransparencyLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CGCCGContextBeginEndTransparencyLayer.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + FB18A4B81D1AD10A00A9555A /* CGCCGContextBeginTransparencyLayerWithRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGCCGContextBeginTransparencyLayerWithRect.h; sourceTree = ""; }; + FB18A4B91D1AD10A00A9555A /* CGCCGContextBeginTransparencyLayerWithRect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGCCGContextBeginTransparencyLayerWithRect.m; sourceTree = ""; }; FBA3A50A1D132C9A00C3C011 /* CGCCGContextReplacePathWithStrokedPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = CGCCGContextReplacePathWithStrokedPath.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; FBA3A50B1D132C9A00C3C011 /* CGCCGContextReplacePathWithStrokedPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CGCCGContextReplacePathWithStrokedPath.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; /* End PBXFileReference section */ @@ -112,6 +115,8 @@ 552816071D062F6B0082C178 /* CGCCGContextViewController.m */, FB1264901D0A0484007C907C /* CGCCGContextBeginEndTransparencyLayer.h */, FB1264911D0A0484007C907C /* CGCCGContextBeginEndTransparencyLayer.m */, + FB18A4B81D1AD10A00A9555A /* CGCCGContextBeginTransparencyLayerWithRect.h */, + FB18A4B91D1AD10A00A9555A /* CGCCGContextBeginTransparencyLayerWithRect.m */, FB10A1981D10792E008EA8A1 /* CGCCGContextSetPatternPhase.h */, FB10A1991D10792E008EA8A1 /* CGCCGContextSetPatternPhase.m */, FBA3A50A1D132C9A00C3C011 /* CGCCGContextReplacePathWithStrokedPath.h */, @@ -207,6 +212,7 @@ 552816081D062F6B0082C178 /* CGCCGContextViewController.m in Sources */, F0D21C861D05FEF9002C32EE /* AppDelegate.m in Sources */, F0D21CBF1D06078D002C32EE /* CGCBaseViewController.m in Sources */, + FB18A4BA1D1AD10A00A9555A /* CGCCGContextBeginTransparencyLayerWithRect.m in Sources */, 552816051D062EC90082C178 /* CGCCGBitmapContentViewController.m in Sources */, F0D21CB71D060466002C32EE /* CGCCGPathApplyViewController.m in Sources */, F0D21C831D05FEF9002C32EE /* main.m in Sources */, diff --git a/samples/CGCatalog/CGCatalog/CGCRootViewController.m b/samples/CGCatalog/CGCatalog/CGCRootViewController.m index f6c67cd2db..c02f51166a 100644 --- a/samples/CGCatalog/CGCatalog/CGCRootViewController.m +++ b/samples/CGCatalog/CGCatalog/CGCRootViewController.m @@ -17,6 +17,7 @@ #import "CGCRootViewController.h" #import "CGCCGBitmapContentViewController.h" #import "CGCCGContextBeginEndTransparencyLayer.h" +#import "CGCCGContextBeginTransparencyLayerWithRect.h" #import "CGCCGContextReplacePathWithStrokedPath.h" #import "CGCCGContextSetPatternPhase.h" #import "CGCCGContextViewController.h" @@ -57,6 +58,7 @@ - (NSArray*)samples { [SampleRow row:@"CGContext" class:[CGCCGContextViewController class]], [SampleRow row:@"CGBitmapContext" class:[CGCCGBitmapContentViewController class]], [SampleRow row:@"CGContextBeginEndTransparencyLayer" class:[CGCCGContextBeginEndTransparencyLayer class]], + [SampleRow row:@"CGContextBeginTransparencyLayerWithRect" class:[CGCCGContextBeginTransparencyLayerWithRect class]], [SampleRow row:@"CGContextSetPatternPhase" class:[CGCCGContextSetPatternPhase class]], [SampleRow row:@"CGContextReplacePathWithStrokedPath" class:[CGCCGContextReplacePathWithStrokedPath class]], ]; diff --git a/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginEndTransparencyLayer.m b/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginEndTransparencyLayer.m index bba4c2b11d..a90594a28a 100644 --- a/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginEndTransparencyLayer.m +++ b/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginEndTransparencyLayer.m @@ -34,21 +34,15 @@ - (void)drawRect:(CGRect)rect { // Rect Size CGFloat rectWidth = maxWidth / 2.0; CGFloat rectHeight = rectWidth; - // CGFloat rectHeight = maxHeight / 2.0; // Draw background rect CGContextSetFillColorWithColor(context, [UIColor yellowColor].CGColor); CGContextFillRect(context, CGRectMake(rectWidth / 2 - 25, maxHeight / 2 - rectHeight / 2 - 25, rectWidth + 25, rectHeight + 25)); - // Note: Shadow or Alpha would be better test samples for this, but are not fully implemented yet in the bridge. - // TODO: Use Shadow or Alpha instead of BlendMode when supported by the bridge - // Enable shadow - /*CGSize shadowOffset = CGSizeMake(10, 20); - CGContextSetShadow(context, shadowOffset, 10);*/ - // Set composite alpha of the transparency layer - // CGContextSetAlpha(context, 0.5); - - CGContextSetBlendMode(context, kCGBlendModeDifference); + // Set the blend mode to use between the background rectangle and the ones in the transparency layer + // Note: The rectangles in the transparency layer should NOT be blended with each other. + // Only the background rectangle should be blended with the ones in the layer. + CGContextSetBlendMode(context, kCGBlendModeHue); // Begin Transparency CGContextBeginTransparencyLayer(context, NULL); diff --git a/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginTransparencyLayerWithRect.h b/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginTransparencyLayerWithRect.h new file mode 100644 index 0000000000..b30e41eab0 --- /dev/null +++ b/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginTransparencyLayerWithRect.h @@ -0,0 +1,24 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +#pragma once + +#import "CGCBaseViewController.h" +#import + +@interface CGCCGContextBeginTransparencyLayerWithRect : CGCBaseViewController + +@end diff --git a/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginTransparencyLayerWithRect.m b/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginTransparencyLayerWithRect.m new file mode 100644 index 0000000000..8b1e14d512 --- /dev/null +++ b/samples/CGCatalog/CGCatalog/Samples/CGCCGContextBeginTransparencyLayerWithRect.m @@ -0,0 +1,86 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +#import "CGCCGContextBeginTransparencyLayerWithRect.h" + +@interface TransparencyViewRect : UIView + +@end + +@implementation TransparencyViewRect + +- (void)drawRect:(CGRect)rect { + CGContextRef context = UIGraphicsGetCurrentContext(); + CGFloat maxWidth = rect.size.width; + CGFloat maxHeight = rect.size.height; + + // White background + CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); + CGContextFillRect(context, rect); + + // Rect Size + CGFloat rectWidth = maxWidth / 2.0; + CGFloat rectHeight = rectWidth; + + // Draw background rect + CGContextSetFillColorWithColor(context, [UIColor yellowColor].CGColor); + CGRect aRect = CGRectMake(rectWidth / 2 - 25, maxHeight / 2 - rectHeight / 2 - 25, rectWidth + 25, rectHeight + 25); + CGContextFillRect(context, aRect); + + // Set the blend mode to use between the background rectangle and the ones in the transparency layer + // Note: The rectangles in the transparency layer should NOT be blended with each other. + // Only the background rectangle should be blended with the ones in the layer. + CGContextSetBlendMode(context, kCGBlendModeHue); + + // Begin Transparency + CGRect bRect = CGRectInset(aRect, 10, 10); + CGContextBeginTransparencyLayerWithRect(context, bRect, NULL); + + CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); + CGRect cRect = CGRectMake(rectWidth / 2 + 25, maxHeight / 2 - rectHeight / 2 - 50, rectWidth, rectHeight); + CGContextFillRect(context, cRect); + CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor); + CGRect dRect = CGRectMake(rectWidth / 2 - 25, maxHeight / 2 - rectHeight / 2 + 25, rectWidth, rectHeight); + CGContextFillRect(context, dRect); + CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor); + CGRect eRect = CGRectMake(rectWidth / 2 - 50, maxHeight / 2 - rectHeight / 2, rectWidth, rectHeight); + CGContextFillRect(context, eRect); + + // End Transparency + CGContextEndTransparencyLayer(context); +} + +@end + +@interface CGCCGContextBeginTransparencyLayerWithRect () + +@property (strong, nonatomic, nullable) TransparencyViewRect* customView; + +@end + +@implementation CGCCGContextBeginTransparencyLayerWithRect + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + + self.customView = + [[TransparencyViewRect alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; + [self.view addSubview:self.customView]; +} + +@end