Drawing lines in a gtk_layout
- From: Jose Fernando Diago <jdiago escher puj edu co>
- To: GTK+ List <gtk-list gnome org>
- Subject: Drawing lines in a gtk_layout
- Date: Fri, 20 Apr 2001 18:28:32 -0500 (COT)
Hello.
I'm actually developing some kind of editor with icons and connections
between them.
I choose the gtk_layout to put my icons because it allows me to put them
in any x,y position and it doesn't need to be redrawn. But now I trying to
draw lines in the layout to connect the icons but the lines never get
drawn. I've also tried with the gtk_fixed and the lines get drawn on it
pretty easy, but it needs to be redrawn.
Anyway has anyone acomplished succesfully the task of drawing lines on a
gtk_layout using gdk_draw_line()?
Here's the code I'm using right now (sorry about the global variables, is
just a test program). Please note, if I comment the line where I create
the layout
drawing = gtk_layout_new (NULL, NULL);
and uncomment the following line
drawing = gtk_fixed_new ();
then things work just fine
Anyway, here is the code:
#include <gtk/gtk.h>
int xini, yini, xfin, yfin;
gboolean bpress_event( GtkWidget *widget, GdkEventButton *event, gpointer
data )
{
printf ("\nbutton press ok");
xini=(int)event->x;
yini=(int)event->y;
return FALSE;
}
gboolean brelease_event( GtkWidget *widget, GdkEventButton *event,
gpointer data)
{
printf ("\nbutton release ok");
xfin=(int)event->x;
yfin=(int)event->y;
gdk_draw_line(widget->window, widget->style->black_gc, xini, yini, xfin,
yfin);
return FALSE;
}
int main(int argc, char **argv)
{
GtkWidget *drawing;
GtkWidget *vbox;
GtkWidget *mainwin;
... stuff
mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
... setting the main window properties and close event, etc...
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(mainwin), vbox);
drawing = gtk_layout_new (NULL, NULL);
// drawing = gtk_fixed_new ();
gtk_box_pack_start(GTK_BOX(vbox), drawing, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT (drawing), "button_press_event",
GTK_SIGNAL_FUNC(bpress_event), NULL);
gtk_signal_connect (GTK_OBJECT (drawing), "button_release_event",
GTK_SIGNAL_FUNC(brelease_event), NULL);
gtk_widget_set_events (drawing, GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK);
/* Let's show the drawing (layout/eventbox) */
gtk_widget_show(drawing);
gtk_widget_show(vbox);
/* Let's show the Main Window */
gtk_widget_show(mainwin);
/* Enter main gtk loop. */
gtk_main();
return(0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]