/
e_arrow.c
executable file
·280 lines (258 loc) · 7.62 KB
/
e_arrow.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
* FIG : Facility for Interactive Generation of figures
* Copyright (c) 1985-1988 by Supoj Sutanthavibul
* Parts Copyright (c) 1989-2002 by Brian V. Smith
* Parts Copyright (c) 1991 by Paul King
*
* Any party obtaining a copy of these files is granted, free of charge, a
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
* nonexclusive right and license to deal in this software and documentation
* files (the "Software"), including without limitation the rights to use,
* copy, modify, merge, publish distribute, sublicense and/or sell copies of
* the Software, and to permit persons who receive copies from any such
* party to do so, with the only requirement being that the above copyright
* and this permission notice remain intact.
*
*/
#include "fig.h"
#include "resources.h"
#include "mode.h"
#include "object.h"
#include "paintop.h"
#include "e_arrow.h"
#include "u_create.h"
#include "u_draw.h"
#include "u_search.h"
#include "u_undo.h"
#include "w_canvas.h"
#include "w_mousefun.h"
#include "u_redraw.h"
#include "w_cursor.h"
static void add_arrow_head(F_line *obj, int type, int x, int y, F_point *p, F_point *q);
static void delete_arrow_head(F_line *obj, int type, int x, int y, F_point *p, F_point *q);
static void add_linearrow(F_line *line, F_point *prev_point, F_point *selected_point);
static void add_arcarrow(F_arc *arc, int point_num);
static void add_splinearrow(F_spline *spline, F_point *prev_point, F_point *selected_point);
void
arrow_head_selected(void)
{
set_mousefun("add arrow", "delete arrow", "", LOC_OBJ, LOC_OBJ, LOC_OBJ);
canvas_kbd_proc = null_proc;
canvas_locmove_proc = null_proc;
canvas_ref_proc = null_proc;
init_searchproc_left(add_arrow_head);
init_searchproc_middle(delete_arrow_head);
canvas_leftbut_proc = point_search_left;
canvas_middlebut_proc = point_search_middle;
canvas_rightbut_proc = null_proc;
set_cursor(pick9_cursor);
reset_action_on();
}
static void
add_arrow_head(F_line *obj, int type, int x, int y, F_point *p, F_point *q)
{
switch (type) {
case O_POLYLINE:
cur_l = (F_line *) obj;
add_linearrow(cur_l, p, q);
break;
case O_SPLINE:
cur_s = (F_spline *) obj;
add_splinearrow(cur_s, p, q);
break;
case O_ARC:
cur_a = (F_arc *) obj;
/* dirty trick - arc point number is stored in p */
add_arcarrow(cur_a, (int) p);
break;
}
}
static void
delete_arrow_head(F_line *obj, int type, int x, int y, F_point *p, F_point *q)
{
switch (type) {
case O_POLYLINE:
cur_l = (F_line *) obj;
delete_linearrow(cur_l, p, q);
break;
case O_SPLINE:
cur_s = (F_spline *) obj;
delete_splinearrow(cur_s, p, q);
break;
case O_ARC:
cur_a = (F_arc *) obj;
/* dirty trick - arc point number is stored in p */
delete_arcarrow(cur_a, (int) p);
break;
}
}
static void
add_linearrow(F_line *line, F_point *prev_point, F_point *selected_point)
{
if (line->points->next == NULL)
return; /* A single point line */
if (prev_point == NULL) { /* selected_point is the first point */
if (line->back_arrow)
return;
line->back_arrow = backward_arrow();
redisplay_line(line);
} else if (selected_point->next == NULL) { /* forward arrow */
if (line->for_arrow)
return;
line->for_arrow = forward_arrow();
redisplay_line(line);
} else
return;
clean_up();
set_last_prevpoint(prev_point);
set_last_selectedpoint(selected_point);
set_latestline(line);
set_action_object(F_ADD_ARROW_HEAD, O_POLYLINE);
set_modifiedflag();
}
static void
add_arcarrow(F_arc *arc, int point_num)
{
/* only allow arrowheads on open arc */
if (arc->type == T_PIE_WEDGE_ARC)
return;
if (point_num == 0) { /* backward arrow */
if (arc->back_arrow)
return;
arc->back_arrow = backward_arrow();
redisplay_arc(arc);
} else if (point_num == 2) {/* for_arrow */
if (arc->for_arrow)
return;
arc->for_arrow = forward_arrow();
redisplay_arc(arc);
} else
return;
clean_up();
set_last_arcpointnum(point_num);
set_latestarc(arc);
set_action_object(F_ADD_ARROW_HEAD, O_ARC);
set_modifiedflag();
}
static void
add_splinearrow(F_spline *spline, F_point *prev_point, F_point *selected_point)
{
if (prev_point == NULL) { /* add backward arrow */
if (spline->back_arrow)
return;
spline->back_arrow = backward_arrow();
redisplay_spline(spline);
} else if (selected_point->next == NULL) { /* add forward arrow */
if (spline->for_arrow)
return;
spline->for_arrow = forward_arrow();
redisplay_spline(spline);
}
clean_up();
set_last_prevpoint(prev_point);
set_last_selectedpoint(selected_point);
set_latestspline(spline);
set_action_object(F_ADD_ARROW_HEAD, O_SPLINE);
set_modifiedflag();
}
void
delete_linearrow(F_line *line, F_point *prev_point, F_point *selected_point)
{
if (line->points->next == NULL)
return; /* A single point line */
if (prev_point == NULL) { /* selected_point is the first point */
if (!line->back_arrow)
return;
draw_line(line, ERASE);
saved_back_arrow=line->back_arrow;
if (saved_for_arrow && saved_for_arrow != line->for_arrow)
free((char *) saved_for_arrow);
saved_for_arrow = NULL;
line->back_arrow = NULL;
redisplay_line(line);
} else if (selected_point->next == NULL) { /* forward arrow */
if (!line->for_arrow)
return;
draw_line(line, ERASE);
saved_for_arrow=line->for_arrow;
if (saved_back_arrow && saved_back_arrow != line->back_arrow)
free((char *) saved_back_arrow);
saved_back_arrow = NULL;
line->for_arrow = NULL;
redisplay_line(line);
} else
return;
clean_up();
set_last_prevpoint(prev_point);
set_last_selectedpoint(selected_point);
set_latestline(line);
set_action_object(F_DELETE_ARROW_HEAD, O_POLYLINE);
set_modifiedflag();
}
void
delete_arcarrow(F_arc *arc, int point_num)
{
if (arc->type == T_PIE_WEDGE_ARC)
return;;
if (point_num == 0) { /* backward arrow */
if (!arc->back_arrow)
return;
draw_arc(arc, ERASE);
saved_back_arrow=arc->back_arrow;
if (saved_for_arrow && saved_for_arrow != arc->for_arrow)
free((char *) saved_for_arrow);
saved_for_arrow = NULL;
arc->back_arrow = NULL;
redisplay_arc(arc);
} else if (point_num == 2) {/* for_arrow */
if (!arc->for_arrow)
return;
draw_arc(arc, ERASE);
saved_for_arrow=arc->for_arrow;
if (saved_back_arrow && saved_back_arrow != arc->back_arrow)
free((char *) saved_back_arrow);
saved_back_arrow = NULL;
arc->for_arrow = NULL;
redisplay_arc(arc);
} else
return;
clean_up();
set_last_arcpointnum(point_num);
set_latestarc(arc);
set_action_object(F_DELETE_ARROW_HEAD, O_ARC);
set_modifiedflag();
}
void
delete_splinearrow(F_spline *spline, F_point *prev_point, F_point *selected_point)
{
if (closed_spline(spline))
return;
if (prev_point == NULL) { /* selected_point is the first point */
if (!spline->back_arrow)
return;
draw_spline(spline, ERASE);
saved_back_arrow=spline->back_arrow;
if (saved_for_arrow && saved_for_arrow != spline->for_arrow)
free((char *) saved_for_arrow);
saved_for_arrow = NULL;
spline->back_arrow = NULL;
redisplay_spline(spline);
} else if (selected_point->next == NULL) { /* forward arrow */
if (!spline->for_arrow)
return;
draw_spline(spline, ERASE);
saved_for_arrow=spline->for_arrow;
if (saved_back_arrow && saved_back_arrow != spline->back_arrow)
free((char *) saved_back_arrow);
saved_back_arrow = NULL;
spline->for_arrow = NULL;
redisplay_spline(spline);
} else
return;
clean_up();
set_last_prevpoint(prev_point);
set_last_selectedpoint(selected_point);
set_latestspline(spline);
set_action_object(F_DELETE_ARROW_HEAD, O_SPLINE);
set_modifiedflag();
}