Making Tiger Look Pretty in Drag

  • List:

      I'm sure a number of you have wondered the same thing (because I see
    many unanswered instances of this issue in the archives):

    1 - How can you change a drag image, mid-drag, in response to
    arbitrary modifier flag changes and possibly other events?
    2 - Is it possible to animate the drag image as in Dashboard's
    drag-from-dock action?

      Searching the archives and the web at large gives me very little
    hope of any supported way to achieve this without some nasty code.
    There is an answer in the archives (
    www.cocoabuilder.com/archive/message/cocoa/2006/11/29/175207 ) which
    suggests you can replace the image in the dragging info. Unfortunately
    it doesn't say how and the documentation suggests you cannot.

      While researching the animating part, I found this:
    www.cocoadev.com/index.pl?AnimatingDragImages which reveals yet
    another unsolved problem. A suggested solution ( overriding
    -draggedImage:movedTo: and changing the image ) does not work either.
    The last modification was in '05 and the project depicted on the page
    does not currently seem to implement this feature (I just checked).

      Can we solve this, please? I mean, seriously ... ;-) If I've missed
    something fundamental here, God how I'd love someone to embarrass me
    publicly with a simple solution. :-)

      I'm coming to the conclusion that the suggestion on the
    above-mentioned wiki page is still the right one for one's own apps
    (despite the last suggestion on the page to the contrary). I'm
    thinking of the following:

    1 - Returning an empty image (returning nil upsets Cocoa).
    2 - Implementing -draggedImage:began/movedTo/ended... to message my
    Pretty Drag mechanism and update it.
    3 - Respond (via my Pretty Drag mechanism) to these update messages by
    positioning a transparent window with a view that renders my animation
    any damned way I please.

      Anyone got a problem with that? ;-)

    --
    I.S.
  • Hi,

    On 15 Oct 2007, at 20:56, I. Savant wrote:
    > 1 - How can you change a drag image, mid-drag, in response to
    > arbitrary modifier flag changes and possibly other events?
    > 2 - Is it possible to animate the drag image as in Dashboard's
    > drag-from-dock action?
    > Searching the archives and the web at large gives me very little
    > hope of any supported way to achieve this without some nasty code.

    I wanted to do this second option - animating the drag-from-dock
    action - and arrived at the same conclusion after searching the
    archives and web.

    > I'm thinking of the following:
    >
    > 1 - Returning an empty image (returning nil upsets Cocoa).
    > 2 - Implementing -draggedImage:began/movedTo/ended... to message my
    > Pretty Drag mechanism and update it.
    > 3 - Respond (via my Pretty Drag mechanism) to these update messages by
    > positioning a transparent window with a view that renders my animation
    > any damned way I please.
    >
    > Anyone got a problem with that? ;-)

    No problem at all - that's pretty much the approach I took. :-)

    1. Created a window controller to manage the overlay window, and
    passed in two images: one for the small icon representation, the
    second for the larger representation. Initiate the drag as normal with
    -dragImage:at:offset:event:pasteboard:source:slideBack with an empty
    image to keep things happy.

    2. In -draggedImage:movedTo: reposition the overlay window to the new
    position; if the position was outside the dock region get the window
    controller to swap representations.

    3. In response to a request to swap representations, I used
    NSViewAnimation to cross fade between two views containing the
    required images.

    The tricky parts that seemed to cause problems (for me at least!) were
    the level of the overlay window - NSFloatingWindowLevel caused me to
    have problems with the drag not being registered in destination views,
    but higher levels worked. Also the slideback action doesn't work if
    you're just moving the overlay window in response to -
    draggedImage:movedTo:.

    I also found it easier to keep the overlay window at the maximum size
    necessary for both images rather than attempting to scale it during
    the cross-fade - it seemed to judder more than I would have liked.

    I'd be happy to share the code but not just yet - it contains some
    Leopard-specific code (though it should be easy to convert for use on
    Tiger), and it needs a bit of cleaning up.

    David

    David Masters, Captain of the CocoaCheerleaders :-)
    <david...>

    Web:     Blog: <A href="http://blog.cocoacheerleaders.com">http://blog.cocoacheerleaders.com
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today