CocoaDev

Edit AllPages

TileView.h

#import <Cocoa/Cocoa.h>

@interface TileView : NSMatrix { NSSize minSize; NSImage *image; }

@interface Tile : NSActionCell @end

TileView.m

#import “TileView.h”

static unsigned TileCount(float dim, float min, float gap, float *cellDim) { unsigned cnt = (unsigned)(dim / (min + gap)); if (!cnt) cnt++; *cellDim = (dim / (float)cnt) - gap; return cnt; }

@implementation TileView // NSMatrix

}

@end

@implementation Tile

@end

–zootbobbalu


I haven’t tried it, but wouldn’t this be a lot easier by using + (NSColor )colorWithPatternImage:(NSImage)image; and then just filling the whole view, forgetting about NSMatrix?


Hey that’s pretty cool. Never noticed that method before. You can draw different images for each cell in the matrix, but colorWithPatternImage is really nice because you can fill shapes. I also noticed that the pattern will start at the bottom left corner of the window, so if you want to have the tile conform to a view you can’t use colorWithPatternImage. –zootbobbalu


Interesting point about starting in the corner of the window, I guess it wouldn’t work too well for this view, then.

You can constrain any arbitrary drawing to fill a shape by doing [shape addClip] before drawing, assuming shape is an NSBezierPath. This will clip all future drawing to be inside the given path, which comes in handy sometimes.