Permalink
Browse files

rendere a grid

  • Loading branch information...
1 parent f90b9d8 commit cb28131212a90986d6af66ede21b0896c17c7270 @trajano committed Jun 22, 2010
Showing with 42 additions and 54 deletions.
  1. +4 −0 src/main/objc/ZaWorldGrid.h
  2. +38 −54 src/main/objc/ZaWorldGrid.m
@@ -12,6 +12,10 @@
* 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
* "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 {
@@ -12,75 +12,59 @@
@implementation ZaWorldGrid
@synthesize location, itemColor, backgroundColor, gridColor, gridVisible;
-- (void)setItemPropertiesToDefault:sender
-
-{
-
- [self setLocation:NSMakePoint(0.0,0.0)];
-
+- (void)setItemPropertiesToDefault:sender {
[self setItemColor:[NSColor redColor]];
-
[self setBackgroundColor:[NSColor grayColor]];
-
-}
-- (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;
-
+ [self setGridColor: [NSColor blackColor]];
}
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
[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;
}
-- (void)drawRect:(NSRect)dirtyRect {
+- (void)drawRect:(NSRect)rect {
// Drawing code here.
- // erase the background by drawing white
-
- [backgroundColor set];
-
- [NSBezierPath fillRect:dirtyRect];
-
-
-
- // set the current color for the draggable item
-
- [[self itemColor] set];
-
-
-
- // draw the draggable item
+ int width = [self frame].size.width;
+ int height = [self frame].size.height ;
+
+ int i = 0 ;
+ int GRIDSIZE= 10;
+
+ // Set the color in the current graphics context for future draw operations
+ [gridColor setStroke];
+
+
+ // Create our drawing path
+
+ NSBezierPath* drawingPath = [NSBezierPath bezierPath];
+ // [drawingPath setLineWidth:0.1];
+ // 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

0 comments on commit cb28131

Please sign in to comment.