Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Spike099

macrumors regular
Original poster
Feb 18, 2007
143
0
Canada
What do you guys think is the best method of implementing drag selection. Basically, the same thing you see when you drag you cursor on the desktop to select icons.

Currently I have an NSView subclass which modifies it's frame according to the NSEvent of a drag operation... However it seems to me that there is a lot of code that could possibly be written already. Any ideas?
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
Having an NSView for the drag rect seems like a flawed design; NSViews aren't designed to be stacked, so whatever you were selecting could possibly show up in front of it. What's the content the user is supposed to be able to select?
 

Spike099

macrumors regular
Original poster
Feb 18, 2007
143
0
Canada
The content are other custom NSView's(look like an icon with an image and label). The icons and selection view are both currently sibling subviews of their super. I was thinking that which ever view is added last would be on top of their siblings. So when a user clicks and drags, a view is added(on top of everything), when the user releases, the view is removed.

Would it be better to just create and track a rect within the superview using drawRect? Instead of sending the mouse events to it's subview?
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
Hm... I think doing it in the superview is probably the best bet. When I implemented drag rects it was in a somewhat simpler system: one custom view, which did all its own drawing.
 

Spike099

macrumors regular
Original poster
Feb 18, 2007
143
0
Canada
Ok, maybe I should have mine do all of it's own drawing too.

If I continue the way I have it now, can I implement layers? So I can send them back and forth? Or is that only possible if everything is draw by the one view.
 

Spike099

macrumors regular
Original poster
Feb 18, 2007
143
0
Canada
I was just reading some apple docs about overusing NSViews... The method I am using right now it said to be inefficient. So, I will use your method Catfish_Man, one NSView doing custom drawings.

Thanks for your help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.