Re: Problems while using NSBezierPath
Re: Problems while using NSBezierPath
- Subject: Re: Problems while using NSBezierPath
- From: Shrinivasa Kini <email@hidden>
- Date: Mon, 29 Aug 2005 19:06:44 -0700
Well I finally got my code working as required.
I did know that calling -setNeedsDisplay:YES will not do accumulated
drawing, but a direct call to -drawRect does. And for this I needed to
-lockFocus on my view and then call -drawRect:[self bounds]. It draws the
link and any other incremental drawing on the view.
Thanks for your help.
-Shrini
On 8/29/05, MacSmith <email@hidden> wrote:
>
>
> On Aug 30, 2005, at 5:27 AM, Shrinivasa Kini wrote:
>
> > Hi,
> >
> > I tried the changes that James recommended. But it still doesn't work.
> > When I need to draw a Link (in the action of a button), I make a
> > call to -
> > [self drawRect:[self bounds]];
> It's not recommended to do that.
> You should call [self setNeedsDisplay:YES] instead. (or -
> setNeedsDisplayInRect for partial repaint.)
> Or call -display to draw immediately.
> And beware of the drawing was not accumulated.
> I mean, by your code, only one mode will be displayed at a time.
> It depends on the states of the flags, mode and linkNode, while last
> drawing.
> HTH,
> James
>
> > This will enter into my code for the link in the drawRect method and
> > should draw the line Bezier Path. But the line is never displayed on
> > the view.
> >
> > My entire drawRect method as it stands today is as below-
> > - (void)drawRect:(NSRect)rect
> > {
> > NS_DURING
> > if ( mode == -1 )
> > {
> > [[NSColor whiteColor] set];
> > NSRectFill(rect);
> > }
> > else if ( mode == NODEMODE )
> > {
> > if ( createNode )
> > {
> > NSBezierPath *bp = [NSBezierPath
> > bezierPathWithOvalInRect:NSMakeRect(mouseLoc.x-10, mouseLoc.y-10, 20,
> > 20)];
> > [[NSColor blueColor] set];
> > [bp fill];
> > [bezierPathArr addObject:bp];
> > }
> > }
> > else if ( mode == LINKMODE )
> > {
> > if ( linkNode == SELECTNODE )
> > {
> > [[NSColor redColor] set];
> > [(NSBezierPath*)[bezierPathArr
> > objectAtIndex:foundBezierPath] fill];
> > }
> > else if ( linkNode == DESELECTNODE )
> > {
> > [[NSColor blueColor] set];
> > [(NSBezierPath*)[bezierPathArr
> > objectAtIndex:foundBezierPath] fill];
> > }
> > else if ( linkNode == DRAWLINK )
> > {
> > NSBezierPath *bl = [NSBezierPath bezierPath];
> > NSRect rect1 = [(NSBezierPath*)[bezierPathArr
> > objectAtIndex:firstSelectedBezierPath] bounds];
> > NSRect rect2 = [(NSBezierPath*)[bezierPathArr
> > objectAtIndex:secondSelectedBezierPath] bounds];
> >
> > [bl moveToPoint:NSMakePoint(rect1.origin.x
> > +30,rect1.origin.y+30)];
> > [bl lineToPoint:NSMakePoint(rect2.origin.x
> > +30,rect2.origin.y+30)];
> > [bl fill];
> > [bl stroke];
> > }
> > }
> > NS_HANDLER
> > NSLog(@"Error : %@",[localException reason]);
> > NS_ENDHANDLER
> > }
> >
> > The variables mode, linkmode are set/reset on the actions of some
> > buttons on my window.
> >
> > Any pointers as to where I might be going wrong?
> >
> > Thanks,
> > Shrini
> >
> > On 8/27/05, James Chen <email@hidden> wrote:
> >
> >>
> >> On Aug 27, 2005, at 3:44 AM, Shrinivasa Kini wrote:
> >>
> >>
> >>> Hi all,
> >>>
> >>> I am writing a piece of software which requires making some nodes
> >>> and
> >>> links on a screen.
> >>> So I am writing a subclass of NSView and creating objects of
> >>> NSBezierPath for showing my Nodes and Links (basically line
> >>> between 2
> >>> points).
> >>> In the NSView subclass - which I call GraphView - I override the
> >>> drawRect:(NSRect)rect method for drawing my objects. The Nodes
> >>> come up
> >>> fine, but the bezierPaths created to show the links are never
> >>> displayed in the view. Here is a snippet of my GraphView code-
> >>>
> >>> - (void)drawRect:(NSRect)rect
> >>> {
> >>> if ( mode == NODEMODE )
> >>> {
> >>> NSRect r;
> >>> NSBezierPath *bp;
> >>>
> >>> r = NSMakeRect(mouseLoc.x-10, mouseLoc.y-10, 20, 20);
> >>> bp = [NSBezierPath bezierPathWithOvalInRect:r];
> >>> [[NSColor blueColor] set];
> >>> [bp fill];
> >>>
> >> // That is weird here to create a node once you get a
> >> update event.
> >>
> >>> [bezierPathArr addObject:bp];
> >>>
> >>> }
> >>> else if ( mode == LINKMODE )
> >>> {
> >>>
> >>
> >> //NSBezierPath *bl = [[NSBezierPath alloc] init];
> >> NSBezierPath *bl =[[NSBezierPath bezierPath];
> >> //Use class method +bezierPath instead or you should
> >> release bl at the end.
> >>
> >>
> >>>
> >>> [[NSColor blackColor] set];
> >>> [NSBezierPath setDefaultLineWidth:5];
> >>> [NSBezierPath setDefaultLineJoinStyle:NSRoundLineCapStyle];
> >>> NSRect rect1 = [(NSBezierPath*)[bezierPathArr
> >>> objectAtIndex:firstSelectedBezierPath] bounds];
> >>> NSRect rect2 = [(NSBezierPath*)[bezierPathArr
> >>> objectAtIndex:secondSelectedBezierPath] bounds];
> >>>
> >>> [bl moveToPoint:NSMakePoint(rect1.origin.x+30,rect1.origin.y
> >>> +30)];
> >>> [bl lineToPoint:NSMakePoint(rect2.origin.x+30,rect2.origin.y
> >>> +30)];
> >>>
> >>>
> >> [bl stroke]; // you forget to draw the path.
> >>
> >>> }
> >>> }
> >>>
> >>>
> >> HTH,
> >> James
> >>
> >>
> >
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden