Note that there are some explanatory texts on larger screens.

plurals
  1. POQuartz paths not drawing like I expect
    text
    copied!<p>I am trying to draw and fill simple paths in Quartz 2d for iPad.</p> <p>The following method from the class SPTCutPattern defines the paths that I want to draw:</p> <pre><code>- (void) initDummyCutPattern { NSArray *piece1Path = [[NSArray alloc] initWithObjects: [NSValue valueWithCGPoint:CGPointMake(0, 0)], [NSValue valueWithCGPoint:CGPointMake(3, 0)], [NSValue valueWithCGPoint:CGPointMake(3, 1)], [NSValue valueWithCGPoint:CGPointMake(2, 1)], [NSValue valueWithCGPoint:CGPointMake(2, 2)], [NSValue valueWithCGPoint:CGPointMake(0, 2)], nil]; SPTPuzzlePiece *Piece1 = [[SPTPuzzlePiece alloc] initWithWidthInGrid:3 andHeightInGrid:2 andLeftInGrid:0 andTopInGrid:0 andBuilt:YES andPathInGrid:piece1Path]; NSArray *piece2Path = [[NSArray alloc] initWithObjects: [NSValue valueWithCGPoint:CGPointMake(3, 0)], [NSValue valueWithCGPoint:CGPointMake(5, 0)], [NSValue valueWithCGPoint:CGPointMake(5, 5)], [NSValue valueWithCGPoint:CGPointMake(4, 5)], [NSValue valueWithCGPoint:CGPointMake(4, 4)], [NSValue valueWithCGPoint:CGPointMake(2, 4)], [NSValue valueWithCGPoint:CGPointMake(2, 3)], [NSValue valueWithCGPoint:CGPointMake(3, 3)], [NSValue valueWithCGPoint:CGPointMake(3, 2)], [NSValue valueWithCGPoint:CGPointMake(2, 2)], [NSValue valueWithCGPoint:CGPointMake(2, 1)], [NSValue valueWithCGPoint:CGPointMake(3, 1)], nil]; SPTPuzzlePiece *Piece2 = [[SPTPuzzlePiece alloc] initWithWidthInGrid:3 andHeightInGrid:5 andLeftInGrid:2 andTopInGrid:0 andBuilt:YES andPathInGrid:piece2Path]; NSArray *piece3Path = [[NSArray alloc] initWithObjects: [NSValue valueWithCGPoint:CGPointMake(0, 2)], [NSValue valueWithCGPoint:CGPointMake(3, 2)], [NSValue valueWithCGPoint:CGPointMake(3, 3)], [NSValue valueWithCGPoint:CGPointMake(2, 3)], [NSValue valueWithCGPoint:CGPointMake(2, 4)], [NSValue valueWithCGPoint:CGPointMake(4, 4)], [NSValue valueWithCGPoint:CGPointMake(4, 5)], [NSValue valueWithCGPoint:CGPointMake(0, 5)], nil]; SPTPuzzlePiece *Piece3 = [[SPTPuzzlePiece alloc] initWithWidthInGrid:4 andHeightInGrid:3 andLeftInGrid:0 andTopInGrid:2 andBuilt:YES andPathInGrid:piece3Path]; self.pieces = [[NSArray alloc] initWithObjects:Piece1, Piece2, Piece3, nil]; } </code></pre> <p>And this method from the class SPTPuzzlePieceView which is supposed to draw the paths:</p> <pre><code>- (void)drawRect:(CGRect)rect { int widthUnit = self.frame.size.width / self.puzzlePiece.widthInGrid; int heightUnit = self.frame.size.height / self.puzzlePiece.heightInGrid; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor); CGContextMoveToPoint(context, [[puzzlePiece.pathInGrid objectAtIndex:0] CGPointValue].x*widthUnit, [[puzzlePiece.pathInGrid objectAtIndex:0] CGPointValue].y*heightUnit); for (NSValue *point in puzzlePiece.pathInGrid) { CGContextAddLineToPoint(context, [point CGPointValue].x*widthUnit, [point CGPointValue].y*heightUnit); } CGContextFillPath(context); } </code></pre> <p>I am getting these three objects, which are absolutely NOT what I expect and want:</p> <p><a href="http://dl.dropbox.com/u/26067393/photo.PNG" rel="nofollow">screenshot</a></p> <p>The objects are supposed to be more (or less) like this:</p> <p><a href="http://dl.dropbox.com/u/26067393/photo2.JPG" rel="nofollow">shapes I wanted</a></p> <p>I am sorry that these methods are totally taken out of context, so I hope you can see what I am trying to do. The drawRect method gets called to draw each of the piece objects I defined in the first method in turn.</p> <p>I cannot figure out why it is not drawing the shapes I want. Help me please.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload