Re: Why "GtkWidget->window" is "NULL" when "gtk_window_new()"



On Tue, 2008-08-12 at 22:24 +0800, Wu Yin wrote:
> So your mean is all the drawing action must be done through the
> "expose-event", isn't it ?

yes.

> And what is the "Cairo API"? Is it the GTK+'s official api in the
> <gtk/gtk.h>?

you should read:

  http://cairographics.org
  http://library.gnome.org/devel/gdk/unstable/gdk-Cairo-Interaction.html

  "Cairo is a graphics library that supports vector graphics and image  
   compositing that can be used with GDK. Since 2.8, GTK+ does most of
   its drawing using Cairo."

ciao,
 Emmanuele.

> On Tue, Aug 12, 2008 at 6:48 PM, Emmanuele Bassi <ebassi gmail com>
> wrote:
>         On Tue, 2008-08-12 at 18:24 +0800, Wu Yin wrote:
>         > Thanks very much. But I have Another question:
>         > I want to draw line on my own initiative, don't use
>         "expose-event" and callback function.
>         
>         
>         why not? that's how you do what you want to do.
>         
>         > Like the following code, but the code can't do what I want.
>         
>         
>         because it's not how you do what you want to do.
>         
>         > Please tell me how to do this?
>         >
>         >
>         > Code:
>         >
>         +-------------------------------------------------------------------------------------
>         > |     int main(int argc, char *argv[])
>         > |     {
>         > |             GtkWidget *w;
>         > |
>         > |             gtk_init(&argc, &argv);
>         > |
>         > |             w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>         > |             g_signal_connect(GTK_OBJECT(w), "destroy",
>         G_CALLBACK(gtk_main_quit), NULL);
>         
>         
>         don't cast to GTK_OBJECT: it's a useless type check, and
>         g_signal_connect() takes a gpointer as the first argument.
>         
>         > |             gtk_widget_realize(w);
>         > |             gdk_draw_line(w->window,
>         w->style->fg_gc[GTK_WIDGET_STATE(w)],
>         > |                             0, 0, 120, 120);
>         
>         
>         don't use gdk_draw_* API: it's long deprecated (gtk+ 2.8
>         deprecated that
>         family of functions).
>         
>         connect to the ::expose-event signal, get the cairo context
>         from the
>         GdkWindow and use the Cairo API to draw:
>         
>          static gboolean
>          my_expose_event (GtkWidget *widget, GdkEvent *event, gpointer
>         data)
>          {
>            cairo_t *cr = gdk_cairo_create (GDK_DRAWABLE
>         (widget->window));
>            GdkColor color;
>         
>            color = w->style->fg[GTK_WIDGET_STATE (widget)]
>         
>            cairo_move_to (cr, 0, 0);
>            cairo_line_to (cr, 120, 120);
>            gdk_cairo_set_source_color (cr, &color);
>         
>            cairo_stroke (cr);
>         
>            cairo_destroy (cr);
>         
>            return FALSE;
>          }
>         
>         [WARNING: untested code, written from memory - use the Cairo
>         API
>         reference to check the functions]
>         
>         
>         ciao,
>          Emmanuele.
>         
>         --
>         Emmanuele Bassi,
>         W: http://www.emmanuelebassi.net
>         B: http://log.emmanuelebassi.net
>         
>         _______________________________________________
>         gtk-list mailing list
>         gtk-list gnome org
>         http://mail.gnome.org/mailman/listinfo/gtk-list
>         
> 
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
-- 
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net



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