File: e_placelib.c

package info (click to toggle)
xfig 1%3A3.2.2-2.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 7,296 kB
  • ctags: 5,252
  • sloc: ansic: 51,328; makefile: 670; sh: 24; csh: 5
file content (267 lines) | stat: -rw-r--r-- 6,530 bytes parent folder | download
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
/*
 * FIG : Facility for Interactive Generation of figures
 * Copyright (c) 1985-1988 by Supoj Sutanthavibul
 * Parts Copyright (c) 1989-1998 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 this copyright notice remain intact.
 *
 */

#include "fig.h"
#include "figx.h"
#include "resources.h"
#include "mode.h"
#include "object.h"
#include "paintop.h"
#include "e_placelib.h"
#include "e_rotate.h"
#include "u_draw.h"
#include "u_elastic.h"
#include "u_list.h"
#include "u_search.h"
#include "u_create.h"
#include "w_canvas.h"
#include "w_library.h"
#include "w_mousefun.h"
#include "w_drawprim.h"		/* for max_char_height */
#include "w_dir.h"
#include "w_util.h"
#include "w_setup.h"
#include "w_zoom.h"

/* EXPORTS */

int	cur_library_object = -1;
int	old_library_object = -1;

/* STATICS */

static int	cur_library_x,cur_library_y,off_library_x,off_library_y;

static void	init_move_object(),move_object(),change_draw_mode();
static void	transform_lib_obj(),place_object();
static void	put_draw();

static int draw_box=0;

void
put_selected()
{
	int x,y;
	set_mousefun("place object","new object","cancel library",
			"change draw mode", "new object", "cancel library");
	set_action_on();
	cur_c = lib_compounds[cur_library_object];
	new_c=copy_compound(cur_c);
	off_library_x=new_c->secorner.x;
	off_library_y=new_c->secorner.y;
	canvas_locmove_proc = init_move_object;
	canvas_leftbut_proc = place_object;
	canvas_middlebut_proc = sel_place_lib_obj;
	canvas_rightbut_proc = finish_place_lib_obj;
	set_cursor(null_cursor);

	/* get the pointer position */
	get_pointer_win_xy(&x, &y);
	/* draw the first image */
	init_move_object(BACKX(x), BACKY(y));
}

/* use this one when the user has just loaded a different library,
   but hasn't chosen a new object yet and cancelled the library popup.
   We want all the motions but there is no object yet. */

void
put_noobj_selected()
{
	set_mousefun("","new object","cancel library",
			"", "new object", "cancel library");
	canvas_locmove_proc = null_proc;
	canvas_leftbut_proc = null_proc;
	canvas_middlebut_proc = sel_place_lib_obj;
	canvas_rightbut_proc = finish_place_lib_noobj;
}

/* allow rotation or flipping of library object before placing on canvas */

static void
transform_lib_obj(kpe, c, keysym)
    XKeyEvent	   *kpe;
    unsigned char   c;
    KeySym	    keysym;
{
    int x,y;

    x = cur_library_x;
    y = cur_library_y;

    /* first erase the existing image */
    put_draw(ERASE);
    if (c == 'r') {
	rotn_dirn = 1;
	act_rotnangle = 90;
	rotate_compound(new_c, x, y);
    } else if (c == 'l') {
	rotn_dirn = -1;
	act_rotnangle = 90;
	rotate_compound(new_c, x, y);
    } else if (c == 'h') {
	flip_compound(new_c, x, y, LR_FLIP);
    } else if (c == 'v') {
	flip_compound(new_c, x, y, UD_FLIP);
    } else {
	/* not any of the rotation/flip keys, put the event back on the stack */
	kpe->window = XtWindow(mode_panel);
	kpe->subwindow = 0;
	XPutBackEvent(kpe->display,(XEvent *)kpe);
	return;
    }
    /* and draw the new image */
    put_draw(PAINT);
}

void
sel_place_lib_obj(p, type, x, y, px, py)
    F_line	   *p;
    int		    type;
    int		    x, y, px, py;
{
    canvas_kbd_proc = transform_lib_obj;
    canvas_locmove_proc = null_proc;
    canvas_leftbut_proc = null_proc;
    canvas_middlebut_proc = null_proc;
    canvas_rightbut_proc = null_proc; 
  
    /* erase any object currently being dragged around the canvas */
    if (lib_compounds && new_c)
	put_draw(ERASE);
    popup_library_panel();
}

static void
put_draw(paint_mode)
int paint_mode;
{
  register int    x1, y1, x2, y2;
  
  if (draw_box) {
      x1=cur_library_x;
      y1=cur_library_y;
      x2=cur_library_x+off_library_x;
      y2=cur_library_y+off_library_y;
      elastic_box(x1, y1, x2, y2);
  } else {
      if (paint_mode==ERASE)
	redisplay_compound(new_c);
      else
	redisplay_objects(new_c);      
  }
}

static void
change_draw_mode(x, y)
    int		    x, y;
{
    put_draw(ERASE);
    draw_box = !draw_box;
    translate_compound(new_c,-new_c->nwcorner.x,-new_c->nwcorner.y);
    if (!draw_box)
	translate_compound(new_c,cur_library_x,cur_library_y);
    
    put_draw(PAINT);
}

static void
place_object(x, y, shift)
    int		    x, y;
    unsigned int    shift;
{
    /* if shift-left button, change drawing mode */
    if (shift) {
	change_draw_mode(x, y);
	return;
    }
    canvas_leftbut_proc = null_proc;
    canvas_middlebut_proc = null_proc;
    canvas_rightbut_proc = null_proc;
    canvas_locmove_proc = null_proc;
    put_draw(ERASE);
    clean_up();
    if (draw_box) 
    	translate_compound(new_c,cur_library_x,cur_library_y);
    add_compound(new_c);
    set_modifiedflag();
    redisplay_compound(new_c);
    put_selected();
}


static void
move_object(x, y)
    int		    x, y;
{
    int dx,dy;
  
    put_draw(ERASE);  
    if (!draw_box) {
	dx=x-cur_library_x;
	dy=y-cur_library_y;
	translate_compound(new_c,dx,dy);
    }
    cur_library_x=x;cur_library_y=y;
    put_draw(PAINT);
}

static void
init_move_object(x, y)
    int		    x, y;
{	
    cur_library_x=x;
    cur_library_y=y;
    if (!draw_box)    
	translate_compound(new_c,x,y);
    
    put_draw(PAINT);
    canvas_locmove_proc = move_object;
}

void
finish_place_lib_obj()
{
    reset_action_on();
    canvas_leftbut_proc = null_proc;
    canvas_middlebut_proc = null_proc;
    canvas_rightbut_proc = null_proc;
    canvas_locmove_proc = null_proc;
    canvas_kbd_proc = null_proc;
    clear_mousefun();
    set_mousefun("","","", "", "", "");
    turn_off_current();
    set_cursor(arrow_cursor);
    put_draw(ERASE);
}

/* use this one when there was no object to place and
   the user is cancelling the library place mode */

void
finish_place_lib_noobj()
{
    canvas_leftbut_proc = null_proc;
    canvas_middlebut_proc = null_proc;
    canvas_rightbut_proc = null_proc;
    canvas_locmove_proc = null_proc;
    canvas_kbd_proc = null_proc;
    clear_mousefun();
    set_mousefun("","","", "", "", "");
    turn_off_current();
    set_cursor(arrow_cursor);
}