WireItem * wire_item_new (Sheet *sheet, Wire *wire) { GooCanvasItem *item; WireItem *wire_item; GooCanvasPoints *points; WireItemPriv *priv; SheetPos start_pos, length; g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (IS_SHEET (sheet), NULL); wire_get_pos_and_length (wire, &start_pos, &length); item = g_object_new (TYPE_WIRE_ITEM, NULL); g_object_set (item, "parent", sheet->object_group, NULL); wire_item = WIRE_ITEM (item); g_object_set (wire_item, "data", wire, NULL); priv = wire_item->priv; priv->resize1 = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (wire_item), -RESIZER_SIZE, -RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize1, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); priv->resize2 = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (wire_item), length.x - RESIZER_SIZE, length.y - RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize2, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); points = goo_canvas_points_new (2); points->coords[0] = 0; points->coords[1] = 0; points->coords[2] = length.x; points->coords[3] = length.y; priv->line = GOO_CANVAS_POLYLINE (goo_canvas_polyline_new ( GOO_CANVAS_ITEM (wire_item), FALSE, 0, "points", points, "stroke-color", "blue", "line-width", 1.0, NULL)); goo_canvas_points_unref (points); ITEM_DATA (wire)->rotated_handler_id = g_signal_connect_data (wire, "rotated", G_CALLBACK (wire_rotated_callback), G_OBJECT (wire_item), NULL, 0); g_signal_connect_data (wire, "flipped", G_CALLBACK (wire_flipped_callback), G_OBJECT (wire_item), NULL, 0); ITEM_DATA (wire)->moved_handler_id = g_signal_connect_object (wire, "moved", G_CALLBACK (wire_moved_callback), G_OBJECT (wire_item), 0); g_signal_connect (wire, "changed", G_CALLBACK (wire_changed_callback), wire_item); g_signal_connect (wire, "delete", G_CALLBACK (wire_delete_callback), wire_item); wire_update_bbox (wire); return wire_item; }
WireItem *wire_item_new (Sheet *sheet, Wire *wire) { GooCanvasItem *item; WireItem *wire_item; ItemData *item_data; GooCanvasPoints *points; WireItemPriv *priv; Coords start_pos, length; g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (IS_SHEET (sheet), NULL); wire_get_pos_and_length (wire, &start_pos, &length); item = g_object_new (TYPE_WIRE_ITEM, NULL); g_object_set (item, "parent", sheet->object_group, NULL); wire_item = WIRE_ITEM (item); g_object_set (wire_item, "data", wire, NULL); priv = wire_item->priv; const int random_color_count = 9; const char *random_color[] = {"blue", "red", "green" /*, "yellow"*/, "orange", "brown", "purple", "pink", "lightblue", "lightgreen"}; priv->resize1 = GOO_CANVAS_RECT ( goo_canvas_rect_new (GOO_CANVAS_ITEM (wire_item), -RESIZER_SIZE, -RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", oregano_options_debug_wires () ? random_color[g_random_int_range (0, random_color_count - 1)] : "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize1, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); priv->resize2 = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (wire_item), length.x - RESIZER_SIZE, length.y - RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", oregano_options_debug_wires () ? random_color[g_random_int_range (0, random_color_count - 1)] : "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize2, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); points = goo_canvas_points_new (2); points->coords[0] = 0; points->coords[1] = 0; points->coords[2] = length.x; points->coords[3] = length.y; priv->line = GOO_CANVAS_POLYLINE (goo_canvas_polyline_new ( GOO_CANVAS_ITEM (wire_item), FALSE, 0, "points", points, "stroke-color", oregano_options_debug_wires () ? random_color[g_random_int_range (0, random_color_count - 1)] : "blue", "line-width", 1.0, "start-arrow", oregano_options_debug_wires () ? TRUE : FALSE, "end-arrow", oregano_options_debug_wires () ? TRUE : FALSE, NULL)); goo_canvas_points_unref (points); item_data = ITEM_DATA (wire); item_data->rotated_handler_id = g_signal_connect_object ( G_OBJECT (wire), "rotated", G_CALLBACK (wire_rotated_callback), G_OBJECT (wire_item), 0); item_data->flipped_handler_id = g_signal_connect_object ( G_OBJECT (wire), "flipped", G_CALLBACK (wire_flipped_callback), G_OBJECT (wire_item), 0); item_data->moved_handler_id = g_signal_connect_object ( G_OBJECT (wire), "moved", G_CALLBACK (wire_moved_callback), G_OBJECT (wire_item), 0); item_data->changed_handler_id = g_signal_connect_object ( G_OBJECT (wire), "changed", G_CALLBACK (wire_changed_callback), G_OBJECT (wire_item), 0); g_signal_connect (wire, "delete", G_CALLBACK (wire_delete_callback), wire_item); wire_update_bbox (wire); return wire_item; }