Re: Transparent Draw Area



Hi,

for now I do it:

Change the window expose event:

static gboolean
window_expose_event (GtkWidget      *widget,
                    GdkEventExpose *event)
{
 GdkRegion *region;
 GtkWidget *child;
 cairo_t *cr;

 /* get our child (in this case, the draw area) */
 child = gtk_bin_get_child (GTK_BIN (widget));

 /* create a cairo context to draw to the window */
 cr = gdk_cairo_create (widget->window);

 /* the source data is the (composited) event box */
 gdk_cairo_set_source_pixmap (cr, child->window,
                              child->allocation.x,
                              child->allocation.y);

 /* draw no more than our expose event intersects our child */
 region = gdk_region_rectangle (&child->allocation);
 gdk_region_intersect (region, event->region);
 gdk_cairo_region (cr, region);
 cairo_clip (cr);

 /* composite, with a 50% opacity */
 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 cairo_paint_with_alpha (cr, 1);

 /* we're done */
 cairo_destroy (cr);

 return FALSE;
}

To take the region of the child.

And in the event of the draw area do it:
static gboolean
on_expose_event(GtkWidget *widget,
   GdkEventExpose *event,
   gpointer data)
{
       struct GraphConf *conf = (struct GraphConf *)data;
       cairo_t *cr;
       cairo_pattern_t *pat1, *pat2, *pat3, *pat4;

       cr = gdk_cairo_create(widget->window);
       cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
       gdk_cairo_region (cr, event->region);
...

Then write what do you want...


And initialize all like this:
My window background is a castle. I can see the cairo graph
over a castle.

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_style(GTK_WIDGET(window), GTK_STYLE(style));

 darea = gtk_drawing_area_new();
 screen = gtk_widget_get_screen(darea);
 rgba = gdk_screen_get_rgba_colormap(screen);
 gtk_widget_set_colormap(darea, rgba);
 gtk_widget_set_app_paintable (GTK_WIDGET (darea), TRUE);

 gtk_container_add(GTK_CONTAINER (window), darea);
 gtk_widget_show(darea);

 init_graph_conf(&gconf);

 g_signal_connect(window, "destroy",
     G_CALLBACK(gtk_main_quit), NULL);

 g_signal_connect(darea, "expose-event",
     G_CALLBACK(on_expose_event), &gconf);

 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
 gtk_window_set_default_size(GTK_WINDOW(window), 320, 400);

 gtk_window_set_title(GTK_WINDOW(window), "Temperature");
 gtk_widget_show_all(window);

 gdk_window_set_composited (darea->window, TRUE);

 g_signal_connect_after(window, "expose-event",
     G_CALLBACK(window_expose_event), NULL);



Thomas Dybdahl Ahle wrote:
You can not make widgets transparent, other than to the other
windows/desktop. Thus in your case, you need to create a new gtk.Window,
and lay it over the rest of your app. You use the POPUP flag to remove
the window-border and some
set_colormap(self.get_screen().get_rgba_colormap())
If you read python, you can look in the beginning of:
http://code.google.com/p/pychess/source/browse/trunk/lib/pychess/widgets/pydock/OverlayWindow.py

fre, 26 09 2008 kl. 13:41 +0200, skrev michael:
Hi all,

I want to create a transparent draw area and using cairo to draw line
with the window background.
My backed is directfb and I don't know if it is supported. I want to
start with an example working on X.

Is there somenthing attribute or function to do this?

Regards Michael



_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

I have a sample like this :)



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