views:

96

answers:

1

I have a Mac Plugin for viewing images. It's originally written in Quickdraw, and I'm trying to move it to Quartz.

My current problem is the origin. In QD, the origin is (sensibly) the upper left corner of the plugin rectangle. In Quartz, it appears to be one screen height below the top of the plugin rectangle (not including firefox buttons, etc). This is effectively somewhere random in the middle of my plugin rectangle.

It also means that I need to know the size of the drawing part of the browser window. I'm sure I can figure out how big a window is, but how do I figure out how much space is taken up by tabs, etc? the Mac doesn't know about those things, does it?

On a related note, does anyone know why Apple decided to put the origin in the lower left? seems kind of dumb to me.

+1  A: 

If you're using NSView, you can create an implementation of the -isFlipped function returning YES which will allow you to draw based on a flipped coordinate system.

Alternatively, if you're not using NSView but are doing raw CoreGraphics drawing, you can modify the CTM like so:

CGContextScaleCTM( context, 1.0, -1.0 );

This comes from this Apple Q&A document.

If you're doing this with a CGContextRef you've been given by something else, you should save the existing CTM first and restore it when you're done:

CGContextSaveGState( context );

// do your stuff here ...

CGContextRestoreGState( context );

Oh, and the origin is in the lower-left because the Quartz rendering system is based on the PDF graphics system, itself based on PostScript, and which has an origin in the lower-left.

Jim Dovey
The scaling thing doesn't really bother me. I can handle things being negative. The problem is that I'm having trouble locking the image to the upper left corner of my plugin-space. Because the origin seems to be the difficult to find, it's hard to translate my image to the correct place when I draw it to the context...
Brian Postow
If you're using flipped view coordinates, then your origin effectively becomes the top-left. Otherwise, it *should* just be a case of lower-left origin of image is plugin view height - image height. The NSMaxY(pluginView.bounds) will give you the y-index of the top edge, so you can use `image.bounds.origin.y = (NSMaxY(pluginView.bounds) - image.size.height);`
Jim Dovey