see fixed code below

> On Oct 1, 2013, at 10:22 AM, Abdul Sowayan <asowa...@vectorworks.net> wrote:
> 
> Hi folks,
> 
> I have two images, a retina and a non-retina image that I would like to use 
> as a Cursor. I crop the transparency out of the images and combine them into 
> one NSImage that has two representations, a retina and a non-retina one. I 
> then use the combined image to set NSCursor’s image. However, this doesn’t 
> end up displaying a retina Cursor. I’m not sure why that is the case.
> 
> My sample code can be downloaded from:
> https://www.dropbox.com/s/k9lj5pjsn253d43/Cursor.zip
> 
> Any help would be greatly appreciated.
> 
> Thanks,
> Abdul

NSCursor* GetCursorUsingNSImage(NSImage* imageNormal, NSImage* imageRetina, 
float hotSpotX, float hotSpotY)
{
    @autoreleasepool
    {
                NSData*                 lowData = [imageNormal 
TIFFRepresentation];
                NSBitmapImageRep*       lowRep = [NSBitmapImageRep 
imageRepWithData:lowData];

                NSData*                 hiData = [imageRetina 
TIFFRepresentation];
                NSBitmapImageRep*       hiRep = [NSBitmapImageRep 
imageRepWithData:hiData];
                
                //      this is the secret sauce:
                [hiRep setSize: [imageNormal size]];

                NSPoint                 hotSpotPt;

                {
                        NSRect          rectLow = [imageNormal 
cursorImageRectWithHotSpotX:hotSpotX hotSpotY:hotSpotY];
                        
                        hotSpotX = hotSpotX - rectLow.origin.x;
                        hotSpotY = NSMaxY(rectLow) - hotSpotY;
                        
                        hotSpotPt = NSMakePoint(hotSpotX, hotSpotY);
                }

                NSImage*                finalImage = [[NSImage alloc] 
initWithSize:[imageNormal size]];

                //      the order you add them does NOT matter
                [finalImage addRepresentation:lowRep];
                [finalImage addRepresentation:hiRep];

                NSCursor*               cursor = [[NSCursor alloc] 
initWithImage:finalImage hotSpot: hotSpotPt];

                return cursor;
    }
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to