Re: Draggable NSImage of custom NSView ???
Re: Draggable NSImage of custom NSView ???
- Subject: Re: Draggable NSImage of custom NSView ???
- From: "John C. Randolph" <email@hidden>
- Date: Thu, 17 Jan 2002 09:44:29 -0800
On Thursday, January 17, 2002, at 06:31 AM, Robert Miller wrote:
>
Hello fellow Cocoans,
>
>
This is probably in the realm of Cocoa 101 but.... I'm trying to
>
obtain a drag image of a custom view and its subviews by first creating
>
an NSImage that is the same size as my custom view, locking
>
focus on the
>
NSImage, and drawing my custom view using its display method ex.
>
>
- (NSImage*) makeMyDragImage
>
{
>
NSImage *dragImg = [[NSImage alloc] initWithSize:[self
>
frame].size];
>
>
[dragImg lockFocus];
>
[self display];
>
[dragImg unlockFocus];
>
return dragImg;
>
}
>
>
of course the image is always empty and nothing gets drawn into it
>
probably because the display call unfocuses the image and focuses
>
'self'.
The image is empty, but focus isn't the problem.
-display doesn't draw anything. What it does is advise the
window that the view in question should get a -drawRect: message
sometime in the very near future. Change the line
[self display];
to
[self drawRect:[self bounds]];
and you should get what you want.
Of course, there's a simpler way, too:
NSImage *dragImage = [[NSImage alloc] initWith
Data:[self
dataWithPDFInsideRect:[self bounds]]];
-jcr
I almost had a psychic girlfriend, but she left me before we
met. -- Steven Wright