[NSBezierPath fillRect:[self bounds]] question
[NSBezierPath fillRect:[self bounds]] question
- Subject: [NSBezierPath fillRect:[self bounds]] question
- From: Jamie Phelps <email@hidden>
- Date: Tue, 26 Feb 2008 19:05:00 -0600
Hey, guys. I'm having what I assume is a simple problem. [NSBezierPath
fillRect:[self bounds]]; fills my NSView subclass fine the first time
drawRect: is called, but breaks the frame on redraw. Here is some more
code for context if needed. I tried adding the initial background fill
to an awakeFromNib: method with no success. If anyone can offer
thoughts on where I'm going wrong I'd appreciate it.
#import <Cocoa/Cocoa.h>
@interface DrawingView : NSView {
NSBezierPath * path;
NSPoint downPoint, currentPoint;
NSRect ovalBounds;
}
@end
#import "DrawingView.h"
@implementation DrawingView
- (id)initWithFrame:(NSRect)rect{
self = [super initWithFrame:rect];
[NSBezierPath setDefaultLineWidth:5.0];
return self;
}
- (void)drawRect:(NSRect)rect{
[[NSColor blueColor] set];
[NSBezierPath fillRect:[self bounds]];
path = [NSBezierPath bezierPathWithOvalInRect:ovalBounds];
[[NSColor yellowColor] set];
[path stroke];
[[NSColor greenColor] set];
[path fill];
[self setNeedsDisplay:YES];
}
- (void)mouseDown:(NSEvent *)event{
NSPoint p = [event locationInWindow];
downPoint = [self convertPoint:p
fromView:nil];
currentPoint = downPoint;
NSLog(@"currentPoint x = %d, y = %d", currentPoint.x,
currentPoint.y);
[self setNeedsDisplay:YES];
}
- (void)mouseUp:(NSEvent *)event {
NSPoint p = [event locationInWindow];
currentPoint = [self convertPoint:p
fromView:nil];
NSLog(@"currentPoint x = %d, y = %d", currentPoint.x,
currentPoint.y);
float minX = MIN(downPoint.x, currentPoint.x);
float maxX = MAX(downPoint.x, currentPoint.x);
float minY = MIN(downPoint.y, currentPoint.y);
float maxY = MAX(downPoint.y, currentPoint.y);
ovalBounds = NSMakeRect(minX, minY, maxX-minX, maxY-minY);
[self drawRect:ovalBounds];
}
@end
Thanks,
Jamie
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden