Update: [cairo] how to interface with an NSWindow (please help!)

Daniel Amelang daniel.amelang at gmail.com
Wed Feb 28 17:23:23 PST 2007

On 2/22/07, Travis Griggs <tgriggs at cincom.com> wrote:
> On Feb 22, 2007, at 0:14, Travis Griggs wrote:
> I'm working on my VisualWorks Smalltalk interface to Cairo. In that
> environment, I have easy access to any NSWindow I open, and the ability to
> send objective-c messages. So what I do is basically:
> 1) fetch the class named NSGraphicsContext
> 2) id nsGC = [NSGraphicsContext graphicsContextWithWindow:
> myNSWindow];
> 3) cgCtx = [nsGC graphicPort];
> 4) cairo_nquartz_surface_create_for_cg_context (cgCtx, 200,
> 200, 1);
> But when I do drawing ops on that surface, nothing happens. :( Am I doing
> this right at all? Or is there a better/different way to do it? Do I need to
> send additional messages to the NSGraphicsContext or to the
> CGGraphicsContext (this is just a struct pointer,right?)?
> I'm using 1.2.6 (I think). I'm confused about the recent sent of messages
> regarding osx apis and stability thereof. Should I upgrade to the new
> snapshots for cairo?
> So, I was wrong. It is doing something. Just not right away. All I have to
> do is hide the window and reexpose it and then it's there! Yay. I've tried
> ending my drawing sequence with a surface flush. But that doesn't have any
> affect. If I use finish, it shows up right away, but of course, none of it
> can be used anymore (have to recreate the cairo objects).

I'm not a Mac guy, but it seems that no one better is paying
attention. Must be the big push to 1.4 that's got everyone busy. So
here I go...bad information is better than no information right? Just
kidding :)

Are you sure that you are drawing in conjuction with an
expose/draw/whatever event? In other words, you say that you can see
the effect of your drawing once you hide the window and re-expose
it...which makes me think that you need to tell the system that you
want to draw on the window. When you want to draw, you should request
a redraw first, wait for the corresponding event/message, then start
drawing. If you just start drawing at anytime, you can get into
trouble. I know Win32 is more forgiving in this respect (if my memory
serves me right), but perhaps OS X isn't.

I'm sorry if you know all this already, I just don't have much to go
by, so I'm being safe by over-explaining.

Oh, and about having to re-create the cairo objects...which objects do
you expect to not have to re-create? I can think of at least one type
of cairo object that is expected to be re-created each time.


More information about the cairo mailing list