Source/Grid.m
changeset 19 3b750982ff39
parent 12 4e567e11f45f
child 22 4cb50131788f
     1.1 --- a/Source/Grid.m	Mon Jul 07 15:47:42 2008 -0700
     1.2 +++ b/Source/Grid.m	Thu Jul 17 13:29:04 2008 -0700
     1.3 @@ -112,7 +112,7 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -@synthesize cellClass=_cellClass, rows=_nRows, columns=_nColumns, spacing=_spacing,
     1.8 +@synthesize cellClass=_cellClass, rows=_nRows, columns=_nColumns, spacing=_spacing, reversed=_reversed,
     1.9              usesDiagonals=_usesDiagonals, allowsMoves=_allowsMoves, allowsCaptures=_allowsCaptures;
    1.10  
    1.11  
    1.12 @@ -136,7 +136,7 @@
    1.13                 suggestedFrame: (CGRect)frame
    1.14  {
    1.15      GridCell *cell = [[_cellClass alloc] initWithGrid: self 
    1.16 -                                        row: row column: col
    1.17 +                                                  row: row column: col
    1.18                                                  frame: frame];
    1.19      cell.name = [NSString stringWithFormat: @"%c%u", ('A'+row),(1+col)];
    1.20      return [cell autorelease];
    1.21 @@ -150,7 +150,12 @@
    1.22      unsigned index = row*_nColumns+col;
    1.23      GridCell *cell = [_cells objectAtIndex: index];
    1.24      if( (id)cell == [NSNull null] ) {
    1.25 -        CGRect frame = CGRectMake(col*_spacing.width, row*_spacing.height,
    1.26 +        unsigned effectiveRow=row, effectiveCol=col;
    1.27 +        if( _reversed ) {
    1.28 +            effectiveRow = _nRows-1    - effectiveRow;
    1.29 +            effectiveCol = _nColumns-1 - effectiveCol;
    1.30 +        }
    1.31 +        CGRect frame = CGRectMake(effectiveCol*_spacing.width, effectiveRow*_spacing.height,
    1.32                                    _spacing.width,_spacing.height);
    1.33          cell = [self createCellAtRow: row column: col suggestedFrame: frame];
    1.34          if( cell ) {
    1.35 @@ -274,6 +279,21 @@
    1.36          }
    1.37  }
    1.38  
    1.39 +- (void) drawBackgroundInContext: (CGContextRef)ctx
    1.40 +{
    1.41 +    if( _backgroundImage ) {
    1.42 +        CGRect bounds = self.bounds;
    1.43 +        if( _reversed ) {
    1.44 +            CGContextSaveGState(ctx);
    1.45 +            CGContextRotateCTM(ctx, M_PI);
    1.46 +            CGContextTranslateCTM(ctx, -bounds.size.width, -bounds.size.height);
    1.47 +        }
    1.48 +        CGContextDrawImage(ctx, bounds, _backgroundImage);
    1.49 +        if( _reversed )
    1.50 +            CGContextRestoreGState(ctx);
    1.51 +    }
    1.52 +}
    1.53 +
    1.54  
    1.55  - (void)drawInContext:(CGContextRef)ctx
    1.56  {
    1.57 @@ -281,8 +301,7 @@
    1.58      // in me; this is more efficient than having each cell have its own drawing.
    1.59      [super drawInContext: ctx];
    1.60      
    1.61 -    if( _backgroundImage )
    1.62 -        CGContextDrawImage(ctx, self.bounds, _backgroundImage);
    1.63 +    [self drawBackgroundInContext: ctx];
    1.64      
    1.65      if( _cellColor ) {
    1.66          CGContextSetFillColorWithColor(ctx, _cellColor);