Example #1
0
void item_data_list_get_absolute_bbox (GList *item_data_list, Coords *p1, Coords *p2)
{
	GList *iter;
	Coords b1, b2;

	if (item_data_list == NULL)
		return;

	item_data_get_absolute_bbox (item_data_list->data, p1, p2);

	for (iter = item_data_list; iter; iter = iter->next) {
		if (G_UNLIKELY (iter->data == NULL))
			continue;
		item_data_get_absolute_bbox (iter->data, &b1, &b2);

		if (p1) {
			p1->x = MIN (p1->x, b1.x);
			p1->y = MIN (p1->y, b1.y);
		}

		if (p2) {
			p2->x = MAX (p2->x, b2.x);
			p2->y = MAX (p2->y, b2.y);
		}
	}
}
Example #2
0
gint
node_store_count_items (NodeStore *store, NodeRect *rect)
{
	GList *list;
	SheetPos p1, p2;
	ItemData *data;
	gint n;

	g_return_val_if_fail (store != NULL, 0);
	g_return_val_if_fail (IS_NODE_STORE (store), 0);

	if (rect == NULL)
		return g_list_length (store->items);

	for (list = store->items, n = 0; list; list = list->next) {
		data = ITEM_DATA (list->data);
		item_data_get_absolute_bbox (data, &p1, &p2);
		if (p1.x <= rect->x1 && p1.y <= rect->y1 &&
			p2.x >= rect->x0 && p2.y >= rect->y0) {
			n++;
		}
	}
	g_list_free_full (list, g_object_unref);

	return n;
}
Example #3
0
void
node_store_get_bounds (NodeStore *store, NodeRect *rect)
{
	GList *list;
	SheetPos p1, p2;

	g_return_if_fail (store != NULL);
	g_return_if_fail (IS_NODE_STORE (store));
	g_return_if_fail (rect != NULL);

	rect->x0 = G_MAXDOUBLE;
	rect->y0 = G_MAXDOUBLE;
	rect->x1 = -G_MAXDOUBLE;
	rect->y1 = -G_MAXDOUBLE;

	for (list = store->items; list; list = list->next) {
		item_data_get_absolute_bbox (ITEM_DATA (list->data), &p1, &p2);

		rect->x0 = MIN (rect->x0, p1.x);
		rect->y0 = MIN (rect->y0, p1.y);
		rect->x1 = MAX (rect->x1, p2.x);
		rect->y1 = MAX (rect->y1, p2.y);
	}
	g_list_free_full (list, g_object_unref);
}
Example #4
0
static void
textbox_flip (ItemData *data, gboolean horizontal, SheetPos *center)
{
	double affine[6];
	ArtPoint src, dst;
	Textbox *textbox;
	TextboxPriv *priv;
	SheetPos b1, b2;
	SheetPos textbox_center, delta;

	g_return_if_fail (data != NULL);
	g_return_if_fail (IS_TEXTBOX (data));

	textbox = TEXTBOX (data);

	if (center) {
		item_data_get_absolute_bbox (ITEM_DATA (textbox), &b1, &b2);
		textbox_center.x = b1.x + (b2.x - b1.x) / 2;
		textbox_center.y = b1.y + (b2.y - b1.y) / 2;
	}

	priv = textbox->priv;

	if (horizontal)
		art_affine_scale (affine, -1, 1);
	else
		art_affine_scale (affine, 1, -1);

	/*
	 * Let the views (canvas items) know about the rotation.
	 */
	g_signal_emit_by_name(G_OBJECT (textbox), "flipped", horizontal);

	if (center) {
		SheetPos textbox_pos;

		item_data_get_pos (ITEM_DATA (textbox), &textbox_pos);

		src.x = textbox_center.x - center->x;
		src.y = textbox_center.y - center->y;
		art_affine_point (&dst, &src, affine);

		delta.x = -src.x + dst.x;
		delta.y = -src.y + dst.y;

		item_data_move (ITEM_DATA (textbox), &delta);
	}
}
Example #5
0
static void wire_rotate (ItemData *data, int angle, Coords *center_pos)
{
    cairo_matrix_t affine;
    double x, y;
    Wire *wire;
    WirePriv *priv;
    Coords b1, b2;
    Coords wire_center_before, wire_center_after, delta;
    Coords delta_cp_before, delta_cp_after;

    g_return_if_fail (data != NULL);
    g_return_if_fail (IS_WIRE (data));

    if (angle == 0)
        return;

    wire = WIRE (data);

    item_data_get_absolute_bbox (ITEM_DATA (wire), &b1, &b2);
    wire_center_before = coords_average (&b1, &b2);

    priv = wire->priv;

    if (priv->direction == WIRE_DIR_VERT) {
        priv->direction = WIRE_DIR_HORIZ;
    } else if (priv->direction == WIRE_DIR_HORIZ) {
        priv->direction = WIRE_DIR_VERT;
    }

    cairo_matrix_init_rotate (&affine, (double)angle * M_PI / 180.0);

    // Rotate the wire's end point.
    x = priv->length.x;
    y = priv->length.y;

    cairo_matrix_transform_point (&affine, &x, &y);

    if (fabs (x) < 1e-2)
        x = 0.0;
    if (fabs (y) < 1e-2)
        y = 0.0;

    priv->length.x = x;
    priv->length.y = y;

    if (center_pos) {
        delta_cp_before = coords_sub (&wire_center_before, center_pos);
        delta_cp_after = delta_cp_before;
        cairo_matrix_transform_point (&affine, &delta_cp_after.x, &delta_cp_after.y);
    }

    // Update bounding box.
    wire_update_bbox (wire);

    item_data_get_absolute_bbox (ITEM_DATA (wire), &b1, &b2);
    wire_center_after = coords_average (&b1, &b2);

    delta = coords_sub (&wire_center_before, &wire_center_after);
    if (center_pos) {
        Coords diff = coords_sub (&delta_cp_after, &delta_cp_before);
        coords_add (&delta, &diff);
    }
    item_data_move (ITEM_DATA (wire), &delta);
    //	item_data_snap (ITEM_DATA (wire), NULL); //FIXME XXX

    // Let the views (canvas items) know about the rotation.
    g_signal_emit_by_name (G_OBJECT (wire), "rotated", angle); // legacy
    g_signal_emit_by_name (G_OBJECT (wire), "changed");
}