Monday, October 3, 2011

no go

I burned a lot of time over the weekend on the Cairo/GTK problem.

My assumption was that putting a Cairo-drawable window in a GTK window would be like initializing and attaching any other widget (like a button, form, text box, etc). The examples and tutorials I could find only did this very simply - it initialized a main GTK window and then put the Cairo window in that. What I wanted to do was not much more complex - I wanted a button in addition to the Cairo window. What I figured would happen is I could have a main Window, embed a VBox which is a container that holds other widgets in a vertical arrangement, and then embed the button and Cairo window into that. What emerged however is that there is no Cairo window. You have to have a different container (unknown) and then somehow set it as drawable (unknown) and hook a callback for doing the drawing with the "expose-event" (why?). Every example had all the drawing functions in the "expose-event" callback - what if I wanted to alter the drawing when I press a button? Do I have to artificially kick that event from the point of view of the drawable window?

I came to the conclusion late Sunday that this was too much work, not well documented, and nobody online has written up a detailed next-step tutorial for practical applications of Cairo in a GTK program.

But THEN I remembered something - I'm using GTK2 because that's what Ubuntu 10.10 supports out of the box. GTK3 changed up how it interacts with Cairo. My brief investigation revealed that the way GTK2 initialized and updated Cairo-based windows completely changed in GTK3. Not only is everything I painfully learned all wrong now, it also doesn't seem to be as painful to do.

So that's how I wasted a weekend where I had more free time than usual on a wild obsolete goose chase. I don't know if trying again next weekend is worth it - there are no tutorials that I can find online for GTK3 and Cairo, and too much of the official documentation assumes that you knew how the old system works. Lots of "instead of doing it like this, do this", but not knowing how the first way of doing it worked is crippling.

I also discovered that the relationship with GTK and GDK is not what I thought it was. I had assumed GTK was the GUI aspect and GDK was everything else (data types, etc), but I found that GDK is a whole layer of drawing libraries between GTK and X. GLib is the "everything else".

I genuinely took away nothing meaningful from the weekend. It might as well have never happened.

EDIT: I wish I had seen this yesterday: http://zetcode.com/tutorials/gtktutorial/gtkevents/

The "timer" example has exactly what I needed to know. I think the missing info is that there are GDK (not GTK) specific functions for interfacing Cairo drawing functionality with GTK widgets. In the example a GTK drawing area (which I'm sure doesn't exist in GTK3) is embedded in a window - this is in contrast to drawing directly on the window which I didn't want to do.

No comments:

Post a Comment