Return to Snippet

Revision: 32030
at September 17, 2010 17:48 by pgnatyuk


Initial Code
- (void) drawArrow
{
	NSLog( @"state = %i", state );

	// background
	NSRect bounds = [self bounds];
	[[NSColor orangeColor] set];
	NSRectFill( bounds );
	
	// arrow
	CGFloat width = bounds.size.width;
	CGFloat height = bounds.size.height;
	
	// no alloc and so no release in the end.
	NSBezierPath* path = [NSBezierPath bezierPath];
	
	[path moveToPoint: NSMakePoint( width * 0.35, height * 0.1 )];
	
	[path lineToPoint: NSMakePoint( width * 0.65, height * 0.1 )];
	[path lineToPoint: NSMakePoint( width * 0.65, height * 0.6 )];
	[path lineToPoint: NSMakePoint( width * 0.9, height * 0.6 )];
	[path lineToPoint: NSMakePoint( width * 0.5, height * 0.9 )];
	[path lineToPoint: NSMakePoint( width * 0.1, height * 0.6 )];
	[path lineToPoint: NSMakePoint( width * 0.35, height * 0.6 )];
	
	[path closePath];
	
	[[NSColor blueColor] set];
	[path fill];
	
	[[NSColor whiteColor] set];
	[path stroke];
}

- (void)drawHouse
{
	NSLog( @"state = %i", state );
	NSRect bounds = [self bounds];
	[[NSColor yellowColor] set];
	NSRectFill( bounds );	
	
	CGFloat width = bounds.size.width;
	CGFloat height = bounds.size.height;
	
	NSBezierPath *path = [NSBezierPath bezierPath];
	
	[path moveToPoint: NSMakePoint( width * 0.1, height * 0.6 )];
	
	[path lineToPoint: NSMakePoint( width * 0.1, height * 0.1 )];
	[path lineToPoint: NSMakePoint( width * 0.9, height * 0.1 )];
	[path lineToPoint: NSMakePoint( width * 0.9, height * 0.6 )];
	[path lineToPoint: NSMakePoint( width * 0.1, height * 0.6 )];
	[path lineToPoint: NSMakePoint( width * 0.5, height * 0.9 )];
	[path lineToPoint: NSMakePoint( width * 0.9, height * 0.6 )];
	 
	[path closePath];
	
	[[NSColor whiteColor] set];
	[path fill];
	 
	[[NSColor blueColor] set];
	[path stroke];
}


- (void)drawRect:(NSRect)dirtyRect 
{
	[NSGraphicsContext saveGraphicsState];
	
	//[self drawHouse]; 
	[self drawArrow];
	
	[NSGraphicsContext restoreGraphicsState];
}

Initial URL


Initial Description
How to draw using NSBezierPath. Call these two methods from -drawRect.

Initial Title
Draw with NSBezierPath

Initial Tags


Initial Language
Objective C