• 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
drag image for multi-cell selection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

drag image for multi-cell selection


  • Subject: drag image for multi-cell selection
  • From: Ken Tozier <email@hidden>
  • Date: Thu, 5 Jul 2007 13:13:18 -0400

Hi

I'm trying to generate a drag image for a multi-cell selection in my custom matrix class and while single cell drag images work fine, I'm apparently doing something wrong while compositing the multi-cell image. Anyone see what I'm doing wrong here?

// create selection drag image
- (NSImage *) selectionImageWithAlpha:(float) inAlpha
{
NSRect imgFrame = [self selectionFrame];
NSImage *resultImage = [[[NSImage alloc] initWithSize: imgFrame.size] autorelease],
*cellImage;

NSEnumerator *enumerator = [selectedCells objectEnumerator];
id cell;

NSRect cellFrame;

[resultImage lockFocus];
while (cell = [enumerator nextObject])
{
cellFrame = [cell frame];
// single cell selections are handled by the cells themselves and, in that situation,
// imageWithAlpha works correctly, so I know "cellImage" is a valid image.
cellImage = [cell imageWithAlpha: 1.0];

// is this the right way to composite images into another image?
[cellImage drawAtPoint: NSMakePoint(cellFrame.origin.x - imgFrame.origin.x, cellFrame.origin.y - imgFrame.origin.y)
fromRect: cellFrame
operation: NSCompositeSourceOver
fraction: inAlpha];
}
[resultImage unlockFocus];

return resultImage;
}


// Calculate frame for the selection
- (NSRect) selectionFrame
{
	NSEnumerator		*enumerator		= [selectedCells objectEnumerator];
	id					cell;
	NSRect				selfFrame		= [self frame],
						cellFrame;

	float				minX			= selfFrame.size.width,
						maxX			= 0,
						minY			= selfFrame.size.height,
						maxY			= 0,
						tempX,
						tempY;

	while (cell = [enumerator nextObject])
	{
		cellFrame		= [cell frame];
		tempX			= cellFrame.origin.x + cellFrame.size.width;
		tempY			= cellFrame.origin.y + cellFrame.size.height;

		if (cellFrame.origin.x < minX)
			minX		= cellFrame.origin.x;

		if (tempX > maxX)
			maxX		= tempX;

		if (cellFrame.origin.y < minY)
			minY		= cellFrame.origin.y;

		if (tempY > maxY)
			maxY		= tempY;
	}

	return NSMakeRect(minX, minY, maxX - minX, maxY - minY);
}

_______________________________________________

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: drag image for multi-cell selection
      • From: Ken Tozier <email@hidden>
  • Prev by Date: Re: Logging to text files
  • Next by Date: Re: Logging to text files
  • Previous by thread: Re: Drag button within bounds of superview.
  • Next by thread: Re: drag image for multi-cell selection
  • Index(es):
    • Date
    • Thread