Update: [cairo] how to interface with an NSWindow (please help!)
tgriggs at cincom.com
Wed Feb 28 18:21:58 PST 2007
On Feb 28, 2007, at 17:23, Daniel Amelang wrote:
> 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:
>> 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
>> 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.
No, no. I'm quite clueless about how it works. So be as pedantic as
you want. It may be that I'm competing with something the nominal VW
engine is doing to manage it's NSWindows.
My experience so far has been that with a Win32 surface, I just get
an HDC and go to town. Drawing draws. Same with the xlib windows. In
fact, I have to take steps to get a sort of "all at once" buffering
affect. But I have a warped version of the opposite right now for
OSX. I get the NSWindow. Create an NSGraphicsContext. And then grab
it's GraphicsPort. Maybe there's some messages I need to send to
NSGraphicsContext that I create during the lifecycle? You're not
saying that I should have to send some sort Cocoa "sync" after each
Cairo draw are you?
> 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.
Well what I meant was... once I send finish() to the surface, it
seems to not be usable anymore. Which makes sense. It's done. So I'd
have to constantly create a surface, draw, and finish to see stuff
"You A students, you'll be back soon teaching here with me. You B
students, you'll actually go on to be real engineers. You C students,
you'll go into management and tell the A and B students what to do."
- My Fluid Dynamics Professor whom I have yet to disprove
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo