fixed dia_image_rgb_data() for non-alpha images
[dia.git] / app / connectionpoint_ops.c
blobf7b41a9480bc87b1eb92f689dbe23ed825901b87
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 <config.h>
20 #include <assert.h>
22 #include "connectionpoint_ops.h"
23 #include "object_ops.h"
24 #include "color.h"
26 static Color connectionpoint_color = { 0.4, 0.4, 1.0 };
28 #define CP_SZ (CONNECTIONPOINT_SIZE/2)
30 void
31 connectionpoint_draw(ConnectionPoint *conpoint,
32 DDisplay *ddisp)
34 int x,y;
35 Point *point = &conpoint->pos;
36 DiaRenderer *renderer = ddisp->renderer;
37 DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (ddisp->renderer);
38 DiaInteractiveRendererInterface *irenderer =
39 DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);
41 ddisplay_transform_coords(ddisp, point->x, point->y, &x, &y);
43 renderer_ops->set_linewidth (renderer, 0.0);
44 renderer_ops->set_linestyle (renderer, LINESTYLE_SOLID);
46 irenderer->draw_pixel_line (renderer,
47 x-CP_SZ,y-CP_SZ,
48 x+CP_SZ,y+CP_SZ,
49 &connectionpoint_color);
51 irenderer->draw_pixel_line (renderer,
52 x+CP_SZ,y-CP_SZ,
53 x-CP_SZ,y+CP_SZ,
54 &connectionpoint_color);
57 void
58 connectionpoint_add_update(ConnectionPoint *conpoint,
59 Diagram *dia)
61 diagram_add_update_pixels(dia, &conpoint->pos,
62 CONNECTIONPOINT_SIZE, CONNECTIONPOINT_SIZE);
65 /* run diagram_update_connections_object on all selected objects. */
66 void
67 diagram_update_connections_selection(Diagram *dia)
69 GList *list = dia->data->selected;
71 while (list!=NULL) {
72 Object * selected_obj = (Object *) list->data;
74 diagram_update_connections_object(dia, selected_obj, TRUE);
76 list = g_list_next(list);
80 /* Updates all objects connected to the 'obj' object.
81 Calls this function recursively for objects modified.
83 If update_nonmoved is TRUE, also objects that have not
84 moved since last time is updated. This is not propagated
85 in the recursion.
87 void
88 diagram_update_connections_object(Diagram *dia, Object *obj,
89 int update_nonmoved)
91 int i,j;
92 ConnectionPoint *cp;
93 GList *list;
94 Object *connected_obj;
95 Handle *handle;
97 for (i=0;i<obj->num_connections;i++) {
98 cp = obj->connections[i];
99 if ((update_nonmoved) ||
100 (distance_point_point_manhattan(&cp->pos, &cp->last_pos) > CHANGED_TRESHOLD)) {
101 cp->last_pos = cp->pos;
103 list = cp->connected;
104 while (list!=NULL) {
105 connected_obj = (Object *) list->data;
107 object_add_updates(connected_obj, dia);
108 handle = NULL;
109 for (j=0;j<connected_obj->num_handles;j++) {
110 if (connected_obj->handles[j]->connected_to == cp) {
111 handle = connected_obj->handles[j];
112 connected_obj->ops->move_handle(connected_obj, handle ,
113 &cp->pos, HANDLE_MOVE_CONNECTED,0);
116 object_add_updates(connected_obj, dia);
118 diagram_update_connections_object(dia, connected_obj, FALSE);
120 list = g_list_next(list);
128 void
129 ddisplay_connect_selected(DDisplay *ddisp)
131 GList *list;
132 Object *selected_obj;
133 int i;
135 list = ddisp->diagram->data->selected;
137 while (list!=NULL) {
138 selected_obj = (Object *) list->data;
140 for (i=0; i<selected_obj->num_handles; i++) {
141 if (selected_obj->handles[i]->connect_type != HANDLE_NONCONNECTABLE) {
142 object_connect_display(ddisp, selected_obj, selected_obj->handles[i]);
146 list = g_list_next(list);
150 void
151 diagram_unconnect_selected(Diagram *dia)
153 GList *list;
154 Object *selected_obj;
155 Handle *handle;
156 int i;
158 list = dia->data->selected;
160 while (list!=NULL) {
161 selected_obj = (Object *) list->data;
163 for (i=0; i<selected_obj->num_handles; i++) {
164 handle = selected_obj->handles[i];
166 if ((handle->connected_to != NULL) &&
167 (handle->connect_type == HANDLE_CONNECTABLE)){
168 /* don't do this if type is HANDLE_CONNECTABLE_BREAK */
169 if (!diagram_is_selected(dia, handle->connected_to->object)) {
170 Change *change = undo_unconnect(dia, selected_obj, handle);
171 (change->apply)(change, dia);
176 list = g_list_next(list);