Re: [gtk-list] Trying to draw in a window
- From: Tim Janik <timj gtk org>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Trying to draw in a window
- Date: Tue, 22 Jun 1999 05:51:40 +0200 (CEST)
On 21 Jun 1999 hubert.fauque@wanadoo.fr wrote:
>
> I am trying to draw in a line in a window; I connect
> a function drawing the line to the expose event, and there
> is the following problem:
> if the window is (partly) behind another window and I click on it
> to bring it in the foreground, only the part of the line that
> was already in the uncovered part of the window appears;
> the other part is immediatly overwritten (by who?);
by gtk, part of a toolkits responsiveness is to redraw exposed regions which
for normal windows will just 'clear' the background. if you want to draw
you own things in such a window, you need to inform gtk about that with the
gtk_widget_set_app_paintable () function.
> #include <gdk/gdk.h>
> #include <gtk/gtk.h>
>
> GdkGC *gc;
> GdkDrawable *ww;
>
> gint expose_event(GtkWidget *widget, GdkEvent *event, gpointer data)
> {
> gdk_draw_line (ww, gc, 10, 20, 100, 20);
rather than using global variables here, i'd suggest you use something like
gdk_draw_line (widget->window,
widget->style->fg_gc[GTK_STATE_NORMAL],
10, 20,
100, 20);
the widget style structure (defined in gtkstyle.h) provides a bunch
of default styles already.
> return FALSE;
> }
>
>
> int main (int argc, char *argv[])
> {
> GtkWidget *w;
> gtk_init (&argc, &argv);
> w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
insert gtk_widget_set_app_paintable (w, TRUE); here
> gtk_widget_show (w);
> ww = w->window;
> gc = gdk_gc_new(ww);
> gtk_signal_connect (GTK_OBJECT(w), "expose_event",
> GTK_SIGNAL_FUNC(expose_event), NULL);
> gdk_draw_line (ww, gc, 10, 20, 100, 20);
you don't need this draw_line call as widgets get automatically
exposed upon initial mapping.
> gtk_main ();
> return 0;
> }
>
> Hubert
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]