• 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: Draggable NSImage of custom NSView ???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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] initWithData:[self
dataWithPDFInsideRect:[self bounds]]];

-jcr

I almost had a psychic girlfriend, but she left me before we
met. -- Steven Wright


References: 
 >Draggable NSImage of custom NSView ??? (From: Robert Miller <email@hidden>)

  • Prev by Date: Re: setting up multiple reps for an image...
  • Next by Date: Re: NSWorkspace File System Methods
  • Previous by thread: Draggable NSImage of custom NSView ???
  • Next by thread: Re: Draggable NSImage of custom NSView ???
  • Index(es):
    • Date
    • Thread