File: actions.c

package info (click to toggle)
acm 5.0-19
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,852 kB
  • ctags: 4,792
  • sloc: ansic: 42,427; makefile: 706; cpp: 293; perl: 280; sh: 198
file content (266 lines) | stat: -rw-r--r-- 5,176 bytes parent folder | download | duplicates (9)
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
/*
 *  Copyright (c) 1994, Riley Rainey,  riley@netcon.com
 *
 *  Permission to use, copy, modify and distribute (without charge) this
 *  software, documentation, images, etc. is granted, provided that this 
 *  comment and the author's name is retained.
 *
 *  This software is provided by the author as is, and without any expressed
 *  or implied warranties, including, but not limited to, the implied
 *  warranties of merchantability and fitness for a particular purpose.  In no
 *  event shall the author be liable for any direct, indirect, incidental, or
 *  consequential damages arising in any way out of the use of this software.
 */

#include <Xm/DrawingA.h>
#include <stdio.h>
#include "gedit.h"

static String normal_translations =
	"<Btn1Down>:		point-begin()	\n\
	<Btn1Up>:		point-end()";

static String extra_translations =
	"Shift<Btn1Down>:	point-begin(extend) \n\
	<Btn1Down>:		point-begin()	\n\
	<Btn1Motion>:		point-motion()	\n\
	<Btn1Up>:		point-end()	\n\
	<Btn2Down>:		close-polygon()";

static XtTranslations	normal, extra;

static void PointBegin(), PointMotion(), PointEnd(), DeleteCurrent(),
		ClosePolygon();

static XtActionsRec	action_list[] = {
	{ "point-begin",	PointBegin },
	{ "point-motion",	PointMotion },
	{ "point-end",		PointEnd },
	{ "close-polygon",	ClosePolygon },
	{ "delete-selection",	DeleteCurrent }
	};

extern void BeginPolygonPoint(), CompletePolygon(), CompleteDrag();
extern void CompleteMarker();
extern void BeginCirclePoint(), DragCirclePoint(), CompleteCircle();

void
InitializeTranslations (app, w1, w2)
XtAppContext	app;
Widget		w1, w2;
{

	XtAppAddActions (app, action_list, XtNumber(action_list));

	normal = XtParseTranslationTable (normal_translations);
	extra = XtParseTranslationTable (extra_translations);

	XtVaSetValues (w1,
		XmNtranslations,	extra,
		NULL);

	XtVaSetValues (w2,
		XmNtranslations,	extra,
		NULL);

}

void InstallNormalTranslations (w)
Widget	w;
{
	view_info_t	*p;

	XtVaGetValues (w,
		XmNuserData,	&p,
		NULL);

	XtVaSetValues (w,
		XmNtranslations,	normal,
		NULL);

	XtVaSetValues (p->other_widget,
		XmNtranslations,	normal,
		NULL);
}

void InstallExtraTranslations (w)
Widget	w;
{
	view_info_t	*p;

	XtVaGetValues (w,
		XmNuserData,	&p,
		NULL);

	XtVaSetValues (w,
		XmNtranslations,	extra,
		NULL);

	XtVaSetValues (p->other_widget,
		XmNtranslations,	extra,
		NULL);
}

/*
 *  The next action procedure is typically associated with Button 1 down.
 *
 *  The action taken here depends on the value of edit_state. But we may:
 *
 *    Determine the polygon nearest the click -- within reason.
 *
 *    Begin the process of entering a 3-D point.
 *
 *    Begin the process of relocating the origin.
 *
 */

static void
PointBegin (w, event, params, num_params)
Widget	w;
XEvent	*event;
String	*params;
Cardinal *num_params;
{
	XButtonEvent	*ev = (XButtonEvent *) event;
	view_info_t	*p;
	Boolean		extend = False;

	if ((*num_params > 0) && (strcmp (*params, "extend") == 0))
		extend = True;

	XtVaGetValues (w,
		XmNuserData,	&p,
		NULL);

	switch (edit_state) {
	case STATE_POINT:
		BeginPick (w, p, ev->x, ev->y, extend);
		break;

	case STATE_POLYGON:
		BeginPolygonPoint(w, p, ev->x, ev->y);
		break;

	case STATE_MOVE_ORIGIN:
		break;
		
	case STATE_CIRCLE:
		BeginCirclePoint (w, p, ev->x, ev->y);
		break;

	case STATE_MARKER:
		BeginPolygonPoint(w, p, ev->x, ev->y);
		break;

	}
}

/*
 *    Move the selected polygon in point mode.
 *
 *    Slide the new point along the perpedicular-axis line.
 *
 *    Move the origin locator.
 */

static void
PointMotion (w, event, params, num_params)
Widget	w;
XEvent	*event;
String	*params;
Cardinal *num_params;
{
	XMotionEvent	*ev = (XMotionEvent *) event;
	view_info_t	*p;

	XtVaGetValues (w,
		XmNuserData,	&p,
		NULL);

	switch (edit_state) {
	case STATE_POINT:
		DragSelection (w, p, ev->x, ev->y);
		break;

	case STATE_POLYGON:
	case STATE_MARKER:
		DragPolygonPoint(w, p, ev->x, ev->y);
		break;
		
	case STATE_CIRCLE:
		DragCirclePoint (w, p, ev->x, ev->y);
		break;

	case STATE_MOVE_ORIGIN:
		break;
	}
}

/*
 *    Lock in a polygon selection.
 *
 *    The point has been positioned and is ready to be registered.
 *
 *    Relocate the origin.
 */

static void
PointEnd (w, event, params, num_params)
Widget	w;
XEvent	*event;
String	*params;
Cardinal *num_params;
{
	XButtonEvent	*ev = (XButtonEvent *) event;
	view_info_t	*p;

	XtVaGetValues (w,
		XmNuserData,	&p,
		NULL);

	switch (edit_state) {
	case STATE_POINT:
		CompleteDrag(w, p, ev->x, ev->y);
		break;

	case STATE_POLYGON:
		CompletePolygonPoint (w, p, ev->x, ev->y);
		break;
		
	case STATE_CIRCLE:
		CompleteCirclePoint (w, p, ev->x, ev->y);
		break;

	case STATE_MOVE_ORIGIN:
		break;

	case STATE_MARKER:
		CompleteMarker (w, p, ev->x, ev->y);
		break;
	}
}

/*
 *    Delete the currently selected object.
 */

static void
DeleteCurrent (w, event, params, num_params)
Widget	w;
XEvent	*event;
String	*params;
Cardinal *num_params;
{
	ClearSelection ();
}

static void
ClosePolygon (w, event, params, num_params)
Widget	w;
XEvent	*event;
String	*params;
Cardinal *num_params;
{
	if (cur_polygon != (polygon_t *) NULL)
		CompletePolygon (w, cur_polygon);
}