Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
static void
setup_canvas (GtkWidget *canvas)
{
  GooCanvasItemModel *root;

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

  create_focus_box (canvas, 110, 80, 50, 30, "red");
  create_focus_box (canvas, 300, 160, 50, 30, "orange");
  create_focus_box (canvas, 500, 50, 50, 30, "yellow");
  create_focus_box (canvas, 70, 400, 50, 30, "blue");
  create_focus_box (canvas, 130, 200, 50, 30, "magenta");
  create_focus_box (canvas, 200, 160, 50, 30, "green");
  create_focus_box (canvas, 450, 450, 50, 30, "cyan");
  create_focus_box (canvas, 300, 350, 50, 30, "grey");
  create_focus_box (canvas, 900, 900, 50, 30, "gold");
  create_focus_box (canvas, 800, 150, 50, 30, "thistle");
  create_focus_box (canvas, 600, 800, 50, 30, "azure");
  create_focus_box (canvas, 700, 250, 50, 30, "moccasin");
  create_focus_box (canvas, 500, 100, 50, 30, "cornsilk");
  create_focus_box (canvas, 200, 750, 50, 30, "plum");
  create_focus_box (canvas, 400, 800, 50, 30, "orchid");
}
Ejemplo n.º 3
0
void
setup_canvas (GtkWidget *canvas)
{
  GooCanvasItemModel *root;

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

  g_print ("\nTable at default size...\n");
  create_table1 (canvas, root, 50, 50, -1, -1, FALSE);

  g_print ("\nTable at reduced size...\n");
  create_table1 (canvas, root, 250, 50, 30, 30, FALSE);

  g_print ("\nTable at enlarged size...\n");
  create_table1 (canvas, root, 450, 50, 100, 100, FALSE);

  g_print ("\nTable with grid lines at default size...\n");
  create_table1 (canvas, root, 50, 250, -1, -1, TRUE);

  g_print ("\nTable with grid lines at reduced size...\n");
  create_table1 (canvas, root, 250, 250, 30, 30, TRUE);

  g_print ("\nTable with grid lines at enlarged size...\n");
  create_table1 (canvas, root, 450, 250, 150, 150, TRUE);

  g_print ("Multispanning table with grid lines at default size...\n");
  create_table2 (canvas, root, 50, 450, -1, -1, TRUE);

  g_print ("Multispanning table with grid lines at reduced size...\n");
  create_table2 (canvas, root, 250, 450, 30, 30, TRUE);

  g_print ("Multispanning table with grid lines at enlarged size...\n");
  create_table2 (canvas, root, 450, 450, 150, 150, TRUE);
}
Ejemplo n.º 4
0
static void
create_canvas (GtkTable *table, gint row, gchar *text, gchar *id)
{
  GtkWidget *label, *canvas;
  GooCanvasItemModel *root, *rect;
  char *view_id;

  label = gtk_label_new (text);
  gtk_table_attach (table, label, 0, 1, row, row + 1,
		    0, 0, 0, 0);
  gtk_widget_show (label);

  canvas = goo_canvas_new ();

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

  gtk_widget_set_size_request (canvas, 200, 100);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 200, 100);
  gtk_table_attach (table, canvas, 1, 2, row, row + 1, 0, 0, 0, 0);
  gtk_widget_show (canvas);

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

  rect = goo_canvas_rect_model_new (root, 0, 0, 200, 100,
				    "stroke-pattern", NULL,
				    "fill-color", "yellow",
				    NULL);
  view_id = g_strdup_printf ("%s-yellow", id);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);

  rect = goo_canvas_rect_model_new (root, 20, 20, 60, 60,
				    "stroke-pattern", NULL,
				    "fill-color", "blue",
				    NULL);
  view_id = g_strdup_printf ("%s-blue", id);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);

  rect = goo_canvas_rect_model_new (root, 120, 20, 60, 60,
				    "stroke-pattern", NULL,
				    "fill-color", "red",
				    NULL);
  view_id = g_strdup_printf ("%s-red", id);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);
}
Ejemplo n.º 5
0
GtkWidget *
create_canvas_arrowhead (void)
{
	GtkWidget *vbox;
	GtkWidget *w;
	GtkWidget *frame;
	GtkWidget *canvas;
	GooCanvasItemModel *root, *item;

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
	gtk_widget_show (vbox);

	w = gtk_label_new ("This demo allows you to edit arrowhead shapes.  Drag the little boxes\n"
			   "to change the shape of the line and its arrowhead.  You can see the\n"
			   "arrows at their normal scale on the right hand side of the window.");
	gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
	gtk_widget_show (w);

	w = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
	gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0);
	gtk_widget_show (w);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
	gtk_container_add (GTK_CONTAINER (w), frame);
	gtk_widget_show (frame);

	canvas = goo_canvas_new ();

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

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

	gtk_widget_set_size_request (canvas, 500, 350);
	goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 500, 350);
	gtk_container_add (GTK_CONTAINER (frame), canvas);
	gtk_widget_show (canvas);


	g_object_set_data (G_OBJECT (canvas), "width",
			   GINT_TO_POINTER (DEFAULT_WIDTH));
	g_object_set_data (G_OBJECT (canvas), "shape_a",
			   GINT_TO_POINTER (DEFAULT_SHAPE_A));
	g_object_set_data (G_OBJECT (canvas), "shape_b",
			   GINT_TO_POINTER (DEFAULT_SHAPE_B));
	g_object_set_data (G_OBJECT (canvas), "shape_c",
			   GINT_TO_POINTER (DEFAULT_SHAPE_C));

	/* Big arrow */

	item = goo_canvas_polyline_model_new_line (root,
						   LEFT, MIDDLE, RIGHT, MIDDLE,
						   "stroke_color", "mediumseagreen",
						   "end-arrow", TRUE,
						   NULL);
	g_object_set_data (G_OBJECT (canvas), "big_arrow", item);

	/* Arrow outline */

	item = goo_canvas_polyline_model_new (root, TRUE, 0,
					      "stroke_color", "black",
					      "line-width", 2.0,
					      "line-cap", CAIRO_LINE_CAP_ROUND,
					      "line-join", CAIRO_LINE_JOIN_ROUND,
					      NULL);
	g_object_set_data (G_OBJECT (canvas), "outline", item);

	/* Drag boxes */

	create_drag_box (canvas, root, "width_drag_box");
	create_drag_box (canvas, root, "shape_a_drag_box");
	create_drag_box (canvas, root, "shape_b_c_drag_box");

	/* Dimensions */

	create_dimension (canvas, root, "width_arrow", "width_text", GOO_CANVAS_ANCHOR_E);
	create_dimension (canvas, root, "shape_a_arrow", "shape_a_text", GOO_CANVAS_ANCHOR_N);
	create_dimension (canvas, root, "shape_b_arrow", "shape_b_text", GOO_CANVAS_ANCHOR_N);
	create_dimension (canvas, root, "shape_c_arrow", "shape_c_text", GOO_CANVAS_ANCHOR_W);

	/* Info */

	create_info (canvas, root, "width_info", LEFT, 260);
	create_info (canvas, root, "shape_a_info", LEFT, 280);
	create_info (canvas, root, "shape_b_info", LEFT, 300);
	create_info (canvas, root, "shape_c_info", LEFT, 320);

	/* Division line */

	goo_canvas_polyline_model_new_line (root, RIGHT + 50, 0, RIGHT + 50, 1000,
					    "fill_color", "black",
					    "line-width", 2.0,
					    NULL);

	/* Sample arrows */

	create_sample_arrow (canvas, root, "sample_1",
			     RIGHT + 100, 30, RIGHT + 100, MIDDLE - 30);
	create_sample_arrow (canvas, root, "sample_2",
			     RIGHT + 70, MIDDLE, RIGHT + 130, MIDDLE);
	create_sample_arrow (canvas, root, "sample_3",
			     RIGHT + 70, MIDDLE + 30, RIGHT + 130, MIDDLE + 120);

	/* Done! */
	
	set_arrow_shape (GOO_CANVAS (canvas));
	return vbox;
}
Ejemplo n.º 6
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)");
}
Ejemplo n.º 7
0
GtkWidget *
create_table_page (void)
{
  GtkWidget *vbox, *scrolled_win;
  GooCanvasItemModel *root, *table;

  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_widget_show (vbox);

  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
				       GTK_SHADOW_IN);
  gtk_widget_show (scrolled_win);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);

  canvas = (GooCanvas*) goo_canvas_new ();
  gtk_widget_set_size_request ((GtkWidget*) canvas, 600, 450);
  goo_canvas_set_bounds (canvas, 0, 0, 1000, 2000);
  gtk_container_add (GTK_CONTAINER (scrolled_win), (GtkWidget*) canvas);

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

#if 1
  create_demo_table (root, 400, 200, -1, -1);
  create_demo_table (root, 400, 260, 100, -1);
#endif

#if 1
  create_table (root, -1, -1, 0, 10, 10, 0, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 180, 10, 30, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 350, 10, 60, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 500, 10, 90, 1.0, DEMO_TEXT_ITEM);
#endif

#if 1
  table = create_table (root, -1, -1, 0, 30, 150, 0, 1.0, DEMO_TEXT_ITEM);
  g_object_set (table, "width", 300.0, "height", 100.0, NULL);
#endif

#if 1
  create_table (root, -1, -1, 1, 200, 200, 30, 0.8, DEMO_TEXT_ITEM);
#endif

#if 0
  table = create_table (root, -1, -1, 0, 10, 700, 0, 1.0, DEMO_WIDGET_ITEM);
  g_object_set (table, "width", 300.0, "height", 200.0, NULL);
#endif

  create_width_for_height_table (root, 100, 1000, 200, -1, 0);
#if 1
  create_width_for_height_table (root, 100, 1200, 300, -1, 0);

  create_width_for_height_table (root, 500, 1000, 200, -1, 30);
  create_width_for_height_table (root, 500, 1200, 300, -1, 30);
#endif

  gtk_widget_show ((GtkWidget*) canvas);

  return vbox;
}
Ejemplo n.º 8
0
GtkWidget *
create_canvas_fifteen (void)
{
	GtkWidget *vbox;
	GtkWidget *frame;
	GtkWidget *canvas;
	GtkWidget *button;
	GooCanvasItemModel **board;
	GooCanvasItemModel *root, *rect G_GNUC_UNUSED, *text;
	int i, x, y;
	char buf[20];

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

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

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

	/* Create the canvas and board */

	canvas = goo_canvas_new ();

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

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

	gtk_widget_set_size_request (canvas,
				     PIECE_SIZE * 4 + 1, PIECE_SIZE * 4 + 1);
	goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0,
			       PIECE_SIZE * 4 + 1, PIECE_SIZE * 4 + 1);
	gtk_container_add (GTK_CONTAINER (frame), canvas);
	gtk_widget_show (canvas);

	board = g_new (GooCanvasItemModel *, 16);
	g_object_set_data (G_OBJECT (canvas), "board", board);
	g_signal_connect (canvas, "destroy",
			  G_CALLBACK (free_stuff), board);

	for (i = 0; i < 15; i++) {
		y = i / 4;
		x = i % 4;

		board[i] = goo_canvas_group_model_new (root, NULL);
		goo_canvas_item_model_translate (board[i], x * PIECE_SIZE,
						 y * PIECE_SIZE);

		rect = goo_canvas_rect_model_new (board[i], 0, 0,
						  PIECE_SIZE, PIECE_SIZE,
						  "fill_color", get_piece_color (i),
						  "stroke_color", "black",
						  "line-width", 1.0,
						  NULL);

		sprintf (buf, "%d", i + 1);

		text = goo_canvas_text_model_new (board[i], buf,
						  PIECE_SIZE / 2.0, PIECE_SIZE / 2.0,
						  -1, GOO_CANVAS_ANCHOR_CENTER,
						  "font", "Sans bold 24",
						  "fill_color", "black",
						  NULL);

		g_object_set_data (G_OBJECT (board[i]), "text", text);

		g_object_set_data (G_OBJECT (board[i]), "piece_num", GINT_TO_POINTER (i));
		g_object_set_data (G_OBJECT (board[i]), "piece_pos", GINT_TO_POINTER (i));

	}

	board[15] = NULL;

	/* Scramble button */

	button = gtk_button_new_with_label ("Scramble");
	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE);
	g_object_set_data (G_OBJECT (button), "board", board);
	g_signal_connect (button, "clicked",
			  G_CALLBACK (scramble),
			  canvas);
	gtk_widget_show (button);

	return vbox;
}
Ejemplo n.º 9
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;
}