Re: drawing a line and a button in a window



hi,

not entirely sure why your program's not working, but this may not matter.
 in any case, a window containing a mix of gtk widgets and the results of
drawing commands is, (correct me where i'm wrong here), not terribly
recommended, me thinks.

i'd say you want a different solution:

1) create a drawing area that will be used to display your diagram
2) as part of the configure event for the drawing area, draw into a pixbuf
everything you require to make your pretty picture (using gdk draw
commands)
3) as part of the expose event, do no drawing, only render the internal
pixbuf you made in step 2 to the screen.  -- DONE

what this means is you have to render your own node (instead of using gtk
make_button calls, but this shouldn't be that much of an issue, no?),
though on the other hand, this gives you complete control over the
drawing/diagram yourself.

richard

> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
>   <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
>   <title></title>
> </head>
> <body bgcolor="#ffffff" text="#000000">
> Hi there,<br>
> <br>
> I've got a problem with drawing a line and a button in a window at the
> same time. When I run the following program I can see the line only and
> no button... Can anybody advise me how display those two items
> simultaneously? My intention is to have a number of buttons displayed
> in the window (those buttons are to represent the nodes in a graph) and
> a mumber of lines among them (those lines are to represent the
> links/connections between the selected pairs of nodes). <br>
> <br>
> I've tried many diffrent things and I'm not sure if this is feasible
> with GTK... <br>
> <br>
> Thanks,<br>
> Michal<br>
> <br>
> <br>
> <small><font face="Courier New, Courier, monospace">#include
> &lt;gtk/gtk.h&gt;<br>
> <br>
> <br>
> gint expose (GtkWidget *widget, GdkEventExpose *event, gpointer data)
> {<br>
>   gdk_draw_line (widget-&gt;window, widget-&gt;style-&gt;black_gc, 100,
> 50, 50, 100);<br>
> }<br>
> <br>
> <br>
> int main (int argc, char **argv) { <br>
>   GtkWidget *window;<br>
>   GtkWidget *button;<br>
>   <br>
>   gtk_init (&amp;argc, &amp;argv);<br>
>   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);<br>
>   button = gtk_button_new_with_label("Button");<br>
>   gtk_container_add(GTK_CONTAINER(window), button);<br>
> <br>
>   gtk_signal_connect (GTK_OBJECT (window), "expose_event",
> GTK_SIGNAL_FUNC (expose), NULL);<br>
>  <br>
>   gtk_widget_show(button);<br>
>   gtk_widget_show (window);<br>
>   <br>
>   gtk_main ();<br>
>   return 0;<br>
> }</font></small><br>
> </body>
> </html>
>
> _______________________________________________
> 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]