• 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: Trouble creating drag image from a partial view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble creating drag image from a partial view


  • Subject: Re: Trouble creating drag image from a partial view
  • From: Alastair Houghton <email@hidden>
  • Date: Fri, 7 Dec 2007 10:50:26 +0000

On 7 Dec 2007, at 05:03, Ken Tozier wrote:

Here's the working code for the drag image of the entire view:

- (NSImage *) dragImageWithAlpha:(float) inAlpha
{
NSRect imgFrame = NSMakeRect(0, 0, [self frame].size.width, [self frame].size.height);

// create view bitmap
[self lockFocus];
NSBitmapImageRep * dragBitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect: imgFrame];
[self unlockFocus];

NSImage *resultImage = [[[NSImage alloc] initWithSize: imgFrame.size] autorelease];

[resultImage addRepresentation: dragBitmap];

Up to here you were fine, but then:

	[resultImage lockFocus];
	[resultImage drawAtPoint: NSZeroPoint
			fromRect: imgFrame
			operation: NSCompositeSourceOver
			fraction: inAlpha];
	[resultImage unlockFocus];

What is the above code supposed to do?! You don't need it, and I'm not in the slightest bit surprised that things are getting confused because you're trying to draw an image *into itself*! I'd be very surprised if that's something that NSImage was designed to support.


All you had to do was the -addRepresentation: call.

Anyone see where I'm going wrong?

Well the only reason the first bit of code works (i.e. for the full view), I think, is that imgFrame.origin happens to be NSZeroPoint, so it's copying the image over itself.


I think you'll find that if you delete the code between -lockFocus and -unlockFocus, it will probably work just fine.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Trouble creating drag image from a partial view
      • From: Ken Tozier <email@hidden>
References: 
 >Trouble creating drag image from a partial view (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Notification for mouse-up on NSStepper
  • Next by Date: Re: How to get the word under the mouse pointer?
  • Previous by thread: Trouble creating drag image from a partial view
  • Next by thread: Re: Trouble creating drag image from a partial view
  • Index(es):
    • Date
    • Thread