Source/Piece.m
changeset 10 6c78cc6bd7a6
parent 1 3eb7be1dd7b6
child 11 436cbdf56810
     1.1 --- a/Source/Piece.m	Mon Mar 10 17:30:57 2008 -0700
     1.2 +++ b/Source/Piece.m	Thu Jul 03 17:44:30 2008 -0700
     1.3 @@ -32,8 +32,7 @@
     1.4  {
     1.5      self = [super init];
     1.6      if (self != nil) {
     1.7 -        self.imageName = imageName;
     1.8 -        [self setImage: GetCGImageNamed(imageName) scale: scale];
     1.9 +        [self setImageNamed: imageName scale: scale];
    1.10          self.zPosition = kPieceZ;
    1.11      }
    1.12      return self;
    1.13 @@ -66,20 +65,25 @@
    1.14  @synthesize imageName=_imageName;
    1.15  
    1.16  
    1.17 +- (void) _setImage: (CGImageRef)image
    1.18 +{
    1.19 +    self.contents = (id) image;
    1.20 +    self.bounds = CGRectMake(0,0,CGImageGetWidth(image),CGImageGetHeight(image));
    1.21 +    self.contentsGravity = kCAGravityResizeAspect;
    1.22 +    self.minificationFilter = kCAFilterLinear;
    1.23 +    self.imageName = nil;
    1.24 +}
    1.25 +
    1.26 +
    1.27  - (void) setImage: (CGImageRef)image scale: (CGFloat)scale
    1.28  {
    1.29 -    self.contents = (id) image;
    1.30 -    self.contentsGravity = @"resize";
    1.31 -    self.minificationFilter = kCAFilterLinear;
    1.32 -    int width = CGImageGetWidth(image), height = CGImageGetHeight(image);
    1.33 -    if( scale > 0 ) {
    1.34 -        if( scale >= 4.0 )
    1.35 -            scale /= MAX(width,height);             // interpret scale as target dimensions
    1.36 -        width = ceil( width * scale);
    1.37 -        height= ceil( height* scale);
    1.38 -    }
    1.39 -    self.bounds = CGRectMake(0,0,width,height);
    1.40 -    self.imageName = nil;
    1.41 +    [self _setImage: CreateScaledImage(image,scale)];
    1.42 +}
    1.43 +
    1.44 +- (void) setImageNamed: (NSString*)imageName scale: (CGFloat)scale
    1.45 +{
    1.46 +    [self _setImage: GetScaledImageNamed(imageName,scale)];
    1.47 +    self.imageName = imageName;
    1.48  }
    1.49  
    1.50  - (void) setImage: (CGImageRef)image