Dragging Rect
Dragging Rect
- Subject: Dragging Rect
- From: Lorenzo <email@hidden>
- Date: Wed, 11 Jun 2003 16:06:39 +0200
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.