Graphics Reference
In-Depth Information
LISTING 4-5
Continued
- ( void )legThree:( id )sender
{
CGPathAddLineToPoint (starPath, NULL , 144.0, 210.0);
[[[window contentView ] layer ] setNeedsDisplay ];
}
- ( void )legFour:( id )sender
{
CGPathAddLineToPoint (starPath, NULL , 298.0, 99.0);
[[[window contentView ] layer ] setNeedsDisplay ];
}
- ( void )legFive:( id )sender
{
CGPathCloseSubpath (starPath);
[[[window contentView ] layer ] setNeedsDisplay ];
}
When we call -setNeedsDisplay on the root layer, -drawLayer gets called and the path in
its current state gets drawn to the layer, as shown in Listing 4-6.
LISTING 4-6
Draw the Path We Have Been Building at Each Timer Call
- ( void )drawLayer:( CALayer *)layer
inContext:( CGContextRef )context
{
if ( layer == [[window contentView ] layer ] )
{
CGColorRef white =
CGColorCreateGenericRGB (1.0, 1.0, 1.0, 1.0);
CGContextSetStrokeColorWithColor (context, white);
CFRelease (white);
CGContextBeginPath (context);
CGContextAddPath (context, starPath);
CGContextSetLineWidth (context, 3.0);
CGContextStrokePath (context);
}
}
 
Search WWH ::




Custom Search