mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-01 02:39:22 +00:00
remove NinePatch
This commit is contained in:
parent
9a1ae41194
commit
967f6a6159
26 changed files with 0 additions and 3643 deletions
|
|
@ -23,8 +23,6 @@
|
|||
#import "Utils.h"
|
||||
#import "PhoneMainView.h"
|
||||
|
||||
#import <NinePatch.h>
|
||||
|
||||
@implementation ChatRoomTableViewController
|
||||
|
||||
@synthesize chatRoomDelegate;
|
||||
|
|
@ -37,10 +35,6 @@
|
|||
|
||||
#pragma mark - ViewController Functions
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
[TUNinePatchCache flushCache]; // Clear cache
|
||||
}
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
self.tableView.accessibilityIdentifier = @"Chat list";
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#import "UILinphone.h"
|
||||
#import "DTAlertView.h"
|
||||
#import "Utils/FileTransferDelegate.h"
|
||||
#import <NinePatch.h>
|
||||
#import <MobileCoreServices/UTCoreTypes.h>
|
||||
#import "Utils.h"
|
||||
#import "UIChatRoomCell.h"
|
||||
|
|
@ -160,7 +159,6 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
[TUNinePatchCache flushCache]; // will remove any images cache (freeing any cached but unused images)
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#import <AssetsLibrary/ALAsset.h>
|
||||
#import <AssetsLibrary/ALAssetRepresentation.h>
|
||||
#import <NinePatch.h>
|
||||
#include "linphone/linphonecore.h"
|
||||
|
||||
@implementation UIChatRoomCell {
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
/*
|
||||
* NinePatch.h
|
||||
* NinePatch
|
||||
*
|
||||
* Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
#import "TUNinePatchProtocols.h"
|
||||
#import "TUNinePatch.h"
|
||||
#import "TUNinePatchCache.h"
|
||||
#import "TUDebugLoggingAssistant.h"
|
||||
|
|
@ -1,430 +0,0 @@
|
|||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
324A2926111CC27800CC0BF0 /* TUNinePatchCachingCategories.h in Headers */ = {isa = PBXBuildFile; fileRef = 324A2924111CC27800CC0BF0 /* TUNinePatchCachingCategories.h */; };
|
||||
324A2927111CC27800CC0BF0 /* TUNinePatchCachingCategories.m in Sources */ = {isa = PBXBuildFile; fileRef = 324A2925111CC27800CC0BF0 /* TUNinePatchCachingCategories.m */; };
|
||||
324A2930111CC2CB00CC0BF0 /* TUCachingNinePatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 324A292E111CC2CB00CC0BF0 /* TUCachingNinePatch.h */; };
|
||||
324A2931111CC2CB00CC0BF0 /* TUCachingNinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 324A292F111CC2CB00CC0BF0 /* TUCachingNinePatch.m */; };
|
||||
324A2940111CE12C00CC0BF0 /* TUNinePatchCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 324A293E111CE12C00CC0BF0 /* TUNinePatchCache.h */; };
|
||||
324A2941111CE12C00CC0BF0 /* TUNinePatchCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 324A293F111CE12C00CC0BF0 /* TUNinePatchCache.m */; };
|
||||
325B80EF11B001C300B86EA1 /* TUDebugLoggingAssistant.h in Headers */ = {isa = PBXBuildFile; fileRef = 325B80ED11B001C300B86EA1 /* TUDebugLoggingAssistant.h */; };
|
||||
325B80F011B001C300B86EA1 /* TUDebugLoggingAssistant.m in Sources */ = {isa = PBXBuildFile; fileRef = 325B80EE11B001C300B86EA1 /* TUDebugLoggingAssistant.m */; };
|
||||
325B80F811B00C9800B86EA1 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 325B80F711B00C9800B86EA1 /* CoreFoundation.framework */; };
|
||||
325B821F11B317E400B86EA1 /* NinePatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 325B821E11B317E400B86EA1 /* NinePatch.h */; };
|
||||
32BBFEFF10E95B5700F57FBC /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32BBFEFE10E95B5700F57FBC /* CoreGraphics.framework */; };
|
||||
32BBFF0610E95B6E00F57FBC /* TUNinePatchProtocols.h in Headers */ = {isa = PBXBuildFile; fileRef = 32BBFF0510E95B6E00F57FBC /* TUNinePatchProtocols.h */; };
|
||||
32BBFF2710E95BCF00F57FBC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32BBFF2610E95BCF00F57FBC /* UIKit.framework */; };
|
||||
32BBFF2C10E95BF900F57FBC /* TUNinePatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 32BBFF2A10E95BF900F57FBC /* TUNinePatch.h */; };
|
||||
32BBFF2D10E95BF900F57FBC /* TUNinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 32BBFF2B10E95BF900F57FBC /* TUNinePatch.m */; };
|
||||
32BBFF3510E95CA700F57FBC /* TUHorizontalNinePatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 32BBFF3310E95CA700F57FBC /* TUHorizontalNinePatch.h */; };
|
||||
32BBFF3610E95CA700F57FBC /* TUHorizontalNinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 32BBFF3410E95CA700F57FBC /* TUHorizontalNinePatch.m */; };
|
||||
32BBFF3910E95CD600F57FBC /* TUVerticalNinePatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 32BBFF3710E95CD600F57FBC /* TUVerticalNinePatch.h */; };
|
||||
32BBFF3A10E95CD600F57FBC /* TUVerticalNinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 32BBFF3810E95CD600F57FBC /* TUVerticalNinePatch.m */; };
|
||||
32BBFF3D10E95D3800F57FBC /* TUFullNinePatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 32BBFF3B10E95D3800F57FBC /* TUFullNinePatch.h */; };
|
||||
32BBFF3E10E95D3800F57FBC /* TUFullNinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 32BBFF3C10E95D3800F57FBC /* TUFullNinePatch.m */; };
|
||||
32BBFF4310E9605300F57FBC /* UIImage-TUNinePatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 32BBFF4110E9605300F57FBC /* UIImage-TUNinePatch.h */; };
|
||||
32BBFF4410E9605300F57FBC /* UIImage-TUNinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 32BBFF4210E9605300F57FBC /* UIImage-TUNinePatch.m */; };
|
||||
AA747D9F0F9514B9006C5449 /* NinePatch_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* NinePatch_Prefix.pch */; };
|
||||
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
324A2924111CC27800CC0BF0 /* TUNinePatchCachingCategories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUNinePatchCachingCategories.h; sourceTree = "<group>"; };
|
||||
324A2925111CC27800CC0BF0 /* TUNinePatchCachingCategories.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUNinePatchCachingCategories.m; sourceTree = "<group>"; };
|
||||
324A292E111CC2CB00CC0BF0 /* TUCachingNinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUCachingNinePatch.h; sourceTree = "<group>"; };
|
||||
324A292F111CC2CB00CC0BF0 /* TUCachingNinePatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUCachingNinePatch.m; sourceTree = "<group>"; };
|
||||
324A293E111CE12C00CC0BF0 /* TUNinePatchCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUNinePatchCache.h; sourceTree = "<group>"; };
|
||||
324A293F111CE12C00CC0BF0 /* TUNinePatchCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUNinePatchCache.m; sourceTree = "<group>"; };
|
||||
325B80ED11B001C300B86EA1 /* TUDebugLoggingAssistant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUDebugLoggingAssistant.h; sourceTree = "<group>"; };
|
||||
325B80EE11B001C300B86EA1 /* TUDebugLoggingAssistant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUDebugLoggingAssistant.m; sourceTree = "<group>"; };
|
||||
325B80F711B00C9800B86EA1 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
|
||||
325B821E11B317E400B86EA1 /* NinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NinePatch.h; sourceTree = "<group>"; };
|
||||
32BBFEFE10E95B5700F57FBC /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
|
||||
32BBFF0510E95B6E00F57FBC /* TUNinePatchProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUNinePatchProtocols.h; sourceTree = "<group>"; };
|
||||
32BBFF2610E95BCF00F57FBC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
||||
32BBFF2A10E95BF900F57FBC /* TUNinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUNinePatch.h; sourceTree = "<group>"; };
|
||||
32BBFF2B10E95BF900F57FBC /* TUNinePatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUNinePatch.m; sourceTree = "<group>"; };
|
||||
32BBFF3310E95CA700F57FBC /* TUHorizontalNinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUHorizontalNinePatch.h; sourceTree = "<group>"; };
|
||||
32BBFF3410E95CA700F57FBC /* TUHorizontalNinePatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUHorizontalNinePatch.m; sourceTree = "<group>"; };
|
||||
32BBFF3710E95CD600F57FBC /* TUVerticalNinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUVerticalNinePatch.h; sourceTree = "<group>"; };
|
||||
32BBFF3810E95CD600F57FBC /* TUVerticalNinePatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUVerticalNinePatch.m; sourceTree = "<group>"; };
|
||||
32BBFF3B10E95D3800F57FBC /* TUFullNinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUFullNinePatch.h; sourceTree = "<group>"; };
|
||||
32BBFF3C10E95D3800F57FBC /* TUFullNinePatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUFullNinePatch.m; sourceTree = "<group>"; };
|
||||
32BBFF4110E9605300F57FBC /* UIImage-TUNinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage-TUNinePatch.h"; sourceTree = "<group>"; };
|
||||
32BBFF4210E9605300F57FBC /* UIImage-TUNinePatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage-TUNinePatch.m"; sourceTree = "<group>"; };
|
||||
AA747D9E0F9514B9006C5449 /* NinePatch_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NinePatch_Prefix.pch; sourceTree = SOURCE_ROOT; };
|
||||
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
D2AAC07E0554694100DB518D /* libNinePatch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libNinePatch.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
D2AAC07C0554694100DB518D /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */,
|
||||
32BBFEFF10E95B5700F57FBC /* CoreGraphics.framework in Frameworks */,
|
||||
32BBFF2710E95BCF00F57FBC /* UIKit.framework in Frameworks */,
|
||||
325B80F811B00C9800B86EA1 /* CoreFoundation.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
034768DFFF38A50411DB9C8B /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D2AAC07E0554694100DB518D /* libNinePatch.a */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
0867D691FE84028FC02AAC07 /* NinePatch */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
08FB77AEFE84172EC02AAC07 /* Classes */,
|
||||
32C88DFF0371C24200C91783 /* Other Sources */,
|
||||
0867D69AFE84028FC02AAC07 /* Frameworks */,
|
||||
034768DFFF38A50411DB9C8B /* Products */,
|
||||
32BBFF2610E95BCF00F57FBC /* UIKit.framework */,
|
||||
325B80F711B00C9800B86EA1 /* CoreFoundation.framework */,
|
||||
325B821E11B317E400B86EA1 /* NinePatch.h */,
|
||||
);
|
||||
name = NinePatch;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32BBFEFE10E95B5700F57FBC /* CoreGraphics.framework */,
|
||||
AACBBE490F95108600F1A2B1 /* Foundation.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
08FB77AEFE84172EC02AAC07 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
325B80EC11B0019B00B86EA1 /* Debugging Utilities */,
|
||||
324A292C111CC2C100CC0BF0 /* Caching */,
|
||||
32BBFF4010E9604300F57FBC /* Categories */,
|
||||
32BBFF3F10E9603E00F57FBC /* NinePatch */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
324A292C111CC2C100CC0BF0 /* Caching */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
324A292E111CC2CB00CC0BF0 /* TUCachingNinePatch.h */,
|
||||
324A292F111CC2CB00CC0BF0 /* TUCachingNinePatch.m */,
|
||||
324A293E111CE12C00CC0BF0 /* TUNinePatchCache.h */,
|
||||
324A293F111CE12C00CC0BF0 /* TUNinePatchCache.m */,
|
||||
);
|
||||
name = Caching;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
325B80EC11B0019B00B86EA1 /* Debugging Utilities */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
325B80ED11B001C300B86EA1 /* TUDebugLoggingAssistant.h */,
|
||||
325B80EE11B001C300B86EA1 /* TUDebugLoggingAssistant.m */,
|
||||
);
|
||||
name = "Debugging Utilities";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
32BBFF3F10E9603E00F57FBC /* NinePatch */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32BBFF0510E95B6E00F57FBC /* TUNinePatchProtocols.h */,
|
||||
32BBFF2A10E95BF900F57FBC /* TUNinePatch.h */,
|
||||
32BBFF2B10E95BF900F57FBC /* TUNinePatch.m */,
|
||||
32BBFF3310E95CA700F57FBC /* TUHorizontalNinePatch.h */,
|
||||
32BBFF3410E95CA700F57FBC /* TUHorizontalNinePatch.m */,
|
||||
32BBFF3710E95CD600F57FBC /* TUVerticalNinePatch.h */,
|
||||
32BBFF3810E95CD600F57FBC /* TUVerticalNinePatch.m */,
|
||||
32BBFF3B10E95D3800F57FBC /* TUFullNinePatch.h */,
|
||||
32BBFF3C10E95D3800F57FBC /* TUFullNinePatch.m */,
|
||||
);
|
||||
name = NinePatch;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
32BBFF4010E9604300F57FBC /* Categories */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32BBFF4110E9605300F57FBC /* UIImage-TUNinePatch.h */,
|
||||
32BBFF4210E9605300F57FBC /* UIImage-TUNinePatch.m */,
|
||||
324A2924111CC27800CC0BF0 /* TUNinePatchCachingCategories.h */,
|
||||
324A2925111CC27800CC0BF0 /* TUNinePatchCachingCategories.m */,
|
||||
);
|
||||
name = Categories;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
32C88DFF0371C24200C91783 /* Other Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
AA747D9E0F9514B9006C5449 /* NinePatch_Prefix.pch */,
|
||||
);
|
||||
name = "Other Sources";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
D2AAC07A0554694100DB518D /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
AA747D9F0F9514B9006C5449 /* NinePatch_Prefix.pch in Headers */,
|
||||
32BBFF0610E95B6E00F57FBC /* TUNinePatchProtocols.h in Headers */,
|
||||
32BBFF2C10E95BF900F57FBC /* TUNinePatch.h in Headers */,
|
||||
32BBFF3510E95CA700F57FBC /* TUHorizontalNinePatch.h in Headers */,
|
||||
32BBFF3910E95CD600F57FBC /* TUVerticalNinePatch.h in Headers */,
|
||||
32BBFF3D10E95D3800F57FBC /* TUFullNinePatch.h in Headers */,
|
||||
32BBFF4310E9605300F57FBC /* UIImage-TUNinePatch.h in Headers */,
|
||||
324A2926111CC27800CC0BF0 /* TUNinePatchCachingCategories.h in Headers */,
|
||||
324A2930111CC2CB00CC0BF0 /* TUCachingNinePatch.h in Headers */,
|
||||
324A2940111CE12C00CC0BF0 /* TUNinePatchCache.h in Headers */,
|
||||
325B80EF11B001C300B86EA1 /* TUDebugLoggingAssistant.h in Headers */,
|
||||
325B821F11B317E400B86EA1 /* NinePatch.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
D2AAC07D0554694100DB518D /* NinePatch */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 1DEB921E08733DC00010E9CD /* Build configuration list for PBXNativeTarget "NinePatch" */;
|
||||
buildPhases = (
|
||||
D2AAC07A0554694100DB518D /* Headers */,
|
||||
D2AAC07B0554694100DB518D /* Sources */,
|
||||
D2AAC07C0554694100DB518D /* Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = NinePatch;
|
||||
productName = NinePatch;
|
||||
productReference = D2AAC07E0554694100DB518D /* libNinePatch.a */;
|
||||
productType = "com.apple.product-type.library.static";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
0867D690FE84028FC02AAC07 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0610;
|
||||
};
|
||||
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "NinePatch" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 1;
|
||||
knownRegions = (
|
||||
English,
|
||||
Japanese,
|
||||
French,
|
||||
German,
|
||||
);
|
||||
mainGroup = 0867D691FE84028FC02AAC07 /* NinePatch */;
|
||||
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
D2AAC07D0554694100DB518D /* NinePatch */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
D2AAC07B0554694100DB518D /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
32BBFF2D10E95BF900F57FBC /* TUNinePatch.m in Sources */,
|
||||
32BBFF3610E95CA700F57FBC /* TUHorizontalNinePatch.m in Sources */,
|
||||
32BBFF3A10E95CD600F57FBC /* TUVerticalNinePatch.m in Sources */,
|
||||
32BBFF3E10E95D3800F57FBC /* TUFullNinePatch.m in Sources */,
|
||||
32BBFF4410E9605300F57FBC /* UIImage-TUNinePatch.m in Sources */,
|
||||
324A2927111CC27800CC0BF0 /* TUNinePatchCachingCategories.m in Sources */,
|
||||
324A2931111CC2CB00CC0BF0 /* TUCachingNinePatch.m in Sources */,
|
||||
324A2941111CE12C00CC0BF0 /* TUNinePatchCache.m in Sources */,
|
||||
325B80F011B001C300B86EA1 /* TUDebugLoggingAssistant.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
1DEB921F08733DC00010E9CD /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = NinePatch_Prefix.pch;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
|
||||
PRODUCT_NAME = NinePatch;
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
1DEB922008733DC00010E9CD /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = s;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = NinePatch_Prefix.pch;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
|
||||
PRODUCT_NAME = NinePatch;
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
1DEB922308733DC00010E9CD /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "Don't Code Sign";
|
||||
GCC_C_LANGUAGE_STANDARD = c99;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PROVISIONING_PROFILE = "";
|
||||
SDKROOT = iphoneos;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
1DEB922408733DC00010E9CD /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "Don't Code Sign";
|
||||
GCC_C_LANGUAGE_STANDARD = c99;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
ONLY_ACTIVE_ARCH = NO;
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PROVISIONING_PROFILE = "";
|
||||
SDKROOT = iphoneos;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
D3D14E7E15A72BD10074A527 /* Distribution */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "Don't Code Sign";
|
||||
GCC_C_LANGUAGE_STANDARD = c99;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
ONLY_ACTIVE_ARCH = NO;
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PROVISIONING_PROFILE = "";
|
||||
SDKROOT = iphoneos;
|
||||
};
|
||||
name = Distribution;
|
||||
};
|
||||
D3D14E7F15A72BD10074A527 /* Distribution */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = s;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = NinePatch_Prefix.pch;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
|
||||
PRODUCT_NAME = NinePatch;
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Distribution;
|
||||
};
|
||||
D3D14E8015A72BD70074A527 /* DistributionAdhoc */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "Don't Code Sign";
|
||||
GCC_C_LANGUAGE_STANDARD = c99;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
ONLY_ACTIVE_ARCH = NO;
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PROVISIONING_PROFILE = "";
|
||||
SDKROOT = iphoneos;
|
||||
};
|
||||
name = DistributionAdhoc;
|
||||
};
|
||||
D3D14E8115A72BD70074A527 /* DistributionAdhoc */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = s;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = NinePatch_Prefix.pch;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
|
||||
PRODUCT_NAME = NinePatch;
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = DistributionAdhoc;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
1DEB921E08733DC00010E9CD /* Build configuration list for PBXNativeTarget "NinePatch" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
1DEB921F08733DC00010E9CD /* Debug */,
|
||||
1DEB922008733DC00010E9CD /* Release */,
|
||||
D3D14E7F15A72BD10074A527 /* Distribution */,
|
||||
D3D14E8115A72BD70074A527 /* DistributionAdhoc */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "NinePatch" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
1DEB922308733DC00010E9CD /* Debug */,
|
||||
1DEB922408733DC00010E9CD /* Release */,
|
||||
D3D14E7E15A72BD10074A527 /* Distribution */,
|
||||
D3D14E8015A72BD70074A527 /* DistributionAdhoc */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 0867D690FE84028FC02AAC07 /* Project object */;
|
||||
}
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the 'CocoaTouchStaticLibrary' target in the 'CocoaTouchStaticLibrary' project.
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
||||
/**
|
||||
This struct is used for doing pixel-tasting. We get CoreGraphics to create a bitmap context wherein the memory representation looks like this struct, then we cast the pointer to that memory to be of this struct's type. Pretty self-explanatory.
|
||||
*/
|
||||
typedef struct _TURGBAPixel {
|
||||
UInt8 red;
|
||||
UInt8 green;
|
||||
UInt8 blue;
|
||||
UInt8 alpha;
|
||||
} TURGBAPixel;
|
||||
|
||||
/**
|
||||
Defined here, used as part of the pixel-tasting code. Helps make sure the memory representation of the bitmap context is made up of stuff that looks just like TURGBAPixel.
|
||||
*/
|
||||
#define TURGBABytesPerPixel (4)
|
||||
|
||||
/**
|
||||
This tests if a pixel is black. Here "black" means alpha isn't at zero (AKA: it's at least partially opaque) and r == g == b == 0.
|
||||
*/
|
||||
#define TURGBAPixelIsBlack(PIXEL) (((PIXEL.red == 0) && (PIXEL.green == 0) && (PIXEL.blue == 0) && (PIXEL.alpha != 0))?(YES):(NO))
|
||||
|
||||
#define TUNotFoundRange (NSMakeRange(NSNotFound,0))
|
||||
#define TUIsNotFoundRange(RANGE) (NSEqualRanges(RANGE, TUNotFoundRange))
|
||||
|
||||
#define TUTruncateBelow(VALUE, FLOOR) ((( VALUE ) < ( FLOOR ))?(( FLOOR )):(( VALUE )))
|
||||
#define TUTruncateAbove(VALUE, CEILING) ((( VALUE ) > ( CEILING ))?(( CEILING )):(( VALUE )))
|
||||
#define TUTruncateWithin(VALUE, FLOOR, CEILING) ((( VALUE ) < ( FLOOR ))?(( FLOOR )):((( VALUE ) > ( CEILING ))?(( CEILING )):(( VALUE ))))
|
||||
#define TUTruncateAtZero(VALUE) TUTruncateBelow(VALUE, 0.0f)
|
||||
|
||||
#define TUForceYesOrNo(ABOOL) ((ABOOL)?(YES):(NO))
|
||||
#define TUYesOrNoString(ABOOL) ((( ABOOL ))?(@"YES"):(@"NO"))
|
||||
|
||||
#define TUWithinEpsilon(EPSILON, X, Y) TUForceYesOrNo((((X-Y) > (-1.0f * EPSILON)) || ((X-Y) < EPSILON)))
|
||||
|
||||
//#define DEBUG
|
||||
//#define NP_ASSERTION_CHECKING
|
||||
//#define IMAGEDEBUG
|
||||
|
||||
// DLog is almost a drop-in replacement for NSLog
|
||||
// DLog();
|
||||
// DLog(@"here");
|
||||
// DLog(@"value: %d", x);
|
||||
// Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable);
|
||||
#ifdef DEBUG
|
||||
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
|
||||
#else
|
||||
#define DLog(...)
|
||||
#endif
|
||||
|
||||
// ALog always displays output regardless of the DEBUG setting
|
||||
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
|
||||
|
||||
#define LLog(STR) DLog(@"%@",STR)
|
||||
|
||||
#define NPLogException(E) DLog(@"Caught '%@' < '%@', '%@' >.",[E name],[E reason],[E userInfo])
|
||||
#define NPLogError(E) DLog(@"Error: '%@', '%@', '%@'.",[E localizedDescription],[E localizedFailureReason],[E localizedRecoveryOptions]);
|
||||
|
||||
#ifdef NP_ASSERTION_CHECKING
|
||||
#define NPLogExceptionRethrowIfAssertionFailure(E) { \
|
||||
NPLogException(E); \
|
||||
if (E && [[E name] isEqualToString:NSInternalInconsistencyException]) { \
|
||||
@throw E; \
|
||||
}}
|
||||
#else
|
||||
#define NPLogExceptionRethrowIfAssertionFailure(E) NPLogException(E)
|
||||
#endif
|
||||
|
||||
#ifdef NP_OUTPUT_LOGGING
|
||||
#define NPFOutputLog(AFLOAT) DLog(@"returning %s: '%f'.",#AFLOAT,AFLOAT)
|
||||
#define NPDOutputLog(ANINT) DLog(@"returning %s: '%d'.",#ANINT,ANINT)
|
||||
#define NPOOutputLog(ANOBJ) DLog(@"returning %s: '%@'.",#ANOBJ,ANOBJ)
|
||||
#define NPBOutputLog(ABOOL) DLog(@"returning %s: '%@'.",#ABOOL,TUYesOrNoString(ABOOL))
|
||||
#define NPCGROutputLog(ARECT) DLog(@"returning %s: '%@'.",#ARECT,NSStringFromCGRect(ARECT))
|
||||
#define NPCGSOutputLog(ASIZE) DLog(@"returning %s: '%@'.",#ASIZE,NSStringFromCGSize(ASIZE))
|
||||
#define NPCGPOutputLog(APOINT) DLog(@"returning %s: '%@'.",#APOINT,NSStringFromCGPoint(APOINT))
|
||||
#define NPNSROutputLog(ARANGE) DLog(@"returning %s: '%@'.",#ARANGE,NSStringFromRange(ARANGE))
|
||||
#else
|
||||
#define NPFOutputLog(...)
|
||||
#define NPDOutputLog(...)
|
||||
#define NPOOutputLog(...)
|
||||
#define NPBOutputLog(...)
|
||||
#define NPCGROutputLog(...)
|
||||
#define NPCGSOutputLog(...)
|
||||
#define NPCGPOutputLog(...)
|
||||
#define NPNSROutputLog(...)
|
||||
#endif
|
||||
|
||||
#ifdef NP_INPUT_LOGGING
|
||||
#define NPAInputLog(...) DLog(##__VA_ARGS__)
|
||||
// convenience input loggers for single-argument messages
|
||||
#define NPAFInputLog(AFLOAT) DLog(@"%s: '%f'",#AFLOAT,AFLOAT)
|
||||
#define NPADInputLog(ANINT) DLog(@"%s: '%d'",#ANINT,ANINT)
|
||||
#define NPAOInputLog(ANOBJ) DLog(@"%s: '%@'",#ANOBJ,ANOBJ)
|
||||
#define NPABInputLog(ABOOL) DLog(@"%s: '%@'",#ABOOL,TUYesOrNoString(ABOOL))
|
||||
#else
|
||||
#define NPAInputLog(...)
|
||||
#define NPAFInputLog(AFLOAT)
|
||||
#define NPADInputLog(ANINT)
|
||||
#define NPAOInputLog(ANOBJ)
|
||||
#define NPABInputLog(ABOOL)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef NP_ASSERTION_CHECKING
|
||||
#define NPParameterAssert(COND) NSParameterAssert(COND)
|
||||
#define NPCParameterAssert(COND) NSCParameterAssert(COND)
|
||||
#define NPAssert(COND,DESC) NSAssert(COND,DESC)
|
||||
#define NPCAssert(COND,DESC) NSCAssert(COND,DESC)
|
||||
#else
|
||||
#define NPParameterAssert(...)
|
||||
#define NPCParameterAssert(...)
|
||||
#define NPAssert(...)
|
||||
#define NPCAssert(...)
|
||||
#endif
|
||||
|
||||
#define STRINGIFY2( x) #x
|
||||
#define STRINGIFY(x) STRINGIFY2(x)
|
||||
#define PASTE2( a, b) a##b
|
||||
#define PASTE( a, b) PASTE2( a, b)
|
||||
#define PASSTHROUGH(X) X
|
||||
|
||||
#define NPOBJCStringOfToken(TOKEN) PASSTHROUGH(PASTE( PASSTHROUGH(@), PASSTHROUGH(STRINGIFY(TOKEN))))
|
||||
|
||||
#define NPSelfProperty(PROP)
|
||||
//#define NPSelfProperty(PROP) (self.PROP)
|
||||
//#define NPSelfProperty(PROP) ([self PROP])
|
||||
|
||||
#define NPAssertPropertyNonNil(PROP) NPAssert((NPSelfProperty(PROP) != nil), ([NSString stringWithFormat:@"self.%s should never be nil.",( (#PROP) )]))
|
||||
|
||||
#define NPParameterAssertNotNilConformsToProtocol(OBJ,PROT) NPParameterAssert((OBJ != nil) && ([OBJ conformsToProtocol:@protocol(PROT)]))
|
||||
#define NPParameterAssertNotNilIsKindOfClass(OBJ,CLASS) NPParameterAssert((OBJ != nil) && ([OBJ isKindOfClass:[CLASS class]]))
|
||||
|
||||
#define NPAssertNilOrConformsToProtocol(OBJ,PROT) NPAssert(((OBJ == nil) || ((OBJ != nil) && [OBJ conformsToProtocol:@protocol(PROT)])),([NSString stringWithFormat:@"Variable %s must either be nil or conform to %s protocol.", ( (#OBJ) ), ( (#PROT) )]))
|
||||
#define NPAssertNilOrIsKindOfClass(OBJ,CLASS) NPAssert(((OBJ == nil) || ((OBJ != nil) && [OBJ isKindOfClass:[CLASS class]])), ([NSString stringWithFormat:@"Variable %s must either be nil or be kind of %s class.", (#OBJ), (#CLASS)]))
|
||||
|
||||
#define NPAssertWithinEpsilon(EPSILON,X,Y) NPAssert( (((X-Y) > (-1.0f * EPSILON)) || ((X-Y) < EPSILON)),([NSString stringWithFormat:@"Should have (%s,%s) within %f but instead (%f,%f).",#X,#Y,EPSILON,X,Y]))
|
||||
#define NPAssertWithinOne(X,Y) NPAssertWithinEpsilon(1.0f,X,Y)
|
||||
|
||||
#define NPAssertThreeSubSizesSumCorrectlyOnOneAxis(AXIS,MASTERSIZE,SIZE_ONE,SIZE_TWO,SIZE_THREE) NPAssertWithinOne(MASTERSIZE.AXIS,( SIZE_ONE.AXIS + SIZE_TWO.AXIS + SIZE_THREE.AXIS ))
|
||||
#define NPAssertCorrectSubsizeWidthDecomposition(MASTER,SIZE_ONE,SIZE_TWO,SIZE_THREE) NPAssertThreeSubSizesSumCorrectlyOnOneAxis(width, MASTER, SIZE_ONE, SIZE_TWO, SIZE_THREE)
|
||||
#define NPAssertCorrectSubsizeHeightDecomposition(MASTER,SIZE_ONE,SIZE_TWO,SIZE_THREE) NPAssertThreeSubSizesSumCorrectlyOnOneAxis(height, MASTER, SIZE_ONE, SIZE_TWO, SIZE_THREE)
|
||||
|
||||
#define NPAssertCorrectSubimageWidthDecomposition(MASTER,IMAGE_ONE,IMAGE_TWO,IMAGE_THREE) NPAssertCorrectSubsizeWidthDecomposition([MASTER size],[IMAGE_ONE size],[IMAGE_TWO size],[IMAGE_THREE size])
|
||||
#define NPAssertCorrectSubimageHeightDecomposition(MASTER,IMAGE_ONE,IMAGE_TWO,IMAGE_THREE) NPAssertCorrectSubsizeWidthDecomposition([MASTER size],[IMAGE_ONE size],[IMAGE_TWO size],[IMAGE_THREE size])
|
||||
|
||||
#ifdef IMAGEDEBUG
|
||||
#define IMLog(IMAGE, IMAGENAME) TUImageLog(IMAGE,[[NSString stringWithFormat:@"debugImage.%.0f.%u.",[NSDate timeIntervalSinceReferenceDate],((NSUInteger) rand())] stringByAppendingString:( IMAGENAME )])
|
||||
#else
|
||||
#define IMLog(IMAGE, IMAGENAME)
|
||||
#endif
|
||||
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
//
|
||||
// TUCachingNinePatch.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
@interface TUCachingNinePatch : NSObject < NSCoding, NSCopying > {
|
||||
id < TUNinePatch > _ninePatch;
|
||||
NSMutableDictionary *_ninePatchImageCache;
|
||||
}
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readonly) id < TUNinePatch > ninePatch;
|
||||
@property(nonatomic, retain, readonly) NSMutableDictionary *ninePatchImageCache;
|
||||
|
||||
// Init + Dealloc
|
||||
-(id)initWithNinePatchNamed:(NSString *)ninePatchName;
|
||||
-(id)initWithNinePatch:(id < TUNinePatch >)ninePatch;
|
||||
+(id)ninePatchCacheWithNinePatchNamed:(NSString *)ninePatchName;
|
||||
+(id)ninePatchCacheWithNinePatch:(id < TUNinePatch >)ninePatch;
|
||||
-(void)dealloc;
|
||||
|
||||
// NSCoding
|
||||
-(id)initWithCoder:(NSCoder *)aDecoder;
|
||||
-(void)encodeWithCoder:(NSCoder *)anEncoder;
|
||||
|
||||
// NSCopying
|
||||
-(id)copyWithZone:(NSZone *)zone;
|
||||
|
||||
// Nib
|
||||
-(void)awakeFromNib;
|
||||
|
||||
// Cache Management
|
||||
-(void)flushCachedImages;
|
||||
|
||||
// Image Access - Utility Accessors
|
||||
-(UIImage *)imageOfSize:(CGSize)size;
|
||||
|
||||
// Cache Access
|
||||
-(void)cacheImage:(UIImage *)image ofSize:(CGSize)size;
|
||||
-(UIImage *)cachedImageOfSize:(CGSize)size;
|
||||
|
||||
// Image Construction
|
||||
-(UIImage *)constructImageOfSize:(CGSize)size;
|
||||
|
||||
@end
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
//
|
||||
// TUCachingNinePatch.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUCachingNinePatch.h"
|
||||
#import "TUNinePatch.h"
|
||||
#import "TUNinePatchCachingCategories.h"
|
||||
|
||||
@interface TUCachingNinePatch ()
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readwrite) id < TUNinePatch > ninePatch;
|
||||
@property(nonatomic, retain, readwrite) NSMutableDictionary *ninePatchImageCache;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TUCachingNinePatch
|
||||
|
||||
#pragma mark Synthesized Properties
|
||||
@synthesize ninePatch = _ninePatch;
|
||||
@synthesize ninePatchImageCache = _ninePatchImageCache;
|
||||
|
||||
#pragma mark Init + Dealloc
|
||||
-(id)initWithNinePatchNamed:(NSString *)ninePatchName {
|
||||
return [self initWithNinePatch:[TUNinePatch ninePatchNamed:ninePatchName]];
|
||||
}
|
||||
|
||||
-(id)initWithNinePatch:(id < TUNinePatch >)ninePatch {
|
||||
if (self = [super init]) {
|
||||
self.ninePatch = ninePatch;
|
||||
self.ninePatchImageCache = [NSMutableDictionary dictionaryWithCapacity:5];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
+(id)ninePatchCacheWithNinePatchNamed:(NSString *)ninePatchName {
|
||||
return [[[self alloc] initWithNinePatchNamed:ninePatchName] autorelease];
|
||||
}
|
||||
|
||||
+(id)ninePatchCacheWithNinePatch:(id < TUNinePatch >)ninePatch {
|
||||
return [[[self alloc] initWithNinePatch:ninePatch] autorelease];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(void)dealloc {
|
||||
self.ninePatch = nil;
|
||||
self.ninePatchImageCache = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark NSCoding
|
||||
-(id)initWithCoder:(NSCoder *)aDecoder {
|
||||
NSParameterAssert(aDecoder != nil);
|
||||
if (self = [super init]) {
|
||||
self.ninePatch = [aDecoder decodeObjectForKey:@"ninePatch"];
|
||||
self.ninePatchImageCache = [aDecoder decodeObjectForKey:@"ninePatchImageCache"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)anEncoder {
|
||||
NSParameterAssert(anEncoder != nil);
|
||||
[anEncoder encodeObject:self.ninePatch
|
||||
forKey:@"ninePatch"];
|
||||
[anEncoder encodeObject:self.ninePatchImageCache
|
||||
forKey:@"ninePatchImageCache"];
|
||||
}
|
||||
|
||||
#pragma mark NSCopying
|
||||
-(id)copyWithZone:(NSZone *)zone {
|
||||
return [[[self class] alloc] initWithNinePatch:self.ninePatch];
|
||||
}
|
||||
|
||||
#pragma mark Nib
|
||||
-(void)awakeFromNib {
|
||||
[super awakeFromNib];
|
||||
if (!self.ninePatchImageCache) {
|
||||
self.ninePatchImageCache = [NSMutableDictionary dictionaryWithCapacity:5];
|
||||
};
|
||||
}
|
||||
|
||||
#pragma mark Cache Management
|
||||
-(void)flushCachedImages {
|
||||
NPAssertPropertyNonNil(ninePatchImageCache);
|
||||
[self.ninePatchImageCache removeAllObjects];
|
||||
}
|
||||
|
||||
#pragma mark Image Access - Utility Accessors
|
||||
-(UIImage *)imageOfSize:(CGSize)size {
|
||||
UIImage *imageOfSize = [self cachedImageOfSize:size];
|
||||
if (!imageOfSize) {
|
||||
imageOfSize = [self constructImageOfSize:size];
|
||||
if (imageOfSize) {
|
||||
[self cacheImage:imageOfSize
|
||||
ofSize:size];
|
||||
}
|
||||
}
|
||||
return imageOfSize;
|
||||
}
|
||||
|
||||
#pragma mark Cache Access
|
||||
-(void)cacheImage:(UIImage *)image ofSize:(CGSize)size {
|
||||
NPParameterAssertNotNilIsKindOfClass(image,UIImage);
|
||||
NPAssertPropertyNonNil(self.ninePatchImageCache);
|
||||
return [self.ninePatchImageCache setObject:image
|
||||
forSize:size];
|
||||
}
|
||||
|
||||
-(UIImage *)cachedImageOfSize:(CGSize)size {
|
||||
NPAssertPropertyNonNil(ninePatchImageCache);
|
||||
return [self.ninePatchImageCache objectForSize:size];
|
||||
}
|
||||
|
||||
#pragma mark Image Construction
|
||||
-(UIImage *)constructImageOfSize:(CGSize)size {
|
||||
NPAssertPropertyNonNil(ninePatch);
|
||||
return (!self.ninePatch)?(nil):([self.ninePatch imageOfSize:size]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
//
|
||||
// TUDebugLoggingAssistant.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface TUDebugLoggingAssistant : NSObject {
|
||||
NSString *_sessionIdentifier;
|
||||
NSMutableSet *_activatedLoggingTags;
|
||||
}
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readonly) NSString *sessionIdentifier;
|
||||
@property(nonatomic, retain, readonly) NSMutableSet *activatedLoggingTags;
|
||||
|
||||
// Init + Dealloc
|
||||
-(id)init;
|
||||
-(void)dealloc;
|
||||
|
||||
// Managing Logging
|
||||
-(void)startLoggingTag:(NSString *)loggingTag;
|
||||
-(void)stopLoggingTag:(NSString *)loggingTag;
|
||||
-(void)startLoggingTags:(NSString *)loggingTag,...;
|
||||
-(void)stopLoggingTags:(NSString *)loggingTag,...;
|
||||
-(void)startLoggingTagsFromArray:(NSArray *)loggingTags;
|
||||
-(void)stopLoggingTagsFromArray:(NSArray *)loggingTags;
|
||||
|
||||
// Formatting
|
||||
-(NSString *)formattedImageLogFilenameForTimestamp:(NSTimeInterval)timestamp specifiedFileName:(NSString *)specifiedFileName;
|
||||
|
||||
// Log-Checking
|
||||
-(BOOL)shouldLogLineWithTag:(NSString *)tag;
|
||||
|
||||
// Singleton Access
|
||||
+(id)shared;
|
||||
|
||||
// Managing Logging
|
||||
+(void)startLoggingTag:(NSString *)loggingTag;
|
||||
+(void)stopLoggingTag:(NSString *)loggingTag;
|
||||
+(void)startLoggingTags:(NSString *)loggingTag,...;
|
||||
+(void)stopLoggingTags:(NSString *)loggingTag,...;
|
||||
+(void)startLoggingTagsFromArray:(NSArray *)loggingTags;
|
||||
+(void)stopLoggingTagsFromArray:(NSArray *)loggingTags;
|
||||
|
||||
// Formatting
|
||||
+(NSString *)formattedImageLogFilenameForTimestamp:(NSTimeInterval)timestamp specifiedFileName:(NSString *)specifiedFileName;
|
||||
|
||||
// Log-Checking
|
||||
+(BOOL)shouldLogLineWithTag:(NSString *)tag;
|
||||
|
||||
@end
|
||||
|
|
@ -1,362 +0,0 @@
|
|||
//
|
||||
// TUDebugLoggingAssistant.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUDebugLoggingAssistant.h"
|
||||
|
||||
@interface TUDebugLoggingAssistant ()
|
||||
|
||||
@property(nonatomic, retain, readwrite) NSString *sessionIdentifier;
|
||||
@property(nonatomic, retain, readwrite) NSMutableSet *activatedLoggingTags;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TUDebugLoggingAssistant
|
||||
|
||||
#pragma mark Synthesized Properties
|
||||
@synthesize sessionIdentifier = _sessionIdentifier;
|
||||
@synthesize activatedLoggingTags = _activatedLoggingTags;
|
||||
|
||||
#pragma mark Init + Dealloc
|
||||
-(id)init {
|
||||
if (self = [super init]) {
|
||||
self.activatedLoggingTags = [NSMutableSet set];
|
||||
NSString *uuidString = @"UUID_ERROR_ENCOUNTERED";
|
||||
@try {
|
||||
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
|
||||
if (uuid) {
|
||||
@try {
|
||||
uuidString = ((NSString *) CFUUIDCreateString(kCFAllocatorDefault, uuid));
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
if (uuidString) {
|
||||
@try {
|
||||
CFRelease(uuidString);
|
||||
}
|
||||
@catch (NSException * ee) {
|
||||
NPLogException(ee);
|
||||
}
|
||||
@finally {
|
||||
uuidString = @"UUID_ERROR_ENCOUNTERED";
|
||||
}
|
||||
}
|
||||
}
|
||||
@finally {
|
||||
@try {
|
||||
CFRelease(uuid);
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
if (uuidString) {
|
||||
self.sessionIdentifier = uuidString;
|
||||
[self.sessionIdentifier release]; // drops retain count back to 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(void)dealloc {
|
||||
self.sessionIdentifier = nil;
|
||||
self.activatedLoggingTags = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark Managing Logging
|
||||
-(void)startLoggingTag:(NSString *)loggingTag {
|
||||
NPAOInputLog(loggingTag);
|
||||
NPParameterAssertNotNilIsKindOfClass(loggingTag,NSString);
|
||||
NPAssertPropertyNonNil(activatedLoggingTags);
|
||||
if (loggingTag) {
|
||||
@try {
|
||||
[self.activatedLoggingTags addObject:loggingTag];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)stopLoggingTag:(NSString *)loggingTag {
|
||||
NPAOInputLog(loggingTag);
|
||||
NPParameterAssertNotNilIsKindOfClass(loggingTag,NSString);
|
||||
NPAssertPropertyNonNil(activatedLoggingTags);
|
||||
if (loggingTag) {
|
||||
@try {
|
||||
[self.activatedLoggingTags removeObject:loggingTag];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)startLoggingTags:(NSString *)loggingTag,... {
|
||||
id eachObject;
|
||||
va_list argumentList;
|
||||
if (loggingTag) {
|
||||
NSMutableArray *workingArray = [NSMutableArray arrayWithObject:loggingTag];
|
||||
va_start(argumentList, loggingTag);
|
||||
@try {
|
||||
while ((eachObject = va_arg(argumentList, id))) {
|
||||
@try {
|
||||
[workingArray addObject:eachObject];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
@try {
|
||||
va_end(argumentList);
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
if (workingArray) {
|
||||
[self startLoggingTagsFromArray:workingArray];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)stopLoggingTags:(NSString *)loggingTag,... {
|
||||
id eachObject;
|
||||
va_list argumentList;
|
||||
if (loggingTag) {
|
||||
NSMutableArray *workingArray = [NSMutableArray arrayWithObject:loggingTag];
|
||||
va_start(argumentList, loggingTag);
|
||||
@try {
|
||||
while ((eachObject = va_arg(argumentList, id))) {
|
||||
@try {
|
||||
[workingArray addObject:eachObject];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
@try {
|
||||
va_end(argumentList);
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
if (workingArray) {
|
||||
[self stopLoggingTagsFromArray:workingArray];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)startLoggingTagsFromArray:(NSArray *)loggingTags {
|
||||
NPAOInputLog(loggingTags);
|
||||
NPParameterAssertNotNilIsKindOfClass(loggingTags,NSArray);
|
||||
NPAssertPropertyNonNil(activatedLoggingTags);
|
||||
if (loggingTags) {
|
||||
// N.B.: we're not shooting for speed here
|
||||
// b/c if you're even instantiating an instance of this
|
||||
// class it means you're in a debug frenzy and have other
|
||||
// issues.
|
||||
//
|
||||
// So here we break out the for loop and insert objects
|
||||
// individually so that the asserts in the [self startLoggingTag:tag]
|
||||
// will get noticed if you're smuggling non-string logging tags in
|
||||
// by passing them in as part of an array.
|
||||
//
|
||||
// No point having type-induced errors in your debugging assistant.
|
||||
for (NSString *loggingTag in loggingTags) {
|
||||
[self startLoggingTag:loggingTag];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)stopLoggingTagsFromArray:(NSArray *)loggingTags {
|
||||
NPAOInputLog(loggingTags);
|
||||
NPParameterAssertNotNilIsKindOfClass(loggingTags,NSArray);
|
||||
NPAssertPropertyNonNil(activatedLoggingTags);
|
||||
if (loggingTags) {
|
||||
// CF comment in startLoggingTagsFromArray
|
||||
// for some context here
|
||||
for (NSString *loggingTag in loggingTags) {
|
||||
[self stopLoggingTag:loggingTag];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Formatting
|
||||
-(NSString *)formattedImageLogFilenameForTimestamp:(NSTimeInterval)timestamp specifiedFileName:(NSString *)specifiedFileName {
|
||||
NPAInputLog(@"formattedImageLogFilenameForTimestamp:'%f' specifiedFileName:'%@'",timestamp,specifiedFileName);
|
||||
NPParameterAssertNotNilIsKindOfClass(specifiedFileName,NSString);
|
||||
NPAssertPropertyNonNil(sessionIdentifier);
|
||||
NSString *outString = nil;
|
||||
@try {
|
||||
if (specifiedFileName) {
|
||||
outString = [NSString stringWithFormat:@"%@_%@_%.0f.png",self.sessionIdentifier,specifiedFileName,timestamp];
|
||||
} else {
|
||||
outString = [NSString stringWithFormat:@"%@_%.0f.png",self.sessionIdentifier,timestamp];
|
||||
}
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
NPOOutputLog(outString);
|
||||
return outString;
|
||||
}
|
||||
|
||||
#pragma mark Log-Checking
|
||||
-(BOOL)shouldLogLineWithTag:(NSString *)tag {
|
||||
NPAInputLog(@"shouldLogLineWithTag:'%@'",tag);
|
||||
NPParameterAssertNotNilIsKindOfClass(tag,NSString);
|
||||
NPAssertPropertyNonNil(activatedLoggingTags);
|
||||
BOOL shouldLogLineWithTag = NO;
|
||||
if (tag) {
|
||||
@try {
|
||||
shouldLogLineWithTag = [self.activatedLoggingTags containsObject:tag];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
shouldLogLineWithTag = NO;
|
||||
}
|
||||
}
|
||||
NPBOutputLog(shouldLogLineWithTag);
|
||||
return shouldLogLineWithTag;
|
||||
}
|
||||
|
||||
#pragma mark Singleton Access
|
||||
+(id)shared {
|
||||
static id shared;
|
||||
if (!shared) {
|
||||
shared = [[[self class] alloc] init];
|
||||
}
|
||||
NPAssertNilOrIsKindOfClass(shared,TUDebugLoggingAssistant);
|
||||
return shared;
|
||||
}
|
||||
|
||||
#pragma mark Managing Logging
|
||||
+(void)startLoggingTag:(NSString *)loggingTag {
|
||||
[[self shared] startLoggingTag:loggingTag];
|
||||
}
|
||||
|
||||
+(void)stopLoggingTag:(NSString *)loggingTag {
|
||||
[[self shared] stopLoggingTag:loggingTag];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
+(void)startLoggingTags:(NSString *)loggingTag,... {
|
||||
id eachObject;
|
||||
va_list argumentList;
|
||||
if (loggingTag) {
|
||||
NSMutableArray *workingArray = [NSMutableArray arrayWithObject:loggingTag];
|
||||
va_start(argumentList, loggingTag);
|
||||
@try {
|
||||
while ((eachObject = va_arg(argumentList, id))) {
|
||||
@try {
|
||||
[workingArray addObject:eachObject];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
@try {
|
||||
va_end(argumentList);
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
if (workingArray) {
|
||||
[self startLoggingTagsFromArray:workingArray];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+(void)stopLoggingTags:(NSString *)loggingTag,... {
|
||||
id eachObject;
|
||||
va_list argumentList;
|
||||
if (loggingTag) {
|
||||
NSMutableArray *workingArray = [NSMutableArray arrayWithObject:loggingTag];
|
||||
va_start(argumentList, loggingTag);
|
||||
@try {
|
||||
while ((eachObject = va_arg(argumentList, id))) {
|
||||
@try {
|
||||
[workingArray addObject:eachObject];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
@try {
|
||||
va_end(argumentList);
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
if (workingArray) {
|
||||
[self stopLoggingTagsFromArray:workingArray];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
+(void)startLoggingTagsFromArray:(NSArray *)loggingTags {
|
||||
[[self shared] startLoggingTagsFromArray:loggingTags];
|
||||
}
|
||||
|
||||
+(void)stopLoggingTagsFromArray:(NSArray *)loggingTags {
|
||||
[[self shared] stopLoggingTagsFromArray:loggingTags];
|
||||
}
|
||||
|
||||
#pragma mark Formatting
|
||||
+(NSString *)formattedImageLogFilenameForTimestamp:(NSTimeInterval)timestamp specifiedFileName:(NSString *)specifiedFileName {
|
||||
return [[self shared] formattedImageLogFilenameForTimestamp:timestamp
|
||||
specifiedFileName:specifiedFileName];
|
||||
}
|
||||
|
||||
#pragma mark Log-Checking
|
||||
+(BOOL)shouldLogLineWithTag:(NSString *)tag {
|
||||
return [[self shared] shouldLogLineWithTag:tag];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
//
|
||||
// TUFullNinePatch.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
#import "TUNinePatch.h"
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
/**
|
||||
Concrete TUNinePatch instance. Handles NinePatches that stretch horizontally and vertically. Only instantiate directly if you know what you're doing.
|
||||
*/
|
||||
@interface TUFullNinePatch : TUNinePatch < TUNinePatch > {
|
||||
UIImage *_upperEdge;
|
||||
UIImage *_lowerEdge;
|
||||
UIImage *_leftEdge;
|
||||
UIImage *_rightEdge;
|
||||
UIImage *_upperLeftCorner;
|
||||
UIImage *_lowerLeftCorner;
|
||||
UIImage *_upperRightCorner;
|
||||
UIImage *_lowerRightCorner;
|
||||
}
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readonly) UIImage *upperEdge;
|
||||
@property(nonatomic, retain, readonly) UIImage *lowerEdge;
|
||||
@property(nonatomic, retain, readonly) UIImage *leftEdge;
|
||||
@property(nonatomic, retain, readonly) UIImage *rightEdge;
|
||||
|
||||
@property(nonatomic, retain, readonly) UIImage *upperLeftCorner;
|
||||
@property(nonatomic, retain, readonly) UIImage *lowerLeftCorner;
|
||||
@property(nonatomic, retain, readonly) UIImage *upperRightCorner;
|
||||
@property(nonatomic, retain, readonly) UIImage *lowerRightCorner;
|
||||
|
||||
// Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally upperLeftCorner:(UIImage *)upperLeftCorner upperRightCorner:(UIImage *)upperRightCorner lowerLeftCorner:(UIImage *)lowerLeftCorner lowerRightCorner:(UIImage *)lowerRightCorner leftEdge:(UIImage *)leftEdge rightEdge:(UIImage *)rightEdge upperEdge:(UIImage *)upperEdge lowerEdge:(UIImage *)lowerEdge;
|
||||
-(void)dealloc;
|
||||
|
||||
// Sanity-Checking Tools
|
||||
-(BOOL)checkSizeSanityAgainstOriginalImage:(UIImage *)originalImage;
|
||||
|
||||
// TUNinePatch Overrides
|
||||
-(void)drawInRect:(CGRect)rect;
|
||||
-(CGFloat)leftEdgeWidth;
|
||||
-(CGFloat)rightEdgeWidth;
|
||||
-(CGFloat)upperEdgeHeight;
|
||||
-(CGFloat)lowerEdgeHeight;
|
||||
|
||||
// Image Logging
|
||||
-(void)logExplodedImage;
|
||||
|
||||
@end
|
||||
|
|
@ -1,318 +0,0 @@
|
|||
//
|
||||
// TUFullNinePatch.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUFullNinePatch.h"
|
||||
#import "TUNinePatchProtocols.h"
|
||||
#import "UIImage-TUNinePatch.h"
|
||||
|
||||
@interface TUFullNinePatch ()
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readwrite) UIImage *upperEdge;
|
||||
@property(nonatomic, retain, readwrite) UIImage *lowerEdge;
|
||||
@property(nonatomic, retain, readwrite) UIImage *leftEdge;
|
||||
@property(nonatomic, retain, readwrite) UIImage *rightEdge;
|
||||
|
||||
@property(nonatomic, retain, readwrite) UIImage *upperLeftCorner;
|
||||
@property(nonatomic, retain, readwrite) UIImage *lowerLeftCorner;
|
||||
@property(nonatomic, retain, readwrite) UIImage *upperRightCorner;
|
||||
@property(nonatomic, retain, readwrite) UIImage *lowerRightCorner;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TUFullNinePatch
|
||||
|
||||
#pragma mark Synthesized Properties
|
||||
@synthesize upperEdge = _upperEdge;
|
||||
@synthesize lowerEdge = _lowerEdge;
|
||||
@synthesize leftEdge = _leftEdge;
|
||||
@synthesize rightEdge = _rightEdge;
|
||||
|
||||
@synthesize upperLeftCorner = _upperLeftCorner;
|
||||
@synthesize lowerLeftCorner = _lowerLeftCorner;
|
||||
@synthesize upperRightCorner = _upperRightCorner;
|
||||
@synthesize lowerRightCorner = _lowerRightCorner;
|
||||
|
||||
#pragma mark NSCoding
|
||||
-(id)initWithCoder:(NSCoder *)coder {
|
||||
if (self = [super initWithCoder:coder]) {
|
||||
self.upperEdge = (UIImage *) [coder decodeObjectForKey:@"upperEdge"];
|
||||
self.lowerEdge = (UIImage *) [coder decodeObjectForKey:@"lowerEdge"];
|
||||
self.leftEdge = (UIImage *) [coder decodeObjectForKey:@"leftEdge"];
|
||||
self.rightEdge = (UIImage *) [coder decodeObjectForKey:@"rightEdge"];
|
||||
self.upperLeftCorner = (UIImage *) [coder decodeObjectForKey:@"upperLeftCorner"];
|
||||
self.lowerLeftCorner = (UIImage *) [coder decodeObjectForKey:@"lowerLeftCorner"];
|
||||
self.upperRightCorner = (UIImage *) [coder decodeObjectForKey:@"upperRightCorner"];
|
||||
self.lowerRightCorner = (UIImage *) [coder decodeObjectForKey:@"lowerRightCorner"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[super encodeWithCoder:coder];
|
||||
|
||||
[coder encodeObject:self.upperEdge
|
||||
forKey:@"upperEdge"];
|
||||
|
||||
[coder encodeObject:self.lowerEdge
|
||||
forKey:@"lowerEdge"];
|
||||
|
||||
[coder encodeObject:self.leftEdge
|
||||
forKey:@"leftEdge"];
|
||||
|
||||
[coder encodeObject:self.rightEdge
|
||||
forKey:@"rightEdge"];
|
||||
|
||||
[coder encodeObject:self.upperLeftCorner
|
||||
forKey:@"upperLeftCorner"];
|
||||
|
||||
[coder encodeObject:self.lowerLeftCorner
|
||||
forKey:@"lowerLeftCorner"];
|
||||
|
||||
[coder encodeObject:self.upperRightCorner
|
||||
forKey:@"upperRightCorner"];
|
||||
|
||||
[coder encodeObject:self.lowerRightCorner
|
||||
forKey:@"lowerRightCorner"];
|
||||
}
|
||||
|
||||
#pragma mark NSCopying
|
||||
-(id)copyWithZone:(NSZone *)zone {
|
||||
return [[[self class] allocWithZone:zone] initWithCenter:self.center
|
||||
contentRegion:self.contentRegion
|
||||
tileCenterVertically:self.tileCenterVertically
|
||||
tileCenterHorizontally:self.tileCenterHorizontally
|
||||
upperLeftCorner:self.upperLeftCorner
|
||||
upperRightCorner:self.upperRightCorner
|
||||
lowerLeftCorner:self.lowerLeftCorner
|
||||
lowerRightCorner:self.lowerRightCorner
|
||||
leftEdge:self.leftEdge
|
||||
rightEdge:self.rightEdge
|
||||
upperEdge:self.upperEdge
|
||||
lowerEdge:self.lowerEdge];
|
||||
}
|
||||
|
||||
#pragma mark Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally upperLeftCorner:(UIImage *)upperLeftCorner upperRightCorner:(UIImage *)upperRightCorner lowerLeftCorner:(UIImage *)lowerLeftCorner lowerRightCorner:(UIImage *)lowerRightCorner leftEdge:(UIImage *)leftEdge rightEdge:(UIImage *)rightEdge upperEdge:(UIImage *)upperEdge lowerEdge:(UIImage *)lowerEdge {
|
||||
NPParameterAssertNotNilIsKindOfClass(upperLeftCorner,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(lowerLeftCorner,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(upperRightCorner,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(lowerRightCorner,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(leftEdge,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(rightEdge,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(upperEdge,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(lowerEdge,UIImage);
|
||||
if (self = [super initWithCenter:center
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:tileCenterVertically
|
||||
tileCenterHorizontally:tileCenterHorizontally]) {
|
||||
self.upperEdge = upperEdge;
|
||||
self.lowerEdge = lowerEdge;
|
||||
self.leftEdge = leftEdge;
|
||||
self.rightEdge = rightEdge;
|
||||
self.upperLeftCorner = upperLeftCorner;
|
||||
self.lowerLeftCorner = lowerLeftCorner;
|
||||
self.upperRightCorner = upperRightCorner;
|
||||
self.lowerRightCorner = lowerRightCorner;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark
|
||||
-(void)dealloc {
|
||||
self.upperEdge = nil;
|
||||
self.lowerEdge = nil;
|
||||
self.leftEdge = nil;
|
||||
self.rightEdge = nil;
|
||||
self.upperLeftCorner = nil;
|
||||
self.lowerLeftCorner = nil;
|
||||
self.upperRightCorner = nil;
|
||||
self.lowerRightCorner = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark Sanity-Checking Tools
|
||||
-(BOOL)checkSizeSanityAgainstOriginalImage:(UIImage *)originalImage {
|
||||
CGSize os = [originalImage size];
|
||||
CGFloat ow = os.width;
|
||||
CGFloat oh = os.height;
|
||||
|
||||
CGFloat tr = ([[self upperEdge] size].width + [[self upperLeftCorner] size].width + [[self upperRightCorner] size].width);
|
||||
CGFloat mr = ([[self center] size].width + [[self leftEdge] size].width + [[self rightEdge] size].width);
|
||||
CGFloat lr = ([[self lowerEdge] size].width + [[self lowerLeftCorner] size].width + [[self lowerRightCorner] size].width);
|
||||
|
||||
|
||||
BOOL topRow = TUWithinEpsilon(1.0f,ow,tr);
|
||||
BOOL midRow = TUWithinEpsilon(1.0f,ow,mr);
|
||||
BOOL lowRow = TUWithinEpsilon(1.0f,ow,lr);
|
||||
|
||||
CGFloat lc = ([[self upperLeftCorner] size].height + [[self lowerLeftCorner] size].height + [[self leftEdge] size].height);
|
||||
CGFloat mc = ([[self center] size].height + [[self upperEdge] size].height + [[self lowerEdge] size].height);
|
||||
CGFloat rc = ([[self upperRightCorner] size].height + [[self lowerRightCorner] size].height + [[self rightEdge] size].height);
|
||||
|
||||
BOOL lCol = TUWithinEpsilon(1.0f,oh,lc);
|
||||
BOOL mCol = TUWithinEpsilon(1.0f,oh,mc);
|
||||
BOOL rCol = TUWithinEpsilon(1.0f,oh,rc);
|
||||
|
||||
BOOL sizesMatch = TUForceYesOrNo(midRow && topRow && lowRow && mCol && lCol && rCol);
|
||||
DLog(@"SANITY sizesMatch: '%@.'",TUYesOrNoString(sizesMatch));
|
||||
DLog(@"SANITY topRow: '%@', midRow:'%@, lowRow:'%@'.", TUYesOrNoString(topRow),TUYesOrNoString(midRow),TUYesOrNoString(lowRow));
|
||||
DLog(@"SANITY lCol: '%@', mCol:'%@, rCol:'%@'.", TUYesOrNoString(lCol),TUYesOrNoString(mCol),TUYesOrNoString(rCol));
|
||||
DLog(@"SANITY <ow: '%.1f', tr: '%.1f', mr: '%.1f', lr: '%.1f'>",ow,tr,mr,lr);
|
||||
DLog(@"SANITY <oh: '%.1f', lc: '%.1f', mc: '%.1f', lc: '%.1f'>",oh,lc,mc,rc);
|
||||
return sizesMatch;
|
||||
}
|
||||
|
||||
#pragma mark TUNinePatch Overrides
|
||||
-(void)drawInRect:(CGRect)rect {
|
||||
NPSelfProperty(center);
|
||||
NPSelfProperty(leftEdge);
|
||||
NPSelfProperty(rightEdge);
|
||||
NPSelfProperty(lowerEdge);
|
||||
NPSelfProperty(upperEdge);
|
||||
NPSelfProperty(upperLeftCorner);
|
||||
NPSelfProperty(upperRightCorner);
|
||||
NPSelfProperty(lowerLeftCorner);
|
||||
NPSelfProperty(lowerRightCorner);
|
||||
|
||||
CGFloat leftEdgeWidth = [self leftEdgeWidth];
|
||||
CGFloat rightEdgeWidth = [self rightEdgeWidth];
|
||||
BOOL hasLeftEdge = (leftEdgeWidth > 0.0f)?(YES):(NO);
|
||||
BOOL hasRightEdge = (rightEdgeWidth > 0.0f)?(YES):(NO);
|
||||
|
||||
CGFloat upperEdgeHeight = [self upperEdgeHeight];
|
||||
CGFloat lowerEdgeHeight = [self lowerEdgeHeight];
|
||||
BOOL hasUpperEdge = (upperEdgeHeight > 0.0f)?(YES):(NO);
|
||||
BOOL hasLowerEdge = (lowerEdgeHeight > 0.0f)?(YES):(NO);
|
||||
|
||||
BOOL hasUpperLeftCorner = (hasLeftEdge && hasUpperEdge)?(YES):(NO);
|
||||
BOOL hasUpperRightCorner = (hasRightEdge && hasUpperEdge)?(YES):(NO);
|
||||
BOOL hasLowerLeftCorner = (hasLeftEdge && hasLowerEdge)?(YES):(NO);
|
||||
BOOL hasLowerRightCorner = (hasRightEdge && hasLowerEdge)?(YES):(NO);
|
||||
|
||||
|
||||
|
||||
CGFloat contentWidth = TUTruncateAtZero(rect.size.width - (leftEdgeWidth + rightEdgeWidth));
|
||||
CGFloat contentHeight = TUTruncateAtZero(rect.size.height - (upperEdgeHeight + lowerEdgeHeight));
|
||||
BOOL hasContentWidth = (contentWidth > 0.0f)?(YES):(NO);
|
||||
BOOL hasContentHeight = (contentWidth > 0.0f)?(YES):(NO);
|
||||
if (hasContentWidth && hasContentHeight) {
|
||||
[self.center drawInRect:CGRectMake(CGRectGetMinX(rect) + leftEdgeWidth, CGRectGetMinY(rect) + upperEdgeHeight, contentWidth, contentHeight)];
|
||||
}
|
||||
if (hasContentWidth) {
|
||||
if (hasUpperEdge) {
|
||||
[self.upperEdge drawInRect:CGRectMake(
|
||||
CGRectGetMinX(rect) + leftEdgeWidth,
|
||||
CGRectGetMinY(rect),
|
||||
contentWidth,
|
||||
upperEdgeHeight)];
|
||||
}
|
||||
if (hasLowerEdge) {
|
||||
[self.lowerEdge drawInRect:CGRectMake(
|
||||
CGRectGetMinX(rect) + leftEdgeWidth,
|
||||
CGRectGetMaxY(rect) - lowerEdgeHeight,
|
||||
contentWidth,
|
||||
lowerEdgeHeight)];
|
||||
}
|
||||
}
|
||||
if (hasContentHeight) {
|
||||
if (hasLeftEdge) {
|
||||
[self.leftEdge drawInRect:CGRectMake(
|
||||
CGRectGetMinX(rect),
|
||||
CGRectGetMinY(rect) + upperEdgeHeight,
|
||||
leftEdgeWidth,
|
||||
contentHeight)];
|
||||
}
|
||||
if (hasRightEdge) {
|
||||
[self.rightEdge drawInRect:CGRectMake(
|
||||
CGRectGetMaxX(rect) - rightEdgeWidth,
|
||||
CGRectGetMinY(rect) + upperEdgeHeight,
|
||||
rightEdgeWidth,
|
||||
contentHeight)];
|
||||
}
|
||||
}
|
||||
if (hasUpperLeftCorner && self.upperLeftCorner) {
|
||||
[self.upperLeftCorner drawAtPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect))];
|
||||
}
|
||||
if (hasUpperRightCorner && self.upperRightCorner) {
|
||||
[self.upperRightCorner drawAtPoint:CGPointMake(CGRectGetMaxX(rect) - rightEdgeWidth, CGRectGetMinY(rect))];
|
||||
}
|
||||
if (hasLowerLeftCorner && self.lowerLeftCorner) {
|
||||
[self.lowerLeftCorner drawAtPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect) - lowerEdgeHeight)];
|
||||
}
|
||||
if (hasLowerRightCorner && self.lowerRightCorner) {
|
||||
[self.lowerRightCorner drawAtPoint:CGPointMake(CGRectGetMaxX(rect) - rightEdgeWidth, CGRectGetMaxY(rect) - lowerEdgeHeight)];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(CGFloat)leftEdgeWidth {
|
||||
return ((self.upperLeftCorner)?
|
||||
([self.upperLeftCorner size].width):
|
||||
(((self.lowerLeftCorner)?
|
||||
([self.lowerLeftCorner size].width):(0.0f))));
|
||||
}
|
||||
|
||||
-(CGFloat)rightEdgeWidth {
|
||||
return ((self.upperRightCorner)?
|
||||
([self.upperRightCorner size].width)
|
||||
:(((self.lowerRightCorner)?
|
||||
([self.lowerRightCorner size].width):(0.0f))));
|
||||
}
|
||||
|
||||
-(CGFloat)upperEdgeHeight {
|
||||
return ((self.upperLeftCorner)?
|
||||
([self.upperLeftCorner size].height)
|
||||
:(((self.upperRightCorner)?
|
||||
([self.upperRightCorner size].height):(0.0f))));
|
||||
}
|
||||
|
||||
-(CGFloat)lowerEdgeHeight {
|
||||
return ((self.lowerLeftCorner)?
|
||||
([self.lowerLeftCorner size].height)
|
||||
:(((self.lowerRightCorner)?
|
||||
([self.lowerRightCorner size].height):(0.0f))));
|
||||
}
|
||||
|
||||
#pragma mark Customized Description Overrides
|
||||
-(NSString *)descriptionPostfix {
|
||||
return [NSString stringWithFormat:@"%@, self.upperEdge:<'%@'>, self.lowerEdge:<'%@'>, self.leftEdge:<'%@'>, self.rightEdge:<'%@'>, self.upperLeftCorner:<'%@'>, self.lowerLeftCorner:<'%@'>, self.upperRightCorner:<'%@'>, self.lowerRightCorner:<'%@'>",
|
||||
[super descriptionPostfix],
|
||||
self.upperEdge,
|
||||
self.lowerEdge,
|
||||
self.leftEdge,
|
||||
self.rightEdge,
|
||||
self.upperLeftCorner,
|
||||
self.lowerLeftCorner,
|
||||
self.upperRightCorner,
|
||||
self.lowerRightCorner];
|
||||
}
|
||||
|
||||
#pragma mark Image Logging
|
||||
-(void)logExplodedImage {
|
||||
CGFloat centerWidth = ((self.center)?(self.center.size.width):(0.0f));
|
||||
CGFloat centerHeight = ((self.center)?(self.center.size.height):(0.0f));
|
||||
CGSize mySize = CGSizeMake(
|
||||
4.0f + (centerWidth + ([self leftEdgeWidth]) + ([self rightEdgeWidth])),
|
||||
4.0f + (centerHeight + ([self upperEdgeHeight]) + ([self lowerEdgeHeight]))
|
||||
);
|
||||
UIGraphicsBeginImageContext(mySize);
|
||||
[self.center drawAtPoint:CGPointMake(2.0f + [self leftEdgeWidth], 2.0f + [self upperEdgeHeight])];
|
||||
[self.upperLeftCorner drawAtPoint:CGPointMake(0.0f, 0.0f)];
|
||||
[self.leftEdge drawAtPoint:CGPointMake(0.0f, [self upperEdgeHeight] + 2.0f)];
|
||||
[self.lowerLeftCorner drawAtPoint:CGPointMake(0.0f, [self upperEdgeHeight] + 4.0f + centerHeight)];
|
||||
[self.upperEdge drawAtPoint:CGPointMake(2.0f + [self leftEdgeWidth], 0.0f)];
|
||||
[self.upperRightCorner drawAtPoint:CGPointMake(4.0f + [self leftEdgeWidth] + centerWidth, 0.0f)];
|
||||
[self.rightEdge drawAtPoint:CGPointMake(4.0f + [self leftEdgeWidth] + centerWidth, 2.0f + [self upperEdgeHeight])];
|
||||
[self.lowerRightCorner drawAtPoint:CGPointMake(4.0f + [self leftEdgeWidth] + centerWidth, 4.0f + [self upperEdgeHeight] + centerHeight)];
|
||||
[self.lowerEdge drawAtPoint:CGPointMake(2.0f + [self leftEdgeWidth], 4.0f + [self upperEdgeHeight] + centerHeight)];
|
||||
IMLog(UIGraphicsGetImageFromCurrentImageContext(), @"explodedNinePatchImage");
|
||||
UIGraphicsEndImageContext();
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
//
|
||||
// TUHorizontalNinePatch.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
#import "TUNinePatch.h"
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
/**
|
||||
Concrete TUNinePatch instance. Handles NinePatches that stretch horizontally but not vertically. Only instantiate directly if you know what you're doing.
|
||||
*/
|
||||
@interface TUHorizontalNinePatch : TUNinePatch < TUNinePatch > {
|
||||
UIImage *_leftEdge;
|
||||
UIImage *_rightEdge;
|
||||
}
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readonly) UIImage *leftEdge;
|
||||
@property(nonatomic, retain, readonly) UIImage *rightEdge;
|
||||
|
||||
// Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally leftEdge:(UIImage *)leftEdge rightEdge:(UIImage *)rightEdge;
|
||||
-(void)dealloc;
|
||||
|
||||
// TUNinePatch Overrides
|
||||
-(void)drawInRect:(CGRect)rect;
|
||||
-(BOOL)stretchesVertically;
|
||||
-(CGSize)sizeForContentOfSize:(CGSize)contentSize;
|
||||
-(CGFloat)leftEdgeWidth;
|
||||
-(CGFloat)rightEdgeWidth;
|
||||
|
||||
@end
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
//
|
||||
// TUHorizontalNinePatch.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUHorizontalNinePatch.h"
|
||||
|
||||
@interface TUHorizontalNinePatch ()
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readwrite) UIImage *leftEdge;
|
||||
@property(nonatomic, retain, readwrite) UIImage *rightEdge;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TUHorizontalNinePatch
|
||||
|
||||
#pragma mark Synthesized Properties
|
||||
@synthesize leftEdge = _leftEdge;
|
||||
@synthesize rightEdge = _rightEdge;
|
||||
|
||||
#pragma mark NSCoding
|
||||
-(id)initWithCoder:(NSCoder *)coder {
|
||||
if (self = [super initWithCoder:coder]) {
|
||||
self.leftEdge = (UIImage *)[coder decodeObjectForKey:@"leftEdge"];
|
||||
self.rightEdge = (UIImage *)[coder decodeObjectForKey:@"rightEdge"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[super encodeWithCoder:coder];
|
||||
|
||||
[coder encodeObject:self.leftEdge
|
||||
forKey:@"leftEdge"];
|
||||
|
||||
[coder encodeObject:self.rightEdge
|
||||
forKey:@"rightEdge"];
|
||||
}
|
||||
|
||||
#pragma mark NSCopying
|
||||
-(id)copyWithZone:(NSZone *)zone {
|
||||
return [[[self class] allocWithZone:zone] initWithCenter:self.center
|
||||
contentRegion:self.contentRegion
|
||||
tileCenterVertically:self.tileCenterVertically
|
||||
tileCenterHorizontally:self.tileCenterHorizontally
|
||||
leftEdge:self.leftEdge
|
||||
rightEdge:self.rightEdge];
|
||||
}
|
||||
|
||||
#pragma mark Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally leftEdge:(UIImage *)leftEdge rightEdge:(UIImage *)rightEdge {
|
||||
NPParameterAssertNotNilIsKindOfClass(leftEdge,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(rightEdge,UIImage);
|
||||
if (self = [super initWithCenter:center
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:tileCenterVertically
|
||||
tileCenterHorizontally:tileCenterHorizontally]) {
|
||||
self.leftEdge = leftEdge;
|
||||
self.rightEdge = rightEdge;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(void)dealloc {
|
||||
self.leftEdge = nil;
|
||||
self.rightEdge = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark TUNinePatch Overrides
|
||||
-(void)drawInRect:(CGRect)rect {
|
||||
CGFloat height = [self minimumHeight];
|
||||
[self.center drawInRect:CGRectMake(CGRectGetMinX(rect) + [self leftEdgeWidth], CGRectGetMinY(rect), CGRectGetWidth(rect) - ([self leftEdgeWidth] + [self rightEdgeWidth]), height)];
|
||||
if (self.leftEdge) {
|
||||
[self.leftEdge drawAtPoint:CGPointMake(CGRectGetMinX(rect),CGRectGetMinY(rect))];
|
||||
}
|
||||
if (self.rightEdge) {
|
||||
[self.rightEdge drawAtPoint:CGPointMake(CGRectGetMaxX(rect) - [self rightEdgeWidth], CGRectGetMinY(rect))];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(BOOL)stretchesVertically {
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(CGSize)sizeForContentOfSize:(CGSize)contentSize {
|
||||
CGSize outSize = [super sizeForContentOfSize:contentSize];
|
||||
outSize.height = [self minimumHeight];
|
||||
return outSize;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(CGFloat)leftEdgeWidth {
|
||||
CGFloat leftEdgeWidth = 0.0f;
|
||||
if (self.leftEdge) {
|
||||
leftEdgeWidth = [self.leftEdge size].width;
|
||||
}
|
||||
return leftEdgeWidth;
|
||||
}
|
||||
|
||||
-(CGFloat)rightEdgeWidth {
|
||||
CGFloat rightEdgeWidth = 0.0f;
|
||||
if (self.leftEdge) {
|
||||
rightEdgeWidth = [self.rightEdge size].width;
|
||||
}
|
||||
return rightEdgeWidth;
|
||||
}
|
||||
|
||||
#pragma mark Customized Description Overrides
|
||||
-(NSString *)descriptionPostfix {
|
||||
return [NSString stringWithFormat:@"%@, self.leftEdge:<'%@'>, self.rightEdge:<'%@'>",
|
||||
[super descriptionPostfix],
|
||||
self.leftEdge,
|
||||
self.rightEdge];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
//
|
||||
// TUNinePatch.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
/**
|
||||
Abstract base class for concrete NinePatches; this is the public interface into the TUNinePatch class cluster. Note particularly that TUNinePatch itself doesn't actually implement the TUNinePatch protocol, but its convenience methods promise to supply objects that do implement TUNinePatch. You should really only be using the classlevel convenience methods on this class unless you know what you're doing. If a method isn't documented it's probably not really for public use yet.
|
||||
*/
|
||||
@interface TUNinePatch : NSObject < NSCoding, NSCopying > {
|
||||
UIImage *_center;
|
||||
CGRect _contentRegion;
|
||||
BOOL _tileCenterVertically;
|
||||
BOOL _tileCenterHorizontally;
|
||||
}
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readonly) UIImage *center;
|
||||
@property(nonatomic, assign, readonly) CGRect contentRegion;
|
||||
@property(nonatomic, assign, readonly) BOOL tileCenterVertically;
|
||||
@property(nonatomic, assign, readonly) BOOL tileCenterHorizontally;
|
||||
|
||||
// NSCoding
|
||||
-(id)initWithCoder:(NSCoder *)coder;
|
||||
-(void)encodeWithCoder:(NSCoder *)coder;
|
||||
|
||||
// NSCopying
|
||||
-(id)copyWithZone:(NSZone *)zone;
|
||||
|
||||
// Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion;
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally;
|
||||
-(void)dealloc;
|
||||
|
||||
// Convenience Constructors
|
||||
/**
|
||||
This parses ninePatchImage and instantiates an instance of the appropriate TUNinePatch subclass.
|
||||
|
||||
@param ninePatchImage A non-nil UIImage object containing the contents of a .9.png file (eg: it still contains the 1px border containing the scaling information).
|
||||
@returns An autoreleased object implementing the TUNinePatch protocol, loaded with the contents of ninePatchImage. Can be nil if errors encountered.
|
||||
*/
|
||||
+(id < TUNinePatch >)ninePatchWithNinePatchImage:(UIImage *)ninePatchImage;
|
||||
|
||||
/**
|
||||
Calls through to ninePatchWithImage:stretchableRegion:contentRegion:tileCenterVertically:tileCenterHorizontally with contentRegion=CGRectZero and NO on the tiling params. Will probably get made private or protected soon.
|
||||
*/
|
||||
+(id < TUNinePatch >)ninePatchWithImage:(UIImage *)image stretchableRegion:(CGRect)stretchableRegion;
|
||||
|
||||
/**
|
||||
Creates a NinePatch using the passed-in image and the passed-in scaling information. This method may go protected soon, leaving only the ninePatchWithNinePatchImage: as a public convenience (possibly with the addition of ninePatchNamed: method as well). The argument for goign protected or private is that if this library winds up expanding discontinuous stretchable regions (as is done on Android) then there would be a separate interface for passing in 4 stretchable regions, making the public interface cmoplicated and "multiple ways in".
|
||||
|
||||
@param image A non-nil UIImage object that contains the displayable content. This is contents of .9.png file AFTER removing the 1px border.
|
||||
@param stretchableRegion Rect specifying the bounds of the central stretchable region. In the .9.png this is specified on the left and top margins.
|
||||
@param contentRegion Rect specifying the bounds of the content region, EG the box into which associated content might fit. In the .9.png this is specified on the bottom and right margins.
|
||||
@param tileCenterVertically (Currently unsupported) is intended to specify whether or not the center scales by resizing or scales by tiling. Not fully supported at this time, only use if you know what you're doing.
|
||||
@param tileCenterHorizontally (Currently unsupported) is intended to specify whether or not the center scales by resizing or scales by tiling. Not fully supported at this time, only use if you know what you're doing.
|
||||
|
||||
@returns An object implementing the TUNinePatch protocol. Can be nil if problems were encountered.
|
||||
*/
|
||||
+(id < TUNinePatch >)ninePatchWithImage:(UIImage *)image stretchableRegion:(CGRect)stretchableRegion contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally;
|
||||
|
||||
// Bundle Loading
|
||||
/**
|
||||
Creates a ninepatch in two steps: it takes filename, and tries to load @"filename.9.png" from the main bundle. If that loads it then attempts to construct a NinePatch from that image file's contents. Differs from UIImage's analogous method in that no caching is done.
|
||||
|
||||
@param filename A non-nil NSString containing the filename of the source image but NOT including ".9.png".
|
||||
@returns An object implementing the TUNinePatch protocol. Can be nil if problems encountered.
|
||||
*/
|
||||
+(id < TUNinePatch >)ninePatchNamed:(NSString *)filename;
|
||||
|
||||
// Nine Patch Image Manipulation - High Level
|
||||
+(CGRect)rectFromHorizontalRange:(NSRange)horizontalRange verticalRange:(NSRange)verticalRange;
|
||||
+(CGRect)stretchableRegionOfNinePatchImage:(UIImage *)ninePatchImage;
|
||||
+(CGRect)contentRegionOfNinePatchImage:(UIImage *)ninePatchImage;
|
||||
+(BOOL)shouldTileCenterHorizontallyForNinePatchImage:(UIImage *)ninePatchImage;
|
||||
+(BOOL)shouldTileCenterVerticallyForNinePatchImage:(UIImage *)ninePatchImage;
|
||||
|
||||
// Drawing Utility
|
||||
-(void)drawInRect:(CGRect)rect;
|
||||
|
||||
// Diagnostic Utilities
|
||||
-(UIImage *)upperEdge;
|
||||
-(UIImage *)lowerEdge;
|
||||
-(UIImage *)leftEdge;
|
||||
-(UIImage *)rightEdge;
|
||||
|
||||
-(UIImage *)upperLeftCorner;
|
||||
-(UIImage *)lowerLeftCorner;
|
||||
-(UIImage *)upperRightCorner;
|
||||
-(UIImage *)lowerRightCorner;
|
||||
|
||||
// TUNinePatch Protocol Methods - Drawing
|
||||
-(void)inContext:(CGContextRef)context drawAtPoint:(CGPoint)point forContentOfSize:(CGSize)contentSize;
|
||||
-(void)inContext:(CGContextRef)context drawCenteredInRect:(CGRect)rect forContentOfSize:(CGSize)contentSize;
|
||||
-(void)inContext:(CGContextRef)context drawInRect:(CGRect)rect;
|
||||
|
||||
// TUNinePatch Protocol Methods - Image Construction
|
||||
-(UIImage *)imageOfSize:(CGSize)size;
|
||||
|
||||
// TUNinePatch Protocol Methods - Sizing
|
||||
-(BOOL)stretchesHorizontally;
|
||||
-(BOOL)stretchesVertically;
|
||||
-(CGFloat)minimumWidth;
|
||||
-(CGFloat)minimumHeight;
|
||||
-(CGSize)minimumSize;
|
||||
-(CGSize)sizeForContentOfSize:(CGSize)contentSize;
|
||||
-(CGPoint)upperLeftCornerForContentWhenDrawnAtPoint:(CGPoint)point;
|
||||
|
||||
// TUNinePatch Protocol Methods - Geometry
|
||||
-(CGFloat)leftEdgeWidth;
|
||||
-(CGFloat)rightEdgeWidth;
|
||||
-(CGFloat)upperEdgeHeight;
|
||||
-(CGFloat)lowerEdgeHeight;
|
||||
|
||||
// Customized Description
|
||||
-(NSString *)description;
|
||||
-(NSString *)descriptionPostfix;
|
||||
|
||||
@end
|
||||
|
|
@ -1,514 +0,0 @@
|
|||
//
|
||||
// TUNinePatch.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUNinePatch.h"
|
||||
#import "TUVerticalNinePatch.h"
|
||||
#import "TUHorizontalNinePatch.h"
|
||||
#import "TUFullNinePatch.h"
|
||||
#import "UIImage-TUNinePatch.h"
|
||||
|
||||
@interface TUNinePatch ()
|
||||
|
||||
@property(nonatomic, retain, readwrite) UIImage *center;
|
||||
@property(nonatomic, assign, readwrite) CGRect contentRegion;
|
||||
@property(nonatomic, assign, readwrite) BOOL tileCenterVertically;
|
||||
@property(nonatomic, assign, readwrite) BOOL tileCenterHorizontally;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TUNinePatch
|
||||
|
||||
#pragma mark Synthesized Properties
|
||||
@synthesize center = _center;
|
||||
@synthesize contentRegion = _contentRegion;
|
||||
@synthesize tileCenterVertically = _tileCenterVertically;
|
||||
@synthesize tileCenterHorizontally = _tileCenterHorizontally;
|
||||
|
||||
#pragma mark NSCoding
|
||||
-(id)initWithCoder:(NSCoder *)coder {
|
||||
NPAOInputLog(coder);
|
||||
if (self = [super init]) {
|
||||
self.center = (UIImage *)[coder decodeObjectForKey:@"center"];
|
||||
self.contentRegion = [coder decodeCGRectForKey:@"contentRegion"];
|
||||
self.tileCenterVertically = [coder decodeBoolForKey:@"tileCenterVertically"];
|
||||
self.tileCenterHorizontally = [coder decodeBoolForKey:@"tileCenterHorizontally"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
NPAOInputLog(coder);
|
||||
[coder encodeObject:self.center
|
||||
forKey:@"center"];
|
||||
|
||||
[coder encodeCGRect:self.contentRegion
|
||||
forKey:@"contentRegion"];
|
||||
|
||||
[coder encodeBool:self.tileCenterVertically
|
||||
forKey:@"tileCenterVertically"];
|
||||
|
||||
[coder encodeBool:self.tileCenterHorizontally
|
||||
forKey:@"tileCenterHorizontally"];
|
||||
}
|
||||
|
||||
#pragma mark NSCopying
|
||||
-(id)copyWithZone:(NSZone *)zone {
|
||||
return [[[self class] allocWithZone:zone] initWithCenter:self.center
|
||||
contentRegion:self.contentRegion
|
||||
tileCenterVertically:self.tileCenterVertically
|
||||
tileCenterHorizontally:self.tileCenterHorizontally];
|
||||
}
|
||||
|
||||
#pragma mark Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion {
|
||||
return [self initWithCenter:center
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:NO
|
||||
tileCenterHorizontally:NO];
|
||||
}
|
||||
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally {
|
||||
NPAInputLog(@"[%@:<0x%x> initWithCenter:%@ contentRegion:%@ tileCenterVertically:%d tileCenterHorizontally:%d]", [self class], ((NSUInteger) self), center, NSStringFromCGRect(contentRegion), tileCenterVertically, tileCenterHorizontally);
|
||||
NPParameterAssertNotNilIsKindOfClass(center, UIImage);
|
||||
if (self = [super init]) {
|
||||
self.center = center;
|
||||
self.contentRegion = contentRegion;
|
||||
self.tileCenterVertically = tileCenterVertically;
|
||||
self.tileCenterHorizontally = tileCenterHorizontally;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(void)dealloc {
|
||||
self.center = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark Convenience Constructors
|
||||
+(id < TUNinePatch >)ninePatchWithNinePatchImage:(UIImage *)ninePatchImage {
|
||||
NPAInputLog(@"ninePatchWithNinePatchImage:'%@'",ninePatchImage);
|
||||
id < TUNinePatch > outPatch = nil;
|
||||
if (ninePatchImage) {
|
||||
@try {
|
||||
outPatch = [self ninePatchWithImage:[ninePatchImage imageAsNinePatchImage]
|
||||
stretchableRegion:[self stretchableRegionOfNinePatchImage:ninePatchImage]
|
||||
contentRegion:[self contentRegionOfNinePatchImage:ninePatchImage]
|
||||
tileCenterVertically:[self shouldTileCenterVerticallyForNinePatchImage:ninePatchImage]
|
||||
tileCenterHorizontally:[self shouldTileCenterHorizontallyForNinePatchImage:ninePatchImage]];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
outPatch = nil;
|
||||
}
|
||||
}
|
||||
NPAssertNilOrConformsToProtocol(outPatch,TUNinePatch);
|
||||
NPOOutputLog(outPatch);
|
||||
return outPatch;
|
||||
}
|
||||
|
||||
+(id < TUNinePatch >)ninePatchWithImage:(UIImage *)image stretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"ninePatchWithImage:'%@' stretchableRegion:'%@'",image,NSStringFromCGRect(stretchableRegion));
|
||||
NPParameterAssertNotNilIsKindOfClass(image,UIImage);
|
||||
return [self ninePatchWithImage:image
|
||||
stretchableRegion:stretchableRegion
|
||||
contentRegion:CGRectZero
|
||||
tileCenterVertically:NO
|
||||
tileCenterHorizontally:NO];
|
||||
}
|
||||
|
||||
+(id < TUNinePatch >)ninePatchWithImage:(UIImage *)image stretchableRegion:(CGRect)stretchableRegion contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally {
|
||||
NPAInputLog(@"ninePatchWithImage:'%@' stretchableRegion:'%@' contentRegion:'%@' tileCenterVertically:'%@' tileCenterHorizontally:'%@'",image,NSStringFromCGRect(stretchableRegion),NSStringFromCGRect(contentRegion),TUYesOrNoString(tileCenterVertically),TUYesOrNoString(tileCenterHorizontally));
|
||||
NPParameterAssertNotNilIsKindOfClass(image,UIImage);
|
||||
NPParameterAssert(stretchableRegion.origin.x >= 0.0f);
|
||||
NPParameterAssert(stretchableRegion.origin.y >= 0.0f);
|
||||
NPParameterAssert([image size].width >= stretchableRegion.origin.x + stretchableRegion.size.width);
|
||||
NPParameterAssert([image size].height >= stretchableRegion.origin.y + stretchableRegion.size.height);
|
||||
id < TUNinePatch > ninePatch = nil;
|
||||
if (image) {
|
||||
CGFloat imageWidth = [image size].width;
|
||||
CGFloat imageHeight = [image size].height;
|
||||
CGRect fixedStretchableRegion = stretchableRegion;
|
||||
CGFloat stretchableRegionMinX = CGRectGetMinX(fixedStretchableRegion);
|
||||
CGFloat stretchableRegionMinY = CGRectGetMinY(fixedStretchableRegion);
|
||||
CGFloat stretchableRegionMaxX = CGRectGetMaxX(fixedStretchableRegion);
|
||||
CGFloat stretchableRegionMaxY = CGRectGetMaxY(fixedStretchableRegion);
|
||||
BOOL stretchesOnLeft = (stretchableRegionMinX > 0.0f)?(YES):(NO);
|
||||
BOOL stretchesOnRight = (stretchableRegionMaxX < imageWidth)?(YES):(NO);
|
||||
BOOL stretchesOnTop = (stretchableRegionMinY > 0.0f)?(YES):(NO);
|
||||
BOOL stretchesOnBottom = (stretchableRegionMaxY < imageHeight)?(YES):(NO);
|
||||
BOOL stretchesHorizontally = (stretchesOnLeft || stretchesOnRight)?(YES):(NO);
|
||||
BOOL stretchesVertically = (stretchesOnTop || stretchesOnBottom)?(YES):(NO);
|
||||
if (stretchesVertically && stretchesHorizontally) {
|
||||
LLog(@"...the specified stretchable region stretches horizontally and vertically.");
|
||||
UIImage *center = [image extractCenterForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *upperLeftCorner = [image extractUpperLeftCornerForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *upperRightCorner = [image extractUpperRightCornerForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *lowerLeftCorner = [image extractLowerLeftCornerForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *lowerRightCorner = [image extractLowerRightCornerForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *leftEdge = [image extractLeftEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *rightEdge = [image extractRightEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *lowerEdge = [image extractLowerEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *upperEdge = [image extractUpperEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
|
||||
// Mega-Block of size sanity checking
|
||||
|
||||
// Given that the only major bug encountered while developing this library
|
||||
// proved to be a difficult-to-track-down source of off-by-one errors in
|
||||
// the sizes of the slices, you can understand the paranoia here.
|
||||
//
|
||||
// Just remember to build with the assertion-checking off.
|
||||
|
||||
NPAssertCorrectSubimageWidthDecomposition(image, upperLeftCorner, upperEdge, upperRightCorner);
|
||||
NPAssertCorrectSubimageWidthDecomposition(image, leftEdge, upperEdge, rightEdge);
|
||||
NPAssertCorrectSubimageWidthDecomposition(image, lowerLeftCorner, lowerEdge, lowerRightCorner);
|
||||
|
||||
NPAssertCorrectSubimageHeightDecomposition(image, upperLeftCorner, leftEdge, lowerLeftCorner);
|
||||
NPAssertCorrectSubimageHeightDecomposition(image, upperEdge, center, lowerEdge);
|
||||
NPAssertCorrectSubimageHeightDecomposition(image, upperRightCorner, rightEdge, lowerRightCorner);
|
||||
|
||||
NPAssertWithinOne(([upperLeftCorner size].height), ([upperRightCorner size].height));
|
||||
NPAssertWithinOne(([upperLeftCorner size].height), ([upperEdge size].height));
|
||||
NPAssertWithinOne(([upperEdge size].height), ([upperRightCorner size].height));
|
||||
|
||||
NPAssertWithinOne(([leftEdge size].height), ([center size].height));
|
||||
NPAssertWithinOne(([center size].height), ([rightEdge size].height));
|
||||
NPAssertWithinOne(([rightEdge size].height), ([leftEdge size].height));
|
||||
|
||||
NPAssertWithinOne(([lowerLeftCorner size].height), ([lowerRightCorner size].height));
|
||||
NPAssertWithinOne(([lowerRightCorner size].height), ([lowerEdge size].height));
|
||||
NPAssertWithinOne(([lowerEdge size].height), ([lowerLeftCorner size].height));
|
||||
|
||||
NPAssertWithinOne(([upperLeftCorner size].width), ([leftEdge size].width));
|
||||
NPAssertWithinOne(([leftEdge size].width), ([lowerLeftCorner size].width));
|
||||
NPAssertWithinOne(([upperLeftCorner size].width), ([lowerLeftCorner size].width));
|
||||
|
||||
NPAssertWithinOne(([upperEdge size].width), ([center size].width));
|
||||
NPAssertWithinOne(([center size].width), ([lowerEdge size].width));
|
||||
NPAssertWithinOne(([upperEdge size].width), ([lowerEdge size].width));
|
||||
|
||||
NPAssertWithinOne(([upperRightCorner size].width), ([rightEdge size].width));
|
||||
NPAssertWithinOne(([rightEdge size].width), ([lowerRightCorner size].width));
|
||||
NPAssertWithinOne(([lowerRightCorner size].width), ([upperRightCorner size].width));
|
||||
|
||||
ninePatch = [[[TUFullNinePatch alloc] initWithCenter:center
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:tileCenterVertically
|
||||
tileCenterHorizontally:tileCenterHorizontally
|
||||
upperLeftCorner:upperLeftCorner
|
||||
upperRightCorner:upperRightCorner
|
||||
lowerLeftCorner:lowerLeftCorner
|
||||
lowerRightCorner:lowerRightCorner
|
||||
leftEdge:leftEdge
|
||||
rightEdge:rightEdge
|
||||
upperEdge:upperEdge
|
||||
lowerEdge:lowerEdge] autorelease];
|
||||
} else if (stretchesVertically) {
|
||||
UIImage *center = [image extractCenterForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *upperEdge = [image extractUpperEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *lowerEdge = [image extractLowerEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
|
||||
NPAssertCorrectSubimageHeightDecomposition(image,center,upperEdge,lowerEdge);
|
||||
NPAssertWithinOne(([center size].width),([upperEdge size].width));
|
||||
NPAssertWithinOne(([lowerEdge size].width),([upperEdge size].width));
|
||||
NPAssertWithinOne(([center size].width),([lowerEdge size].width));
|
||||
|
||||
ninePatch = [[[TUVerticalNinePatch alloc] initWithCenter:center
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:tileCenterVertically
|
||||
tileCenterHorizontally:tileCenterHorizontally
|
||||
upperEdge:upperEdge
|
||||
lowerEdge:lowerEdge] autorelease];
|
||||
} else if (stretchesHorizontally) {
|
||||
UIImage *center = [image extractCenterForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *leftEdge = [image extractLeftEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
UIImage *rightEdge = [image extractRightEdgeForStretchableRegion:fixedStretchableRegion];
|
||||
|
||||
NPAssertCorrectSubimageWidthDecomposition(image, leftEdge, center, rightEdge);
|
||||
NPAssertWithinOne(([center size].height),([leftEdge size].height));
|
||||
NPAssertWithinOne(([center size].height),([rightEdge size].height));
|
||||
NPAssertWithinOne(([leftEdge size].height),([rightEdge size].height));
|
||||
|
||||
ninePatch = [[[TUHorizontalNinePatch alloc] initWithCenter:center
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:tileCenterVertically
|
||||
tileCenterHorizontally:tileCenterHorizontally
|
||||
leftEdge:leftEdge
|
||||
rightEdge:rightEdge] autorelease];
|
||||
} else {
|
||||
ninePatch = [[[self alloc] initWithCenter:image
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:tileCenterVertically
|
||||
tileCenterHorizontally:tileCenterHorizontally] autorelease];
|
||||
}
|
||||
}
|
||||
NPAssertNilOrConformsToProtocol(ninePatch,TUNinePatch);
|
||||
NPOOutputLog(ninePatch);
|
||||
return ninePatch;
|
||||
}
|
||||
|
||||
#pragma mark Bundle Loading
|
||||
+(id < TUNinePatch >)ninePatchNamed:(NSString *)filename {
|
||||
NPParameterAssertNotNilIsKindOfClass(filename,NSString);
|
||||
id < TUNinePatch > outPatch = nil;
|
||||
if (filename) {
|
||||
NSBundle *mainBundle = [NSBundle mainBundle];
|
||||
if (mainBundle) {
|
||||
NSString *filePath = [mainBundle pathForResource:[NSString stringWithFormat:@"%@.9",filename]
|
||||
ofType:@"png"];
|
||||
if (filePath) {
|
||||
UIImage *ninepatch = [[UIImage alloc] initWithContentsOfFile:filePath];
|
||||
if (ninepatch) {
|
||||
@try {
|
||||
outPatch = [self ninePatchWithNinePatchImage:ninepatch];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
outPatch = nil;
|
||||
}
|
||||
@finally {
|
||||
[ninepatch release];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NPAssertNilOrConformsToProtocol(outPatch,TUNinePatch);
|
||||
NPOOutputLog(outPatch);
|
||||
return outPatch;
|
||||
}
|
||||
|
||||
#pragma mark Nine Patch Image Manipulation - High Level
|
||||
+(CGRect)rectFromHorizontalRange:(NSRange)horizontalRange verticalRange:(NSRange)verticalRange {
|
||||
NPAInputLog(@"rectFromHorizontalRange:'%@' verticalRange:'%@'",NSStringFromRange(horizontalRange),NSStringFromRange(verticalRange));
|
||||
CGFloat minX = (TUIsNotFoundRange(horizontalRange))?(0.0f):((CGFloat) horizontalRange.location);
|
||||
CGFloat width = (TUIsNotFoundRange(horizontalRange))?(0.0f):((CGFloat) horizontalRange.length);
|
||||
CGFloat minY = (TUIsNotFoundRange(verticalRange)?(0.0f):((CGFloat) verticalRange.location));
|
||||
CGFloat height = (TUIsNotFoundRange(verticalRange)?(0.0f):((CGFloat) verticalRange.length));
|
||||
CGRect outRect = CGRectMake(minX,minY,width,height);
|
||||
NPCGROutputLog(outRect);
|
||||
return outRect;
|
||||
}
|
||||
|
||||
+(CGRect)stretchableRegionOfNinePatchImage:(UIImage *)ninePatchImage {
|
||||
NPAInputLog(@"stretchableRegionOfNinePatchImage:'%@'",ninePatchImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(ninePatchImage,UIImage);
|
||||
CGRect outRect = CGRectZero;
|
||||
if (ninePatchImage) {
|
||||
outRect = [self rectFromHorizontalRange:[ninePatchImage blackPixelRangeInUpperStrip]
|
||||
verticalRange:[ninePatchImage blackPixelRangeInLeftStrip]];
|
||||
}
|
||||
NPCGROutputLog(outRect);
|
||||
return outRect;
|
||||
}
|
||||
|
||||
+(CGRect)contentRegionOfNinePatchImage:(UIImage *)ninePatchImage {
|
||||
NPAInputLog(@"contentRegionOfNinePatchImage:'%@'",ninePatchImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(ninePatchImage,UIImage);
|
||||
CGRect outRect = CGRectZero;
|
||||
if (ninePatchImage) {
|
||||
outRect = [self rectFromHorizontalRange:[ninePatchImage blackPixelRangeInLowerStrip]
|
||||
verticalRange:[ninePatchImage blackPixelRangeInRightStrip]];
|
||||
}
|
||||
NPCGROutputLog(outRect);
|
||||
return outRect;
|
||||
}
|
||||
|
||||
+(BOOL)shouldTileCenterHorizontallyForNinePatchImage:(UIImage *)ninePatchImage {
|
||||
NPAInputLog(@"shouldTileCenterHorizontallyForNinePatchImage:'%@'",ninePatchImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(ninePatchImage,UIImage);
|
||||
BOOL shouldTileCenterHorizontallyForNinePatchImage = NO;
|
||||
if (ninePatchImage) {
|
||||
shouldTileCenterHorizontallyForNinePatchImage = [ninePatchImage upperLeftCornerIsBlackPixel];
|
||||
}
|
||||
NPBOutputLog(shouldTileCenterHorizontallyForNinePatchImage);
|
||||
return shouldTileCenterHorizontallyForNinePatchImage;
|
||||
}
|
||||
|
||||
+(BOOL)shouldTileCenterVerticallyForNinePatchImage:(UIImage *)ninePatchImage {
|
||||
NPAInputLog(@"shouldTileCenterHorizontallyForNinePatchImage:'%@'",ninePatchImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(ninePatchImage,UIImage);
|
||||
BOOL shouldTileCenterVerticallyForNinePatchImage = NO;
|
||||
if (ninePatchImage) {
|
||||
shouldTileCenterVerticallyForNinePatchImage = [ninePatchImage lowerLeftCornerIsBlackPixel];
|
||||
}
|
||||
NPBOutputLog(shouldTileCenterVerticallyForNinePatchImage);
|
||||
return shouldTileCenterVerticallyForNinePatchImage;
|
||||
}
|
||||
|
||||
#pragma mark Drawing Utility
|
||||
-(void)drawInRect:(CGRect)rect {
|
||||
if (self.center) {
|
||||
if (self.tileCenterHorizontally && self.tileCenterVertically) {
|
||||
[self.center drawAsPatternInRect:rect];
|
||||
} else {
|
||||
// NB: this behavior is not 100% accurate
|
||||
// in that it only works right for tiling on and off
|
||||
// half-tiling has to wait
|
||||
[self.center drawInRect:rect];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Diagnostic Utilities
|
||||
-(UIImage *)upperEdge {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage *)lowerEdge {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage *)leftEdge {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage *)rightEdge {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage *)upperLeftCorner {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage *)lowerLeftCorner {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage *)upperRightCorner {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage *)lowerRightCorner {
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark TUNinePatch Protocol Methods - Drawing
|
||||
-(void)inContext:(CGContextRef)context drawAtPoint:(CGPoint)point forContentOfSize:(CGSize)contentSize {
|
||||
NPParameterAssert(context != nil);
|
||||
NPAInputLog(@"inContext:'%@' drawAtPoint:'%@' forContentOfSize:'%@'",context,NSStringFromCGPoint(point),NSStringFromCGSize(contentSize));
|
||||
CGSize size = [self sizeForContentOfSize:contentSize];
|
||||
[self inContext:context
|
||||
drawInRect:CGRectMake(point.x, point.y, size.width, size.height)];
|
||||
}
|
||||
|
||||
-(void)inContext:(CGContextRef)context drawCenteredInRect:(CGRect)rect forContentOfSize:(CGSize)contentSize {
|
||||
NPParameterAssert(context != nil);
|
||||
NPAInputLog(@"inContext:'%@' drawCenteredInRect:'%@' forContentOfSize:'%@'",context,NSStringFromCGRect(rect),NSStringFromCGSize(contentSize));
|
||||
CGSize size = [self sizeForContentOfSize:contentSize];
|
||||
CGFloat xStart = floorf((CGRectGetWidth(rect) - size.width) * 0.5f);
|
||||
CGFloat yStart = floorf((CGRectGetHeight(rect) - size.height) * 0.5f);
|
||||
[self inContext:context
|
||||
drawInRect:CGRectMake(xStart, yStart, size.width, size.height)];
|
||||
}
|
||||
|
||||
-(void)inContext:(CGContextRef)context drawInRect:(CGRect)rect {
|
||||
if (context) {
|
||||
CGContextSaveGState(context);
|
||||
CGContextBeginTransparencyLayer(context, nil);
|
||||
@try {
|
||||
[self drawInRect:rect];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
NPLogException(e);
|
||||
}
|
||||
@finally {
|
||||
CGContextEndTransparencyLayer(context);
|
||||
CGContextRestoreGState(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark TUNinePatch Protocol Methods - Image Construction
|
||||
-(UIImage *)imageOfSize:(CGSize)size {
|
||||
UIImage *image = nil;
|
||||
UIGraphicsBeginImageContext(size);
|
||||
[self drawInRect:CGRectMake(0.0f,0.0f,size.width,size.height)];
|
||||
image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
return image;
|
||||
}
|
||||
|
||||
#pragma mark TUNinePatch Protocol Methods - Sizing
|
||||
-(BOOL)stretchesHorizontally {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)stretchesVertically {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(CGFloat)minimumWidth {
|
||||
CGFloat minimumWidth = 0.0f;
|
||||
if (self.center) {
|
||||
minimumWidth = [self.center size].width + self.rightEdgeWidth + self.leftEdgeWidth;
|
||||
}
|
||||
return minimumWidth;
|
||||
}
|
||||
|
||||
-(CGFloat)minimumHeight {
|
||||
CGFloat minimumHeight = 0.0f;
|
||||
if (self.center) {
|
||||
minimumHeight = [self.center size].height + self.upperEdgeHeight + self.lowerEdgeHeight;
|
||||
}
|
||||
return minimumHeight;
|
||||
}
|
||||
|
||||
-(CGSize)minimumSize {
|
||||
return CGSizeMake([self minimumWidth], [self minimumHeight]);
|
||||
}
|
||||
|
||||
-(CGSize)sizeForContentOfSize:(CGSize)contentSize {
|
||||
CGSize outSize = [self minimumSize];
|
||||
CGFloat contentRegionWidth = CGRectGetWidth(self.contentRegion);
|
||||
CGFloat contentRegionHeight = CGRectGetHeight(self.contentRegion);
|
||||
if ((contentRegionWidth > 0.0f) || (contentRegionHeight > 0.0f)) {
|
||||
// WE HAVE CONTENT REGION
|
||||
outSize.width += (contentSize.width > contentRegionWidth)?(contentSize.width - contentRegionWidth):(0.0f);
|
||||
outSize.height += (contentSize.height > contentRegionHeight)?(contentSize.height - contentRegionHeight):(0.0f);
|
||||
} else {
|
||||
// WE ONLY NEED A SIMPLE "WHICH IS BIGGER?" CHECK
|
||||
outSize.width = (contentSize.width > outSize.width)?(contentSize.width):(outSize.width);
|
||||
outSize.height = (contentSize.height > outSize.height)?(contentSize.height):(outSize.height);
|
||||
}
|
||||
return outSize;
|
||||
}
|
||||
|
||||
-(CGPoint)upperLeftCornerForContentWhenDrawnAtPoint:(CGPoint)point {
|
||||
return CGPointMake(point.x + CGRectGetMinX(self.contentRegion), point.y + CGRectGetMinY(self.contentRegion));
|
||||
}
|
||||
|
||||
#pragma mark TUNinePatch Protocol Methods - Geometry
|
||||
-(CGFloat)leftEdgeWidth {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
-(CGFloat)rightEdgeWidth {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
-(CGFloat)upperEdgeHeight {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
-(CGFloat)lowerEdgeHeight {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
#pragma mark Customized Description
|
||||
-(NSString *)description {
|
||||
return [NSString stringWithFormat:@"<%@>:( %@ )",[super description],[self descriptionPostfix]];
|
||||
}
|
||||
|
||||
-(NSString *)descriptionPostfix {
|
||||
return [NSString stringWithFormat:@"center:<'%@'>, contentRegion:<'%@'>", self.center, NSStringFromCGRect(self.contentRegion)];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
//
|
||||
// TUNinePatchCache.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
@class TUCachingNinePatch;
|
||||
/**
|
||||
|
||||
This class is included to make it easy to work with NinePatches if (1) all you want are static images (you don't care much about drawing into CGContextRefs) and (2) . Its semantics are probably non-optimal but are very straightforward: it caches every single request you make to it (both NinePatches and the rendered images). If you're only generating a handful of images and/or you're not super memory-constrained you should probably use this class. It has functionality for flushing the cache with various levels of granularity if you need such functionality.
|
||||
|
||||
One thing that's maybe not so obvious is that the methods on this class span two levels of abstraction and caching. Briefly:
|
||||
- an instance of TUCachingNinePatch has a ninePatch property (that is a TUNinePatch-implementing object)
|
||||
- TUCachingNinePatch caches all images it generates
|
||||
- TUNinePatchCache generates and caches instance of TUCachingNinePatch (which in turn cache images)
|
||||
|
||||
Where the danger zone emerges is ninePatchNamed: this constructs a TUCachingNinePatch (which as part of its construction constructs an object implementing TUNinePatch), caches the TUCachingNinePatch instance, and returns that instance's ninePatch property (which is what actually implements the TUNinePatch protocol). This is in fact the behavior we wanted when we made this library, but it is a little subtle.
|
||||
|
||||
*/
|
||||
@interface TUNinePatchCache : NSObject {
|
||||
NSMutableDictionary *_ninePatchCache;
|
||||
}
|
||||
|
||||
// Synthesized Properties
|
||||
/**
|
||||
This is where the NinePatches get cached. You should pretty much never look at or manipulate this directly. If I believed in private instance variables this's be private. Maybe I'll make it private soon.
|
||||
*/
|
||||
@property(nonatomic, retain, readonly) NSMutableDictionary *ninePatchCache;
|
||||
|
||||
-(id)init;
|
||||
/**
|
||||
Gets at the application's shared instance, creating it if it doesn't exist.
|
||||
*/
|
||||
+(id)shared;
|
||||
|
||||
// Getting Ninepatches Directly
|
||||
/**
|
||||
Use this method to get at the actual NinePatch you want to interact with (if eg you're using this cache but need finer-grained control than just generating images). Will load the NinePatch (from the app's main bundle) if it doesn't exist yet.
|
||||
|
||||
@param ninePatchName The name of the NinePatch you're trying to get at.
|
||||
@returns The NinePatch object you wanted. Can return nil if problems were encountered.
|
||||
*/
|
||||
-(id < TUNinePatch >)ninePatchNamed:(NSString *)ninePachName;
|
||||
|
||||
// These methods should be private, if I believed in private methods
|
||||
-(TUCachingNinePatch *)cachingNinePatchNamed:(NSString *)ninePatchName;
|
||||
-(void)cacheCachingNinePatch:(TUCachingNinePatch *)cachingNinePatch named:(NSString *)ninePatchName;
|
||||
-(TUCachingNinePatch *)cachedCachingNinePatchNamed:(NSString *)ninePatchName;
|
||||
-(TUCachingNinePatch *)constructCachingNinePatchNamed:(NSString *)ninePatchName;
|
||||
|
||||
// Getting Images Directly
|
||||
/**
|
||||
This method renders the image at the requested size using the NinePatch with the passed-in name. Tries to use a cached image and/or NinePatch as possible, otherwise loading from scratch. Any NinePatch or image it loads is subsequently cached.
|
||||
|
||||
@param size The size the output image should be rendered at.
|
||||
@param ninePatchName the name of the NinePatch you want to use to render the image. Don't include @".9.png" in the name.
|
||||
@returns An image rendered from the specified ninePatchName at the requested size. Can return nil if difficulties were encountered. Image should be retained if it is important it be held onto by the recipient, but should not be released by the recipient.
|
||||
*/
|
||||
-(UIImage *)imageOfSize:(CGSize)size forNinePatchNamed:(NSString *)ninePatchName;
|
||||
|
||||
// Getting Ninepatches - Convenience
|
||||
/**
|
||||
Semantics same as instance-level method of same name, but calls through to the singleton instance.
|
||||
*/
|
||||
+(id < TUNinePatch >)ninePatchNamed:(NSString *)ninePatchName;
|
||||
|
||||
// Getting Images - Convenience
|
||||
/**
|
||||
This is a convenience method; calls instance method of the same name on the singleton. Easiest way to use this in your code.
|
||||
*/
|
||||
+(UIImage *)imageOfSize:(CGSize)size forNinePatchNamed:(NSString *)ninePatchName;
|
||||
|
||||
// Cache Management - Direct
|
||||
/**
|
||||
Flushes all cached content (NinePatches AND their cached rendered images, if any).
|
||||
*/
|
||||
-(void)flushCache;
|
||||
/**
|
||||
Flushes only the content for the NinePatch with the passed-in name. Won't complain if there's no cached NinePatch with the passed-in name.
|
||||
*/
|
||||
-(void)flushCacheForNinePatchNamed:(NSString *)name;
|
||||
|
||||
// Cache Management - Convenience
|
||||
/**
|
||||
Flushes all cached content from the singleton.
|
||||
*/
|
||||
+(void)flushCache;
|
||||
|
||||
/**
|
||||
Flushes the NinePatch with the passed-in name from the singleton (which also flushes any cached images).
|
||||
*/
|
||||
+(void)flushCacheForNinePatchNamed:(NSString *)name;
|
||||
|
||||
@end
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
//
|
||||
// TUNinePatchCache.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUNinePatchCache.h"
|
||||
#import "TUCachingNinePatch.h"
|
||||
#import "TUNinePatch.h"
|
||||
|
||||
@interface TUNinePatchCache ()
|
||||
|
||||
@property(nonatomic, retain, readwrite) NSMutableDictionary *ninePatchCache;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TUNinePatchCache
|
||||
|
||||
#pragma mark Synthesized Properties
|
||||
@synthesize ninePatchCache = _ninePatchCache;
|
||||
|
||||
#pragma mark Init + Dealloc
|
||||
-(id)init {
|
||||
if (self = [super init]) {
|
||||
self.ninePatchCache = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
+(id)shared {
|
||||
static TUNinePatchCache *shared;
|
||||
if (!shared) {
|
||||
shared = [[self alloc] init];
|
||||
}
|
||||
return shared;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(void)dealloc {
|
||||
self.ninePatchCache = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark Getting Ninepatches Directly
|
||||
// Getting Ninepatches Directly
|
||||
-(id < TUNinePatch >)ninePatchNamed:(NSString *)ninePatchName {
|
||||
TUCachingNinePatch *cachingNinePatch = [self cachingNinePatchNamed:ninePatchName];
|
||||
NPAssertNilOrIsKindOfClass(cachingNinePatch,TUCachingNinePatch);
|
||||
return (!cachingNinePatch)?(nil):([cachingNinePatch ninePatch]);
|
||||
}
|
||||
|
||||
|
||||
-(TUCachingNinePatch *)cachingNinePatchNamed:(NSString *)ninePatchName {
|
||||
TUCachingNinePatch *cachingNinePatch = [self cachedCachingNinePatchNamed:ninePatchName];
|
||||
NPAssertNilOrIsKindOfClass(cachingNinePatch,TUCachingNinePatch);
|
||||
if (!cachingNinePatch) {
|
||||
cachingNinePatch = [self constructCachingNinePatchNamed:ninePatchName];
|
||||
NPAssertNilOrIsKindOfClass(cachingNinePatch,TUCachingNinePatch);
|
||||
if (cachingNinePatch) {
|
||||
[self cacheCachingNinePatch:cachingNinePatch
|
||||
named:ninePatchName];
|
||||
}
|
||||
}
|
||||
return cachingNinePatch;
|
||||
}
|
||||
|
||||
-(void)cacheCachingNinePatch:(TUCachingNinePatch *)cachingNinePatch named:(NSString *)ninePatchName {
|
||||
NPAssertPropertyNonNil(ninePatchCache);
|
||||
if (cachingNinePatch && ninePatchName) {
|
||||
[self.ninePatchCache setObject:cachingNinePatch
|
||||
forKey:ninePatchName];
|
||||
}
|
||||
}
|
||||
|
||||
-(TUCachingNinePatch *)cachedCachingNinePatchNamed:(NSString *)ninePatchName {
|
||||
return (!ninePatchName)?(nil):([self.ninePatchCache objectForKey:ninePatchName]);
|
||||
}
|
||||
|
||||
-(TUCachingNinePatch *)constructCachingNinePatchNamed:(NSString *)ninePatchName {
|
||||
return (!ninePatchName)?(nil):([TUCachingNinePatch ninePatchCacheWithNinePatchNamed:ninePatchName]);
|
||||
}
|
||||
|
||||
#pragma mark Getting Images Directly
|
||||
-(UIImage *)imageOfSize:(CGSize)size forNinePatchNamed:(NSString *)ninePatchName {
|
||||
NPParameterAssertNotNilIsKindOfClass(ninePatchName,NSString);
|
||||
UIImage *image = nil;
|
||||
TUCachingNinePatch *cachingNinePatch = [self cachingNinePatchNamed:ninePatchName];
|
||||
if (cachingNinePatch) {
|
||||
image = [cachingNinePatch imageOfSize:size];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
#pragma mark Getting Ninepatches - Convenience
|
||||
+(TUCachingNinePatch *)cachingNinePatchNamed:(NSString *)ninePatchName {
|
||||
return [[self shared] ninePatchNamed:ninePatchName];
|
||||
}
|
||||
|
||||
+(id < TUNinePatch >)ninePatchNamed:(NSString *)ninePatchName {
|
||||
TUCachingNinePatch *cachingNinePatch = [[self shared] cachingNinePatchNamed:ninePatchName];
|
||||
NPAssertNilOrIsKindOfClass(cachingNinePatch,TUCachingNinePatch);
|
||||
return (!cachingNinePatch)?(nil):([cachingNinePatch ninePatch]);
|
||||
}
|
||||
|
||||
#pragma mark Getting Images - Convenience
|
||||
+(UIImage *)imageOfSize:(CGSize)size forNinePatchNamed:(NSString *)ninePatchName {
|
||||
return [[self shared] imageOfSize:size
|
||||
forNinePatchNamed:ninePatchName];
|
||||
}
|
||||
|
||||
#pragma mark Cache Management - Direct
|
||||
-(void)flushCache {
|
||||
[self.ninePatchCache removeAllObjects];
|
||||
}
|
||||
-(void)flushCacheForNinePatchNamed:(NSString *)name {
|
||||
if (name) {
|
||||
[self.ninePatchCache removeObjectForKey:name];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Cache Management - Convenience
|
||||
+(void)flushCache {
|
||||
[[self shared] flushCache];
|
||||
}
|
||||
|
||||
+(void)flushCacheForNinePatchNamed:(NSString *)name {
|
||||
[[self shared] flushCacheForNinePatchNamed:name];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
//
|
||||
// TUNinePatchCachingCategories.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
@interface NSString (NinePatchCaching)
|
||||
|
||||
+(NSString *)ninePatchKeyStringForSize:(CGSize)size;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSDictionary (NinePatchCaching)
|
||||
|
||||
-(id)objectForSize:(CGSize)size;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSMutableDictionary (NinePatchCaching)
|
||||
|
||||
-(void)setObject:(id)object forSize:(CGSize)size;
|
||||
|
||||
@end
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
//
|
||||
// TUNinePatchCachingCategories.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2010 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUNinePatchCachingCategories.h"
|
||||
|
||||
@implementation NSString (NinePatchCaching)
|
||||
|
||||
/**
|
||||
It's not clear we can't just use NSStringFromCGSize. This might get cut in a future revision.
|
||||
*/
|
||||
+(NSString *)ninePatchKeyStringForSize:(CGSize)size {
|
||||
return [NSString stringWithFormat:@"ninePatchKeyString.%#.0f.%#.0f",size.width,size.height];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSDictionary (NinePatchCaching)
|
||||
|
||||
/**
|
||||
Convenience method to make it a little less annoying to pull objects out of the caches keyed by their size.
|
||||
*/
|
||||
-(id)objectForSize:(CGSize)size {
|
||||
id object = nil;
|
||||
NSString *key = [NSString ninePatchKeyStringForSize:size];
|
||||
if (key) {
|
||||
object = [self objectForKey:key];
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSMutableDictionary (NinePatchCaching)
|
||||
|
||||
/**
|
||||
Convenience method to make it a little less annoying to put objects in the caches keyed by their size.
|
||||
*/
|
||||
-(void)setObject:(id)object forSize:(CGSize)size {
|
||||
if (object) {
|
||||
NSString *key = [NSString ninePatchKeyStringForSize:size];
|
||||
if (key) {
|
||||
[self setObject:object
|
||||
forKey:key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
//
|
||||
// TUNinePatch.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
/**
|
||||
|
||||
Defines the methods shared by all concrete NinePatch classes. Expect many of these methods to be removed from the
|
||||
protocol as the library is improved.
|
||||
|
||||
*/
|
||||
@protocol TUNinePatch < NSObject, NSCoding, NSCopying >
|
||||
|
||||
// TUNinePatch Protocol Methods - Drawing
|
||||
/**
|
||||
This draws the NinePatch with its upper-left corner at a specified location in a specified context, scaled to fit content of the size. This is a good method to use when drawing NinePatches that use the content bounds. This method will probably be improved in the future to return the upper-left corner for the content to be drawn.
|
||||
|
||||
@param context A non-nil CGContextRef into which NinePatch will be drawn.
|
||||
@param point The upper left corner the NinePatch will be drawn at.
|
||||
@param size The size of the content the NinePatch will be sized to contain.
|
||||
*/
|
||||
-(void)inContext:(CGContextRef)context drawAtPoint:(CGPoint)point forContentOfSize:(CGSize)size;
|
||||
|
||||
/**
|
||||
This draws the NinePatch centered (horizontally and vertically) inside the containmentRect in the specified context, sized to fit content of the passed-in size. This is essentially a convenience method wrapping inContext:drawAtPoint:forContentOfSize:. Like its cousin it'll probably be modified to return information about where the content should be drawn. Will let the NinePatch overflow the containmentRect if the necessary size is sufficiently large; it'll be centered, just too big.
|
||||
|
||||
@param context A non-nil CGContextRef into which NinePatch will be drawn.
|
||||
@param containmentRect the rect in which the NinePatch will be centered.
|
||||
@param size The size of the content the NinePatch will be sized to contain.
|
||||
*/
|
||||
-(void)inContext:(CGContextRef)context drawCenteredInRect:(CGRect)containmentRect forContentOfSize:(CGSize)size;
|
||||
|
||||
/**
|
||||
This method draws the NinePatch into the passed-in context filling the passed-in rect. In all current implementations of TUNinePatch the other drawing utilities eventually call through this method to do their actual drawing.
|
||||
|
||||
@param context A non-nil CGContextRef into which NinePatch will be drawn.
|
||||
@param rect The rect into which the NinePatch will be drawn. NinePatch is scaled to fill the rect.
|
||||
*/
|
||||
-(void)inContext:(CGContextRef)context drawInRect:(CGRect)rect;
|
||||
|
||||
// TUNinePatch Protocol Methods - Image Construction
|
||||
/**
|
||||
Renders the NinePatch into an image of the requested size. Implementations vary in their memory management here -- to guarantee the returned image hangs around you should retain it.
|
||||
|
||||
@param size The size the output UIImage should be.
|
||||
@returns A UIImage rendering of the NinePatch scaled like the passed-in size.
|
||||
*/
|
||||
-(UIImage *)imageOfSize:(CGSize)size;
|
||||
|
||||
// TUNinePatch Protocol Methods - Sizing
|
||||
/**
|
||||
Returns YES if the NinePatch scales horizontally, NO otherwise. May be removed from protocol in future.
|
||||
*/
|
||||
-(BOOL)stretchesHorizontally;
|
||||
/**
|
||||
Returns YES if the NinePatch scales vertically, NO otherwise. May be removed from protocol in future.
|
||||
*/
|
||||
-(BOOL)stretchesVertically;
|
||||
|
||||
/**
|
||||
Returns smallest horizontal size you scan scale NinePatch down to. This is usually equal to the leftEdge + the rightEdge (sending central column width -> 0). May be removed from protocol in future.
|
||||
|
||||
@returns minimumWidth the smallest width NinePatch will render at.
|
||||
*/
|
||||
-(CGFloat)minimumWidth;
|
||||
|
||||
/**
|
||||
Returns smallest vertical size you scan scale NinePatch down to. This is usually equal to the topEdge + bottomEdge (sending central row height -> 0). May be removed from protocol in future.
|
||||
|
||||
@returns minimumHeight the smallest height NinePatch will render at.
|
||||
*/
|
||||
-(CGFloat)minimumHeight;
|
||||
|
||||
/**
|
||||
Returns CGSize created from minimumWidth and minimumHeight in the obvious way.
|
||||
*/
|
||||
-(CGSize)minimumSize;
|
||||
|
||||
/**
|
||||
This is used for layout. Recall that NinePatch allows you to specify a "content region" (into which the content must fit) as a way of standardizing the amount of padding you do when using a particular NinePatch. This method returns the size the NinePatch needs to be drawn at to correctly accommodate content of the passed-in size. Note that for NinePatches that don't specify anything wrt content size this is the identity function.
|
||||
|
||||
@param contentSize The size of the content you're using the NinePatch to display.
|
||||
@returns The size you need to draw the NinePatch at to accommodate the content.
|
||||
*/
|
||||
-(CGSize)sizeForContentOfSize:(CGSize)contentSize;
|
||||
|
||||
/**
|
||||
This is used for layout. This is basically a convenience function to calculate the offset for where "content" starts. It's the identity function when the NinePatch doesn't specify anything for the content region.
|
||||
|
||||
@param point The point at which you're planning to place the upper left corner of the NinePatch when you draw it.
|
||||
@returns The point at which you need to place the upper left corner of the content you're going to draw.
|
||||
*/
|
||||
-(CGPoint)upperLeftCornerForContentWhenDrawnAtPoint:(CGPoint)point;
|
||||
|
||||
// TUNinePatch Protocol Methods - Geometry
|
||||
/**
|
||||
The width of the left column. This geometric property lookup is probably going to get removed from the protocol.
|
||||
*/
|
||||
-(CGFloat)leftEdgeWidth;
|
||||
|
||||
/**
|
||||
The width of the right column. This geometric property lookup is probably going to get removed from the protocol.
|
||||
*/
|
||||
-(CGFloat)rightEdgeWidth;
|
||||
|
||||
/**
|
||||
The width of the upper row. This geometric property lookup is probably going to get removed from the protocol.
|
||||
*/
|
||||
-(CGFloat)upperEdgeHeight;
|
||||
|
||||
/**
|
||||
The width of the lower column. This geometric property lookup is probably going to get removed from the protocol.
|
||||
*/
|
||||
-(CGFloat)lowerEdgeHeight;
|
||||
|
||||
@end
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
//
|
||||
// TUVerticalNinePatch.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import "TUNinePatch.h"
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
/**
|
||||
Concrete TUNinePatch instance. Handles NinePatches that only stretch vertically. Only instantiate directly if you know what you're doing.
|
||||
*/
|
||||
@interface TUVerticalNinePatch : TUNinePatch < TUNinePatch > {
|
||||
UIImage *_upperEdge;
|
||||
UIImage *_lowerEdge;
|
||||
}
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readonly) UIImage *upperEdge;
|
||||
@property(nonatomic, retain, readonly) UIImage *lowerEdge;
|
||||
|
||||
// Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally upperEdge:(UIImage *)upperEdge lowerEdge:(UIImage *)lowerEdge;
|
||||
-(void)dealloc;
|
||||
|
||||
// TUNinePatch Overrides
|
||||
-(void)drawInRect:(CGRect)rect;
|
||||
-(BOOL)stretchesHorizontally;
|
||||
-(CGSize)sizeForContentOfSize:(CGSize)contentSize;
|
||||
-(CGFloat)upperEdgeHeight;
|
||||
-(CGFloat)lowerEdgeHeight;
|
||||
|
||||
@end
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
//
|
||||
// TUVerticalNinePatch.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUVerticalNinePatch.h"
|
||||
|
||||
@interface TUVerticalNinePatch ()
|
||||
|
||||
// Synthesized Properties
|
||||
@property(nonatomic, retain, readwrite) UIImage *upperEdge;
|
||||
@property(nonatomic, retain, readwrite) UIImage *lowerEdge;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TUVerticalNinePatch
|
||||
|
||||
#pragma mark Synthesized Properties
|
||||
@synthesize upperEdge = _upperEdge;
|
||||
@synthesize lowerEdge = _lowerEdge;
|
||||
|
||||
#pragma mark NSCoding
|
||||
-(id)initWithCoder:(NSCoder *)coder {
|
||||
if (self = [super initWithCoder:coder]) {
|
||||
self.upperEdge = (UIImage *)[coder decodeObjectForKey:@"upperEdge"];
|
||||
self.lowerEdge = (UIImage *)[coder decodeObjectForKey:@"lowerEdge"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[super encodeWithCoder:coder];
|
||||
|
||||
[coder encodeObject:self.upperEdge
|
||||
forKey:@"upperEdge"];
|
||||
|
||||
[coder encodeObject:self.lowerEdge
|
||||
forKey:@"lowerEdge"];
|
||||
}
|
||||
|
||||
#pragma mark NSCopying
|
||||
-(id)copyWithZone:(NSZone *)zone {
|
||||
return [[[self class] allocWithZone:zone] initWithCenter:self.center
|
||||
contentRegion:self.contentRegion
|
||||
tileCenterVertically:self.tileCenterVertically
|
||||
tileCenterHorizontally:self.tileCenterHorizontally
|
||||
upperEdge:self.upperEdge
|
||||
lowerEdge:self.lowerEdge];
|
||||
}
|
||||
|
||||
#pragma mark Init + Dealloc
|
||||
-(id)initWithCenter:(UIImage *)center contentRegion:(CGRect)contentRegion tileCenterVertically:(BOOL)tileCenterVertically tileCenterHorizontally:(BOOL)tileCenterHorizontally upperEdge:(UIImage *)upperEdge lowerEdge:(UIImage *)lowerEdge {
|
||||
NPParameterAssertNotNilIsKindOfClass(upperEdge,UIImage);
|
||||
NPParameterAssertNotNilIsKindOfClass(lowerEdge,UIImage);
|
||||
if (self = [super initWithCenter:center
|
||||
contentRegion:contentRegion
|
||||
tileCenterVertically:tileCenterVertically
|
||||
tileCenterHorizontally:tileCenterHorizontally]) {
|
||||
self.upperEdge = upperEdge;
|
||||
self.lowerEdge = lowerEdge;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(void)dealloc {
|
||||
self.upperEdge = nil;
|
||||
self.lowerEdge = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark TUNinePatch Overrides
|
||||
-(void)drawInRect:(CGRect)rect {
|
||||
NPSelfProperty(center);
|
||||
NPSelfProperty(upperEdge);
|
||||
NPSelfProperty(lowerEdge);
|
||||
CGFloat width = [self minimumWidth];
|
||||
[self.center drawInRect:CGRectMake(CGRectGetMinX(rect), CGRectGetMinY(rect) + [self upperEdgeHeight], width, CGRectGetHeight(rect) - ([self upperEdgeHeight] + [self lowerEdgeHeight]))];
|
||||
if (self.upperEdge) {
|
||||
[self.upperEdge drawAtPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect))];
|
||||
}
|
||||
if (self.lowerEdge) {
|
||||
[self.lowerEdge drawAtPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect) - [self lowerEdgeHeight])];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(BOOL)stretchesHorizontally {
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(CGSize)sizeForContentOfSize:(CGSize)contentSize {
|
||||
NPAInputLog(@"sizeForContentOfSize:'%@'",NSStringFromCGSize(contentSize));
|
||||
CGSize outSize = [super sizeForContentOfSize:contentSize];
|
||||
outSize.width = [self minimumWidth];
|
||||
NPCGSOutputLog(outSize);
|
||||
return outSize;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(CGFloat)upperEdgeHeight {
|
||||
NPSelfProperty(upperEdge);
|
||||
CGFloat upperEdgeHeight = 0.0f;
|
||||
if (self.upperEdge) {
|
||||
upperEdgeHeight = [self.upperEdge size].height;
|
||||
}
|
||||
NPFOutputLog(upperEdgeHeight);
|
||||
return upperEdgeHeight;
|
||||
}
|
||||
|
||||
-(CGFloat)lowerEdgeHeight {
|
||||
NPSelfProperty(lowerEdge);
|
||||
CGFloat lowerEdgeHeight = 0.0f;
|
||||
if (self.lowerEdge) {
|
||||
lowerEdgeHeight = [self.lowerEdge size].height;
|
||||
}
|
||||
NPFOutputLog(lowerEdgeHeight);
|
||||
return lowerEdgeHeight;
|
||||
}
|
||||
|
||||
#pragma mark Customized Description Overrides
|
||||
-(NSString *)descriptionPostfix {
|
||||
return [NSString stringWithFormat:@"%@, self.upperEdge:<'%@'>, self.lowerEdge:<'%@'>",
|
||||
[super descriptionPostfix],
|
||||
self.upperEdge,
|
||||
self.lowerEdge];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
//
|
||||
// UIImage-TUNinePatch.h
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
void TUImageLog(UIImage *image, NSString *imageName);
|
||||
/**
|
||||
This category implements all the image-slicing, pixel-tasting, and similar image-manipulation and image-analysis functions. These are only used in methods that'll probably become private real soon now, so maybe a "not much to see here" sign is called for.
|
||||
*/
|
||||
@interface UIImage (TUNinePatch)
|
||||
|
||||
// Black Pixel Searching - Corners
|
||||
-(BOOL)upperLeftCornerIsBlackPixel;
|
||||
-(BOOL)upperRightCornerIsBlackPixel;
|
||||
-(BOOL)lowerLeftCornerIsBlackPixel;
|
||||
-(BOOL)lowerRightCornerIsBlackPixel;
|
||||
|
||||
// Pixel Tasting - Single Pixel
|
||||
-(BOOL)isBlackPixel;
|
||||
|
||||
// Black Pixel Searching - Strips
|
||||
-(NSRange)blackPixelRangeInUpperStrip;
|
||||
-(NSRange)blackPixelRangeInLowerStrip;
|
||||
-(NSRange)blackPixelRangeInLeftStrip;
|
||||
-(NSRange)blackPixelRangeInRightStrip;
|
||||
|
||||
// Pixel Tasting - Strips
|
||||
-(NSRange)blackPixelRangeAsVerticalStrip;
|
||||
-(NSRange)blackPixelRangeAsHorizontalStrip;
|
||||
|
||||
// Corners - Rects
|
||||
-(CGRect)upperLeftCornerRect;
|
||||
-(CGRect)lowerLeftCornerRect;
|
||||
-(CGRect)upperRightCornerRect;
|
||||
-(CGRect)lowerRightCornerRect;
|
||||
|
||||
// Corners - Slicing
|
||||
-(UIImage *)upperLeftCorner;
|
||||
-(UIImage *)lowerLeftCorner;
|
||||
-(UIImage *)upperRightCorner;
|
||||
-(UIImage *)lowerRightCorner;
|
||||
|
||||
// Strips - Sizing
|
||||
-(CGRect)upperStripRect;
|
||||
-(CGRect)lowerStripRect;
|
||||
-(CGRect)leftStripRect;
|
||||
-(CGRect)rightStripRect;
|
||||
|
||||
// Strips - Slicing
|
||||
-(UIImage *)upperStrip;
|
||||
-(UIImage *)lowerStrip;
|
||||
-(UIImage *)leftStrip;
|
||||
-(UIImage *)rightStrip;
|
||||
|
||||
// Subimage Slicing
|
||||
-(UIImage *)subImageInRect:(CGRect)rect;
|
||||
|
||||
// Nine-Patch Content Extraction
|
||||
-(UIImage *)imageAsNinePatchImage;
|
||||
|
||||
-(UIImage *)extractUpperLeftCornerForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractUpperRightCornerForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractLowerLeftCornerForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractLowerRightCornerForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractLeftEdgeForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractRightEdgeForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractUpperEdgeForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractLowerEdgeForStretchableRegion:(CGRect)stretchableRegion;
|
||||
-(UIImage *)extractCenterForStretchableRegion:(CGRect)stretchableRegion;
|
||||
|
||||
@end
|
||||
|
|
@ -1,539 +0,0 @@
|
|||
//
|
||||
// UIImage-TUNinePatch.m
|
||||
// NinePatch
|
||||
//
|
||||
// Copyright 2009 Tortuga 22, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIImage-TUNinePatch.h"
|
||||
#import "TUNinePatchProtocols.h"
|
||||
|
||||
void TUImageLog(UIImage *image, NSString *imageName) {
|
||||
if (image && imageName) {
|
||||
NSString *fullFileName = [imageName stringByAppendingString:@".png"];
|
||||
if (fullFileName) {
|
||||
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
|
||||
if (documentsDirectory) {
|
||||
NSString *fullFilePath = [documentsDirectory stringByAppendingPathComponent:fullFileName];
|
||||
if (fullFilePath) {
|
||||
NSData *pngData = UIImagePNGRepresentation(image);
|
||||
if (pngData) {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if (fileManager) {
|
||||
BOOL succeeded = [fileManager createFileAtPath:fullFilePath contents:pngData attributes:nil];
|
||||
if (succeeded) {
|
||||
DLog(@"Seemingly successfully wrote image to file at: '%@'.",fullFilePath);
|
||||
} else {
|
||||
DLog(@"Seemingly failed to write image to file at: '%@'.",fullFilePath);
|
||||
}
|
||||
} else {
|
||||
LLog(@"Couldn't get default fileManager, aborting imagelog.");
|
||||
}
|
||||
} else {
|
||||
LLog(@"Couldn't get PNGRepresentation, aborting imagelog.");
|
||||
}
|
||||
} else {
|
||||
LLog(@"Couldn't get fullFilePath, aborting imagelog.");
|
||||
}
|
||||
} else {
|
||||
LLog(@"Couldn't get fullFilePath, aborting imagelog.");
|
||||
}
|
||||
} else {
|
||||
DLog(@"Could't get fullFileName, aborting imageLog.");
|
||||
}
|
||||
} else {
|
||||
DLog(@"Can't log image: '%@', imageName: '%@', as one or both are nil.",image, imageName);
|
||||
}
|
||||
}
|
||||
|
||||
@implementation UIImage (TUNinePatch)
|
||||
|
||||
#pragma mark Black Pixel Searching - Corners
|
||||
-(BOOL)upperLeftCornerIsBlackPixel {
|
||||
BOOL upperLeftCornerIsBlackPixel = NO;
|
||||
UIImage *upperLeftCorner = [self upperLeftCorner];
|
||||
if (upperLeftCorner) {
|
||||
upperLeftCornerIsBlackPixel = [upperLeftCorner isBlackPixel];
|
||||
}
|
||||
NPBOutputLog(upperLeftCornerIsBlackPixel);
|
||||
return upperLeftCornerIsBlackPixel;
|
||||
}
|
||||
|
||||
-(BOOL)upperRightCornerIsBlackPixel {
|
||||
BOOL upperRightCornerIsBlackPixel = NO;
|
||||
UIImage *upperRightCorner = [self upperRightCorner];
|
||||
if (upperRightCorner) {
|
||||
upperRightCornerIsBlackPixel = [upperRightCorner isBlackPixel];
|
||||
}
|
||||
NPBOutputLog(upperRightCornerIsBlackPixel);
|
||||
return upperRightCornerIsBlackPixel;
|
||||
}
|
||||
|
||||
-(BOOL)lowerLeftCornerIsBlackPixel {
|
||||
BOOL lowerLeftCornerIsBlackPixel = NO;
|
||||
UIImage *lowerLeftCorner = [self lowerLeftCorner];
|
||||
if (lowerLeftCorner) {
|
||||
lowerLeftCornerIsBlackPixel = [lowerLeftCorner isBlackPixel];
|
||||
}
|
||||
NPBOutputLog(lowerLeftCornerIsBlackPixel);
|
||||
return lowerLeftCornerIsBlackPixel;
|
||||
}
|
||||
|
||||
-(BOOL)lowerRightCornerIsBlackPixel {
|
||||
BOOL lowerRightCornerIsBlackPixel = NO;
|
||||
UIImage *lowerRightCorner = [self lowerRightCorner];
|
||||
if (lowerRightCorner) {
|
||||
lowerRightCornerIsBlackPixel = [lowerRightCorner isBlackPixel];
|
||||
}
|
||||
NPBOutputLog(lowerRightCornerIsBlackPixel);
|
||||
return lowerRightCornerIsBlackPixel;
|
||||
}
|
||||
|
||||
#pragma mark Pixel Tasting - Single Pixel
|
||||
-(BOOL)isBlackPixel {
|
||||
NPAssert(([self size].width > 0.0f), @"Should have width > 0.0f");
|
||||
NPAssert(([self size].height > 0.0f), @"Should have height > 0.0f");
|
||||
BOOL isBlackPixel = NO;
|
||||
if (([self size].width > 0.0f) && ([self size].height > 0.0f)) {
|
||||
CGImageRef cgImage = [self CGImage];
|
||||
NSUInteger width = CGImageGetWidth(cgImage);
|
||||
NSUInteger height = CGImageGetHeight(cgImage);
|
||||
NSUInteger bytesPerRow = width * TURGBABytesPerPixel;
|
||||
NSUInteger bitsPerComponent = 8;
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
UInt8 *pixelByteData = malloc(width * height * TURGBABytesPerPixel);
|
||||
|
||||
|
||||
CGContextRef context = CGBitmapContextCreate(
|
||||
(void *)pixelByteData,
|
||||
width,
|
||||
height,
|
||||
bitsPerComponent,
|
||||
bytesPerRow,
|
||||
colorSpace,
|
||||
kCGImageAlphaPremultipliedLast);
|
||||
|
||||
CGContextDrawImage(context, CGRectMake(0.0f,0.0f,1.0f,1.0f), cgImage);
|
||||
TURGBAPixel *pixelData = (TURGBAPixel *) CGBitmapContextGetData(context);
|
||||
if (pixelData) {
|
||||
isBlackPixel = TURGBAPixelIsBlack(pixelData[0]);
|
||||
}
|
||||
CGContextRelease(context);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
free(pixelByteData);
|
||||
}
|
||||
NPBOutputLog(isBlackPixel);
|
||||
return isBlackPixel;
|
||||
}
|
||||
|
||||
#pragma mark Black Pixel Searching - Strips
|
||||
-(NSRange)blackPixelRangeInUpperStrip {
|
||||
NSRange blackPixelRangeInUpperStrip = TUNotFoundRange;
|
||||
UIImage *upperStrip = [self upperStrip];
|
||||
if (upperStrip) {
|
||||
blackPixelRangeInUpperStrip = [upperStrip blackPixelRangeAsHorizontalStrip];
|
||||
}
|
||||
NPNSROutputLog(blackPixelRangeInUpperStrip);
|
||||
return blackPixelRangeInUpperStrip;
|
||||
}
|
||||
|
||||
-(NSRange)blackPixelRangeInLowerStrip {
|
||||
NSRange blackPixelRangeInLowerStrip = TUNotFoundRange;
|
||||
UIImage *lowerStrip = [self lowerStrip];
|
||||
if (lowerStrip) {
|
||||
blackPixelRangeInLowerStrip = [lowerStrip blackPixelRangeAsHorizontalStrip];
|
||||
}
|
||||
NPNSROutputLog(blackPixelRangeInLowerStrip);
|
||||
return blackPixelRangeInLowerStrip;
|
||||
}
|
||||
|
||||
-(NSRange)blackPixelRangeInLeftStrip {
|
||||
NSRange blackPixelRangeInLeftStrip = TUNotFoundRange;
|
||||
UIImage *leftStrip = [self leftStrip];
|
||||
if (leftStrip) {
|
||||
blackPixelRangeInLeftStrip = [leftStrip blackPixelRangeAsVerticalStrip];
|
||||
}
|
||||
NPNSROutputLog(blackPixelRangeInLeftStrip);
|
||||
return blackPixelRangeInLeftStrip;
|
||||
}
|
||||
|
||||
-(NSRange)blackPixelRangeInRightStrip {
|
||||
NSRange blackPixelRangeInRightStrip = TUNotFoundRange;
|
||||
UIImage *rightStrip = [self rightStrip];
|
||||
if (rightStrip) {
|
||||
blackPixelRangeInRightStrip = [rightStrip blackPixelRangeAsVerticalStrip];
|
||||
}
|
||||
NPNSROutputLog(blackPixelRangeInRightStrip);
|
||||
return blackPixelRangeInRightStrip;
|
||||
}
|
||||
|
||||
#pragma mark Pixel Tasting - Strips
|
||||
-(NSRange)blackPixelRangeAsVerticalStrip {
|
||||
NPAssert([self size].width == 1.0f, @"This method assumes the image has width == 1.0f");
|
||||
NSRange blackPixelRangeAsVerticalStrip = TUNotFoundRange;
|
||||
NSUInteger firstBlackPixel = NSNotFound;
|
||||
NSUInteger lastBlackPixel = NSNotFound;
|
||||
if ([self size].height > 0.0f) {
|
||||
CGImageRef cgImage = [self CGImage];
|
||||
|
||||
NSUInteger width = CGImageGetWidth(cgImage);
|
||||
NSUInteger height = CGImageGetHeight(cgImage);
|
||||
NSUInteger bytesPerRow = width * TURGBABytesPerPixel;
|
||||
NSUInteger bitsPerComponent = 8;
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
UInt8 *pixelByteData = malloc(width * height * TURGBABytesPerPixel);
|
||||
|
||||
CGContextRef context = CGBitmapContextCreate(
|
||||
(void *)pixelByteData,
|
||||
width,
|
||||
height,
|
||||
bitsPerComponent,
|
||||
bytesPerRow,
|
||||
colorSpace,
|
||||
kCGImageAlphaPremultipliedLast);
|
||||
|
||||
// NEW: seeing nondetermnistic errors where sometimes the image is parsed right
|
||||
// and sometimes not parsed right. The followthing three lines paint the context
|
||||
// to solid white, then paste the image over it, so this ought to normalize the
|
||||
// outcome a bit more.
|
||||
CGRect contextBounds = CGRectMake(0.0f, 0.0f, width, height);
|
||||
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
|
||||
CGContextFillRect(context, contextBounds);
|
||||
|
||||
// Having normalized the context we now paint the image
|
||||
CGContextDrawImage(context, contextBounds, cgImage);
|
||||
TURGBAPixel *pixelData = (TURGBAPixel *) CGBitmapContextGetData(context);
|
||||
if (pixelData) {
|
||||
// CF note in the AsHorizontal method below
|
||||
for (NSUInteger i = 0; i < height; i++) {
|
||||
if (TURGBAPixelIsBlack(pixelData[((height - 1) - i)])) {
|
||||
firstBlackPixel = ((height - 1) - i);
|
||||
}
|
||||
if (TURGBAPixelIsBlack(pixelData[i])) {
|
||||
lastBlackPixel = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ((firstBlackPixel != NSNotFound) && (lastBlackPixel != NSNotFound)) {
|
||||
NPAssert(lastBlackPixel >= firstBlackPixel, ([NSString stringWithFormat:@"Got firstBlackPixel:'%d' and lastBlackPixel:'%d'.",firstBlackPixel,lastBlackPixel]));
|
||||
blackPixelRangeAsVerticalStrip.location = TUTruncateWithin(firstBlackPixel, 0, height - 1) / self.scale;
|
||||
// We can't just use TUTruncateAtZero on lastBlackPixel - firstBlackPixel here.
|
||||
// The semantics of pixel coordinates are such that a zero difference between lastBlackPixel and firstBlackPixel is ok
|
||||
// but < 0 is obv. very bad.
|
||||
// Thus 1 + TUTruncateAtZero(lastBlackPixel - firstBlackPixel) won't work.
|
||||
// and fixing the expression s.t. it does work is more complicated than
|
||||
// just breaking it down like so.
|
||||
NSInteger length = lastBlackPixel - firstBlackPixel;
|
||||
if (length >= 0) {
|
||||
length += 1;
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
blackPixelRangeAsVerticalStrip.length = length/self.scale;
|
||||
}
|
||||
}
|
||||
CGContextRelease(context);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
free(pixelByteData);
|
||||
}
|
||||
NPNSROutputLog(blackPixelRangeAsVerticalStrip);
|
||||
return blackPixelRangeAsVerticalStrip;
|
||||
}
|
||||
|
||||
-(NSRange)blackPixelRangeAsHorizontalStrip {
|
||||
NPAssert([self size].height == 1.0f, @"This method assumes the image has height == 1.0f");
|
||||
NSRange blackPixelRangeAsHorizontalStrip = TUNotFoundRange;
|
||||
NSUInteger firstBlackPixel = NSNotFound;
|
||||
NSUInteger lastBlackPixel = NSNotFound;
|
||||
if ([self size].width > 0.0f) {
|
||||
CGImageRef cgImage = [self CGImage];
|
||||
|
||||
NSUInteger width = CGImageGetWidth(cgImage);
|
||||
NSUInteger height = CGImageGetHeight(cgImage);
|
||||
NSUInteger bytesPerRow = width * TURGBABytesPerPixel;
|
||||
NSUInteger bitsPerComponent = 8;
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
UInt8 *pixelByteData = malloc(width * height * TURGBABytesPerPixel);
|
||||
|
||||
CGContextRef context = CGBitmapContextCreate(
|
||||
(void *)pixelByteData,
|
||||
width,
|
||||
height,
|
||||
bitsPerComponent,
|
||||
bytesPerRow,
|
||||
colorSpace,
|
||||
kCGImageAlphaPremultipliedLast);
|
||||
|
||||
// NEW: seeing nondetermnistic errors where sometimes the image is parsed right
|
||||
// and sometimes not parsed right. The followthing three lines paint the context
|
||||
// to solid white, then paste the image over it, so this ought to normalize the
|
||||
// outcome a bit more.
|
||||
CGRect contextBounds = CGRectMake(0.0f, 0.0f, width, height);
|
||||
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
|
||||
CGContextFillRect(context, contextBounds);
|
||||
|
||||
// Having normalized the context we now paint the image
|
||||
CGContextDrawImage(context, contextBounds, cgImage);
|
||||
TURGBAPixel *pixelData = (TURGBAPixel *) CGBitmapContextGetData(context);
|
||||
if (pixelData) {
|
||||
// The for loop below is walking the strip from both ends.
|
||||
// Basically you could do this check a bunch of ways, with a
|
||||
// bunch of trade-offs in terms of how fast it is and how robust it
|
||||
// is and how any "format errors" in your nine patch manifest.
|
||||
//
|
||||
// What I have found is that ninepatch is a fussy format, with a
|
||||
// common failure mode being that you painted a pixel "black" but
|
||||
// either got the alpha wrong, or it wasn't quite black, or it
|
||||
// didn't composite to black, etc., and thus get invalid ninepatches.
|
||||
//
|
||||
// What I do here is just look for the highest and lowest black pixels,
|
||||
// and treat anything in between as also black. EG:
|
||||
//
|
||||
// - if X == black and O == not-black
|
||||
// - then these square brackes - [ and ] - enclose the "black" region
|
||||
//
|
||||
// - then: OOOOXXXXXOOOOO -> OOOO[XXXXX]OOOOO
|
||||
// - but also: OOOXXOOXXOOO -> OOO[XXOOXX]OOO
|
||||
// - and even: OXOOOOOOOXO -> O[XOOOOOOOX]O
|
||||
//
|
||||
// This is a judgement call on my part, in that the approach I can take to
|
||||
// accomplish this is straightforward without any complicated state tracking,
|
||||
// and the behavior it has in the face of "invalid" nine-patches is generally
|
||||
// what I meant, anyways.
|
||||
//
|
||||
// The actual implementation is straightforward but suboptimal.
|
||||
// I look through the array once, iterating i from 0->(width -1).
|
||||
// On each iteration I taste the pixel @ i and at (width - 1) -1,
|
||||
// and if the pixel @ i is black I set the "lastBlackPixel" == i
|
||||
// and if the pixel @ (width - 1) - i is black I set the "firstBlackPixel"
|
||||
// to (width - 1) - i.
|
||||
//
|
||||
// Once the loop is done the values in the lastBlackPixel and firstBlackPixel
|
||||
// contain what they ought to have.
|
||||
//
|
||||
// Given the continual risk of hard-to-spot off-by-one errors throughout this
|
||||
// library I've opted to keep it dumb and suboptimal in places like this one,
|
||||
// so that I can be more comfortable that what problems there are are elsewhere.
|
||||
//
|
||||
// If you subseqently do add an improved loop please wrap it in ifdefs like
|
||||
// #ifdef CLEVERNESS YOUR-CODE #else DUMB-CODE #endif
|
||||
//
|
||||
for (NSUInteger i = 0; i < width; i++) {
|
||||
if (TURGBAPixelIsBlack(pixelData[((width - 1) - i)])) {
|
||||
firstBlackPixel = ((width - 1) - i);
|
||||
}
|
||||
if (TURGBAPixelIsBlack(pixelData[i])) {
|
||||
lastBlackPixel = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ((firstBlackPixel != NSNotFound) && (lastBlackPixel != NSNotFound)) {
|
||||
NPAssert(lastBlackPixel >= firstBlackPixel, ([NSString stringWithFormat:@"Got firstBlackPixel:'%d' and lastBlackPixel:'%d'.",firstBlackPixel,lastBlackPixel]));
|
||||
blackPixelRangeAsHorizontalStrip.location = TUTruncateWithin(firstBlackPixel, 0, width - 1) / self.scale;
|
||||
// We can't just use TUTruncateAtZero on lastBlackPixel - firstBlackPixel here.
|
||||
// The semantics of pixel coordinates are such that a zero difference between lastBlackPixel and firstBlackPixel is ok
|
||||
// but < 0 is obv. very bad.
|
||||
// Thus 1 + TUTruncateAtZero(lastBlackPixel - firstBlackPixel) won't work.
|
||||
// and fixing the expression s.t. it does work is more complicated than
|
||||
// just breaking it down like so.
|
||||
NSInteger length = lastBlackPixel - firstBlackPixel;
|
||||
if (length >= 0) {
|
||||
length += 1;
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
blackPixelRangeAsHorizontalStrip.length = length / self.scale;
|
||||
}
|
||||
}
|
||||
CGContextRelease(context);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
free(pixelByteData);
|
||||
}
|
||||
NPNSROutputLog(blackPixelRangeAsHorizontalStrip);
|
||||
return blackPixelRangeAsHorizontalStrip;
|
||||
}
|
||||
|
||||
#pragma mark Corners - Rects
|
||||
-(CGRect)upperLeftCornerRect {
|
||||
return CGRectMake(0.0f, 0.0f, 1.0f/self.scale, 1.0f/self.scale);
|
||||
}
|
||||
|
||||
-(CGRect)lowerLeftCornerRect {
|
||||
return CGRectMake(0.0f, [self size].height - (1.0f/self.scale), 1.0f/self.scale, 1.0f/self.scale);
|
||||
}
|
||||
|
||||
-(CGRect)upperRightCornerRect {
|
||||
return CGRectMake([self size].width - (1.0f/self.scale), 0.0f, 1.0f/self.scale, 1.0f/self.scale);
|
||||
}
|
||||
|
||||
-(CGRect)lowerRightCornerRect {
|
||||
return CGRectMake([self size].width - 1.0f, [self size].height - (1.0f/self.scale), 1.0f/self.scale, 1.0f/self.scale);
|
||||
}
|
||||
|
||||
#pragma mark Corners - Slicing
|
||||
-(UIImage *)upperLeftCorner {
|
||||
return [self subImageInRect:[self upperLeftCornerRect]];
|
||||
}
|
||||
|
||||
-(UIImage *)lowerLeftCorner {
|
||||
return [self subImageInRect:[self lowerLeftCornerRect]];
|
||||
}
|
||||
|
||||
-(UIImage *)upperRightCorner {
|
||||
return [self subImageInRect:[self upperRightCornerRect]];
|
||||
}
|
||||
|
||||
-(UIImage *)lowerRightCorner {
|
||||
return [self subImageInRect:[self lowerRightCornerRect]];
|
||||
}
|
||||
|
||||
#pragma mark Strips - Sizing
|
||||
-(CGRect)upperStripRect {
|
||||
CGSize selfSize = [self size];
|
||||
CGFloat stripWidth = TUTruncateAtZero(selfSize.width - (2.0f/self.scale));
|
||||
return CGRectMake((1.0f/self.scale), 0.0f, stripWidth, 1.0f/self.scale);
|
||||
}
|
||||
|
||||
-(CGRect)lowerStripRect {
|
||||
CGSize selfSize = [self size];
|
||||
CGFloat stripWidth = TUTruncateAtZero(selfSize.width - (2.0f/self.scale));
|
||||
return CGRectMake(1.0f/self.scale, selfSize.height - (1.0f/self.scale), stripWidth, 1.0f/self.scale);
|
||||
}
|
||||
|
||||
-(CGRect)leftStripRect {
|
||||
CGSize selfSize = [self size];
|
||||
CGFloat stripHeight = TUTruncateAtZero(selfSize.height - (2.0f/self.scale));
|
||||
return CGRectMake(0.0f, 1.0f/self.scale, 1.0f/self.scale, stripHeight);
|
||||
}
|
||||
|
||||
-(CGRect)rightStripRect {
|
||||
CGSize selfSize = [self size];
|
||||
CGFloat stripHeight = TUTruncateAtZero(selfSize.height - (2.0f/self.scale));
|
||||
return CGRectMake(selfSize.width - (1.0f/self.scale), 1.0f/self.scale, 1.0f/self.scale, stripHeight);
|
||||
}
|
||||
|
||||
#pragma mark Strips - Slicing
|
||||
-(UIImage *)upperStrip {
|
||||
return [self subImageInRect:[self upperStripRect]];
|
||||
}
|
||||
|
||||
-(UIImage *)lowerStrip {
|
||||
return [self subImageInRect:[self lowerStripRect]];
|
||||
}
|
||||
|
||||
-(UIImage *)leftStrip {
|
||||
return [self subImageInRect:[self leftStripRect]];
|
||||
}
|
||||
|
||||
-(UIImage *)rightStrip {
|
||||
return [self subImageInRect:[self rightStripRect]];
|
||||
}
|
||||
|
||||
-(UIImage *)subImageInRect:(CGRect)rect {
|
||||
NPAInputLog(@"subImageInRect:'%@'",NSStringFromCGRect(rect));
|
||||
UIImage *subImage = nil;
|
||||
CGImageRef cir = [self CGImage];
|
||||
if (cir) {
|
||||
rect.origin.x *= self.scale;
|
||||
rect.origin.y *= self.scale;
|
||||
rect.size.width *= self.scale;
|
||||
rect.size.height *= self.scale;
|
||||
CGImageRef subCGImage = CGImageCreateWithImageInRect(cir, rect);
|
||||
if (subCGImage) {
|
||||
subImage = [UIImage imageWithCGImage:subCGImage scale:self.scale orientation:self.imageOrientation];
|
||||
CGImageRelease(subCGImage);
|
||||
NPAssertNilOrIsKindOfClass(subImage,UIImage);
|
||||
NPAssert((CGSizeEqualToSize([subImage size], rect.size)), @"Shouldn't get unequal subimage and requested sizes.");
|
||||
} else {
|
||||
DLog(@"Couldn't create subImage in rect: '%@'.", NSStringFromCGRect(rect));
|
||||
}
|
||||
} else {
|
||||
LLog(@"self.CGImage is somehow nil.");
|
||||
}
|
||||
//DLog(@"[%@:<0x%x> subImageInRect:%@] yielded subImage: '%@' of size: '%@'", [self class], ((NSUInteger) self), NSStringFromCGRect(rect), subImage, NSStringFromCGSize([subImage size]));
|
||||
//IMLog(self, @"subImageInRectSourceImage");
|
||||
//IMLog(subImage, @"subImageInRect");
|
||||
NPOOutputLog(subImage);
|
||||
return subImage;
|
||||
}
|
||||
|
||||
#pragma mark Nine-Patch Content Extraction
|
||||
-(UIImage *)imageAsNinePatchImage {
|
||||
UIImage *imageOfNinePatchImage = nil;
|
||||
CGFloat width = [self size].width - (2.0f/self.scale);
|
||||
CGFloat height = [self size].height - (2.0f/self.scale);
|
||||
if (width > 0.0f && height > 0.0f) {
|
||||
imageOfNinePatchImage = [self subImageInRect:CGRectMake((1.0f/self.scale), (1.0f/self.scale), width, height)];
|
||||
}
|
||||
NPOOutputLog(imageOfNinePatchImage);
|
||||
return imageOfNinePatchImage;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(UIImage *)extractUpperLeftCornerForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractUpperLeftCornerForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *upperLeftCorner = [self subImageInRect:CGRectMake(0.0f, 0.0f, CGRectGetMinX(stretchableRegion), CGRectGetMinY(stretchableRegion))];
|
||||
NPOOutputLog(upperLeftCorner);
|
||||
return upperLeftCorner;
|
||||
}
|
||||
|
||||
-(UIImage *)extractUpperRightCornerForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractUpperRightCornerForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *upperRightCorner = [self subImageInRect:CGRectMake(CGRectGetMaxX(stretchableRegion), 0.0f, [self size].width - CGRectGetMaxX(stretchableRegion), CGRectGetMinY(stretchableRegion))];
|
||||
NPOOutputLog(upperRightCorner);
|
||||
return upperRightCorner;
|
||||
}
|
||||
|
||||
-(UIImage *)extractLowerLeftCornerForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractUpperRightCornerForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *lowerLeftCorner = [self subImageInRect:CGRectMake(0.0f, CGRectGetMaxY(stretchableRegion), CGRectGetMinX(stretchableRegion), [self size].height - CGRectGetMaxY(stretchableRegion))];
|
||||
NPOOutputLog(lowerLeftCorner);
|
||||
return lowerLeftCorner;
|
||||
}
|
||||
|
||||
-(UIImage *)extractLowerRightCornerForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractLowerRightCornerForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *lowerRightCorner = [self subImageInRect:CGRectMake(CGRectGetMaxX(stretchableRegion), CGRectGetMaxY(stretchableRegion), [self size].width - CGRectGetMaxX(stretchableRegion), [self size].height - CGRectGetMaxY(stretchableRegion))];
|
||||
NPOOutputLog(lowerRightCorner);
|
||||
return lowerRightCorner;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(UIImage *)extractLeftEdgeForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractLeftEdgeForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *leftEdge = [self subImageInRect:CGRectMake(0.0f, CGRectGetMinY(stretchableRegion), CGRectGetMinX(stretchableRegion), CGRectGetHeight(stretchableRegion))];
|
||||
NPOOutputLog(leftEdge);
|
||||
return leftEdge;
|
||||
}
|
||||
|
||||
-(UIImage *)extractRightEdgeForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractRightEdgeForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *rightEdge = [self subImageInRect:CGRectMake(CGRectGetMaxX(stretchableRegion), CGRectGetMinY(stretchableRegion), [self size].width - CGRectGetMaxX(stretchableRegion), CGRectGetHeight(stretchableRegion))];
|
||||
NPOOutputLog(rightEdge);
|
||||
return rightEdge;
|
||||
}
|
||||
|
||||
-(UIImage *)extractUpperEdgeForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractUpperEdgeForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *upperEdge = [self subImageInRect:CGRectMake(CGRectGetMinX(stretchableRegion), 0.0f, CGRectGetWidth(stretchableRegion), CGRectGetMinY(stretchableRegion))];
|
||||
NPOOutputLog(upperEdge);
|
||||
return upperEdge;
|
||||
}
|
||||
|
||||
-(UIImage *)extractLowerEdgeForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractLowerEdgeForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *lowerEdge = [self subImageInRect:CGRectMake(CGRectGetMinX(stretchableRegion), CGRectGetMaxY(stretchableRegion), CGRectGetWidth(stretchableRegion), [self size].height - CGRectGetMaxY(stretchableRegion))];
|
||||
NPOOutputLog(center);
|
||||
return lowerEdge;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
-(UIImage *)extractCenterForStretchableRegion:(CGRect)stretchableRegion {
|
||||
NPAInputLog(@"extractCenterForStretchableRegion:'%@'",NSStringFromCGRect(stretchableRegion));
|
||||
UIImage *center = [self subImageInRect:stretchableRegion];
|
||||
NPOOutputLog(center);
|
||||
return center;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -310,7 +310,6 @@
|
|||
70E542F313E147E3002BA2C0 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70E542F213E147E3002BA2C0 /* OpenGLES.framework */; };
|
||||
70E542F513E147EB002BA2C0 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70E542F413E147EB002BA2C0 /* QuartzCore.framework */; };
|
||||
C90FAA7915AF54E6002091CB /* HistoryDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C90FAA7715AF54E6002091CB /* HistoryDetailsViewController.m */; };
|
||||
D30562151671DC4900C97967 /* libNinePatch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D3B90E1915C2CB5800F64F8C /* libNinePatch.a */; };
|
||||
D30562161671DC4900C97967 /* libXMLRPC.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D3554ED115CA79AA00478841 /* libXMLRPC.a */; };
|
||||
D306459E1611EC2A00BB571E /* UILoadingImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = D306459D1611EC2900BB571E /* UILoadingImageView.m */; };
|
||||
D3128FE115AABC7E00A2147A /* ContactDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D3128FDF15AABC7E00A2147A /* ContactDetailsViewController.m */; };
|
||||
|
|
@ -408,7 +407,6 @@
|
|||
F066515517F9A02E0064280C /* UITransparentTVCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F066515417F9A02E0064280C /* UITransparentTVCell.m */; };
|
||||
F088488A19FF8C41007FFCF3 /* UIContactCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F088488D19FF8C41007FFCF3 /* UIContactCell.xib */; };
|
||||
F08D468D1AA86849001E8CB5 /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F0B026F21AA710AF00FF49F7 /* libiconv.dylib */; };
|
||||
F08F118519C09C6B007D70C2 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F03A9B3318C0CF7000C4D7FE /* XCTest.framework */; };
|
||||
F08F118619C09C6B007D70C2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
|
||||
F08F118719C09C6B007D70C2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
|
||||
F0938159188E629800A55DFA /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = F0938158188E629800A55DFA /* iTunesArtwork */; };
|
||||
|
|
@ -519,20 +517,6 @@
|
|||
remoteGlobalIDString = 903B0DB512F7574800BD6E09;
|
||||
remoteInfo = libXMLRPC;
|
||||
};
|
||||
D3B90E1815C2CB5800F64F8C /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = D3B90E1115C2CB5700F64F8C /* NinePatch.xcodeproj */;
|
||||
proxyType = 2;
|
||||
remoteGlobalIDString = D2AAC07E0554694100DB518D;
|
||||
remoteInfo = NinePatch;
|
||||
};
|
||||
D3B90E1A15C2CBC800F64F8C /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = D3B90E1115C2CB5700F64F8C /* NinePatch.xcodeproj */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = D2AAC07D0554694100DB518D;
|
||||
remoteInfo = NinePatch;
|
||||
};
|
||||
F08F119119C09C6B007D70C2 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
|
||||
|
|
@ -1028,7 +1012,6 @@
|
|||
D3A55FBB15877E5E003FD403 /* UIContactCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIContactCell.m; sourceTree = "<group>"; };
|
||||
D3A8BB6E15A6C7D500F96BE5 /* UIChatRoomCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIChatRoomCell.h; sourceTree = "<group>"; };
|
||||
D3A8BB6F15A6C7D500F96BE5 /* UIChatRoomCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIChatRoomCell.m; sourceTree = "<group>"; };
|
||||
D3B90E1115C2CB5700F64F8C /* NinePatch.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = NinePatch.xcodeproj; path = Utils/NinePatch/NinePatch.xcodeproj; sourceTree = "<group>"; };
|
||||
D3C6526515AC1A8F0092A874 /* UIEditableTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditableTableViewCell.h; sourceTree = "<group>"; };
|
||||
D3C6526615AC1A8F0092A874 /* UIEditableTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIEditableTableViewCell.m; sourceTree = "<group>"; };
|
||||
D3E84F3C15B018A600420DAC /* UILinphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILinphone.h; sourceTree = "<group>"; };
|
||||
|
|
@ -1061,7 +1044,6 @@
|
|||
D3F9A9EC15AF277D0045320F /* UACellBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UACellBackgroundView.h; path = Utils/UACellBackgroundView/UACellBackgroundView.h; sourceTree = "<group>"; };
|
||||
D3F9A9ED15AF277D0045320F /* UACellBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UACellBackgroundView.m; path = Utils/UACellBackgroundView/UACellBackgroundView.m; sourceTree = "<group>"; };
|
||||
F0181B6B18BF7B1200A9A357 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
|
||||
F03A9B3318C0CF7000C4D7FE /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
|
||||
F03A9B7E18C0D9C900C4D7FE /* libcunit.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcunit.a; path = "liblinphone-sdk/apple-darwin/lib/libcunit.a"; sourceTree = "<group>"; };
|
||||
F03A9B9418C0DAE100C4D7FE /* libstdc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.dylib"; path = "usr/lib/libstdc++.dylib"; sourceTree = SDKROOT; };
|
||||
F03A9B9718C0DB6F00C4D7FE /* libc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libc++.dylib"; path = "usr/lib/libc++.dylib"; sourceTree = SDKROOT; };
|
||||
|
|
@ -1191,7 +1173,6 @@
|
|||
223CA7E616D9255800EF1BEC /* libantlr3c.a in Frameworks */,
|
||||
223CA7E716D9255800EF1BEC /* libbellesip.a in Frameworks */,
|
||||
045B5CB318D72E9A0088350C /* libbzrtp.a in Frameworks */,
|
||||
D30562151671DC4900C97967 /* libNinePatch.a in Frameworks */,
|
||||
D30562161671DC4900C97967 /* libXMLRPC.a in Frameworks */,
|
||||
22B5F03510CE6B2F00777D97 /* AddressBook.framework in Frameworks */,
|
||||
22B5EFA310CE50BD00777D97 /* AddressBookUI.framework in Frameworks */,
|
||||
|
|
@ -1242,7 +1223,6 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
63058AD61B4E92D400EFAE36 /* liblinphonetester.a in Frameworks */,
|
||||
F08F118519C09C6B007D70C2 /* XCTest.framework in Frameworks */,
|
||||
F08F118719C09C6B007D70C2 /* UIKit.framework in Frameworks */,
|
||||
F08F118619C09C6B007D70C2 /* Foundation.framework in Frameworks */,
|
||||
);
|
||||
|
|
@ -1595,7 +1575,6 @@
|
|||
F0181B6B18BF7B1200A9A357 /* SenTestingKit.framework */,
|
||||
2264B6D111200342002C2C53 /* SystemConfiguration.framework */,
|
||||
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,
|
||||
F03A9B3318C0CF7000C4D7FE /* XCTest.framework */,
|
||||
F03A9B7E18C0D9C900C4D7FE /* libcunit.a */,
|
||||
);
|
||||
name = Frameworks;
|
||||
|
|
@ -1913,7 +1892,6 @@
|
|||
63B81A021B57DA33009604A6 /* TPKeyboardAvoiding */,
|
||||
D3ED40141602172200BF332B /* GrowingTextView */,
|
||||
D3807FC715C2894A005BE9BC /* InAppSettingsKit */,
|
||||
D3B90E1115C2CB5700F64F8C /* NinePatch.xcodeproj */,
|
||||
D326483615887D5200930C67 /* OrderedDictionary.h */,
|
||||
D326483715887D5200930C67 /* OrderedDictionary.m */,
|
||||
D3F7997E15BD31EC0018C273 /* TPMultiLayoutViewController */,
|
||||
|
|
@ -2041,14 +2019,6 @@
|
|||
path = Settings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D3B90E1215C2CB5700F64F8C /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D3B90E1915C2CB5800F64F8C /* libNinePatch.a */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D3ED40141602172200BF332B /* GrowingTextView */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -2097,7 +2067,6 @@
|
|||
);
|
||||
dependencies = (
|
||||
D3554ED515CA79B900478841 /* PBXTargetDependency */,
|
||||
D3B90E1B15C2CBC800F64F8C /* PBXTargetDependency */,
|
||||
);
|
||||
name = linphone;
|
||||
productName = linphone;
|
||||
|
|
@ -2215,10 +2184,6 @@
|
|||
ProductGroup = 630589F31B4E816900EFAE36 /* Products */;
|
||||
ProjectRef = 630589F21B4E816900EFAE36 /* KIF.xcodeproj */;
|
||||
},
|
||||
{
|
||||
ProductGroup = D3B90E1215C2CB5700F64F8C /* Products */;
|
||||
ProjectRef = D3B90E1115C2CB5700F64F8C /* NinePatch.xcodeproj */;
|
||||
},
|
||||
{
|
||||
ProductGroup = D3554EC615CA79A900478841 /* Products */;
|
||||
ProjectRef = D3554EC515CA79A900478841 /* XMLRPC.xcodeproj */;
|
||||
|
|
@ -2284,13 +2249,6 @@
|
|||
remoteRef = D3554ED015CA79AA00478841 /* PBXContainerItemProxy */;
|
||||
sourceTree = BUILT_PRODUCTS_DIR;
|
||||
};
|
||||
D3B90E1915C2CB5800F64F8C /* libNinePatch.a */ = {
|
||||
isa = PBXReferenceProxy;
|
||||
fileType = archive.ar;
|
||||
path = libNinePatch.a;
|
||||
remoteRef = D3B90E1815C2CB5800F64F8C /* PBXContainerItemProxy */;
|
||||
sourceTree = BUILT_PRODUCTS_DIR;
|
||||
};
|
||||
/* End PBXReferenceProxy section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
|
|
@ -2754,11 +2712,6 @@
|
|||
name = libXMLRPC;
|
||||
targetProxy = D3554ED415CA79B900478841 /* PBXContainerItemProxy */;
|
||||
};
|
||||
D3B90E1B15C2CBC800F64F8C /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
name = NinePatch;
|
||||
targetProxy = D3B90E1A15C2CBC800F64F8C /* PBXContainerItemProxy */;
|
||||
};
|
||||
F08F119219C09C6B007D70C2 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = F0BB8BD41936208100974404 /* liblinphoneTester */;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue