Re: Re: Re: Re: Re: Getting a Cairo context



Le 26 mars 2015, Emmanuele Bassi a écrit :

What I do in a similar situation is keeping a kind of carbon copy of the
bare drawing:

- get two pixmaps from the drawing area :
  bare_pixmap=gdk_pixmap_new(d_area->window,width,height,-1);
  full_pixmap=gdk_pixmap_new(d_area->window,width,height,-1);

- draw your "background" on bare_pixmap

- when you have to redraw, just copy bare_pixmap to full_pixmap, add stuff
  to full_pixmap, then display it:

  gdk_draw_drawable(full_pixmap,copy_gc,bare_pixmap,0,0,0,0,-1,-1);
  (add stuff to full_pixmap)
  gdk_draw_drawable(d_area->window, copy_gc, full_pixmap, x, y, x, y, width,
height);

Where copy_gc has been defined this way:
  GdkGC *copy_gc=d_area->style->fg_gc[GTK_WIDGET_STATE (d_area)];

This is really GTK+ 2.x only, and even then it's pretty much X11-only.

It works in Windows, cross-compiled in Linux with "mxe" (MinGW cross env).

Pixmaps are really Cairo surfaces, these days, and GCs are Cairo
contexts. The widget state is part of the GtkStyleContext, and the
gtk_render_* API substitute the background rendering. Even for GTK+
2.x API you should not be using gdk_draw_* and GdkGC API at all,
unless your code is supposed to work with GTK+ 2.6.

It is supposed to use the latest GTK+ 2 (2.24 I guess).

I'm eager to read a tutorial on GTK2 programming. I think I never found one, so I'm using the reference manuals, which is a rather tough way to learn indeed. (gtk-demo doesn't have examples of what I need)

Your help is appreciated.

--
Lucas Levrel


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]