/ Published in: Objective C
How to draw using NSBezierPath. Call these two methods from -drawRect.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
- (void) drawArrow { NSLog( @"state = %i", state ); // background NSRect bounds = [self bounds]; NSRectFill( bounds ); // arrow CGFloat width = bounds.size.width; CGFloat height = bounds.size.height; // no alloc and so no release in the end. [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]; [path fill]; [path stroke]; } - (void)drawHouse { NSLog( @"state = %i", state ); NSRect bounds = [self bounds]; NSRectFill( bounds ); CGFloat width = bounds.size.width; CGFloat height = bounds.size.height; [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]; [path fill]; [path stroke]; } - (void)drawRect:(NSRect)dirtyRect { //[self drawHouse]; [self drawArrow]; }