示例#1
0
static void
create_demo_table (GooCanvasItemModel *root,
		   gdouble        x,
		   gdouble        y,
		   gdouble        width,
		   gdouble        height)
{
  GooCanvasItemModel *table, *square, *circle, *triangle;
  GooCanvasItem *item;

  table = goo_canvas_table_model_new (root,
				      "row-spacing", 4.0,
				      "column-spacing", 4.0,
				      "width", width,
				      "height", height,
				      NULL);
  goo_canvas_item_model_translate (table, x, y);

  square = goo_canvas_rect_model_new (table, 0.0, 0.0, 50.0, 50.0,
				      "fill-color", "red",
				      NULL);
  goo_canvas_item_model_set_child_properties (table, square,
					      "row", 0,
					      "column", 0,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, square);
  g_object_set_data (G_OBJECT (item), "id", "Red square");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);

  circle = goo_canvas_ellipse_model_new (table, 0.0, 0.0, 25.0, 25.0,
					 "fill-color", "blue",
					 NULL);
  goo_canvas_item_model_set_child_properties (table, circle,
					      "row", 0,
					      "column", 1,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, circle);
  g_object_set_data (G_OBJECT (item), "id", "Blue circle");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);

  triangle = goo_canvas_polyline_model_new (table, TRUE, 3,
					    25.0, 0.0, 0.0, 50.0, 50.0, 50.0,
					    "fill-color", "yellow",
					    NULL);
  goo_canvas_item_model_set_child_properties (table, triangle,
					      "row", 0,
					      "column", 2,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, triangle);
  g_object_set_data (G_OBJECT (item), "id", "Yellow triangle");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);
}
示例#2
0
static GooCanvasItemModel*
create_model (GdkPixbuf *pixbuf)
{
  GooCanvasItemModel *root;
  GooCanvasItemModel *item;
  GooCanvasItemModel* child;

  root = goo_canvas_group_model_new (NULL, NULL);

  /* Test clipping of GooCanvasGroup: We put the rectangle and the ellipse into
   * a group with width=200 and height=200. */
  item = goo_canvas_group_model_new (root, "x", 50.0, "y", 350.0, "width", 200.0, "height", 200.0, NULL);
  /*goo_canvas_item_model_rotate(item, 45.0, 150.0, 450.0);*/

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 100, 100, "fill-color", "blue", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_rotate(child, 45.0, 50.0, 50.0);

  child = goo_canvas_ellipse_model_new (item, 150, 00, 50, 50, "fill-color", "red", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");

  item = goo_canvas_polyline_model_new (root, FALSE, 5.0, 250.0, 350.0, 275.0, 400.0, 300.0, 350.0, 325.0, 400.0, 350.0, 350.0, "stroke-color", "cyan", "line-width", 5.0, NULL);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_path_model_new (root, "M20,500 C20,450 100,450 100,500", "stroke-color", "green", "line-width", 5.0, NULL);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_image_model_new (root, pixbuf, 150, 450, /*"fill-color", "yellow", */NULL);
  g_object_unref (pixbuf);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_text_model_new (root, "Hello, World!", 250, 450, -1, GOO_CANVAS_ANCHOR_NW, "fill-color", "magenta", "wrap", PANGO_WRAP_WORD_CHAR, NULL);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  item = goo_canvas_table_model_new (root, "horz-grid-line-width", 2.0, "vert-grid-line-width", 2.0, "row-spacing", 2.0, "column-spacing", 2.0, NULL);
  goo_canvas_item_model_translate (item, 10.0, 10.0);
  g_object_set_data (G_OBJECT (item), "setup-dnd-signals", "TRUE");

  child = goo_canvas_rect_model_new (item, 10.0, 10.0, 50.0, 50.0, "fill-color", "blue", "x", 10.0, "y", 25.0, NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties (item, child, "column", 0, "row", 0, "columns", 1, "rows", 1, NULL);
  /*goo_canvas_item_model_translate (child, 10.0, 10.0);*/

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 50.0, 50.0, "fill-color", "red", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties (item, child, "column", 1, "row", 0, "columns", 1, "rows", 1, NULL);

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 50.0, 50.0, "fill-color", "green", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties(item, child, "column", 0, "row", 1, "columns", 1, "rows", 1, NULL);

  child = goo_canvas_rect_model_new (item, 0.0, 0.0, 50.0, 50.0, "fill-color", "yellow", NULL);
  g_object_set_data (G_OBJECT (child), "setup-dnd-signals", "TRUE");
  goo_canvas_item_model_set_child_properties (item, child, "column", 1, "row", 1, "columns", 1, "rows", 1, NULL);

  return root;
}
示例#3
0
static void
setup_canvas (GooCanvas *canvas)
{
  GooCanvasItemModel *root, *model, *table;
  GooCanvasItem *item;

  root = goo_canvas_group_model_new (NULL, NULL);
  goo_canvas_set_root_item_model (canvas, root);
  g_object_unref (root);

  /* Plain items without clip path. */
  model = goo_canvas_ellipse_model_new (root, 0, 0, 50, 30,
					"fill-color", "blue",
					NULL);
  goo_canvas_item_model_translate (model, 100, 100);
  goo_canvas_item_model_rotate (model, 30, 0, 0);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Blue ellipse (unclipped)");

  model = goo_canvas_rect_model_new (root, 200, 50, 100, 100,
				     "fill-color", "red",
				     "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Red rectangle (unclipped)");

  model = goo_canvas_rect_model_new (root, 380, 50, 100, 100,
				     "fill-color", "yellow",
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Yellow rectangle (unclipped)");

  model = goo_canvas_text_model_new (root, "Sample Text", 520, 100, -1, GOO_CANVAS_ANCHOR_NW,
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Text (unclipped)");


  /* Clipped items. */
  model = goo_canvas_ellipse_model_new (root, 0, 0, 50, 30,
					"fill-color", "blue",
					"clip-path", "M 0 0 h 100 v 100 h -100 Z",
					NULL);
  goo_canvas_item_model_translate (model, 100, 300);
  goo_canvas_item_model_rotate (model, 30, 0, 0);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Blue ellipse");

  model = goo_canvas_rect_model_new (root, 200, 250, 100, 100,
				     "fill-color", "red",
				     "clip-path", "M 250 300 h 100 v 100 h -100 Z",
				     "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Red rectangle");

  model = goo_canvas_rect_model_new (root, 380, 250, 100, 100,
				     "fill-color", "yellow",
				     "clip-path", "M480,230 l40,100 l-80 0 z",
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Yellow rectangle");

  model = goo_canvas_text_model_new (root, "Sample Text", 520, 300, -1, GOO_CANVAS_ANCHOR_NW,
				     "clip-path", "M535,300 h75 v40 h-75 z",
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Text (unclipped)");


  /* Table with clipped items. */
  table = goo_canvas_table_model_new (root, NULL);

  goo_canvas_item_model_translate (table, 200, 400);
  goo_canvas_item_model_rotate (table, 30, 0, 0);

  model = goo_canvas_ellipse_model_new (table, 0, 0, 50, 30,
					"fill-color", "blue",
					"clip-path", "M 0 0 h 100 v 100 h -100 Z",
					NULL);
  goo_canvas_item_model_translate (model, 100, 300);
  goo_canvas_item_model_rotate (model, 30, 0, 0);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Blue ellipse");

  model = goo_canvas_rect_model_new (table, 200, 250, 100, 100,
				     "fill-color", "red",
				     "clip-path", "M 250 300 h 100 v 100 h -100 Z",
				     "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
				     NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "column", 1,
					      NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Red rectangle");

  model = goo_canvas_rect_model_new (table, 380, 250, 100, 100,
				     "fill-color", "yellow",
				     "clip-path", "M480,230 l40,100 l-80 0 z",
				     NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "column", 2,
					      NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Yellow rectangle");

  model = goo_canvas_text_model_new (table, "Sample Text", 520, 300, -1, GOO_CANVAS_ANCHOR_NW,
				     "clip-path", "M535,300 h75 v40 h-75 z",
				     NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "column", 3,
					      NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), "Text (unclipped)");
}
示例#4
0
GtkWidget *
create_canvas_features (void)
{
	GtkWidget *vbox;
	GtkWidget *w;
	GtkWidget *frame;
	GtkWidget *canvas;
	GooCanvasItemModel *root, *item;
	GooCanvasItemModel *parent1;
	GooCanvasItemModel *parent2;
	GooCanvasItemModel *group;

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
	g_object_set (vbox, "margin", 4, NULL);
	gtk_widget_show (vbox);

	/* Instructions */

	w = gtk_label_new ("Reparent test:  click on the items to switch them between parents");
	gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE);
	gtk_widget_show (w);

	/* Frame and canvas */

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
	gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE);
	gtk_widget_show (frame);

	g_object_set (frame,
		      "halign", GTK_ALIGN_CENTER,
		      "valign", GTK_ALIGN_CENTER,
		      NULL);

	canvas = goo_canvas_new ();

	g_signal_connect (canvas, "item_created",
			  G_CALLBACK (on_item_created), NULL);

	root = goo_canvas_group_model_new (NULL, NULL);

	gtk_widget_set_size_request (canvas, 400, 200);
	goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 400, 200);
	gtk_container_add (GTK_CONTAINER (frame), canvas);
	gtk_widget_show (canvas);

	/* First parent and box */

	parent1 = goo_canvas_group_model_new (root, NULL);

	goo_canvas_rect_model_new (parent1, 0, 0, 200, 200,
				   "fill_color", "tan",
				   NULL);

	/* Second parent and box */

	parent2 = goo_canvas_group_model_new (root, NULL);
	goo_canvas_item_model_translate (parent2, 200, 0);

	goo_canvas_rect_model_new (parent2, 0, 0, 200, 200,
				   "fill_color", "#204060",
				   NULL);

	/* Big circle to be reparented */

	item = goo_canvas_ellipse_model_new (parent1, 100, 100, 90, 90,
					     "stroke_color", "black",
					     "fill_color", "mediumseagreen",
					     "line-width", 3.0,
					     NULL);
	g_object_set_data (G_OBJECT (item), "parent1", parent1);
	g_object_set_data (G_OBJECT (item), "parent2", parent2);
#if 0
	g_signal_connect (G_OBJECT (item), "event",
			  G_CALLBACK (item_event),
			  NULL);
#endif

	/* A group to be reparented */

	group = goo_canvas_group_model_new (parent2, NULL);
	goo_canvas_item_model_translate (group, 100, 100);

	goo_canvas_ellipse_model_new (group, 0, 0, 50, 50,
				      "stroke_color", "black",
				      "fill_color", "wheat",
				      "line_width", 3.0,
				      NULL);
	goo_canvas_ellipse_model_new (group, 0, 0, 25, 25,
				      "fill_color", "steelblue",
				      NULL);

	g_object_set_data (G_OBJECT (group), "parent1", parent1);
	g_object_set_data (G_OBJECT (group), "parent2", parent2);
#if 0
	g_signal_connect (G_OBJECT (group), "event",
			  G_CALLBACK (item_event),
			    NULL);
#endif

	goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root);
	g_object_unref (root);

	/* Done */

	return vbox;
}