Re: still cant get bezier paths working for me.
Re: still cant get bezier paths working for me.
- Subject: Re: still cant get bezier paths working for me.
- From: Graham <email@hidden>
- Date: Tue, 26 Feb 2008 16:41:41 +1100
On mouse down: open a new path, moveTo the current point. Store this
path somewhere your view can find it (hint: in an ivar)
On mouse dragged: append a lineTo element to the path with the
current point. Use the path's bounds so far (plus a bit to allow for
the stroke width) to refresh the view.
On drawRect: stroke the path so far.
If you need to draw all the paths you've created so far, you'll need
to store each path in a list (array) and draw all of them in drawRect:
HTH,
--------
S.O.S.
On 26/02/2008, at 3:55 PM, Development wrote:
Well... bezierpaths have officially confused me beyond reason... I
am hoping that some one will be able to help me based on the amount
of code that I can paste in to an email with out it getting bounced.
First, I am trying to create a pen tool similar to something you'd
find in photoshop. After more reading and trial and error I have
gotten a tad closer but not much. This code is based on the sketch
example code, I figured that would be a good place to start.
However I am thinking that it is not possible to use bezier paths
for this.
First time through I've tried to use an instance variable to
maintain the path, but it had two problems, the first is that the
rectangle around the path shifted size, even though I had though
append path would prevent this. When the rect shifted sizes it cut
out the edges of what ever I drew. Second, as soon as I let off the
mouse button the application would crash. The instance variable was
the cause. I attempted to NSLog it to get some information but that
would cause the application to crash also. The variable however was
not NULL or nil so I honestly do not know how to deal with this...
I could not find the reason for it.
Next I just return the current part of the path but then I only end
up with a dot chasing the cursor. But no crash.
I tried using a point array but apparently I don't understand how
they work, I thought it was like any plain old char array. below is
the code that produces the single dot... if some one could suggest
how I could make the line persistent I'd be grateful. Should I be
trying to keep an array of point returning newPath with appendPoints?
- (NSBezierPath *)bezierPath {
if(![self strokeLineWidth]){
return NULL;
}
if(!lastPointSet){
lastPoint = [self bounds].origin;
lastPointSet= YES;
}
NSPoint dotPoint = [[[[self document]windowController]graphicView]
currentPoint];
NSBezierPath * newPath =[NSBezierPath bezierPath];
[[self fillColor]set];
[newPath moveToPoint:dotPoint];
[newPath lineToPoint:lastPoint];
[newPath stroke];
lastPoint = dotPoint;
return newPath;
}
_______________________________________________
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:
40ictinternational.com.au
This email sent to email@hidden
_______________________________________________
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