Source/Piece.m
changeset 14 4585c74d809c
parent 9 a59acc683080
     1.1 --- a/Source/Piece.m	Thu May 29 15:04:06 2008 -0700
     1.2 +++ b/Source/Piece.m	Tue Jul 08 20:32:52 2008 -0700
     1.3 @@ -27,13 +27,23 @@
     1.4  @implementation Piece
     1.5  
     1.6  
     1.7 +- (id) init
     1.8 +{
     1.9 +    self = [super init];
    1.10 +    if (self != nil) {
    1.11 +        self.zPosition = kPieceZ;
    1.12 +    }
    1.13 +    return self;
    1.14 +}
    1.15 +
    1.16 +
    1.17 +
    1.18  - (id) initWithImageNamed: (NSString*)imageName
    1.19                      scale: (CGFloat)scale
    1.20  {
    1.21 -    self = [super init];
    1.22 +    self = [self init];
    1.23      if (self != nil) {
    1.24          [self setImageNamed: imageName scale: scale];
    1.25 -        self.zPosition = kPieceZ;
    1.26      }
    1.27      return self;
    1.28  }
    1.29 @@ -124,4 +134,29 @@
    1.30  }
    1.31  
    1.32  
    1.33 +#if ! TARGET_OS_IPHONE
    1.34 +
    1.35 +// An image from another app can be dragged onto a Piece to change its background pattern.
    1.36 +
    1.37 +- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
    1.38 +{
    1.39 +    if( CanGetCGImageFromPasteboard([sender draggingPasteboard]) )
    1.40 +        return NSDragOperationCopy;
    1.41 +    else
    1.42 +        return NSDragOperationNone;
    1.43 +}
    1.44 +
    1.45 +- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
    1.46 +{
    1.47 +    CGImageRef image = GetCGImageFromPasteboard([sender draggingPasteboard],sender);
    1.48 +    if( image ) {
    1.49 +        [self setValue: (id)image ofStyleProperty: @"contents"];
    1.50 +        return YES;
    1.51 +    } else
    1.52 +        return NO;
    1.53 +}
    1.54 +
    1.55 +#endif
    1.56 +
    1.57 +
    1.58  @end