Re: Custom widget painting with GtkStyle



Cairo drowing works fine.

I saw in gtkstyle.c that gtk_paint_box just sets background and draws
shadow. Now, if I paint shadow directly instead of box (with
gtk_paint_shadow) it works! Strange. I need to read more about these
engines/themes and try gtk_rc_* func as you suggested.

I can post complete example code tomorrow, if you need it.

Yes, please. Thanks

Sebastian
2009/12/19 Artur Galyamov :
Hi, Sebastian!

static gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event)
{
 Âstatic GtkStyle *style = NULL;

 Âint x = widget->allocation.x;
 Âint y = widget->allocation.y;
 Âint width = widget->allocation.width;
 Âint height = widget->allocation.height;

 Âif (!style)
   Â// key phrase:
   Âstyle = gtk_rc_get_style_by_paths(gtk_settings_get_default(), NULL,
     Â"GtkButton", GTK_TYPE_BUTTON);

 Âgtk_style_attach(style, widget->window);

 Âgtk_paint_box(style, widget->window,
   ÂGTK_STATE_NORMAL,
   ÂGTK_SHADOW_OUT, &event->area,
   Âwidget, "button",
   Âx, y, width, height);

 Âgtk_style_detach(style);
 Âreturn FALSE;
}

Style engine may or may not heavily depend on widget's class or even
properties, so don't expect exact emulation for all classes on all
engines. I think it is why things are not documented.

See $SRC/gtk/gtkbutton.c on how to paint button's focus, default, etc
exactly as GtkButton does.

--
Artur

19.12.09, 14:09, "Sebastian PajÄk" :

Hi
I'm trying to create a shape for my custom widget using GtkStyle
(gtk_paint func. family). For a start I want a shape like a button has
(shadow + relief). This is my code for expose event:
static int
clv_expose(GtkWidget *widget, GdkEventExpose *event) // clv is a
subclass of GtkConainer
{
  int x = widget->allocation.x;
  int y = widget->allocation.y;
  int width = widget->allocation.width;
  int height = widget->allocation.height;
  gtk_paint_box(widget->style, widget->window,
         GTK_STATE_NORMAL,
         GTK_SHADOW_IN, &event->area,
         widget, "button",
         x+4, y+4, width-8, height-8);
  std::printf("EXPOSE");
  return FALSE;
}
clv_expose is connected and is called. Unfortunately it doesn't work.
Only empty, flat window is showing, no shadow like in a button. Do you
know what can be wrong? Is GtkConainer good for sublassing in this
situation?
I cannot find any info on gtk/gdk drawing using google (only cairo).
Gtk API reference is very poor abou it. Some hints, simple exmples or
howtos will be helpful for a GTK+ beginner like me :).
Thanks in advance
Sebastian
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


--
Artur




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