Navigation Menu

Skip to content

Commit

Permalink
rendere a grid
Browse files Browse the repository at this point in the history
  • Loading branch information
trajano committed Jun 22, 2010
1 parent f90b9d8 commit cb28131
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 54 deletions.
4 changes: 4 additions & 0 deletions src/main/objc/ZaWorldGrid.h
Expand Up @@ -12,6 +12,10 @@
* This is a generic Grid view that allows for a grid layout of sprites. I * This is a generic Grid view that allows for a grid layout of sprites. I
* may eventually redo this to support animation so there would most likely be a * may eventually redo this to support animation so there would most likely be a
* "next" view. * "next" view.
*
* A grid will contain the data for an entire floor. The model has its coordinate
* system in the cartetian coordinate system and it it do a tranform so that the bottom left is drawn.
* It will draw the entire area for now.
*/ */


@interface ZaWorldGrid : NSView { @interface ZaWorldGrid : NSView {
Expand Down
92 changes: 38 additions & 54 deletions src/main/objc/ZaWorldGrid.m
Expand Up @@ -12,75 +12,59 @@
@implementation ZaWorldGrid @implementation ZaWorldGrid
@synthesize location, itemColor, backgroundColor, gridColor, gridVisible; @synthesize location, itemColor, backgroundColor, gridColor, gridVisible;


- (void)setItemPropertiesToDefault:sender - (void)setItemPropertiesToDefault:sender {

{

[self setLocation:NSMakePoint(0.0,0.0)];

[self setItemColor:[NSColor redColor]]; [self setItemColor:[NSColor redColor]];

[self setBackgroundColor:[NSColor grayColor]]; [self setBackgroundColor:[NSColor grayColor]];

[self setGridColor: [NSColor blackColor]];
}
- (NSRect)calculatedItemBounds

{

NSRect calculatedRect;



// calculate the bounds of the draggable item

// relative to the location

calculatedRect.origin=location;



// the example assumes that the width and height

// are fixed values

calculatedRect.size.width=60.0;

calculatedRect.size.height=200.0;



return calculatedRect;

} }


- (id)initWithFrame:(NSRect)frame { - (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
// Initialization code here. // Initialization code here.
[self setItemPropertiesToDefault:self]; [self setItemPropertiesToDefault:self];

// Set the size of the object to a large size.
NSSize mapSize;
mapSize.width = 1000;
mapSize.height = 1000;
[self setFrameSize: mapSize];
} }
return self; return self;
} }


- (void)drawRect:(NSRect)dirtyRect { - (void)drawRect:(NSRect)rect {
// Drawing code here. // Drawing code here.
// erase the background by drawing white int width = [self frame].size.width;

int height = [self frame].size.height ;
[backgroundColor set];

int i = 0 ;
[NSBezierPath fillRect:dirtyRect]; int GRIDSIZE= 10;



// Set the color in the current graphics context for future draw operations

[gridColor setStroke];
// set the current color for the draggable item


[[self itemColor] set]; // Create our drawing path



NSBezierPath* drawingPath = [NSBezierPath bezierPath];

// [drawingPath setLineWidth:0.1];
// draw the draggable item // Draw a grid
// first the vertical lines
for( i = 0 ; i <= width ; i=i+GRIDSIZE ) {
// see http://www.cocoabuilder.com/archive/cocoa/53752-how-to-draw-1-pixel-line.html
// for the reason why I had to add 0.5
[drawingPath moveToPoint:NSMakePoint(i + 0.5, 0)];
[drawingPath lineToPoint:NSMakePoint(i + 0.5, height)];
} // then the horizontal lines
for( i = 0 ; i <= height ; i=i+GRIDSIZE ) {
[drawingPath moveToPoint:NSMakePoint(0, i + 0.5)];
[drawingPath lineToPoint:NSMakePoint(width, i + 0.5)];
}
// TODO transform to shift the map if it is smaller than the rect that was passed in.
// actually draw the grid
[drawingPath stroke];


[NSBezierPath fillRect:[self calculatedItemBounds]];
} }


@end @end

0 comments on commit cb28131

Please sign in to comment.