File: ThinkAheadViewDelegate.m

package info (click to toggle)
gridlock.app 1.10-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,556 kB
  • sloc: objc: 10,334; ansic: 669; makefile: 12
file content (48 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
//  ThinkAheadViewDelegate.m
//  Gridlock
//
//  Created by Brian on 3/26/05.
//  Copyright 2005 __MyCompanyName__. All rights reserved.
//

#import "ThinkAheadViewDelegate.h"
#import "ImageStore.h"

@implementation ThinkAheadViewDelegate

-(BOOL)drawCellWithValue:(int)value atRow:(int)row column:(int)col inRect:(NSRect)rect forGame:(id)game {
  if (value==-11) {
    NSRect changeRect = NSInsetRect(rect, rect.size.width/3, rect.size.height/3);
    NSImage *wallImage = [[ImageStore defaultStore] bitmapImageWithName:@"wall.tiff" size:changeRect.size];
    [wallImage compositeToPoint:changeRect.origin operation:NSCompositeSourceOver];
  }
  else {
    if (value==-10) {
      // bigger move indicator
      NSRect changeRect = NSInsetRect(rect, rect.size.width/3, rect.size.height/3);
      [[NSColor blackColor] set];
      [[NSBezierPath bezierPathWithOvalInRect:changeRect] fill];
    }
    else {
      NSString *str = [[NSNumber numberWithInt:value] stringValue];
      // get text size at 12 points
      NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
      [attrs setObject:[NSFont labelFontOfSize:12] forKey:NSFontAttributeName];
      [attrs setObject:((value>=0) ? [NSColor greenColor] : [NSColor redColor]) forKey:NSForegroundColorAttributeName];
      NSSize size = [str sizeWithAttributes:attrs];
      
      // scale to take 80% of the height
      double ratio = 0.6*rect.size.height/size.height;
      [attrs setObject:[NSFont labelFontOfSize:12*ratio] forKey:NSFontAttributeName];
      
      // draw in center
      size = [str sizeWithAttributes:attrs];
      [str drawAtPoint:NSMakePoint(rect.origin.x+(rect.size.width-size.width)/2,
                                   rect.origin.y+(rect.size.height-size.height)/2) withAttributes:attrs];
    }
  }
  return YES;
}

@end