Graphics Reference
In-Depth Information
}
- ( void )touchesBegan:( NSSet *)touches withEvent:( UIEvent *)event
{
//get the starting point
CGPoint point = [[touches anyObject ] locationInView : self ];
//add brush stroke
[ self addBrushStrokeAtPoint :point];
}
- ( void )touchesMoved:( NSSet *)touches withEvent:( UIEvent *)event
{
//get the touch point
CGPoint point = [[touches anyObject ] locationInView : self ];
//add brush stroke
[ self addBrushStrokeAtPoint :point];
}
- ( void )addBrushStrokeAtPoint:( CGPoint )point
{
//add brush stroke to array
[ self . strokes addObject :[ NSValue valueWithCGPoint :point]];
//needs redraw
[ self setNeedsDisplay ];
}
- ( void )drawRect:( CGRect )rect
{
//redraw strokes
for ( NSValue *value in self . strokes )
{
//get point
CGPoint point = [value CGPointValue ];
//get brush rect
CGRect brushRect = CGRectMake (point. x - BRUSH_SIZE/ 2 ,
point. y - BRUSH_SIZE/ 2 ,
BRUSH_SIZE, BRUSH_SIZE);
//draw brush stroke
[[ UIImage imageNamed : @"Chalk.png" ] drawInRect :brushRect];
Search WWH ::




Custom Search