Re: Drag image of NSView
Re: Drag image of NSView
- Subject: Re: Drag image of NSView
- From: Ken Tozier <email@hidden>
- Date: Sat, 15 Oct 2005 00:09:28 -0400
Thanks John and Ryan.
Ryan,
What representation type are you setting in the following pboard
setup line? Tiff like this?
[pboard setData: [image TIFFRepresentation] forType: NSTIFFPboardType];
Or something else?
Thanks
Ken
On Oct 14, 2005, at 11:55 PM, Ryan Britton wrote:
I use something like this to grab a view as an image for dragging.
This is in the - (void)mouseDragged:(NSEvent *)theEvent method for
my NSView subclass. This view is a container for a number of other
entry views that can be reordered.
if (!startedDrag)
{
/* other code - Sets "entry" which is the subview of this
view I want an image for */
[entry lockFocus];
bitmap = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:
[entry bounds]] autorelease];;
[entry unlockFocus];
image = [[[NSImage alloc] initWithSize:[entry bounds].size]
autorelease];
[image addRepresentation:bitmap];
/* set up the dragging pasteboard */
startedDrag = YES;
[self dragImage:image at:NSMakePoint(NSMinX([entry frame]),
NSMaxY([entry frame])) offset:NSMakeSize(0.0, 0.0)
event:lastMouseDown pasteboard:draggingPasteboard source:self
slideBack:YES];
}
On Oct 14, 2005, at 8:35 PM, John Pannell wrote:
Hi Ken-
The example code (assuming you pulled this from the NSView docs)
only addresses the case where the object being dragged is an
actual image (i.e. the contents of an NSImageView or cell). There
is no method on NSView that will return an image looking like the
view.
Actually, if you are Tiger only, NSView has a method
(bitmapImageRepForCachingDisplayInRect:) that would fit the bill -
you could pass the rect for the whole view and then construct an
NSImage from the NSBitmapImageRep returned.
Note that this would send the message that the user is dragging
the entire view somewhere, which is not appropriate for frequently
used compound views (NSMatrix, NSTableView, etc.) A more common
pattern would have users dragging the data represented by a cell
of one of these views, and cells with images have methods to pull
the image from them. Not knowing your specific situation, I can't
comment much further.
I just got done implementing drag and drop in my app, feel free to
mail off-list with more specifics if you would like and I'd be
happy to assist if I can.
HTH!
John
John Pannell
Positive Spin Media
http://www.positivespinmedia.com
On Oct 14, 2005, at 8:59 PM, Ken Tozier wrote:
I'm sure this is an easy one but the Apple Drag and Drop info
located here "http://developer.apple.com/documentation/Cocoa/
Conceptual/DragandDrop/index.html?http://developer.apple.com/
documentation/Cocoa/Conceptual/DragandDrop/DragandDrop.html"
gives no indication of how to actually create a transparent
snapshot of an NSView for use as a drag image.
The documentation for NSView's
dragImage:at:offset:event:pasteboard:source:slideBack: method
shows the following snippet for getting the image
[pboard setData:[[self image] TIFFRepresentation]
forType:NSTIFFPboardType];
[self dragImage:[self image] at:[self imageLocation]
offset:dragOffset event:theEvent pasteboard:pboard source:self
slideBack:YES];
Problem is though, NSView has no "image" method. Nor do it's
superclasses "NSResponder" or "NSObject" so where are they
getting the image? Is this some deprecated method of NSView?
Anyway. If there is some better documentation around or if
someone could provide a simple code snippet of how to get a
transparent image of a view for a drag icon, it would be much
appreciated
Thanks for any help
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40positivespinmedia.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden