added gas bottle shape
[dia.git] / app / connectionpoint_ops.c
blobe9e60259f0e19a1731378d1f6c587515f56e96a3
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #include <assert.h>
20 #include "connectionpoint_ops.h"
21 #include "object_ops.h"
22 #include "color.h"
24 static Color connectionpoint_color = { 0.4, 0.4, 1.0 };
26 #define CP_SZ (CONNECTIONPOINT_SIZE/2)
28 void
29 connectionpoint_draw(ConnectionPoint *conpoint,
30 DDisplay *ddisp)
32 int x,y;
33 Point *point = &conpoint->pos;
34 Renderer *renderer = ddisp->renderer;
36 ddisplay_transform_coords(ddisp, point->x, point->y, &x, &y);
38 (renderer->ops->set_linewidth)(renderer, 0.0);
39 (renderer->ops->set_linestyle)(renderer, LINESTYLE_SOLID);
41 (renderer->interactive_ops->draw_pixel_line)(renderer,
42 x-CP_SZ,y-CP_SZ,
43 x+CP_SZ,y+CP_SZ,
44 &connectionpoint_color);
46 (renderer->interactive_ops->draw_pixel_line)(renderer,
47 x+CP_SZ,y-CP_SZ,
48 x-CP_SZ,y+CP_SZ,
49 &connectionpoint_color);
53 void
54 connectionpoint_add_update(ConnectionPoint *conpoint,
55 Diagram *dia)
57 diagram_add_update_pixels(dia, &conpoint->pos,
58 CONNECTIONPOINT_SIZE, CONNECTIONPOINT_SIZE);
61 /* run diagram_update_connections_object on all selected objects. */
62 void
63 diagram_update_connections_selection(Diagram *dia)
65 GList *list = dia->data->selected;
67 while (list!=NULL) {
68 Object * selected_obj = (Object *) list->data;
70 diagram_update_connections_object(dia, selected_obj, TRUE);
72 list = g_list_next(list);
76 /* Updates all objects connected to the 'obj' object.
77 Calls this function recursively for objects modified.
79 If update_nonmoved is TRUE, also objects that have not
80 moved since last time is updated. This is not propagated
81 in the recursion.
83 void
84 diagram_update_connections_object(Diagram *dia, Object *obj,
85 int update_nonmoved)
87 int i,j;
88 ConnectionPoint *cp;
89 GList *list;
90 Object *connected_obj;
91 Handle *handle;
93 for (i=0;i<obj->num_connections;i++) {
94 cp = obj->connections[i];
95 if ((update_nonmoved) ||
96 (distance_point_point_manhattan(&cp->pos, &cp->last_pos) > CHANGED_TRESHOLD)) {
97 cp->last_pos = cp->pos;
99 list = cp->connected;
100 while (list!=NULL) {
101 connected_obj = (Object *) list->data;
103 handle = NULL;
104 for (j=0;j<connected_obj->num_handles;j++) {
105 if (connected_obj->handles[j]->connected_to == cp)
106 handle = connected_obj->handles[j];
108 assert(handle!=NULL);
110 object_add_updates(connected_obj, dia);
111 connected_obj->ops->move_handle(connected_obj, handle ,
112 &cp->pos, HANDLE_MOVE_CONNECTED,0);
113 object_add_updates(connected_obj, dia);
115 diagram_update_connections_object(dia, connected_obj, FALSE);
117 list = g_list_next(list);
125 void
126 ddisplay_connect_selected(DDisplay *ddisp)
128 GList *list;
129 Object *selected_obj;
130 int i;
132 list = ddisp->diagram->data->selected;
134 while (list!=NULL) {
135 selected_obj = (Object *) list->data;
137 for (i=0; i<selected_obj->num_handles; i++) {
138 if (selected_obj->handles[i]->connect_type != HANDLE_NONCONNECTABLE) {
139 object_connect_display(ddisp, selected_obj, selected_obj->handles[i]);
143 list = g_list_next(list);
147 void
148 diagram_unconnect_selected(Diagram *dia)
150 GList *list;
151 Object *selected_obj;
152 Handle *handle;
153 int i;
155 list = dia->data->selected;
157 while (list!=NULL) {
158 selected_obj = (Object *) list->data;
160 for (i=0; i<selected_obj->num_handles; i++) {
161 handle = selected_obj->handles[i];
163 if ((handle->connected_to != NULL) &&
164 (handle->connect_type == HANDLE_CONNECTABLE)){
165 /* don't do this if type is HANDLE_CONNECTABLE_BREAK */
166 if (!diagram_is_selected(dia, handle->connected_to->object)) {
167 Change *change = undo_unconnect(dia, selected_obj, handle);
168 (change->apply)(change, dia);
173 list = g_list_next(list);