Another cairo problem: transferring data between gtk drawing area and backup cairo surface
by hazel from LinuxQuestions.org on (#6KPA8)
So I have managed to draw all the musical glyphs that I need (except for crotchet rest, which still looks all wrong). Now I have a more fundamental problem.
The way pmwScribe works is that you pin glyphs on a musical stave which is actually a gtk drawing area. This has a backing pixbuf on which the actual drawing is done by the appropriate glyph subroutine. The rectangular area that is to contain the glyph is then refreshed from the pixbuf so that the glyphs become visible to the user. At the same time, the corresponding pmw code is written into the .pmw text file that will generate the score when processed by Philp's Music Writer.
In the old (GTK2) version of this program, the backup was a GdkPixbuf. With GTK3, you have to do it with a cairo surface. I can create such a surface with the properties of the widget's window by using gdk_window_create_similar_surface(). And I can create a cairo context for this surface and write my glyphs using it (I don't actually know if all that works ;) but the individual bits of drawing code do work and the whole thing compiles).
But no amount of poring over cairo manuals has yet explained to me how to do the transfers from that surface to the window. It surely has to involve some kind of expose event/draw signal handler containing a cairo_paint() operation, but I can't find simple code for painting from an offscreen cairo surface onto a window.
The way pmwScribe works is that you pin glyphs on a musical stave which is actually a gtk drawing area. This has a backing pixbuf on which the actual drawing is done by the appropriate glyph subroutine. The rectangular area that is to contain the glyph is then refreshed from the pixbuf so that the glyphs become visible to the user. At the same time, the corresponding pmw code is written into the .pmw text file that will generate the score when processed by Philp's Music Writer.
In the old (GTK2) version of this program, the backup was a GdkPixbuf. With GTK3, you have to do it with a cairo surface. I can create such a surface with the properties of the widget's window by using gdk_window_create_similar_surface(). And I can create a cairo context for this surface and write my glyphs using it (I don't actually know if all that works ;) but the individual bits of drawing code do work and the whole thing compiles).
But no amount of poring over cairo manuals has yet explained to me how to do the transfers from that surface to the window. It surely has to involve some kind of expose event/draw signal handler containing a cairo_paint() operation, but I can't find simple code for painting from an offscreen cairo surface onto a window.