Beispiel #1
0
GtkWidget *
create_events_page (void)
{
  GtkWidget *vbox, *alignment, *frame, *label, *canvas;

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

  /* Instructions */

  label = gtk_label_new ("Move the mouse over the items to check they receive the right motion events.\nThe first 2 items in each group are 1) invisible and 2) visible but unpainted.");
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  /* Frame and canvas */

  alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
  gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
  gtk_widget_show (alignment);

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

  canvas = goo_canvas_new ();

  gtk_widget_set_size_request (canvas, 600, 450);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 600, 450);
  gtk_container_add (GTK_CONTAINER (frame), canvas);
  gtk_widget_show (canvas);

  create_events_area (canvas, 0, GOO_CANVAS_EVENTS_NONE, "none");
  create_events_area (canvas, 1, GOO_CANVAS_EVENTS_VISIBLE_PAINTED, "visible-painted");
  create_events_area (canvas, 2, GOO_CANVAS_EVENTS_VISIBLE_FILL, "visible-fill");
  create_events_area (canvas, 3, GOO_CANVAS_EVENTS_VISIBLE_STROKE, "visible-stroke");
  create_events_area (canvas, 4, GOO_CANVAS_EVENTS_VISIBLE, "visible");
  create_events_area (canvas, 5, GOO_CANVAS_EVENTS_PAINTED, "painted");
  create_events_area (canvas, 6, GOO_CANVAS_EVENTS_FILL, "fill");
  create_events_area (canvas, 7, GOO_CANVAS_EVENTS_STROKE, "stroke");
  create_events_area (canvas, 8, GOO_CANVAS_EVENTS_ALL, "all");

  return vbox;
}
Beispiel #2
0
static void
create_canvas (GtkGrid *grid, gint row, gchar *text, gchar *id)
{
  GtkWidget *label, *canvas;
  GooCanvasItem *root, *rect;
  char *view_id;

  label = gtk_label_new (text);
  gtk_grid_attach (grid, label, 0, row, 1, 1);
  gtk_widget_show (label);

  canvas = goo_canvas_new ();

  gtk_widget_set_size_request (canvas, 200, 100);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 200, 100);
  gtk_grid_attach (grid, canvas, 1, row, 1, 1);
  gtk_widget_show (canvas);

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

  rect = goo_canvas_rect_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);
  setup_item_signals (rect);

  rect = goo_canvas_rect_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);
  setup_item_signals (rect);

  rect = goo_canvas_rect_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);
  setup_item_signals (rect);
}
Beispiel #3
0
static GtkWidget*
create_window (GooCanvasItemModel *model)
{
  GtkWidget *window, *vbox, *label, *scrolled_win, *canvas;

  /* Create the window and widgets. */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
  gtk_widget_show (window);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

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

  label = gtk_label_new ("Use Ctrl+Left Click to move items or Ctrl+Right Click to resize items");
  g_object_set (label, "halign", GTK_ALIGN_START, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE);
  gtk_widget_show (label);

  /* Create top canvas. */
  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);

  canvas = goo_canvas_new ();
  g_object_set (G_OBJECT (canvas), "integer-layout", TRUE, NULL);
/*  gtk_widget_set_size_request (canvas, 600, 250);*/
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

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

  goo_canvas_set_root_item_model (GOO_CANVAS (canvas), model);

  return window;
}
Beispiel #4
0
GtkWidget *
create_animation_page (void)
{
  GtkWidget *vbox, *hbox, *w, *scrolled_win, *canvas;

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

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  w = gtk_button_new_with_label("Start Animation");
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (start_animation_clicked),
		    NULL);

  w = gtk_button_new_with_label("Stop Animation");
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (stop_animation_clicked),
		    NULL);


  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 = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 600, 450);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  setup_canvas (canvas);

  return vbox;
}
Beispiel #5
0
/* create a new canvas */
canvas_goocanvas::canvas_goocanvas()
  : canvas_t(goo_canvas_new())
{
  GooCanvasItem *root = goo_canvas_get_root_item(GOO_CANVAS(widget));

  /* create the groups */
  for(unsigned int gr = 0; gr < group.size(); gr++)
    group[gr] = goo_canvas_group_new(root, nullptr);

  GObject *w = G_OBJECT(widget);
  g_signal_connect_swapped(w, "destroy",
                           G_CALLBACK(canvas_delete), this);

  g_object_set(w, "anchor", GTK_ANCHOR_CENTER, nullptr);

  gtk_widget_set_events(widget,
                        GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                        GDK_SCROLL_MASK | GDK_POINTER_MOTION_MASK |
                        GDK_POINTER_MOTION_HINT_MASK);
}
Beispiel #6
0
GtkWidget *
create_table_page (void)
{
  GtkWidget *vbox, *scrolled_win, *canvas;
  GooCanvasItem *root, *table;

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
  g_object_set (vbox, "margin", 4, NULL);
  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);

  canvas = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 600, 450);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 3000);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

#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, FALSE);
  create_table (root, -1, -1, 0, 180, 10, 30, 1.0, DEMO_TEXT_ITEM, FALSE);
  create_table (root, -1, -1, 0, 350, 10, 60, 1.0, DEMO_TEXT_ITEM, FALSE);
  create_table (root, -1, -1, 0, 500, 10, 90, 1.0, DEMO_TEXT_ITEM, FALSE);
#endif

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

#if 1
  table = create_table (root, -1, -1, 0, 30, 1400, 0, 1.0, DEMO_TEXT_ITEM_2, TRUE);
  g_object_set (table, "width", 300.0, "height", 300.0, NULL);

  table = create_table (root, -1, -1, 0, 630, 1430, 30, 1.0, DEMO_TEXT_ITEM_2, TRUE);
  g_object_set (table, "width", 300.0, "height", 300.0, NULL);


  table = create_table (root, -1, -1, 0, 30, 1800, 0, 1.0, DEMO_TEXT_ITEM_3, TRUE);
  table = create_table (root, -1, -1, 0, 630, 1830, 30, 1.0, DEMO_TEXT_ITEM_3, TRUE);
#endif

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

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

#if 1
  create_width_for_height_table (root, 100, 1000, 200, -1, 0);
  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 (canvas);

  return vbox;
}
static VALUE
rg_initialize(VALUE self)
{
    RBGTK_INITIALIZE(self, goo_canvas_new());
    return Qnil;
}
Beispiel #8
0
GtkWidget *
create_canvas_features (void)
{
	GtkWidget *vbox;
	GtkWidget *w;
	GtkWidget *alignment;
	GtkWidget *frame;
	GtkWidget *canvas;
	GooCanvasItem *root, *item;
	GooCanvasItem *parent1;
	GooCanvasItem *parent2;
	GooCanvasItem *group;

	vbox = gtk_vbox_new (FALSE, 4);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
	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, 0);
	gtk_widget_show (w);

	/* Frame and canvas */

	alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
	gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
	gtk_widget_show (alignment);

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

	canvas = goo_canvas_new ();
	root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

	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_new (root, NULL);

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

	/* Second parent and box */

	parent2 = goo_canvas_group_new (root, NULL);
	goo_canvas_item_translate (parent2, 200, 0);

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

	/* Big circle to be reparented */

	item = goo_canvas_ellipse_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);
	g_signal_connect (item, "button_press_event",
			  G_CALLBACK (on_button_press), NULL);

	/* A group to be reparented */

	group = goo_canvas_group_new (parent2, NULL);
	goo_canvas_item_translate (group, 100, 100);

	goo_canvas_ellipse_new (group, 0, 0, 50, 50,
				"stroke_color", "black",
				"fill_color", "wheat",
				"line_width", 3.0,
				NULL);
	goo_canvas_ellipse_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);
	g_signal_connect (group, "button_press_event",
			  G_CALLBACK (on_button_press), NULL);

	return vbox;
}
Beispiel #9
0
// part_browser_create
//
// Creates a new part browser. This is only called once per schematic window.
GtkWidget *
part_browser_create (SchematicView *schematic_view)
{
	Browser *br;
	GtkBuilder *gui;
	GError *perror = NULL;
	char *msg;
	GtkWidget *w, *view;
	GtkCellRenderer *cell_text;
	GtkTreeViewColumn *cell_column;
	static GtkTargetEntry dnd_types[] =
		{ { "x-application/oregano-part", 0, DRAG_PART_INFO } };

	static int dnd_num_types = sizeof (dnd_types) / sizeof (dnd_types[0]);
	GtkTreePath *path;

	if ((gui = gtk_builder_new ()) == NULL) {
		oregano_error (_("Could not create part browser"));
		return NULL;
	} 
	else 
		gtk_builder_set_translation_domain (gui, NULL);

	br = g_new0 (Browser, 1);
	br->preview = NULL;
	br->schematic_view = schematic_view;
	br->hidden = FALSE;

	schematic_view_set_browser (schematic_view, br);

	if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/part-browser.ui", 
	    &perror) <= 0) {
		msg = perror->message;
		oregano_error_with_title (_("Could not create part browser"), msg);
		g_error_free (perror);
		return NULL;
	}

	view = GTK_WIDGET (gtk_builder_get_object (gui, "viewport1"));
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view), 
	    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (view),
	                                            115);
	
	w = goo_canvas_new ();
	gtk_container_add (GTK_CONTAINER (view), GTK_WIDGET (w));
	
	br->canvas = w;

	g_signal_connect (w, "realize", (GCallback) preview_realized, br);

	//gtk_widget_set_size_request (w, PREVIEW_WIDTH,
	//	PREVIEW_HEIGHT + PREVIEW_TEXT_HEIGHT);
	goo_canvas_set_bounds (GOO_CANVAS (w), 0, 0, PREVIEW_WIDTH,
		(PREVIEW_HEIGHT + PREVIEW_TEXT_HEIGHT));

	br->description = GOO_CANVAS_TEXT (goo_canvas_text_new (
	           goo_canvas_get_root_item (GOO_CANVAS (br->canvas)), 
	           "", 0.0, PREVIEW_HEIGHT - 9.0, 100.0, GOO_CANVAS_ANCHOR_NORTH_WEST,
	           "font", "sans 9", 
	           NULL));  

	// Set up dnd. 
	g_signal_connect (G_OBJECT (br->canvas), "drag_data_get",
		G_CALLBACK (drag_data_get), br);

	gtk_drag_source_set (br->canvas, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
		dnd_types, dnd_num_types, GDK_ACTION_MOVE);

	br->filter_entry = GTK_ENTRY (gtk_builder_get_object (gui, "part_search"));

	g_signal_connect (G_OBJECT (br->filter_entry), "changed",
		G_CALLBACK (part_search_change), br);
	g_signal_connect (G_OBJECT (br->filter_entry), "activate",
		G_CALLBACK (part_search_activate), br);

	// Buttons. 
	w = GTK_WIDGET (gtk_builder_get_object (gui, "place_button"));
	g_signal_connect (G_OBJECT (w), "clicked",
		G_CALLBACK (place_cmd), br);

	// Update the libraries option menu 
	br->library = g_list_nth_data (oregano.libraries, 0);
	part_browser_setup_libs (br, gui);

	// Parts list. 
	w = GTK_WIDGET (gtk_builder_get_object (gui, "parts_list"));
	br->list = w;

	// Create the List Model for TreeView, this is a Real model 
	br->real_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
	cell_text = gtk_cell_renderer_text_new ();
	cell_column = gtk_tree_view_column_new_with_attributes (
		"", cell_text, 
	    "text", 0,
	    NULL);

	// Create the sort model for the items, this sort the real model 
	br->sort_model = gtk_tree_model_sort_new_with_model (
		GTK_TREE_MODEL (br->real_model));

	gtk_tree_sortable_set_sort_column_id (
		GTK_TREE_SORTABLE (br->sort_model),
		0, GTK_SORT_ASCENDING);

	// Create the filter sorted model. This filter items based on user
	//   request for fast item search 
	br->filter_model = gtk_tree_model_filter_new (br->sort_model, NULL);
	gtk_tree_model_filter_set_visible_func (
		GTK_TREE_MODEL_FILTER (br->filter_model),
		part_list_filter_func, br, NULL);

	// If we have TreeFilter use it, if not, just use sorting model only 
	if (br->filter_model)
		gtk_tree_view_set_model (GTK_TREE_VIEW (w), br->filter_model);
	else
		gtk_tree_view_set_model (GTK_TREE_VIEW (w), br->sort_model);

	gtk_tree_view_append_column (GTK_TREE_VIEW (w), cell_column);
	update_list (br);

	// Set up TreeView dnd.
	g_signal_connect (G_OBJECT (w), "drag_data_get",
		G_CALLBACK (drag_data_get), br);

	gtk_drag_source_set (w, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
		dnd_types, dnd_num_types, GDK_ACTION_MOVE);

	g_signal_connect (G_OBJECT (w), "cursor_changed", 
		G_CALLBACK (select_row), br);
	g_signal_connect (G_OBJECT (w), "row_activated", 
	    G_CALLBACK (part_selected), br);

	br->viewport = GTK_WIDGET (gtk_builder_get_object (gui, 
	    "part_browser_vbox"));

	path = gtk_tree_path_new_first ();
	gtk_tree_view_set_cursor (GTK_TREE_VIEW (w), path, NULL, FALSE);
	gtk_tree_path_free (path);

	gtk_widget_unparent (br->viewport);
	return br->viewport;
}
Beispiel #10
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;
}
Beispiel #11
0
int
main ()
{
  GtkWidget *window, *vbox, *hbox, *w, *scrolled_win;
  GtkWidget *label, *entry, *textview;
  GtkTextBuffer *buffer;
  GooCanvasItem *root, *witem;

  /* Initialize GTK+. */
  gtk_init ();

  /* Create the window and widgets. */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
  gtk_widget_show (window);
  g_signal_connect (window, "delete_event", G_CALLBACK (on_delete_event),
		    NULL);

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

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
  gtk_box_pack_start (GTK_BOX (vbox), hbox);
  gtk_widget_show (hbox);

  w = gtk_button_new_with_label ("Add Widget");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (add_widget_clicked), NULL);

  w = gtk_button_new_with_label ("Remove Widget");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (remove_widget_clicked), NULL);

  w = gtk_button_new_with_label ("Move Widget");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (move_widget_clicked), NULL);

  w = gtk_button_new_with_label ("Change Anchor");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (change_anchor_clicked), NULL);

  w = gtk_button_new_with_label ("Change Widget");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (change_widget_clicked), NULL);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
  gtk_box_pack_start (GTK_BOX (vbox), hbox);
  gtk_widget_show (hbox);

  w = gtk_button_new_with_label ("Hide Canvas");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (hide_canvas_clicked), NULL);

  w = gtk_button_new_with_label ("Show Canvas");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (show_canvas_clicked), NULL);

  w = gtk_button_new_with_label ("Hide Item");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (hide_item_clicked), NULL);

  w = gtk_button_new_with_label ("Show Item");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (show_item_clicked), NULL);

  w = gtk_button_new_with_label ("Change Transform");
  gtk_box_pack_start (GTK_BOX (hbox), w);
  gtk_widget_show (w);
  g_signal_connect (w, "clicked", G_CALLBACK (change_transform_clicked), NULL);

  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);
  gtk_widget_set_halign (scrolled_win, GTK_ALIGN_FILL);
  gtk_widget_set_valign (scrolled_win, GTK_ALIGN_FILL);
  gtk_widget_set_hexpand (scrolled_win, TRUE);
  gtk_widget_set_vexpand (scrolled_win, TRUE);

  canvas = goo_canvas_new ();
  gtk_widget_set_can_focus (canvas, TRUE);
  gtk_widget_set_size_request (canvas, 600, 450);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

  /* Add a few simple items. */
  label = gtk_label_new ("Hello World");
  witem = goo_canvas_widget_new (root, label, 50, 50, 200, 100, NULL);
  g_object_set_data (G_OBJECT (witem), "id", "hello");

  entry = gtk_entry_new ();
  move_item = goo_canvas_widget_new (root, entry, 50, 250, 200, 50, NULL);
  g_object_set_data (G_OBJECT (move_item), "id", "entry1");

  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "Size: -1 x -1");
  witem = goo_canvas_widget_new (root, entry, 50, 300, -1, -1, NULL);
  g_object_set_data (G_OBJECT (witem), "id", "entry2");

  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "Size: 100 x -1");
  witem = goo_canvas_widget_new (root, entry, 50, 350, 100, -1, NULL);
  g_object_set_data (G_OBJECT (witem), "id", "entry3");

  /* Use a textview so we can see the width & height of the widget. */
  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
				       GTK_SHADOW_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
				  GTK_POLICY_NEVER, GTK_POLICY_NEVER);
  textview = gtk_text_view_new ();
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
  gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), "Size: -1 x 100", -1);
  gtk_widget_show (textview);
  gtk_container_add (GTK_CONTAINER (scrolled_win), textview);
  gtk_widget_set_size_request (scrolled_win, 160, 50);
  witem = goo_canvas_widget_new (root, scrolled_win, 50, 400, -1, 100, NULL);
  g_object_set_data (G_OBJECT (witem), "id", "scrolledwin");

  /* Create a vbox item with several child entry widgets to check focus
     traversal.*/
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);

  entry = gtk_entry_new ();
  gtk_widget_show (entry);
  gtk_box_pack_start (GTK_BOX (vbox), entry);

  entry = gtk_entry_new ();
  gtk_widget_show (entry);
  gtk_box_pack_start (GTK_BOX (vbox), entry);

  entry = gtk_entry_new ();
  gtk_widget_show (entry);
  gtk_box_pack_start (GTK_BOX (vbox), entry);

  witem = goo_canvas_widget_new (root, vbox, 50, 600, -1, -1, NULL);
  g_object_set_data (G_OBJECT (witem), "id", "vbox");

  /* Create a few normal canvas items that take keyboard focus. */
  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");


  gtk_widget_show (canvas);

  /* Pass control to the GTK+ main event loop. */
  gtk_main ();

  return 0;
}
Beispiel #12
0
GtkWidget *
create_canvas_fifteen (void)
{
	GtkWidget *vbox;
	GtkWidget *alignment;
	GtkWidget *frame;
	GtkWidget *canvas;
	GtkWidget *button;
	GooCanvasItem **board;
	GooCanvasItem *root, *rect, *text;
	int i, x, y;
	char buf[20];

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

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

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

	/* Create the canvas and board */

	canvas = goo_canvas_new ();
	g_object_set (G_OBJECT (canvas),
		      "automatic-bounds", TRUE,
		      "bounds-from-origin", FALSE,
		      NULL);
	root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

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

	board = g_new (GooCanvasItem *, 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_new (root, NULL);
		goo_canvas_item_translate (board[i], x * PIECE_SIZE,
					   y * PIECE_SIZE);
		setup_item_signals (board[i]);

		rect = goo_canvas_rect_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_new (board[i], buf,
					    PIECE_SIZE / 2.0, PIECE_SIZE / 2.0,
					    -1, GTK_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, 0);
	g_object_set_data (G_OBJECT (button), "board", board);
	g_signal_connect (button, "clicked",
			  G_CALLBACK (scramble),
			  canvas);
	gtk_widget_show (button);

	return vbox;
}
Beispiel #13
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;
}
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;
}
Beispiel #15
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;
}
Beispiel #16
0
int
main (int argc, char *argv[])
{
  GtkWidget *window, *vbox, *label, *scrolled_win, *canvas;

  /* Initialize GTK+. */
  gtk_set_locale ();
  gtk_init (&argc, &argv);

  /* Create the window and widgets. */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
  gtk_widget_show (window);
  g_signal_connect (window, "delete_event", G_CALLBACK (on_delete_event),
		    NULL);

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

  label = gtk_label_new ("Normal Layout");
  gtk_widget_show (label);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  /* Create top canvas. */
  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, FALSE, FALSE, 0);

  canvas = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 600, 250);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  g_print ("\n\nNormal Canvas...\n");
  setup_canvas (canvas);

  label = gtk_label_new ("Integer Layout");
  gtk_widget_show (label);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  /* Create bottom canvas. */
  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, FALSE, FALSE, 0);

  canvas = goo_canvas_new ();
  g_object_set (canvas,
		"integer-layout", TRUE,
		NULL);
  gtk_widget_set_size_request (canvas, 600, 250);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  g_print ("\n\nInteger Layout Canvas...\n");
  setup_canvas (canvas);

  gtk_main ();

  return 0;
}
int
main (int argc, char *argv[])
{
  GtkWidget *window, *scrolled_win, *canvas;
  GooCanvasItem *root, *rect_item, *text_item, *image_item;

	GdkPixbuf *pb;

  /* Initialize GTK+. */
  gtk_set_locale ();
  gtk_init (&argc, &argv);
	


	pb=gdk_pixbuf_new_from_file("test-screenshot.png", NULL);


	if(!pb) {
		printf("error: gdk_pixbuf_new_from_file");
		exit(1);
	}

  /* Create the window and widgets. */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 740, 700);
  gtk_widget_show (window);
  g_signal_connect (window, "delete_event", (GtkSignalFunc) on_delete_event,
                    NULL);

  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_container_add (GTK_CONTAINER (window), scrolled_win);

  canvas = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 640, 600);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

	image_item = goo_canvas_image_new (root, pb, 0, 0, NULL);

  /* Add a few simple items. */
  rect_item = goo_canvas_rect_new (root, 20, 20, 200, 200,
                                   "line-width", 5.0,
                                   "radius-x", 10.0,
                                   "radius-y", 5.0,
                                   "stroke-color", "red",
                                   NULL);
                                   
  GooCanvasItem *polyline0 = goo_canvas_polyline_new_line (root,
                                                        100.0, 100.0,
                                                        500.0, 500.0,
                                                        "stroke-color", "red",
                                                        "line-width", 5.0,
                                                        "start-arrow", TRUE,
                                                        NULL);
                            

  //text_item = goo_canvas_text_new (root, PACKAGE_STRING, 300, 300, -1,
                                   //GTK_ANCHOR_CENTER,
                                   //"font", "Sans 24px",
                                   //NULL);
  //goo_canvas_item_rotate (text_item, 45, 300, 300);

  /* Connect a signal handler for the rectangle item. */
  g_signal_connect (rect_item, "button_press_event",
                    (GtkSignalFunc) on_rect_button_press, NULL);

  /* Pass control to the GTK+ main event loop. */
  gtk_main ();

  return 0;
}
Beispiel #18
0
GtkWidget *
create_large_items_page (void)
{
  GtkWidget *vbox, *hbox, *w, *scrolled_win, *canvas;
  GtkAdjustment *adj;
  GooCanvasItem *root, *item;
  gchar *text;

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

  text = g_strdup_printf ("This is a very large canvas, from (%i, %i) to (%i, %i).\nThe maximum zoom is %i. At this scale the canvas comes very close to the GDK window size limit (32-bit gint).\nThe items have been specially written to work around cairo's limits (transformed coords must be < +/- 32768).",
			  CANVAS_LEFT, CANVAS_TOP,
			  CANVAS_RIGHT, CANVAS_BOTTOM, MAX_ZOOM);
  w = gtk_label_new (text);
  g_free (text);
  gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  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);

  /* Create the canvas. */
  canvas = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 600, 450);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

  g_signal_connect (root, "motion_notify_event",
		    G_CALLBACK (on_motion_notify), NULL);

#if 1
  item = goo_demo_large_rect_new (root, CANVAS_LEFT + 10, CANVAS_TOP + 10,
				  CANVAS_RIGHT - CANVAS_LEFT - 20,
				  CANVAS_BOTTOM - CANVAS_TOP - 20,
				  "fill-color", "yellow",
				  NULL);
  g_object_set_data (G_OBJECT (item), "id", "Large Yellow Rect");
#endif

#if 1
  item = goo_demo_large_rect_new (root, CANVAS_LEFT + 100, CANVAS_TOP + 100,
				  CANVAS_RIGHT - CANVAS_LEFT - 200, 50,
				  "fill-color", "orange",
				  NULL);
  g_object_set_data (G_OBJECT (item), "id", "Large Orange Rect");
#endif

#if 1
  item = goo_demo_large_line_new (root, CANVAS_LEFT + 100, CANVAS_TOP + 200,
				  CANVAS_RIGHT - 100, CANVAS_TOP + 200,
				  "stroke-color", "purple",
				  "line-width", 10.0,
				  NULL);
  g_object_set_data (G_OBJECT (item), "id", "Large Purple Line");
#endif

#if 1
  item = goo_demo_large_line_new (root, CANVAS_LEFT + 100, CANVAS_TOP + 300,
				  CANVAS_RIGHT - 100, CANVAS_BOTTOM - 100,
				  "stroke-color", "blue",
				  "line-width", 10.0,
				  NULL);
  g_object_set_data (G_OBJECT (item), "id", "Large Blue Line");
  /*goo_canvas_item_rotate (item, 10, CANVAS_LEFT + 100, CANVAS_TOP + 200);*/
#endif

  goo_canvas_set_bounds (GOO_CANVAS (canvas), CANVAS_LEFT, CANVAS_TOP,
			 CANVAS_RIGHT, CANVAS_BOTTOM);
  gtk_widget_show (canvas);

  /* Zoom */
  w = gtk_label_new ("Zoom:");
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

  adj = GTK_ADJUSTMENT (gtk_adjustment_new (1.00, 0.05, 10.00, 0.05, 0.50, 0.50));
  w = gtk_spin_button_new (adj, 0.0, 2);
  g_signal_connect (adj, "value_changed",
		    G_CALLBACK (zoom_changed),
		    canvas);
  gtk_widget_set_size_request (w, 50, -1);
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

  return vbox;
}
Beispiel #19
0
static void
display_files(GooCanvasItem *root_item, gchar *rootdir)
{
  GooCanvasItem *item;
  const gchar *one_dirent;
  GDir  *dir;

  /* Initial image position */
  guint ix  = 0.0;
  guint iy  = 30.0;

  GtkWidget	  *w;
  GooCanvasItem *bg_item;

  GtkWidget *canvas; /* The scrolled part */

  GList  *dir_list  = NULL;
  GList  *file_list = NULL;
  GList  *listrunner;

  GtkAdjustment *adj;

  if(!rootitem)
    return;

  /* Display the directory content */
  dir = g_dir_open(rootdir, 0, NULL);

  if (!dir) {
    g_warning("gcompris_file_selector : no root directory found in %s", rootdir);
    g_free(rootdir);
    return;
  }

  /* Delete the previous file root if any */
  if(file_root_item)
    goo_canvas_item_remove(file_root_item);

  /* Create a root item to put the image list in it */
  file_root_item = goo_canvas_group_new (root_item, NULL);

  /*
   * Create the scrollbar
   * --------------------
   */
  canvas = goo_canvas_new();

  goo_canvas_widget_new (file_root_item,
			 canvas,
			 DRAWING_AREA_X1,
			 DRAWING_AREA_Y1,
			 DRAWING_AREA_X2 - DRAWING_AREA_X1 - 20.0,
			 DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 35.0,
			 NULL);

  gtk_widget_show (canvas);

  /* Set the new canvas to the background color or it's white */
  bg_item = goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
				 0,
				 0,
				 DRAWING_AREA_X2 - DRAWING_AREA_X1 + 200,
				 DRAWING_AREA_Y2 - DRAWING_AREA_Y1,
				 "fill-color-rgba", gc_skin_get_color("gcompris/fileselectbg"),
				 "line-width", 0.0,
				 NULL);


  adj = \
    GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00,
					IMAGE_HEIGHT,
					10, IMAGE_HEIGHT,
					(DRAWING_AREA_Y2 - DRAWING_AREA_Y1)/3)
		    );
  w = gtk_vscrollbar_new (adj);

  goo_canvas_widget_new (file_root_item,
			 w,
			 DRAWING_AREA_X2 - 15.0,
			 DRAWING_AREA_Y1,
			 30.0,
			 DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 20.0,
			 NULL);
  gtk_widget_show (w);

  /* Set the scrollwheel event */
  g_signal_connect (adj, "value_changed",
		    (GtkSignalFunc) item_event_scroll,
		    canvas);

  /* Display the directory name
   * --------------------------
   */

  item = goo_canvas_text_new (file_root_item,
			      rootdir,
			      (gdouble)control_area_x1,
			      (gdouble)directory_label_y,
			      -1,
			      GTK_ANCHOR_NW,
			      "font", "Sans 7",
			      "fill-color-rgba",
			      gc_skin_get_color("gcompris/fileselectcol"),
			      NULL);

  /* Insert all files in a sorted list */

  while((one_dirent = g_dir_read_name(dir)) != NULL)
    {
      gchar *filename;

      filename = g_strdup_printf("%s/%s",
				 rootdir, (gchar*)(one_dirent));

      if(g_file_test(filename, G_FILE_TEST_IS_DIR))
	{
	  dir_list = g_list_insert_sorted(dir_list, filename,
					  (GCompareFunc)strcmp);
	}
      else
	{
	  file_list = g_list_insert_sorted(file_list, filename,
					   (GCompareFunc)strcmp);
	}
    }

  /* Concat the directory list and file list */
  file_list = g_list_concat(dir_list, file_list);

  g_list_free(dir_list);
  dir_list = NULL;

  /* We have the list sorted, now display it */
  listrunner = g_list_first(file_list);
  while(listrunner)
    {
      /* add the file to the display */
      gchar *svg_id;

      gchar *allfilename = listrunner->data;
      gchar *filename    = g_path_get_basename(allfilename);
      gchar *ext = g_strrstr(filename, ".");
      gchar *file_wo_ext = g_strdup(filename);

      if(ext)
	{
	  gchar *ext2 = g_strrstr(file_wo_ext, ".");
	  *ext2 = '\0';
	}

      if(g_file_test(allfilename, G_FILE_TEST_IS_DIR))
	svg_id = "#FOLDER";
      else
	svg_id = "#FILE";

      item = goo_canvas_svg_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
				 gc_skin_rsvg_get(),
				 "svg-id", svg_id,
				 NULL);

      SET_ITEM_LOCATION_CENTER(item,
			       ix + (IMAGE_WIDTH + IMAGE_GAP)/2,
			       iy);

      if(g_file_test(allfilename, G_FILE_TEST_IS_DIR))
	{
	  g_signal_connect(item, "button_press_event",
			   (GtkSignalFunc) item_event_directory,
			   allfilename);
	}
      else
	{
	  g_signal_connect(item, "button_press_event",
			   (GtkSignalFunc) item_event_file_selector,
			   allfilename);
	}
      gc_item_focus_init(item, NULL);

      g_object_set_data_full (G_OBJECT (item),
			      "allfilename", allfilename, g_free);
      /* The type */
      if(ext)
	{
	  GooCanvasItem *_item = \
	    goo_canvas_text_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
				 ext,
				 ix + (IMAGE_WIDTH + IMAGE_GAP)/2,
				 iy + 10,
				 -1,
				 GTK_ANCHOR_CENTER,
				 "font", "Sans 6",
				 "fill-color-rgba",
				 gc_skin_get_color("gcompris/fileselectcol"),
				 NULL);
	  g_signal_connect(_item, "button_press_event",
			   (GtkSignalFunc) item_event_file_selector,
			   allfilename);
	  gc_item_focus_init(_item, item);
	}

      /* The filename */
      GooCanvasItem *name_item = \
	goo_canvas_text_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
			     file_wo_ext,
			     ix + (IMAGE_WIDTH + IMAGE_GAP)/2,
			     iy + IMAGE_HEIGHT - 30,
			     -1,
			     GTK_ANCHOR_CENTER,
			     "font", "Sans 7",
			     "fill-color-rgba", gc_skin_get_color("gcompris/fileselectcol"),
			     NULL);
      g_free(file_wo_ext);
      g_free(filename);

      if(g_file_test(allfilename, G_FILE_TEST_IS_DIR))
	{
	  g_signal_connect(name_item, "button_press_event",
			   (GtkSignalFunc) item_event_directory,
			   allfilename);
	}
      else
	{
	  g_signal_connect(name_item, "button_press_event",
			   (GtkSignalFunc) item_event_file_selector,
			   allfilename);
	}
      gc_item_focus_init(name_item, item);

      ix += IMAGE_WIDTH + IMAGE_GAP;

      if(ix >= DRAWING_AREA_X2 - DRAWING_AREA_X1 -
	 (IMAGE_WIDTH + IMAGE_GAP) )
	{
	  ix=0;

	  iy+=IMAGE_HEIGHT + IMAGE_GAP;

	  goo_canvas_set_bounds (GOO_CANVAS(canvas),
				 0, 0,
				 DRAWING_AREA_X2- DRAWING_AREA_X1,
				 iy + IMAGE_HEIGHT + IMAGE_GAP);

	  if(iy >= DRAWING_AREA_Y2-DRAWING_AREA_Y1)
	    {
	      g_object_set(bg_item,
			   "height", (double)iy + IMAGE_HEIGHT + IMAGE_GAP,
			   NULL);
	      g_object_set(adj,
			   "upper", (double)iy - IMAGE_HEIGHT + IMAGE_GAP - 1,
			   NULL);
	    }
	}
      listrunner = g_list_next(listrunner);
    }

  g_dir_close(dir);
  g_list_free(file_list);

}
Beispiel #20
0
void
gc_selector_images_start (GcomprisBoard *gcomprisBoard, gchar *dataset,
			  ImageSelectorCallBack iscb,
			  void *user_context)
{

  gint		 y_start = 0;
  gchar		*dataseturl = NULL;

  GtkWidget	*w;

  if(sugar_detected())
  {
    sugar_choose_image(iscb, user_context);
    return;
  }

  if(rootitem)
    return;

  gc_bar_hide(TRUE);

  gc_board_pause(TRUE);

  imageSelectorCallBack = iscb;
  current_user_context = user_context;

  rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()),
				   NULL);

  images_selector_displayed = TRUE;

  goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", "#IMAGE_SELECTOR",
			     "pointer-events", GOO_CANVAS_EVENTS_NONE,
			     NULL);

  y_start += 110;

  /*
   * Create the list scrollbar
   * -------------------------
   */
  canvas_list_selector = goo_canvas_new ();

  goo_canvas_widget_new (rootitem,
			 canvas_list_selector,
			 LIST_AREA_X1,
			 LIST_AREA_Y1,
			 LIST_AREA_X2 - LIST_AREA_X1,
			 LIST_AREA_Y2 - LIST_AREA_Y1 - 35.0,
			 NULL);

  gtk_widget_show (canvas_list_selector);

  /* Set the new canvas to the background color or it's white */
  list_bg_item = goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas_list_selector)),
				      0,
				      0,
				      (LIST_AREA_X2 - LIST_AREA_X1)
				      * gc_zoom_factor_get(),
				      (LIST_AREA_Y2 - LIST_AREA_Y1)
				      * gc_zoom_factor_get(),
				      "fill-color-rgba",
				      gc_skin_get_color("gcompris/imageselectbg_left"),
				      "line-width", 0.0,
				      NULL);

  list_adj = \
    GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00,
					0.00,
					10, IMAGE_HEIGHT,
					(LIST_AREA_Y2 - LIST_AREA_Y1)
					* gc_zoom_factor_get())
		    );

  w = gtk_vscrollbar_new (list_adj);

  goo_canvas_widget_new (rootitem,
			 w,
			 LIST_AREA_X2 - 5.0,
			 LIST_AREA_Y1,
			 30.0,
			 LIST_AREA_Y2 - LIST_AREA_Y1 - 20.0,
			 NULL);
  gtk_widget_show (w);

  /* Set the scrollwheel event */
  g_signal_connect (list_adj, "value_changed",
		    (GCallback) item_event_scroll,
		    canvas_list_selector);

  /*
   * Create the image scrollbar
   * --------------------------
   */
  canvas_image_selector = goo_canvas_new ();

  goo_canvas_widget_new (rootitem,
			 canvas_image_selector,
			 DRAWING_AREA_X1,
			 DRAWING_AREA_Y1,
			 DRAWING_AREA_X2 - DRAWING_AREA_X1,
			 DRAWING_AREA_Y2 - DRAWING_AREA_Y1,
			 NULL);

  gtk_widget_show (canvas_image_selector);

  /* Set the new canvas to the background color or it's white */
  image_bg_item = \
    goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas_image_selector)),
			 0,
			 0,
			 (DRAWING_AREA_X2 - DRAWING_AREA_X1)
			 * gc_zoom_factor_get(),
			 (DRAWING_AREA_Y2 - DRAWING_AREA_Y1)
			 * gc_zoom_factor_get(),
			 "fill-color-rgba",
			 gc_skin_get_color("gcompris/imageselectbg_right"),
			 "line-width", 0.0,
			 NULL);

  image_adj = \
    GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00,
					0.00,
					10, IMAGE_HEIGHT,
					(DRAWING_AREA_Y2 - DRAWING_AREA_Y1)
					* gc_zoom_factor_get())
		    );

  w = gtk_vscrollbar_new (image_adj);

  goo_canvas_widget_new (rootitem,
			 w,
			 DRAWING_AREA_X2 - 5.0,
			 DRAWING_AREA_Y1,
			 30.0,
			 DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 20.0,
			 NULL);
  gtk_widget_show (w);

  /* Set the scrollwheel event */
  g_signal_connect (image_adj, "value_changed",
		    (GCallback) item_event_scroll,
		    canvas_image_selector);

  /*
   * DISPLAY IMAGES
   */

  /* Initial image position */
  isy = 0.0;

  /* I need  the following :
     -> if dataset is a file read it.
     -> if dataset is a directory, read all xml file in it.
  */
  dataseturl = \
    gc_file_find_absolute(dataset,
			  NULL);

  /* if the file doesn't exist */
  if(g_file_test ((dataseturl), G_FILE_TEST_IS_DIR) )
    {
      g_warning("dataset %s is a directory. Trying to read xml", dataseturl);

      read_dataset_directory(dataseturl);
    }
  else if(dataseturl)
    {
      /* Read the given data set file, local or net */
      read_xml_file(dataseturl);
    }
  else
    {
      /* Network code for dataset directory */
      GSList *filelist = NULL;
      GSList *i = NULL;

      g_free(dataseturl);
      dataseturl = g_strconcat("boards/", dataset, NULL);
      /* TODO */
      filelist = NULL; //gc_net_dir_read_name(dataseturl, ".xml");

      for (i = filelist; i != NULL; i = g_slist_next (i))
	{
	  gchar *url = gc_file_find_absolute(i->data,
					     NULL);
	  g_warning("processing dataset=%s\n", (char *)i->data);
	  read_xml_file(url);
	  g_free(url);
	}

      g_slist_free(filelist);

    }
  g_free(dataseturl);

  /*
   * OK Button
   * ---------
   */
  gc_util_button_text_svg(rootitem,
			  (BOARDWIDTH*0.5),
			  BOARDHEIGHT - 32,
			  "#BUTTON_TEXT",
			  _("OK"),
			  (GCallback) item_event_images_selector,
			  "/ok/");
}