Source/Grid.m
changeset 11 436cbdf56810
parent 10 6c78cc6bd7a6
child 12 4e567e11f45f
     1.1 --- a/Source/Grid.m	Thu Jul 03 17:44:30 2008 -0700
     1.2 +++ b/Source/Grid.m	Sat Jul 05 17:46:43 2008 -0700
     1.3 @@ -102,8 +102,18 @@
     1.4  - (CGColorRef) lineColor                        {return _lineColor;}
     1.5  - (void) setLineColor: (CGColorRef)lineColor    {setcolor(&_lineColor,lineColor);}
     1.6  
     1.7 +- (CGImageRef) backgroundImage                  {return _backgroundImage;}
     1.8 +- (void) setBackgroundImage: (CGImageRef)image
     1.9 +{
    1.10 +    if( image != _backgroundImage ) {
    1.11 +        CGImageRelease(_backgroundImage);
    1.12 +        _backgroundImage = CGImageRetain(image);
    1.13 +    }
    1.14 +}
    1.15 +
    1.16  @synthesize cellClass=_cellClass, rows=_nRows, columns=_nColumns, spacing=_spacing,
    1.17 -            usesDiagonals=_usesDiagonals, allowsMoves=_allowsMoves, allowsCaptures=_allowsCaptures;
    1.18 +            usesDiagonals=_usesDiagonals, allowsMoves=_allowsMoves, allowsCaptures=_allowsCaptures,
    1.19 +            cells=_cells;
    1.20  
    1.21  
    1.22  #pragma mark -
    1.23 @@ -205,6 +215,10 @@
    1.24      // Custom CALayer drawing implementation. Delegates to the cells to draw themselves
    1.25      // in me; this is more efficient than having each cell have its own drawing.
    1.26      [super drawInContext: ctx];
    1.27 +    
    1.28 +    if( _backgroundImage )
    1.29 +        CGContextDrawImage(ctx, self.bounds, _backgroundImage);
    1.30 +    
    1.31      if( _cellColor ) {
    1.32          CGContextSetFillColorWithColor(ctx, _cellColor);
    1.33          [self drawCellsInContext: ctx fill: YES];
    1.34 @@ -348,13 +362,11 @@
    1.35  
    1.36  #if ! TARGET_OS_IPHONE
    1.37  
    1.38 -// An image from another app can be dragged onto a Dispenser to change the Piece's appearance.
    1.39 -
    1.40 +// An image from another app can be dragged onto a Grid to change its background pattern.
    1.41  
    1.42  - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
    1.43  {
    1.44 -    NSPasteboard *pb = [sender draggingPasteboard];
    1.45 -    if( [NSImage canInitWithPasteboard: pb] )
    1.46 +    if( CanGetCGImageFromPasteboard([sender draggingPasteboard]) )
    1.47          return NSDragOperationCopy;
    1.48      else
    1.49          return NSDragOperationNone;
    1.50 @@ -362,7 +374,7 @@
    1.51  
    1.52  - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
    1.53  {
    1.54 -    CGImageRef image = GetCGImageFromPasteboard([sender draggingPasteboard]);
    1.55 +    CGImageRef image = GetCGImageFromPasteboard([sender draggingPasteboard],sender);
    1.56      if( image ) {
    1.57          CGColorRef pattern = CreatePatternColor(image);
    1.58          _grid.cellColor = pattern;
    1.59 @@ -456,7 +468,7 @@
    1.60  
    1.61  - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
    1.62  {
    1.63 -    CGImageRef image = GetCGImageFromPasteboard([sender draggingPasteboard]);
    1.64 +    CGImageRef image = GetCGImageFromPasteboard([sender draggingPasteboard],sender);
    1.65      if( image ) {
    1.66          CGColorRef color = CreatePatternColor(image);
    1.67          RectGrid *rectGrid = (RectGrid*)_grid;