1#import "_CPTFillImage.h" 2#import "CPTImage.h" 3 4/** @cond */ 5@interface _CPTFillImage() 6 7@property (nonatomic, readwrite, copy) CPTImage *fillImage; 8 9@end 10/** @endcond */ 11 12/** @brief Draws CPTImage area fills. 13 * 14 * Drawing methods are provided to fill rectangular areas and arbitrary drawing paths. 15 **/ 16 17@implementation _CPTFillImage 18 19/** @property fillImage 20 * @brief The fill image. 21 **/ 22@synthesize fillImage; 23 24#pragma mark - 25#pragma mark init/dealloc 26 27/** @brief Initializes a newly allocated _CPTFillImage object with the provided image. 28 * @param anImage The image. 29 * @return The initialized _CPTFillImage object. 30 **/ 31-(id)initWithImage:(CPTImage *)anImage 32{ 33 if ( (self = [super init]) ) { 34 fillImage = [anImage retain]; 35 } 36 return self; 37} 38 39-(void)dealloc 40{ 41 [fillImage release]; 42 [super dealloc]; 43} 44 45#pragma mark - 46#pragma mark Drawing 47 48/** @brief Draws the image into the given graphics context inside the provided rectangle. 49 * @param theRect The rectangle to draw into. 50 * @param theContext The graphics context to draw into. 51 **/ 52-(void)fillRect:(CGRect)theRect inContext:(CGContextRef)theContext 53{ 54 [self.fillImage drawInRect:theRect inContext:theContext]; 55} 56 57/** @brief Draws the image into the given graphics context clipped to the current drawing path. 58 * @param theContext The graphics context to draw into. 59 **/ 60-(void)fillPathInContext:(CGContextRef)theContext 61{ 62 CGContextSaveGState(theContext); 63 64 CGRect bounds = CGContextGetPathBoundingBox(theContext); 65 CGContextClip(theContext); 66 [self.fillImage drawInRect:bounds inContext:theContext]; 67 68 CGContextRestoreGState(theContext); 69} 70 71#pragma mark - 72#pragma mark NSCopying methods 73 74-(id)copyWithZone:(NSZone *)zone 75{ 76 _CPTFillImage *copy = [[[self class] allocWithZone:zone] init]; 77 copy->fillImage = [self->fillImage copyWithZone:zone]; 78 79 return copy; 80} 81 82#pragma mark - 83#pragma mark NSCoding methods 84 85-(Class)classForCoder 86{ 87 return [CPTFill class]; 88} 89 90-(void)encodeWithCoder:(NSCoder *)coder 91{ 92 [coder encodeObject:self.fillImage forKey:@"_CPTFillImage.fillImage"]; 93} 94 95-(id)initWithCoder:(NSCoder *)coder 96{ 97 if ( (self = [super init]) ) { 98 fillImage = [[coder decodeObjectForKey:@"_CPTFillImage.fillImage"] retain]; 99 } 100 return self; 101} 102 103@end 104