diff --git a/CA360.xcodeproj/project.pbxproj b/CA360.xcodeproj/project.pbxproj index 61628d6..7297de4 100755 --- a/CA360.xcodeproj/project.pbxproj +++ b/CA360.xcodeproj/project.pbxproj @@ -31,6 +31,10 @@ DFF70C9F1039DE170052EE6A /* Steve.png in Resources */ = {isa = PBXBuildFile; fileRef = DFF70C9D1039DE170052EE6A /* Steve.png */; }; DFF70CA01039DE170052EE6A /* Ben.png in Resources */ = {isa = PBXBuildFile; fileRef = DFF70C9C1039DE170052EE6A /* Ben.png */; }; DFF70CA11039DE170052EE6A /* Steve.png in Resources */ = {isa = PBXBuildFile; fileRef = DFF70C9D1039DE170052EE6A /* Steve.png */; }; + DFF70D151039F83E0052EE6A /* StyleProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = DFF70D141039F83E0052EE6A /* StyleProperties.m */; }; + DFF70D161039F83E0052EE6A /* StyleProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = DFF70D141039F83E0052EE6A /* StyleProperties.m */; }; + DFF70D78103A0BB40052EE6A /* StarMask.png in Resources */ = {isa = PBXBuildFile; fileRef = DFF70D77103A0BB40052EE6A /* StarMask.png */; }; + DFF70D79103A0BB40052EE6A /* StarMask.png in Resources */ = {isa = PBXBuildFile; fileRef = DFF70D77103A0BB40052EE6A /* StarMask.png */; }; DFF7F28D103601FE0067ED5B /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DFF7F28C103601FE0067ED5B /* OCMock.framework */; }; DFF7F2F5103602470067ED5B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DFF7F2F4103602470067ED5B /* QuartzCore.framework */; }; DFF7F2F6103602470067ED5B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DFF7F2F4103602470067ED5B /* QuartzCore.framework */; }; @@ -98,6 +102,9 @@ DFF70C4D1039DA0A0052EE6A /* CA360-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = "CA360-Info.plist"; sourceTree = ""; }; DFF70C9C1039DE170052EE6A /* Ben.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Ben.png; sourceTree = ""; }; DFF70C9D1039DE170052EE6A /* Steve.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Steve.png; sourceTree = ""; }; + DFF70D131039F83E0052EE6A /* StyleProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleProperties.h; path = Classes/Samples/StyleProperties.h; sourceTree = ""; }; + DFF70D141039F83E0052EE6A /* StyleProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StyleProperties.m; path = Classes/Samples/StyleProperties.m; sourceTree = ""; }; + DFF70D77103A0BB40052EE6A /* StarMask.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = StarMask.png; sourceTree = ""; }; DFF7F25D103601B20067ED5B /* UnitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; DFF7F28C103601FE0067ED5B /* OCMock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = OCMock.framework; sourceTree = ""; }; DFF7F2F4103602470067ED5B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -212,6 +219,7 @@ DFF70C451039D9E60052EE6A /* FTSLogo.png */, DFF70C9C1039DE170052EE6A /* Ben.png */, DFF70C9D1039DE170052EE6A /* Steve.png */, + DFF70D77103A0BB40052EE6A /* StarMask.png */, DFF70C4B1039DA0A0052EE6A /* UnitTests-Info.plist */, DFF70C4C1039DA0A0052EE6A /* MainWindow.xib */, DFF70C4D1039DA0A0052EE6A /* CA360-Info.plist */, @@ -293,6 +301,8 @@ DFF70C311039D8BC0052EE6A /* ImageContent.m */, DFF7F610103632570067ED5B /* LayerDrawing.h */, DFF7F611103632570067ED5B /* LayerDrawing.m */, + DFF70D131039F83E0052EE6A /* StyleProperties.h */, + DFF70D141039F83E0052EE6A /* StyleProperties.m */, ); name = "Content & Style Properties"; sourceTree = ""; @@ -381,6 +391,7 @@ DFF70C4F1039DA0A0052EE6A /* MainWindow.xib in Resources */, DFF70C9E1039DE170052EE6A /* Ben.png in Resources */, DFF70C9F1039DE170052EE6A /* Steve.png in Resources */, + DFF70D78103A0BB40052EE6A /* StarMask.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -394,6 +405,7 @@ DFF70C531039DA0A0052EE6A /* CA360-Info.plist in Resources */, DFF70CA01039DE170052EE6A /* Ben.png in Resources */, DFF70CA11039DE170052EE6A /* Steve.png in Resources */, + DFF70D79103A0BB40052EE6A /* StarMask.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -435,6 +447,7 @@ DF8014A31038D12900B48250 /* CALayer+FTDebugDrawing.m in Sources */, DF8015631038E1C400B48250 /* LayerTransforms.m in Sources */, DFF70C321039D8BC0052EE6A /* ImageContent.m in Sources */, + DFF70D151039F83E0052EE6A /* StyleProperties.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -456,6 +469,7 @@ DF8014A21038D12900B48250 /* CALayer+FTDebugDrawing.m in Sources */, DF8015621038E1C400B48250 /* LayerTransforms.m in Sources */, DFF70C331039D8BC0052EE6A /* ImageContent.m in Sources */, + DFF70D161039F83E0052EE6A /* StyleProperties.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Classes/Samples/GradientLayers.m b/Classes/Samples/GradientLayers.m index f37ab69..ef38905 100644 --- a/Classes/Samples/GradientLayers.m +++ b/Classes/Samples/GradientLayers.m @@ -1,10 +1,26 @@ -// -// GradientLayers.m -// CA360 -// -// Created by Nathan Eror on 8/15/09. -// Copyright 2009 __MyCompanyName__. All rights reserved. -// +/* + The MIT License + + Copyright (c) 2009 Free Time Studios and Nathan Eror + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 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 "GradientLayers.h" diff --git a/Classes/Samples/SampleManager.m b/Classes/Samples/SampleManager.m index a826e88..efe5f89 100644 --- a/Classes/Samples/SampleManager.m +++ b/Classes/Samples/SampleManager.m @@ -34,6 +34,7 @@ of this software and associated documentation files (the "Software"), to deal #import "GradientLayers.h" #import "LayerTransforms.h" #import "ImageContent.h" +#import "StyleProperties.h" @interface SampleManager (Private) @@ -57,7 +58,7 @@ - (id)init { if (self != nil) { NSArray *geom = [NSArray arrayWithObjects:[GeometryProperties class], [LayerTransforms class], nil]; NSArray *hier = [NSArray arrayWithObjects:[LayerTree class], nil]; - NSArray *drawing = [NSArray arrayWithObjects:[ImageContent class], [LayerDrawing class], nil]; + NSArray *drawing = [NSArray arrayWithObjects:[ImageContent class], [LayerDrawing class], [StyleProperties class], nil]; NSArray *animation = [NSArray arrayWithObjects:[SimpleAnimation class], [KeyframeAnimation class], nil]; NSArray *special = [NSArray arrayWithObjects:[ShapeLayers class], [GradientLayers class], nil]; diff --git a/Classes/Samples/StyleProperties.h b/Classes/Samples/StyleProperties.h new file mode 100644 index 0000000..4e2bc57 --- /dev/null +++ b/Classes/Samples/StyleProperties.h @@ -0,0 +1,38 @@ +/* + The MIT License + + Copyright (c) 2009 Free Time Studios and Nathan Eror + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 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 + + +@interface StyleProperties : UIViewController { + CALayer *simpleLayer_; + CALayer *maskLayer_; + + UIButton *roundCornersButton_; + UIButton *toggleBorderButton_; + UIButton *toggleOpacityButton_; + UIButton *toggleMaskButton_; +} + +@end diff --git a/Classes/Samples/StyleProperties.m b/Classes/Samples/StyleProperties.m new file mode 100644 index 0000000..0e8663e --- /dev/null +++ b/Classes/Samples/StyleProperties.m @@ -0,0 +1,149 @@ +/* + The MIT License + + Copyright (c) 2009 Free Time Studios and Nathan Eror + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 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 "StyleProperties.h" +#import + + +@implementation StyleProperties + ++ (NSString *)friendlyName { + return @"Style Properties"; +} + +#pragma mark init and dealloc + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { + self.title = [[self class] friendlyName]; + } + return self; +} + +- (void)dealloc { + FTRELEASE(simpleLayer_); + FTRELEASE(maskLayer_); + FTRELEASE(roundCornersButton_); + FTRELEASE(toggleBorderButton_); + FTRELEASE(toggleOpacityButton_); + FTRELEASE(toggleMaskButton_); + [super dealloc]; +} + +#pragma mark Load and unload the view + +- (void)loadView { + UIView *myView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; + myView.backgroundColor = [UIColor grayColor]; + + roundCornersButton_ = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; + roundCornersButton_.frame = CGRectMake(10.f, 10.f, 145.f, 44.f); + [roundCornersButton_ setTitle:@"Round Corners" forState:UIControlStateNormal]; + [roundCornersButton_ addTarget:self action:@selector(roundCorners:) forControlEvents:UIControlEventTouchUpInside]; + [myView addSubview:roundCornersButton_]; + + toggleBorderButton_ = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; + toggleBorderButton_.frame = CGRectMake(165.f, 10.f, 145.f, 44.f); + [toggleBorderButton_ setTitle:@"Toggle Border" forState:UIControlStateNormal]; + [toggleBorderButton_ addTarget:self action:@selector(toggleBorder:) forControlEvents:UIControlEventTouchUpInside]; + [myView addSubview:toggleBorderButton_]; + + toggleOpacityButton_ = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; + toggleOpacityButton_.frame = CGRectMake(10.f, 60.f, 145.f, 44.f); + [toggleOpacityButton_ setTitle:@"Toggle Opacity" forState:UIControlStateNormal]; + [toggleOpacityButton_ addTarget:self action:@selector(toggleOpacity:) forControlEvents:UIControlEventTouchUpInside]; + [myView addSubview:toggleOpacityButton_]; + + toggleMaskButton_ = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; + toggleMaskButton_.frame = CGRectMake(165.f, 60.f, 145.f, 44.f); + [toggleMaskButton_ setTitle:@"Toggle Mask Layer" forState:UIControlStateNormal]; + [toggleMaskButton_ addTarget:self action:@selector(toggleMaskLayer:) forControlEvents:UIControlEventTouchUpInside]; + [myView addSubview:toggleMaskButton_]; + + simpleLayer_ = [[CALayer layer] retain]; + maskLayer_ = [[CALayer layer] retain]; + [myView.layer addSublayer:simpleLayer_]; + self.view = myView; +} + +- (void)viewDidUnload { + FTRELEASE(simpleLayer_); + FTRELEASE(maskLayer_); + FTRELEASE(roundCornersButton_); + FTRELEASE(toggleBorderButton_); + FTRELEASE(toggleOpacityButton_); + FTRELEASE(toggleMaskButton_); +} + +#pragma mark View drawing + +- (void)viewWillAppear:(BOOL)animated { + simpleLayer_.backgroundColor = [[UIColor whiteColor] CGColor]; + simpleLayer_.bounds = CGRectMake(0.f, 0.f, 200.f, 200.f); + simpleLayer_.position = CGPointMake(160.f, 250.f); + [simpleLayer_ setNeedsDisplay]; + + maskLayer_.bounds = simpleLayer_.bounds; + maskLayer_.anchorPoint = CGPointZero; + maskLayer_.contents = (id)[[UIImage imageNamed:@"StarMask.png"] CGImage]; +} + +- (void)viewWillDisappear:(BOOL)animated { +} + +#pragma mark Event Handlers + +- (void)roundCorners:(id)sender { + if(simpleLayer_.cornerRadius > 0.f) { + simpleLayer_.cornerRadius = 0.f; + } else { + simpleLayer_.cornerRadius = 25.f; + } +} + +- (void)toggleBorder:(id)sender { + if(simpleLayer_.borderWidth > 0.f) { + simpleLayer_.borderWidth = 0.f; + } else { + simpleLayer_.borderWidth = 4.f; + simpleLayer_.borderColor = [[UIColor redColor] CGColor]; + } +} + +- (void)toggleOpacity:(id)sender { + if(simpleLayer_.opacity < 1.f) { + simpleLayer_.opacity = 1.f; + } else { + simpleLayer_.opacity = .25f; + } +} + +- (void)toggleMaskLayer:(id)sender { + CALayer *mask = (simpleLayer_.mask == nil) ? maskLayer_ : nil; + [simpleLayer_ removeFromSuperlayer]; + simpleLayer_.mask = mask; + [self.view.layer addSublayer:simpleLayer_]; +} + +@end diff --git a/Resources/StarMask.png b/Resources/StarMask.png new file mode 100644 index 0000000..17ab25b Binary files /dev/null and b/Resources/StarMask.png differ