File: control_click.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (378 lines) | stat: -rw-r--r-- 12,163 bytes parent folder | download | duplicates (5)
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				control_click.c

Purpose:
	Handle ButtonPress event which came from control window.

Input:
	(1) Pointer to MolComplexS structure, with macromol. complexes.
	(2) Number of macromolecular complexes.
	(3) Pointer to RuntimeS structure.
	(4) Pointer to ConfigS structure, with configuration data.
	(5) Pointer to GUIS structure, with GUI data.
	(6) Pointer to NearestAtomS structure.
	(7) The number of pixels in the main window free area.
	(8) Pointer to refreshI.
	(9) Pointer to XButtonEvent structure.

Output:
	(1) The click may cause rotation,  translation,  slab change or
	    fading change.
	(2) Return value.

Return value:
	(1) Positive if some transformation is done.
	(2) Zero if click is ignored (no button pressed).

Notes:
	(1) Indices are assigned as follows:
             0 = KP_0
             1 = KP_1
             2 = KP_2
             3 = KP_3
             4 = KP_4
             5 = KP_5
             6 = KP_6
             7 = KP_7
             8 = KP_8
             9 = KP_9
            10 = KP_Decimal
            11 = KP_Enter
            12 = KP_Add
            13 = KP_Subtract
            14 = KP_Multiply
            15 = KP_Divide
            16 = F1
            17 = F2
            18 = F3
            19 = F4

========includes:============================================================*/

#include <stdio.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======function prototypes:=================================================*/

int		IdentifyButton_ (XButtonEvent *, GUIS *);
size_t		MainRefresh_ (MolComplexS *, int,
			      RuntimeS *, ConfigS *, GUIS *,
			      NearestAtomS *, size_t, unsigned int);
int		ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
int		DockingRefresh_ (RuntimeS *, GUIS *);
double		TranslationShift_ (ConfigS *, GUIS *, double);
void		Translate_ (MolComplexS *, int,
			    RuntimeS *, ConfigS *, double, int);
double		RotationAngle_ (ConfigS *, GUIS *, double);
int		Rotate_ (MolComplexS *, int,
			 RuntimeS *, ConfigS *, double, int);
double		SlabShift_ (ConfigS *, GUIS *, double);
void		MoveBackSlab_ (MolComplexS *, int, ConfigS *, double);
void		MoveFrontSlab_ (MolComplexS *, int, ConfigS *, double);
double		FadingShift_ (ConfigS *, GUIS *, double);
void		MoveBackFading_ (MolComplexS *, int, ConfigS *, double);
void		MoveFrontFading_ (MolComplexS *, int, ConfigS *, double);

/*======handle ButtonPress from control window:==============================*/

int ControlClick_ (MolComplexS *mol_complexSP, int mol_complexesN,
		   RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
		   NearestAtomS *nearest_atomSP, size_t pixelsN,
		   unsigned int *refreshIP,
		   XButtonEvent *button_eventSP)
{
int		buttonI;
double		shift;
double		rotation_angle;

/* Identify dummy button which was pressed: */
buttonI = IdentifyButton_ (button_eventSP, guiSP);

/* Hit or miss: */
if (buttonI < 0) return 0;

/* Apply the requested transformation: */
switch (buttonI)
	{
	/* Translation along z, negative shift: */
	case 0:
		(*refreshIP)++;
		shift = TranslationShift_ (configSP, guiSP, -1.0);
		Translate_ (mol_complexSP, mol_complexesN,
			    runtimeSP, configSP, shift, 3);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Move back slab surface along z, positive shift: */
	case 1:
		(*refreshIP)++;
		shift = SlabShift_ (configSP, guiSP, 1.0);
		MoveBackSlab_ (mol_complexSP, mol_complexesN,
			       configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Positive rotation around x: */
	case 2:
		(*refreshIP)++;
		rotation_angle = RotationAngle_ (configSP, guiSP, 1.0);
		Rotate_ (mol_complexSP, mol_complexesN,
			 runtimeSP, configSP, rotation_angle, 1);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Move back slab surface along z, negative shift: */
	case 3:
		(*refreshIP)++;
		shift = SlabShift_ (configSP, guiSP, -1.0);
		MoveBackSlab_ (mol_complexSP, mol_complexesN,
			       configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Positive rotation around y: */
	case 4:
		(*refreshIP)++;
		rotation_angle = RotationAngle_ (configSP, guiSP, +1.0);
		Rotate_ (mol_complexSP, mol_complexesN,
			 runtimeSP, configSP, rotation_angle, 2);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Translation along z, positive shift: */
	case 5:
		(*refreshIP)++;
		shift = TranslationShift_ (configSP, guiSP, +1.0);
		Translate_ (mol_complexSP, mol_complexesN,
			    runtimeSP, configSP, shift, 3);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Negative rotation around y: */
	case 6:
		(*refreshIP)++;
		rotation_angle = RotationAngle_ (configSP, guiSP, -1.0);
		Rotate_ (mol_complexSP, mol_complexesN,
			 runtimeSP, configSP, rotation_angle, 2);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Negative rotation around z: */
	case 7:
		(*refreshIP)++;
		rotation_angle = RotationAngle_ (configSP, guiSP, -1.0);
		Rotate_ (mol_complexSP, mol_complexesN,
			 runtimeSP, configSP, rotation_angle, 3);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Negative rotation aroung x: */
	case 8:
		(*refreshIP)++;
		rotation_angle = RotationAngle_ (configSP, guiSP, -1.0);
		Rotate_ (mol_complexSP, mol_complexesN,
			 runtimeSP, configSP, rotation_angle, 1);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Positive rotation around z: */
	case 9:
		(*refreshIP)++;
		rotation_angle = RotationAngle_ (configSP, guiSP, +1.0);
		Rotate_ (mol_complexSP, mol_complexesN,
			 runtimeSP, configSP, rotation_angle, 3);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Move front slab surface along z, positive shift: */
	case 10:
		(*refreshIP)++;
		shift = SlabShift_ (configSP, guiSP, 1.0);
		MoveFrontSlab_ (mol_complexSP, mol_complexesN,
				configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Move front slab surface along z, negative shift: */
	case 11:
		(*refreshIP)++;
		shift = SlabShift_ (configSP, guiSP, -1.0);
		MoveFrontSlab_ (mol_complexSP, mol_complexesN,
				configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Translation along y, positive shift: */
	case 12:
		(*refreshIP)++;
		shift = TranslationShift_ (configSP, guiSP, +1.0);
		Translate_ (mol_complexSP, mol_complexesN,
			    runtimeSP, configSP, shift, 2);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Translation along y, negative shift: */
	case 13:
		(*refreshIP)++;
		shift = TranslationShift_ (configSP, guiSP, -1.0);
		Translate_ (mol_complexSP, mol_complexesN,
			    runtimeSP, configSP, shift, 2);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Translation along x, positive shift: */
	case 14:
		(*refreshIP)++;
		shift = TranslationShift_ (configSP, guiSP, +1.0);
		Translate_ (mol_complexSP, mol_complexesN,
			    runtimeSP, configSP, shift, 1);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Translation along x, negative shift: */
	case 15:
		(*refreshIP)++;
		shift = TranslationShift_ (configSP, guiSP, -1.0);
		Translate_ (mol_complexSP, mol_complexesN,
			    runtimeSP, configSP, shift, 1);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP);
		break;

	/* Move back fading surface, positive shift: */
	case 16:
		(*refreshIP)++;
		shift = FadingShift_ (configSP, guiSP, 1.0);
		MoveBackFading_ (mol_complexSP, mol_complexesN,
				 configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Move back fading surface, negative shift: */
	case 17:
		(*refreshIP)++;
		shift = FadingShift_ (configSP, guiSP, -1.0);
		MoveBackFading_ (mol_complexSP, mol_complexesN,
				 configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Move front fading surface, positive shift: */
	case 18:
		(*refreshIP)++;
		shift = FadingShift_ (configSP, guiSP, 1.0);
		MoveFrontFading_ (mol_complexSP, mol_complexesN,
				  configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Move front fading surface, negative shift: */
	case 19:
		(*refreshIP)++;
		shift = FadingShift_ (configSP, guiSP, -1.0);
		MoveFrontFading_ (mol_complexSP, mol_complexesN,
				  configSP, shift);
		MainRefresh_ (mol_complexSP, mol_complexesN,
			      runtimeSP, configSP, guiSP,
			      nearest_atomSP, pixelsN, *refreshIP);
		ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
				 configSP, guiSP);
		break;

	/* Unresolved: */
	default:
		;
	}

/* Return positive value: */
return 1;
}

/*===========================================================================*/