• 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: Dragging to select rectangle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dragging to select rectangle


  • Subject: Re: Dragging to select rectangle
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Wed, 3 Sep 2003 23:18:32 +0200

At 17:14 Uhr -0600 02.09.2003, John Nairn wrote:
a. Use mouseDown method and keep control while mouse is down updating current rectangle as needed until mouse is released.

b. Implement drag and drop methods with feedback to connect origin to current position.

AFAIK selection rectangles should be done this way:

1) record the click position at mouseDown
2) record the other click coordinate at mouseDragged
3) setNeedsDisplay on your view
4) change the drawRect method of your view to draw your selection rectangle if you're in selection mode, based on the two recorded coordinates
5) handle the selection rectangle and clear the recorded coordinates and setNeedsDisplay again

As to how to record the coordinates: I usually use an NSRect as a member variable, and a BOOL to indicate whether we're currently selecting or not (so the selection rectangle isn't drawn on regular redraws).

Static variables are bad, as it could cause other views of the same class to accidentally be redrawn with part of a selection rectangle in them.

This may seem a little complicated, but doesn't hog the CPU as a loop in mouseDown will do (which would get you a spinning pizza of death anyway), and doesn't require messing with drag & drop, unless you want to support dragging the selected rectangle.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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.
References: 
 >Dragging to select rectangle (From: John Nairn <email@hidden>)

  • Prev by Date: Re: NSImage from Palm Bitmap?
  • Next by Date: Re: NSImage from Palm Bitmap?
  • Previous by thread: Re: Dragging to select rectangle
  • Next by thread: Re: Dragging to select rectangle
  • Index(es):
    • Date
    • Thread