Skip navigation.
 
mlRe: NSView and array of moveable NSImages
FROM : Scott Anguish
DATE : Thu Apr 05 21:49:56 2007

On Apr 5, 2007, at 3:01 PM, Fen Soares wrote:

> Therefore, I have an NSView into which I am drawing an array of 
> NSImages. I
> would like to be able to move them around by dragging the mouse, 
> but feel as
> though extensive mouse and z-index visibility testing is overkill, 
> but after
> a good deal of surfing cannot see an alternative.
>
> Is there a well trodden path to maintaining this sprite-like 
> behaviour in
> Cocoa?


Absolutely.

You have a single view that displays all the items. and you track the 
image rectangles, draw them, and do the hit-testing and dragging 
yourself.

There isn't much extensive to it.  You simply start at the closest 
rectangle and test the bounds against the mouse location.  First hit 
is the one that you drag.

Have a look at the Views Programming Guide for Cocoa. it has an 
example that does just this (although with a single rectangle, but 
that is easy to extend)

Related mailsAuthorDate
mlNSView and array of moveable NSImages Fen Soares Apr 5, 21:01
mlRe: NSView and array of moveable NSImages Scott Anguish Apr 5, 21:49
mlRe: NSView and array of moveable NSImages I. Savant Apr 5, 22:01
mlRe: NSView and array of moveable NSImages Scott Anguish Apr 5, 22:07
mlRe: NSView and array of moveable NSImages Scott Anguish Apr 5, 22:10
mlRe: NSView and array of moveable NSImages Michael Watson Apr 5, 22:13
mlRe: NSView and array of moveable NSImages Michael Watson Apr 5, 22:14
mlRe: NSView and array of moveable NSImages I. Savant Apr 5, 22:16
mlRe: NSView and array of moveable NSImages Fen Soares Apr 6, 10:10