Re: Dragging Rect
Re: Dragging Rect
- Subject: Re: Dragging Rect
- From: John Haney <email@hidden>
- Date: Wed, 11 Jun 2003 09:59:25 -0700 (PDT)
Lorenzo,
Calling [super drawRect:] doesn't draw the subviews.
That is managed at a different level.
Instead, you may want to have a separate view for just
the dragging rect which sits on top of all the other
objects the user is selecting. That way, this view
will indeed be called last, since it's on top.
- John Haney
http://www.johnhaney.com/
--- Lorenzo <email@hidden> wrote:
>
Hi,
>
I would like to draw a typical rectangle while I am
>
selecting objects in my
>
view by dragging the mouse.
>
I did that, but the rectangle has been drawn under
>
the objects, instead I
>
would like to draw the rectangle *over* the objects.
>
I did this in my subclassed NSView class.
>
>
In the drawRect method, I told the view to draw the
>
objects first using
>
[super drawRect:rect], then the rectangle using
>
NSFrameRect(dragRect).
>
So, where is my error?
>
>
>
/////////////////////////////////////
>
- (void)mouseDown:(NSEvent*)theEvent
>
{
>
initialLocation = [self convertPoint:[theEvent
>
locationInWindow]
>
fromView:nil];
>
}
>
>
>
/////////////////////////////////////
>
- (void)mouseDragged:(NSEvent *)theEvent
>
{
>
isDragging = YES;
>
>
currentLocation = [self convertPoint:[theEvent
>
locationInWindow]
>
fromView:nil];
>
dragRect = MYRectFromPoints(initialLocation,
>
currentLocation);
>
[self setNeedsDisplayInRect:dragRect];
>
}
>
>
>
/////////////////////////////////////
>
- (void)mouseUp:(NSEvent *)theEvent
>
{
>
isDragging = NO;
>
[self setNeedsDisplayInRect:[self frame]];
>
}
>
>
>
/////////////////////////////////////
>
-(void)drawRect:(NSRect)rect
>
{
>
[backgroundColor set];
>
NSRectFill([self bounds]);
>
[super drawRect:rect];
>
>
if(isDragging){
>
[[NSColor orangeColor] set];
>
NSFrameRect(dragRect);
>
}
>
}
>
>
>
Best Regards
>
--
>
Lorenzo
>
email: email@hidden
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be
ignored.
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.