19.12.09, 16:45, "Sebastian Pająk" <spcon...@gmail.com>: > I'm attaching a GtkStyle to my widget's window inside "realize" > callback (like I saw it in gtkbutton.c). So I think there is no need > to do it inside "expose" callback.
Me too -- example was very flat and all-in-one. But if you still get empty window, try moving attaches back into "expose" action and don't set style to widget, just use it directly. More troubleshooting points: http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-set-style http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-get-modifier-style http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-style-set If still empty, try this in expose: cairo_t *cr = gdk_cairo_create(widget->window); cairo_move_to(cr, x, y); cairo_line_rel(cr, width, height); cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width(cr, 5); cairo_stroke(cr); cairo_destroy(cr); If *still* empty, pay attention to GTK_APP_PAINTABLE flag. gtk_widget_set_app_paintable(widget, TRUE); > Essentially all I want now is to draw "something" I can see like > relief/shadow/line, because now I can see no effect of my > gtk_paint_box call. I thought GTK_SHADOW_OUT or IN flag creates this > 3D effect... Am I wrong? > btw. Does GtkStyle uses Cairo for painting? Maybe I will use Cairo if > it's more low-level layer of gtk+. Style engines are not part of Gtk+, but are plugins to which GtkStyle is nothing more than interface. Engine may draw with cairo or other graphics lib, you never know. So "state", "shadow" and "detail" are all just hints -- 3d effect is created by some (i.e. most) engines, not by Gtk+ (but there is default style implementation in Gtk+, afaik). User may select his favorite style engine with "theme selector" application in DE. I'm using clearlooks. gtk_rc_get_style_by_paths() creates proper style for GtkButton, and then you use it directly, this is why it should work, imho. Please correct me, if i'm wrong. Cairo way is pretty simple, but manually created image may not match currently selected theme :( I can post complete example code tomorrow, if you need it. > 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 _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list