Drag Selection

Discussion in 'Mac Programming' started by Spike099, Sep 29, 2007.

  1. Spike099 macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #1
    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?
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    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?
     
  3. Spike099 thread starter macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #3
    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?
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    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.
     
  5. Spike099 thread starter macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #5
    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.
     
  6. Spike099 thread starter macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #6
    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.
     

Share This Page