=?UTF-8?Q?goo=5Fcanvas=5Fpolyline=5Fnew=5Fline=20dynamic=20move?=



Hi,

I have two item "connected" with a goo_canvas_polyline_new_line and I want
it to follow when moving one of the two connected item.

I have tried multiple signals but it doesn't work.

(I will have multiple connected item in the future, item1 <--- polyline --
item2 --- polyline --> item3).

Any idea for that case ?

Thanks in advance.


Code :


static gboolean
on_motion_notify(GooCanvasItem *item, GooCanvasItem *target,
GdkEventMotion *event, gpointer data)
{
	GooCanvasItem *tmp;
	if (dragging && (event->state & GDK_BUTTON1_MASK)) {
		double new_x = event->x;
		double new_y = event->y;
		goo_canvas_item_translate(item, new_x - drag_x, new_y - drag_y);
		tmp = goo_canvas_item_get_child(item, 10);
		if (tmp != NULL) {
			printf("parent move\n");
		}
		else {
			tmp = goo_canvas_item_get_child(item, 20);
			if (tmp != NULL)
				printf("child move\n");
		}
	}

	return TRUE;
}

static gboolean
on_button_press(GooCanvasItem *item, GooCanvasItem *target, GdkEventButton
*event, gpointer data)
{
	GooCanvas *canvas;
	GdkCursor *fleur;


	canvas = goo_canvas_item_get_canvas (item);

	switch (event->button) {
		case 1:
			if (event->state & GDK_SHIFT_MASK)
				goo_canvas_item_remove (item);
			else {
				drag_x = event->x;
				drag_y = event->y;
				fleur = gdk_cursor_new(GDK_FLEUR);
				goo_canvas_pointer_grab(canvas, item,
					   GDK_POINTER_MOTION_MASK | 
					   GDK_POINTER_MOTION_HINT_MASK | 
					   GDK_BUTTON_RELEASE_MASK,
					   fleur,
					   event->time);
				gdk_cursor_unref (fleur);
				dragging = TRUE;
			}
		break;
		
		case 3:
			popup_menu_(event);


		default:
		break;
	}

	return TRUE;
}


static gboolean
on_button_release(GooCanvasItem *item, GooCanvasItem *target,
GdkEventButton *event, gpointer data)
{
	GooCanvas *canvas;

	canvas = goo_canvas_item_get_canvas(item);
	goo_canvas_pointer_ungrab (canvas, item, event->time);
	dragging = FALSE;
	return TRUE;
}

static void
setup_item(GooCanvasItem *item)
{
	g_signal_connect (item, "motion_notify_event",
	    G_CALLBACK (on_motion_notify), NULL);
	g_signal_connect (item, "button_press_event",
	    G_CALLBACK (on_button_press), NULL);
	g_signal_connect (item, "button_release_event",
	    G_CALLBACK (on_button_release), NULL);
}



GooCanvasItem * 
canvas_add_item(GooCanvas *canvas, gdouble x, gdouble y, char *file)
{
	GooCanvasItem *root, *item;
	GdkPixbuf * image;
	
	image = gdk_pixbuf_new_from_file(file, NULL);

	root = goo_canvas_get_root_item(canvas);
	item = goo_canvas_image_new(root, image, x, y, NULL);
	setup_item(item);
	
	return item;
}

GooCanvasItem *  
canvas_connect_item(GooCanvas *canvas, GooCanvasItem *parent,
GooCanvasItem *child) 
{
	GooCanvasItem *root, *item;
	GooCanvasBounds parent_bounds, child_bounds;
	
	goo_canvas_item_get_bounds(parent, &parent_bounds);
	goo_canvas_item_get_bounds(child, &child_bounds);
	
	root = goo_canvas_get_root_item(canvas);
	item = goo_canvas_polyline_new_line(root, parent_bounds.x2,
parent_bounds.y2, 
		child_bounds.x1, child_bounds.y1, "end-arrow", TRUE, NULL);
	
	return item;
} 


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