Re: Dragging Rect
Re: Dragging Rect
- Subject: Re: Dragging Rect
- From: John Haney <email@hidden>
- Date: Wed, 11 Jun 2003 10:23:17 -0700 (PDT)
Lorenzo,
Good point... how about this instead:
override -display instead. You may need to lockFocus,
draw your rect, then unlockFocus after calling [super
display].
From the Apple docs...
- (void)display
Displays the receiver and all its subviews if
possible, invoking each NSView's lockFocus, drawRect:,
and unlockFocus methods as necessary. ...
- John Haney
http://www.johnhaney.com/
--- Lorenzo <email@hidden> wrote:
>
Hi John,
>
thank you, I understood. In facts when I removed the
>
call
>
[super drawRect:]
>
the obects have been redrawn the same...
>
>
But, don't you think adding a view just for the
>
dragging rect is a heavy
>
task?
>
>
>
Best Regards
>
--
>
Lorenzo
>
email: email@hidden
>
>
> From: John Haney <email@hidden>
>
> Date: Wed, 11 Jun 2003 09:59:25 -0700 (PDT)
>
> To: Lorenzo <email@hidden>,
>
email@hidden
>
> Subject: Re: Dragging Rect
>
>
>
> 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
>
__________________________________
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.