Esempio n. 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);
}
void ApplicationModel::snapToGrid(void)
{
    GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj();    
    GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj();
    if(model && canvas)
    {
        GooCanvasItem* item = goo_canvas_get_item(canvas, model); 
        GooCanvasBounds bi;
        goo_canvas_item_get_bounds(item, &bi);
        double xs, ys;
        g_object_get (parentWindow->m_Grid,
               "x_step", &xs,
               "y_step", &ys,
               NULL);
        double c_x = (int) (((int)bi.x1) % (int)xs);
        double c_y = (int) (((int)bi.y1) % (int)ys);
        //printf("cx:%f, cy:%f\n", c_x, c_y);
        //printf("x:%f, y:%f\n", bi.x1, bi.y1);
        if(parentWindow->m_snapToGrid)
            goo_canvas_item_translate(item, -c_x, -c_y); 
        // force update
        goo_canvas_item_get_bounds(item, &bi);
        this->points.clear();
        GyPoint pt;
        pt.x = bi.x1;
        pt.y = bi.y1;
        this->points.push_back(pt);
        updateCoordination();
    }
}
Esempio n. 3
0
static void
create_demo_item (GooCanvasItemModel *table,
		  gint           demo_item_type,
		  gint           row,
		  gint           column,
		  gint           rows,
		  gint           columns,
		  gchar         *text)
{
  GooCanvasItemModel *model = NULL;
  GooCanvasItem *item;
  GValue value = { 0 };
  guint new_row;

  switch (demo_item_type)
    {
    case DEMO_RECT_ITEM:
      model = goo_canvas_rect_model_new (table, 0, 0, 38, 19,
					 "fill-color", "red",
					 NULL);
      break;
    case DEMO_TEXT_ITEM:
      model = goo_canvas_text_model_new (table, text, 0, 0, -1, GTK_ANCHOR_NW,
					 NULL);
      break;
    }

  g_value_init (&value, G_TYPE_UINT);
  g_value_set_uint (&value, row);
  goo_canvas_item_model_set_child_property (table, model, "row", &value);
  g_value_set_uint (&value, column);
  goo_canvas_item_model_set_child_property (table, model, "column", &value);
  g_value_set_uint (&value, rows);
  goo_canvas_item_model_set_child_property (table, model, "rows", &value);
  g_value_set_uint (&value, columns);
  goo_canvas_item_model_set_child_property (table, model, "columns", &value);

  /* Test the get function. */
  goo_canvas_item_model_get_child_property (table, model, "row", &value);
  new_row = g_value_get_uint (&value);
  if (new_row != row)
    g_warning ("Got bad row setting: %i should be: %i\n", new_row, row);

#if 1
  goo_canvas_item_model_set_child_properties (table, model,
					      "x-expand", TRUE,
					      "x-fill", TRUE,
					      "y-expand", TRUE,
					      "y-fill", TRUE,
					      NULL);
#endif

  item = goo_canvas_get_item (canvas, model);
  g_object_set_data (G_OBJECT (item), "id", text);
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);
}
Esempio n. 4
0
static void
create_width_for_height_table (GooCanvasItemModel *root,
			       gdouble        x,
			       gdouble        y,
			       gdouble        width,
			       gdouble        height,
			       gdouble        rotation)
{
  GooCanvasItemModel *table, *model;
  GooCanvasItem *item;
  gchar *text = "This is a long paragraph that will have to be split over a few lines so we can see if its allocated height changes when its allocated width is changed.";

  table = goo_canvas_table_model_new (root,
#if 1
				      "width", width,
				      "height", height,
#endif
				      NULL);
  goo_canvas_item_model_translate (table, x, y);
  goo_canvas_item_model_rotate (table, rotation, 0, 0);

  model = goo_canvas_rect_model_new (table, 0.0, 0.0, width - 2, 10.0,
				     "fill-color", "red",
				     NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "row", 0,
					      "column", 0,
					      "x-shrink", TRUE,
					      NULL);

#if 1
  model = goo_canvas_text_model_new (table, text, 0, 0, -1, GTK_ANCHOR_NW, NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "row", 1,
					      "column", 0,
					      "x-expand", TRUE,
					      "x-fill", TRUE,
					      "x-shrink", TRUE,
					      "y-expand", TRUE,
					      "y-fill", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, model);
  g_object_set_data (G_OBJECT (item), "id", "Text Item");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);
#endif

  model = goo_canvas_rect_model_new (table, 0.0, 0.0, width - 2, 10.0,
				     "fill-color", "red",
				     NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "row", 2,
					      "column", 0,
					      "x-shrink", TRUE,
					      NULL);
}
Esempio n. 5
0
gboolean
i7_node_get_label_coordinates(I7Node *self, gint *x, gint *y, GooCanvas *canvas)
{
	g_return_val_if_fail(self || I7_IS_NODE(self), FALSE);
	g_return_val_if_fail(canvas || GOO_IS_CANVAS(canvas), FALSE);

	I7_NODE_USE_PRIVATE;

	return i7_goo_canvas_item_get_onscreen_coordinates(goo_canvas_get_item(canvas, GOO_CANVAS_ITEM_MODEL(priv->label_item)), canvas, x, y);
}
Esempio n. 6
0
Gdk::Point MidpointModel::getContactPoint(void)
{
    GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj();    
    GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj();
    if(model && canvas)
    {
        GooCanvasItem* item = goo_canvas_get_item(canvas, model); 
        GooCanvasBounds bi;
        goo_canvas_item_get_bounds(item, &bi);
        goo_canvas_item_get_bounds(item, &bi);
        return Gdk::Point((int)(bi.x2-POINT_SIZE/2.0), (int)(bi.y2-POINT_SIZE/2.0));
    }    
    return Gdk::Point(-1, -1);
}
Esempio n. 7
0
Gdk::Point ExternalPortModel::getContactPoint(ArrowModel* arrow)
{
    GooCanvasItemModel* model = (GooCanvasItemModel*) poly->gobj();    
    GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj();
    if(model && canvas)
    {
        GooCanvasItem* item = goo_canvas_get_item(canvas, model); 
        if(item)
        {
            GooCanvasBounds bi;
            goo_canvas_item_get_bounds(item, &bi);
            if(type == INPUTD)
                return Gdk::Point((int)(bi.x1+PORT_DEPTH), (int)(bi.y2-((bi.y2-bi.y1)/2.0)));
            return Gdk::Point((int)(bi.x2), (int)(bi.y2-((bi.y2-bi.y1)/2.0)));
        }            
    }    
    return Gdk::Point(-1, -1);
}
Esempio n. 8
0
void ExternalPortModel::snapToGrid(void)
{
    GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj();    
    GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj();
    if(model && canvas)
    {
        GooCanvasItem* item = goo_canvas_get_item(canvas, model); 
        GooCanvasBounds bi;
        goo_canvas_item_get_bounds(item, &bi);
        double xs, ys;
        g_object_get (parentWindow->m_Grid,
               "x_step", &xs,
               "y_step", &ys,
               NULL);
        double c_x = (int) (((int)bi.x1) % (int)xs);
        double c_y = (int) (((int)bi.y1) % (int)ys);
        if(parentWindow->m_snapToGrid)
            goo_canvas_item_translate(item, -c_x, -c_y); 
        // force update
        goo_canvas_item_get_bounds(item, &bi);
        updateArrowCoordination();
    }
}
Esempio n. 9
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)");
}
Esempio n. 10
0
void
i7_node_calculate_size(I7Node *self, GooCanvasItemModel *skein, GooCanvas *canvas)
{
	I7_NODE_USE_PRIVATE;
	GooCanvasBounds size;
	GooCanvasItem *item;
	double command_width, command_height;
	double label_width = 0.0, label_height = 0.0;
	gboolean command_width_changed, command_height_changed;
	gboolean label_width_changed, label_height_changed;

	/* Calculate the bounds of the command text and label text */
	item = goo_canvas_get_item(canvas, priv->command_item);
	goo_canvas_item_get_bounds(item, &size);

	command_width = size.x2 - size.x1;
	command_height = size.y2 - size.y1;

	if(i7_node_has_label(self)) {
		item = goo_canvas_get_item(canvas, priv->label_item);
		goo_canvas_item_get_bounds(item, &size);
		label_width = size.x2 - size.x1;
		label_height = size.y2 - size.y1;
	}

	command_width_changed = command_width != 0.0 && priv->command_width != command_width;
	command_height_changed = command_height != 0.0 && priv->command_height != command_height;
	label_width_changed = label_width != 0.0 && priv->label_width != label_width;
	label_height_changed = label_height != 0.0 && priv->label_height != label_height;
	
	if(command_width_changed || command_height_changed)
		redraw_command(self, command_width, command_height);

	if(command_height_changed)
		g_object_set(priv->label_item, "x", 0.0, "y", -command_height, NULL);

	/* Draw the label background */
	if(i7_node_has_label(self)) {
		if(label_width_changed || label_height_changed)
			redraw_label(self, label_width, label_height);

		if(label_width_changed || label_height_changed || command_height_changed)
			g_object_set(priv->label_shape_item,
			    "x", -0.5 * label_width - label_height,
			    "y", -command_height - 0.5 * label_height,
				NULL);
	} else {
		g_object_set(priv->label_shape_item,
			"data", "",
			"visibility", GOO_CANVAS_ITEM_HIDDEN,
			NULL);
	}

	/* Move the differs badge */
	g_object_set(priv->badge_item, 
		"x", command_width / 2,
		"y", command_height / 2 - DIFFERS_BADGE_RADIUS,
		"width", DIFFERS_BADGE_RADIUS * 2,
		"height", DIFFERS_BADGE_RADIUS * 2,
		NULL);
}
Esempio n. 11
0
void
create_table1 (GtkWidget          *canvas,
	       GooCanvasItemModel *parent,
	       gdouble             x,
	       gdouble             y,
	       gdouble             width,
	       gdouble             height,
	       gboolean            with_grid_lines)
{
  GooCanvasItemModel *table, *items[9];
  GooCanvasItem *item;
  GooCanvasBounds bounds;
  gint i = 0;

  table = goo_canvas_table_model_new (parent,
				      "width", width,
				      "height", height,
				      NULL);
  goo_canvas_item_model_translate (table, x, y);

  if (with_grid_lines)
    {
      g_object_set (G_OBJECT (table),
		    "row-spacing",  2.0,
		    "column-spacing", 2.0,
		    "x-border-spacing", 1.0,
		    "y-border-spacing", 1.0,
		    "horz-grid-line-width", 1.0,
		    "vert-grid-line-width", 2.0,
		    NULL);
    }

  items[i++] = create_item (table, 17.3, 12.9, 0, 0, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 33.1, 17.2, 1, 0, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 41.6, 23.9, 2, 0, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

  items[i++] = create_item (table, 7.1, 5.7, 0, 1, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 13.5, 18.2, 1, 1, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 25.2, 22.1, 2, 1, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

  items[i++] = create_item (table, 11.3, 11.7, 0, 2, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 21.7, 18.8, 1, 2, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 22.2, 13.8, 2, 2, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

  for (i = 0; i < 9; i++)
    {
      item = goo_canvas_get_item (GOO_CANVAS (canvas), items[i]);
      goo_canvas_item_get_bounds (item, &bounds);
      g_print ("Item %i: %g,%g - %g,%g\n", i,
	       bounds.x1 - x, bounds.y1 - y,
	       bounds.x2 - x, bounds.y2 - y);
    }
}