Source/BoardUIView.m
changeset 6 af9b2b929b03
parent 3 40d225cf9c43
child 8 45c82a071aca
     1.1 --- a/Source/BoardUIView.m	Tue Mar 11 09:21:53 2008 -0700
     1.2 +++ b/Source/BoardUIView.m	Wed Mar 12 15:51:32 2008 -0700
     1.3 @@ -42,19 +42,33 @@
     1.4  
     1.5  - (void) startGameNamed: (NSString*)gameClassName
     1.6  {
     1.7 +    Class gameClass = NSClassFromString(gameClassName);
     1.8 +    NSAssert1(gameClass,@"Unknown game '%@'",gameClassName);
     1.9 +    
    1.10 +    setObj(&_game,nil);
    1.11      if( _gameboard ) {
    1.12          [_gameboard removeFromSuperlayer];
    1.13          _gameboard = nil;
    1.14      }
    1.15 +
    1.16 +    CALayer *rootLayer = self.layer;
    1.17 +    self.layer.affineTransform = CGAffineTransformIdentity;
    1.18 +    CGRect frame = rootLayer.frame;
    1.19 +    frame.origin.x = frame.origin.y = 0;
    1.20 +    rootLayer.bounds = frame;
    1.21 +
    1.22 +    if( [gameClass landscapeOriented] && frame.size.height > frame.size.width ) {
    1.23 +        rootLayer.affineTransform = CGAffineTransformMakeRotation(M_PI/2);
    1.24 +        frame = CGRectMake(0,0,frame.size.height,frame.size.width);
    1.25 +        rootLayer.bounds = frame;
    1.26 +    }
    1.27 +    
    1.28      _gameboard = [[GGBLayer alloc] init];
    1.29 -    _gameboard.frame = [self gameBoardFrame];
    1.30 -    _gameboard.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
    1.31 -    [self.layer addSublayer: _gameboard];
    1.32 +    _gameboard.frame = frame;
    1.33 +    [rootLayer addSublayer: _gameboard];
    1.34      [_gameboard release];
    1.35      
    1.36 -    Class gameClass = NSClassFromString(gameClassName);
    1.37 -    NSAssert1(gameClass,@"Unknown game '%@'",gameClassName);
    1.38 -    setObj(&_game, [[gameClass alloc] initWithBoard: _gameboard]);
    1.39 +    _game = [[gameClass alloc] initWithBoard: _gameboard];
    1.40  }
    1.41  
    1.42