Re: BezierPath issues
Re: BezierPath issues
- Subject: Re: BezierPath issues
- From: Ricky Sharp <email@hidden>
- Date: Sun, 24 Feb 2008 17:26:04 -0600
On Feb 24, 2008, at 3:53 PM, Development wrote:
I'm trying to adapt a part of the sketch example in to a program for
light drawing functions. Unfortunately not being very good with
graphics I'm having a great deal of trouble. I was hoping that it
was possible to create the free form drawing within a bezierpath but
if it is I don't see how. Below is the bezier path creation code I
am using to try and create the freeform drawing.. This code produces
a single angled line (Always the exact same angle) about 5px long
and nothing more no matter how much I move the mouse, then when I
release the mouse button the application crashes with a bad access
and I'll mark the line where it crashes.
- (NSBezierPath *)bezierPath {
NSRect bounds = [self bounds];
if(![self strokeLineWidth]){
NSLog(@"Zero stroke w3idth");
return penPath;
}
[penPath setLineWidth:[self strokeLineWidth]];
if(!lastPointSet){
lastPoint = [self bounds].origin;
lastPointSet= YES;
}
NSRect dot = NSMakeRect(bounds.size.width,bounds.size.height,[self
strokeLineWidth],[self strokeLineWidth]);
NSPoint dotPoint = NSMakePoint(dot.origin.x,dot.origin.y);
Not sure why you're constructing a rect here. It will always be for a
region outside your bounds.
Your dotPoint variable is just being set to the same point over and
over again.
if(!penPath){
NSLog(@"returning NULL");
return NULL;
}
[penPath moveToPoint:dotPoint]; //This is where it crashes on mouse
up.
You're going to have to post more code. For example, how are you
dealing with penPath? Are you properly retaining it?
[penPath lineToPoint:lastPoint];
Shouldn't this be [penPath lineToPoint:dotPoint]; ?
lastPoint = dotPoint;
[penPath appendBezierPathWithRect:dot];
Why are you appending the rect here? Note that it's always a point
physically outside your actual bounds.
return penPath;
}
I'm sure this is a simple problem but I cannot seem to figure it out.
Aside from the crash, you're going to have to change your code to work
with capturing points from mouse movement. And you'll then need to
also deal with very fast movement that will tend to give you straight
lines between points (maybe that's what you want?)
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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