views:

155

answers:

2

Here is what I'm trying to accomplish: I'm working on an open source TI calculator emulator where I'm currently trying to add skin support. The skin image is just an NSImageView with its image set to the skin image. I override the mouseDown: method and get the location of the mouse in the NSImageView coordinates using convertPointFromBase: with locationInWindow return value as the point to convert.

I then grab the underlying NSBitmapImageRep from the NSImageView using bestRepresentationForDevice: with a nil argument. Finally I call getPixel:atX:y on the NSBitmapImageRep with point.x and point.y for the location.

However, the origin of the NSImageView begins in the bottom left (as usual), whereas the coordinates for the NSBitmapImageRep begin in the top left. I can't seem to find an obvious way to compensate for this, so the hit testing for button clicks doesn't function properly. Any help is greatly appreciated.

A: 

Seems pretty easy to me, just calculate the y coordinate based on the height of the rect:

NSPoint pointInFlippedRect(NSPoint inPoint, NSRect aRect)
{
    return NSMakePoint(inPoint.x , NSHeight(aRect) - inPoint.y);
}
Rob Keniger
A: 

I never considered overriding isFlipped to return YES in my NSImageView subclass. That takes care of the problem.

Please mark this question as "answered" using Keniger's answer so it doesn't clutter the list of unanswered questions.
Dustin Voss