• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[NSBezierPath fillRect:[self bounds]] question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[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


  • Follow-Ups:
    • Re: [NSBezierPath fillRect:[self bounds]] question
      • From: Rob Keniger <email@hidden>
  • Prev by Date: Re: Can CoreData return only unique results of an attribute
  • Next by Date: Re: Observing with GC
  • Previous by thread: Re: Can CoreData return only unique results of an attribute
  • Next by thread: Re: [NSBezierPath fillRect:[self bounds]] question
  • Index(es):
    • Date
    • Thread