• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: selection drag within nsview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: selection drag within nsview


  • Subject: Re: selection drag within nsview
  • From: Volker Runkel <email@hidden>
  • Date: Tue, 21 Nov 2006 12:12:48 -0800

Hi Maximilian,


you have to draw the selection rectangle yourself in your drawRect method. There is no predefined method or similiar for it. It might look hard in the beginning to do so, but it gets easier after some experiences!

For example can you monitor mouse events within your views rectangle and draw according to the mouse position. For example I am using the follwoing code to draw a selection rectangle inside a view, after I detected that the mouseEntered my views bounds and as long as the left mouse button is down:

- (void) mouseDown: (NSEvent *) theEvent
{
	BOOL keepOn = YES;
    BOOL isInside = YES;
    NSPoint mouseLoc;
	mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
	isInside = [self mouse:mouseLoc inRect:[self bounds]];
	lastSelectionRect.origin.x = mouseLoc.x;
	lastSelectionRect.size.width=0;
	selStart = ceil(mouseLoc.x*reductionFactor);

    while (keepOn) {
        theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask];
        mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
        isInside = [self mouse:mouseLoc inRect:[self bounds]];

        switch ([theEvent type]) {
            case NSLeftMouseDragged:
				lastSelectionRect.size.width = mouseLoc.x - lastSelectionRect.origin.x;
				selSize = floor(mouseLoc.x*reductionFactor) - selStart;
				[self setNeedsDisplay:YES];
				break;
            case NSLeftMouseUp:
				//if (isInside) [self doSomethingSignificant];
				[self setNeedsDisplay:YES];
				keepOn = NO;
				break;
            default:
				/* Ignore any other kind of event. */
				break;
        }

    };

    return;
}


Inside my drawRect method I draw a sligthly filled rectangle at the appropriate position:

...
if (lastSelectionRect.origin.x > 0) {
	[[NSColor colorWithDeviceRed:0.33 green:0.0 blue:0.0 alpha:0.5] set];
	NSRectFillUsingOperation(lastSelectionRect, NSCompositePlusDarker);
}
...

Volker

---------
Volker Runkel
vrunkel at mac dot com
sent from a Mac :-)
---------


Am 21/11/06 um 20:00 schrieb "maximilian marcoll" <email@hidden>:
>
>hi!
>
>i'm looking for a way to select some custom objects within a nsview
>by dragging,
>using this white rectangular selection frame you also have on the
>desktop etc.
>
>(searching the reference lib didn't bring anything up.)
>
>i'm a cocoa newbie so please forgive me if i'm missing something
>obvious...
>
>any help would be really great!
>
>thank you
>
>max
>
>
>_____________________________________________
>
>m a x i m i l i a n   m a r c o l l
>http://www.maximilianmarcoll.de
>
>d i s . p l a y c e
>http://dis.playce.info
>
>
>
>
> _______________________________________________
>
>Cocoa-dev mailing list      (email@hidden)
>
>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
>
>
 _______________________________________________

Cocoa-dev mailing list      (email@hidden)

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

References: 
 >selection drag within nsview (From: maximilian marcoll <email@hidden>)

  • Prev by Date: Re: External kill of an NSThread?
  • Next by Date: Re: External kill of an NSThread?
  • Previous by thread: selection drag within nsview
  • Next by thread: Re: selection drag within nsview
  • Index(es):
    • Date
    • Thread