I wrote a widget GtkTransparent that makes your custom shape
widget easily. If you want to get an arc shape widget, you
can write the following:

static gboolean
expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
  cairo_t *cr;

  /* Normally:
  cr = gdk_cairo_create (widget->window);
  cr = gtk_transparent_cairo_create (GTK_TRANSPARENT (widget));

  cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 1.0);
  cairo_move_to (cr, 0, 0);
  cairo_arc (cr, 50, 50, 50, 0, 2 * M_PI);
  cairo_fill (cr);

  return FALSE;

= How to use?

You need a new cairo surface. The surface is
cairo-combined-surface. You can get by:

  % cg-clone

And you can install by the following commands:

  % cd cairo
  % ./ --enable-combined
  % make
  % make install

Then you need to get GtkTransparent source by:

  % svn co libgtktransparent

And you need to compile:

  % cd libgtktransparent
  % ./
  % ./configure
  % make

Now, you can try some samples:

  % sample/simple # An arc shape widget
  % sample/dnd    # Three arc shape widgets that are DnD available

= Advantages over GnomeCanvas

  * GtkTransparent handles signals same as other
    widgets. GnomeCanvas widget handles all signal as one
    "event" signal.

  * GtkTransparent makes all shape what you want with
    cairo. GnomeCanvas uses GnomeCanvas related
    widget. cairo is used in normal widgets like
    GtkDrawingArea. So learning cost of GtkTransparent is
    lower than GnomeCanvas.

= Known problems

  * GtkTransparent can't tell invalidated region to
    GdkWindow well.
  * cairo-combined-surface must have many bugs.
  * ...


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