Re: Drawing in a Widget



If I change the program to the following and let's see GdkGCValues *values
by using gdb, the reason then is obvious!
line_width = 0 ..............

#include <gtk/gtk.h>

int main(int argc, char **argv)
{
        GtkWidget *window;
        GdkGC *gc;
        GdkGCValues *values;

       values=g_malloc(sizeof(GdkGCValues ));
        gc=g_malloc(sizeof(GdkGC));
        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_usize(window, 100, 100);
        gtk_widget_realize(window);

        gc=(window->style->fg_gc[GTK_WIDGET_STATE(window)]);
        gdk_gc_get_values               (gc,values);

        gdk_draw_rectangle(window->window, window->style->fg_gc[GTK_WIDGET_STATE(window)], 1, 1, 1, 20, 20);

        gtk_widget_show(window);

        gtk_main();



15              gtk_widget_realize(window);
(gdb)
17              gc=(window->style->fg_gc[GTK_WIDGET_STATE(window)]);
(gdb) print gc
$1 = (GdkGC *) 0x8049e20
(gdb) print *gc
$2 = {dummy_var = 0}
(gdb) n
18              gdk_gc_get_values               (gc,values);
(gdb) n
20              gdk_draw_rectangle(window->window, window->style->fg_gc[GTK_WIDGET_STATE(window)], 1, 1, 1, 20,
20);
(gdb) print values
$3 = (GdkGCValues *) 0x8049dc0
(gdb) print *values
$4 = {foreground = {pixel = 0, red = 0, green = 0, blue = 0}, background = {pixel = 1, red = 0, green = 0, blue =
0},
  font = 0x806c3e8, function = GDK_COPY, fill = GDK_SOLID, tile = 0x0, stipple = 0x0, clip_mask = 0x0,
  subwindow_mode = GDK_CLIP_BY_CHILDREN, ts_x_origin = 0, ts_y_origin = 0, clip_x_origin = 0, clip_y_origin = 0,
  graphics_exposures = 0, line_width = 0, line_style = GDK_LINE_SOLID, cap_style = GDK_CAP_BUTT,
  join_style = GDK_JOIN_MITER}
(gdb)


Havoc Pennington wrote:

> Fabiano Fantini Vitale <ffv@conectiva.com.br> writes:
> >
> > i like to known why doesn`t appear a rectangle inside
> > the widget window  in the follow small code .
> >
> > #include <gtk/gtk.h>
> >
> > int main(int argc, char **argv)
> > {
> >         GtkWidget *window;
> >
> >         gtk_init(&argc, &argv);
> >
> >         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> >         gtk_widget_set_usize(window, 100, 100);
> >         gtk_widget_realize(window);
> >
> >         gdk_draw_rectangle(window->window, window->style->fg_gc[GTK_WIDGET_STATE(window)], 1, 1, 1, 20, 20);
> >
>
> Read the "scribble" example in the tutorial. GDK drawables don't remember
> their contents; you have to refresh them when you get expose events.
>
> Havoc
>
> _______________________________________________
> gtk-list mailing list
> gtk-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-list





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