Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2011, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define _PROCESS3D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <string.h>
40
#include <stdlib.h>
41
#include <unistd.h>
42
#include <stdio.h>
43
#include <sys/types.h>
44
#include <sys/time.h>
45
46
47
#include "cfuns.h"
48
#include "header.h"
49
#include "cpanel.h"
50
#include "volume.h"
51
#include "mode.h"
52
#include "process.h"
53
#include "draw.h"
54
#include "sockio.h"
55
#include "com.h"
56
#include "util.H1"
57
#include "Gfun.H1"
58
#include "pixmap.h"
59
#include "XShade.h"
60
#include "XSpadFill.h"
61
#include "all_3d.H1"
62
63
#define inside(A,B) (((XButtonEvent *)event)->x >= A && \
64
((XButtonEvent *)event)->x <= B)
65
66
67
void
68
buttonAction (int bKey)
69
{
70
71
const char* s1;
72
const char* s2;
73
int strL, strL1, strL2, offShade=14;
74
75
/* Button colors which are offColor, RED, are turned off, and those which
76
are onColor, GREEN, indicate the mode is in effect. */
77
78
switch (bKey) {
79
80
case hideControl:
81
if (viewport->haveControl) {
82
viewport->haveControl = no;
83
XUnmapWindow(dsply,control->controlWindow);
84
}
85
break;
86
87
case region3D:
88
clearControlMessage();
89
strcpy(control->message,viewport->title);
90
writeControlMessage();
91
if (viewport->regionOn) {
92
viewport->regionOn = no;
93
(control->buttonQueue[region3D]).textColor = offColor;
94
viewData.box = 0;
95
if (mono) {
96
XChangeShade(dsply,offShade);
97
XShadeRectangle(dsply,control->controlWindow,
98
(control->buttonQueue[region3D]).buttonX,
99
(control->buttonQueue[region3D]).buttonY,
100
(control->buttonQueue[region3D]).buttonWidth,
101
(control->buttonQueue[region3D]).buttonHeight);
102
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
103
GDrawRectangle(globalGC1, control->controlWindow,
104
(control->buttonQueue[region3D]).buttonX,
105
(control->buttonQueue[region3D]).buttonY,
106
(control->buttonQueue[region3D]).buttonWidth,
107
(control->buttonQueue[region3D]).buttonHeight,Xoption);
108
}
109
} else { /* inverted color for region off */
110
viewport->regionOn = yes;
111
viewData.box = 1;
112
(control->buttonQueue[region3D]).textColor = onColor;
113
if (mono) {
114
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
115
XFillRectangle(dsply, control->controlWindow, globalGC1,
116
(control->buttonQueue[region3D]).buttonX,
117
(control->buttonQueue[region3D]).buttonY,
118
(control->buttonQueue[region3D]).buttonWidth,
119
(control->buttonQueue[region3D]).buttonHeight);
120
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
121
GDrawRectangle(globalGC1, control->controlWindow,
122
(control->buttonQueue[region3D]).buttonX,
123
(control->buttonQueue[region3D]).buttonY,
124
(control->buttonQueue[region3D]).buttonWidth,
125
(control->buttonQueue[region3D]).buttonHeight,Xoption);
126
}
127
}
128
129
s = (control->buttonQueue[region3D]).text;
130
strL = strlen(s);
131
132
GSetForeground(processGC,
133
(float)monoColor((control->buttonQueue[region3D]).textColor),Xoption);
134
GDrawImageString(processGC,control->controlWindow,
135
(control->buttonQueue[region3D]).buttonX +
136
centerX(processGC,s,strL,
137
(control->buttonQueue[region3D]).buttonWidth),
138
(control->buttonQueue[region3D]).buttonY +
139
centerY(processGC,
140
(control->buttonQueue[region3D]).buttonHeight),
141
s,strL,Xoption);
142
redoSmooth = yes;
143
drawViewport(Xoption);
144
break;
145
146
147
148
case bwColor:
149
clearControlMessage();
150
strcpy(control->message,viewport->title);
151
writeControlMessage();
152
if (!mono) {
153
if (viewport->monoOn) {
154
viewport->monoOn = no;
155
if (viewport->hueTop == viewport->hueOffset) redoColor = yes;
156
else redoDither = yes;
157
(control->buttonQueue[bwColor]).textColor = offColor;
158
(control->buttonQueue[bwColor]).text = "BW";
159
} else {
160
viewport->monoOn = yes;
161
maxGreyShade = XInitShades(dsply,scrn);
162
if (viewport->hueTop == viewport->hueOffset) redoColor = yes;
163
else redoDither = yes;
164
(control->buttonQueue[bwColor]).textColor = onColor;
165
(control->buttonQueue[bwColor]).text = "BW";
166
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
167
XFillRectangle(dsply, control->controlWindow, globalGC1,
168
(control->buttonQueue[bwColor]).buttonX,
169
(control->buttonQueue[bwColor]).buttonY,
170
(control->buttonQueue[bwColor]).buttonWidth,
171
(control->buttonQueue[bwColor]).buttonHeight);
172
GSetForeground(globalGC1,(float)monoColor(buttonColor),Xoption);
173
GDrawRectangle(globalGC1, control->controlWindow,
174
(control->buttonQueue[bwColor]).buttonX,
175
(control->buttonQueue[bwColor]).buttonY,
176
(control->buttonQueue[bwColor]).buttonWidth,
177
(control->buttonQueue[bwColor]).buttonHeight,Xoption);
178
}
179
180
s = (control->buttonQueue[bwColor]).text;
181
strL = strlen(s);
182
183
GSetForeground(processGC,
184
(float)monoColor((control->buttonQueue[bwColor]).textColor),Xoption);
185
GDrawImageString(processGC,control->controlWindow,
186
(control->buttonQueue[bwColor]).buttonX +
187
centerX(processGC,s,strL,
188
(control->buttonQueue[bwColor]).buttonWidth),
189
(control->buttonQueue[bwColor]).buttonY +
190
centerY(processGC,
191
(control->buttonQueue[bwColor]).buttonHeight),
192
s,strL,Xoption);
193
drawColorMap();
194
redoSmooth = yes;
195
writeTitle();
196
drawViewport(Xoption);
197
}
198
break;
199
200
201
202
case outlineOnOff:
203
clearControlMessage();
204
strcpy(control->message,viewport->title);
205
writeControlMessage();
206
if (viewData.outlineRenderOn) {
207
viewData.outlineRenderOn = 0;
208
(control->buttonQueue[outlineOnOff]).textColor = offColor;
209
if (mono) {
210
XChangeShade(dsply,offShade);
211
XShadeRectangle(dsply,control->controlWindow,
212
(control->buttonQueue[outlineOnOff]).buttonX,
213
(control->buttonQueue[outlineOnOff]).buttonY,
214
(control->buttonQueue[outlineOnOff]).buttonWidth,
215
(control->buttonQueue[outlineOnOff]).buttonHeight);
216
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
217
GDrawRectangle(globalGC1, control->controlWindow,
218
(control->buttonQueue[outlineOnOff]).buttonX,
219
(control->buttonQueue[outlineOnOff]).buttonY,
220
(control->buttonQueue[outlineOnOff]).buttonWidth,
221
(control->buttonQueue[outlineOnOff]).buttonHeight,Xoption);
222
}
223
} else {
224
viewData.outlineRenderOn = 1;
225
(control->buttonQueue[outlineOnOff]).textColor = onColor;
226
if (mono) {
227
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
228
XFillRectangle(dsply, control->controlWindow, globalGC1,
229
(control->buttonQueue[outlineOnOff]).buttonX,
230
(control->buttonQueue[outlineOnOff]).buttonY,
231
(control->buttonQueue[outlineOnOff]).buttonWidth,
232
(control->buttonQueue[outlineOnOff]).buttonHeight);
233
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
234
GDrawRectangle(globalGC1, control->controlWindow,
235
(control->buttonQueue[outlineOnOff]).buttonX,
236
(control->buttonQueue[outlineOnOff]).buttonY,
237
(control->buttonQueue[outlineOnOff]).buttonWidth,
238
(control->buttonQueue[outlineOnOff]).buttonHeight,Xoption);
239
}
240
}
241
s = (control->buttonQueue[outlineOnOff]).text;
242
strL = strlen(s);
243
244
GSetForeground(processGC,
245
(float)monoColor((control->buttonQueue[outlineOnOff]).textColor),Xoption);
246
GDrawImageString(processGC,control->controlWindow,
247
(control->buttonQueue[outlineOnOff]).buttonX +
248
centerX(processGC,s,strL,
249
(control->buttonQueue[outlineOnOff]).buttonWidth),
250
(control->buttonQueue[outlineOnOff]).buttonY +
251
centerY(processGC,
252
(control->buttonQueue[outlineOnOff]).buttonHeight),
253
s,strL,Xoption);
254
if (viewData.style == render) {
255
drawViewport(Xoption);
256
}
257
break;
258
259
260
case lighting:
261
if (saveFlag) {
262
doingPanel = CONTROLpanel;
263
XUnmapWindow(dsply,saveWindow);
264
}
265
doingPanel = LIGHTpanel;
266
tempLightPointer[0] = viewport->lightVector[0];
267
tempLightPointer[1] = viewport->lightVector[1];
268
tempLightPointer[2] = viewport->lightVector[2];
269
tempLightIntensity = lightIntensity;
270
XMapWindow(dsply,lightingWindow);
271
break;
272
273
274
case viewVolume:
275
if (saveFlag) {
276
doingPanel = CONTROLpanel;
277
XUnmapWindow(dsply,saveWindow);
278
}
279
doingPanel = VOLUMEpanel;
280
XMapWindow(dsply,volumeWindow);
281
redrawView = yes;
282
drawViewport(Xoption); /* draw it with doingVolume set to yes */
283
break;
284
285
286
case volumeReturn:
287
doingPanel = CONTROLpanel;
288
redoSmooth = yes;
289
redrawView = yes;
290
XUnmapWindow(dsply,volumeWindow);
291
break;
292
293
294
case volumeAbort:
295
doingPanel = CONTROLpanel;
296
redrawView = yes;
297
XUnmapWindow(dsply,volumeWindow);
298
break;
299
300
301
case lightReturn:
302
doingPanel = CONTROLpanel;
303
viewport->lightVector[0] = lightPointer[0] = tempLightPointer[0];
304
viewport->lightVector[1] = lightPointer[1] = tempLightPointer[1];
305
viewport->lightVector[2] = lightPointer[2] = tempLightPointer[2];
306
lightIntensity = tempLightIntensity;
307
normalizeVector(viewport->lightVector);
308
redrawView = ((viewData.style == render) || (viewData.style == smooth));
309
if (movingLight || changedIntensity) redoSmooth = yes;
310
XUnmapWindow(dsply,lightingWindow);
311
break;
312
313
314
case lightAbort:
315
movingLight = no; changedIntensity = no;
316
doingPanel = CONTROLpanel;
317
XUnmapWindow(dsply,lightingWindow);
318
break;
319
320
321
case resetView:
322
clearControlMessage();
323
strcpy(control->message,viewport->title);
324
writeControlMessage();
325
viewport->axesOn = yes;
326
viewport->regionOn = no; viewData.box = 0;
327
viewData.outlineRenderOn = 0;
328
viewport->monoOn = no;
329
viewport->zoomXOn = viewport->zoomYOn = viewport->zoomZOn = yes;
330
viewport->originrOn = yes; viewport->objectrOn = no;
331
viewport->originFlag = no;
332
viewport->xyOn = viewport->xzOn = viewport->yzOn = no;
333
viewport->lightVector[0] = -0.5;
334
viewport->lightVector[1] = 0.5;
335
viewport->lightVector[2] = 0.5;
336
viewport->translucency = viewData.translucency;
337
viewport->deltaX = viewport->deltaX0;
338
viewport->deltaY = viewport->deltaY0;
339
viewport->deltaY = viewport->deltaZ0;
340
viewport->scale = viewport->scale0;
341
viewport->scaleX = viewport->scaleY = viewport->scaleZ = 1.0;
342
if (!equal(viewport->theta,viewport->theta0) || !equal(viewport->phi,viewport->phi0))
343
rotated = yes;
344
viewport->theta = viewport->axestheta = viewport->theta0 = viewData.theta;
345
viewport->phi = viewport->axesphi = viewport->phi0 = viewData.phi;
346
viewport->thetaObj = 0.0;
347
viewport->phiObj = 0.0;
348
redoSmooth = yes;
349
drawViewport(Xoption);
350
if (viewport->haveControl) drawControlPanel();
351
writeTitle();
352
break;
353
354
355
case axesOnOff:
356
clearControlMessage();
357
strcpy(control->message,viewport->title);
358
writeControlMessage();
359
if (viewport->axesOn) {
360
viewport->axesOn = no;
361
(control->buttonQueue[axesOnOff]).textColor = offColor;
362
if (mono) {
363
XChangeShade(dsply,offShade);
364
XShadeRectangle(dsply,control->controlWindow,
365
(control->buttonQueue[axesOnOff]).buttonX,
366
(control->buttonQueue[axesOnOff]).buttonY,
367
(control->buttonQueue[axesOnOff]).buttonWidth,
368
(control->buttonQueue[axesOnOff]).buttonHeight);
369
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
370
GDrawRectangle(globalGC1, control->controlWindow,
371
(control->buttonQueue[axesOnOff]).buttonX,
372
(control->buttonQueue[axesOnOff]).buttonY,
373
(control->buttonQueue[axesOnOff]).buttonWidth,
374
(control->buttonQueue[axesOnOff]).buttonHeight,Xoption);
375
}
376
} else { /* draw invert-color button */
377
viewport->axesOn = yes;
378
(control->buttonQueue[axesOnOff]).textColor = onColor;
379
if (mono) {
380
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
381
XFillRectangle(dsply, control->controlWindow, globalGC1,
382
(control->buttonQueue[axesOnOff]).buttonX,
383
(control->buttonQueue[axesOnOff]).buttonY,
384
(control->buttonQueue[axesOnOff]).buttonWidth,
385
(control->buttonQueue[axesOnOff]).buttonHeight);
386
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
387
GDrawRectangle(globalGC1, control->controlWindow,
388
(control->buttonQueue[axesOnOff]).buttonX,
389
(control->buttonQueue[axesOnOff]).buttonY,
390
(control->buttonQueue[axesOnOff]).buttonWidth,
391
(control->buttonQueue[axesOnOff]).buttonHeight,Xoption);
392
}
393
}
394
395
s = (control->buttonQueue[axesOnOff]).text;
396
strL = strlen(s);
397
398
GSetForeground(processGC,
399
(float)monoColor((control->buttonQueue[axesOnOff]).textColor),Xoption);
400
GDrawImageString(processGC,control->controlWindow,
401
(control->buttonQueue[axesOnOff]).buttonX +
402
centerX(processGC,s,strL,
403
(control->buttonQueue[axesOnOff]).buttonWidth),
404
(control->buttonQueue[axesOnOff]).buttonY +
405
centerY(processGC,
406
(control->buttonQueue[axesOnOff]).buttonHeight),
407
s,strL,Xoption);
408
if (viewData.style == smooth) {
409
if (multiColorFlag) redoDither = yes;
410
else redoColor = yes;
411
}
412
drawViewport(Xoption);
413
break;
414
415
416
case zoomx:
417
if (viewport->zoomXOn) {
418
viewport->zoomXOn = no;
419
(control->buttonQueue[zoomx]).textColor = offColor;
420
if (mono) {
421
XChangeShade(dsply,offShade);
422
XShadeRectangle(dsply,control->controlWindow,
423
(control->buttonQueue[zoomx]).buttonX,
424
(control->buttonQueue[zoomx]).buttonY,
425
(control->buttonQueue[zoomx]).buttonWidth,
426
(control->buttonQueue[zoomx]).buttonHeight);
427
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
428
GDrawRectangle(globalGC1, control->controlWindow,
429
(control->buttonQueue[zoomx]).buttonX,
430
(control->buttonQueue[zoomx]).buttonY,
431
(control->buttonQueue[zoomx]).buttonWidth,
432
(control->buttonQueue[zoomx]).buttonHeight,Xoption);
433
}
434
} else {
435
viewport->zoomXOn = yes;
436
(control->buttonQueue[zoomx]).textColor = onColor;
437
if (mono) {
438
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
439
XFillRectangle(dsply, control->controlWindow, globalGC1,
440
(control->buttonQueue[zoomx]).buttonX,
441
(control->buttonQueue[zoomx]).buttonY,
442
(control->buttonQueue[zoomx]).buttonWidth,
443
(control->buttonQueue[zoomx]).buttonHeight);
444
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
445
GDrawRectangle(globalGC1, control->controlWindow,
446
(control->buttonQueue[zoomx]).buttonX,
447
(control->buttonQueue[zoomx]).buttonY,
448
(control->buttonQueue[zoomx]).buttonWidth,
449
(control->buttonQueue[zoomx]).buttonHeight,Xoption);
450
}
451
}
452
453
s = (control->buttonQueue[zoomx]).text;
454
strL = strlen(s);
455
456
GSetForeground(processGC,
457
(float)monoColor((control->buttonQueue[zoomx]).textColor),Xoption);
458
GDrawImageString(processGC,control->controlWindow,
459
(control->buttonQueue[zoomx]).buttonX +
460
centerX(processGC,s,strL,
461
(control->buttonQueue[zoomx]).buttonWidth),
462
(control->buttonQueue[zoomx]).buttonY +
463
centerY(processGC,
464
(control->buttonQueue[zoomx]).buttonHeight),
465
s,strL,Xoption);
466
clearControlMessage();
467
strcpy(control->message,viewport->title);
468
writeControlMessage();
469
break;
470
471
472
case zoomy:
473
if (viewport->zoomYOn) {
474
viewport->zoomYOn = no;
475
(control->buttonQueue[zoomy]).textColor = offColor;
476
if (mono) {
477
XChangeShade(dsply,offShade);
478
XShadeRectangle(dsply,control->controlWindow,
479
(control->buttonQueue[zoomy]).buttonX,
480
(control->buttonQueue[zoomy]).buttonY,
481
(control->buttonQueue[zoomy]).buttonWidth,
482
(control->buttonQueue[zoomy]).buttonHeight);
483
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
484
GDrawRectangle(globalGC1, control->controlWindow,
485
(control->buttonQueue[zoomy]).buttonX,
486
(control->buttonQueue[zoomy]).buttonY,
487
(control->buttonQueue[zoomy]).buttonWidth,
488
(control->buttonQueue[zoomy]).buttonHeight,Xoption);
489
}
490
} else {
491
viewport->zoomYOn = yes;
492
(control->buttonQueue[zoomy]).textColor = onColor;
493
if (mono) {
494
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
495
XFillRectangle(dsply, control->controlWindow, globalGC1,
496
(control->buttonQueue[zoomy]).buttonX,
497
(control->buttonQueue[zoomy]).buttonY,
498
(control->buttonQueue[zoomy]).buttonWidth,
499
(control->buttonQueue[zoomy]).buttonHeight);
500
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
501
GDrawRectangle(globalGC1, control->controlWindow,
502
(control->buttonQueue[zoomy]).buttonX,
503
(control->buttonQueue[zoomy]).buttonY,
504
(control->buttonQueue[zoomy]).buttonWidth,
505
(control->buttonQueue[zoomy]).buttonHeight,Xoption);
506
}
507
}
508
509
s = (control->buttonQueue[zoomy]).text;
510
strL = strlen(s);
511
512
GSetForeground(processGC,
513
(float)monoColor((control->buttonQueue[zoomy]).textColor),Xoption);
514
GDrawImageString(processGC,control->controlWindow,
515
(control->buttonQueue[zoomy]).buttonX +
516
centerX(processGC,s,strL,
517
(control->buttonQueue[zoomy]).buttonWidth),
518
(control->buttonQueue[zoomy]).buttonY +
519
centerY(processGC,
520
(control->buttonQueue[zoomy]).buttonHeight),
521
s,strL,Xoption);
522
clearControlMessage();
523
strcpy(control->message,viewport->title);
524
writeControlMessage();
525
break;
526
527
528
case zoomz:
529
if (viewport->zoomZOn) {
530
viewport->zoomZOn = no;
531
(control->buttonQueue[zoomz]).textColor = offColor;
532
if (mono) {
533
XChangeShade(dsply,offShade);
534
XShadeRectangle(dsply,control->controlWindow,
535
(control->buttonQueue[zoomz]).buttonX,
536
(control->buttonQueue[zoomz]).buttonY,
537
(control->buttonQueue[zoomz]).buttonWidth,
538
(control->buttonQueue[zoomz]).buttonHeight);
539
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
540
GDrawRectangle(globalGC1, control->controlWindow,
541
(control->buttonQueue[zoomz]).buttonX,
542
(control->buttonQueue[zoomz]).buttonY,
543
(control->buttonQueue[zoomz]).buttonWidth,
544
(control->buttonQueue[zoomz]).buttonHeight,Xoption);
545
}
546
} else {
547
viewport->zoomZOn = yes;
548
(control->buttonQueue[zoomz]).textColor = onColor;
549
if (mono) {
550
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
551
XFillRectangle(dsply, control->controlWindow, globalGC1,
552
(control->buttonQueue[zoomz]).buttonX,
553
(control->buttonQueue[zoomz]).buttonY,
554
(control->buttonQueue[zoomz]).buttonWidth,
555
(control->buttonQueue[zoomz]).buttonHeight);
556
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
557
GDrawRectangle(globalGC1, control->controlWindow,
558
(control->buttonQueue[zoomz]).buttonX,
559
(control->buttonQueue[zoomz]).buttonY,
560
(control->buttonQueue[zoomz]).buttonWidth,
561
(control->buttonQueue[zoomz]).buttonHeight,Xoption);
562
}
563
}
564
565
s = (control->buttonQueue[zoomz]).text;
566
strL = strlen(s);
567
568
GSetForeground(processGC,
569
(float)monoColor((control->buttonQueue[zoomz]).textColor),Xoption);
570
GDrawImageString(processGC,control->controlWindow,
571
(control->buttonQueue[zoomz]).buttonX +
572
centerX(processGC,s,strL,
573
(control->buttonQueue[zoomz]).buttonWidth),
574
(control->buttonQueue[zoomz]).buttonY +
575
centerY(processGC,
576
(control->buttonQueue[zoomz]).buttonHeight),
577
s,strL,Xoption);
578
clearControlMessage();
579
strcpy(control->message,viewport->title);
580
writeControlMessage();
581
break;
582
583
584
case originr:
585
viewport->originrOn = yes;
586
(control->buttonQueue[originr]).textColor = onColor;
587
viewport->objectrOn = no;
588
(control->buttonQueue[objectr]).textColor = offColor;
589
viewport->originFlag = yes;
590
if (mono) {
591
XChangeShade(dsply,offShade);
592
XShadeRectangle(dsply,control->controlWindow,
593
(control->buttonQueue[objectr]).buttonX,
594
(control->buttonQueue[objectr]).buttonY,
595
(control->buttonQueue[objectr]).buttonWidth,
596
(control->buttonQueue[objectr]).buttonHeight);
597
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
598
GDrawRectangle(globalGC1, control->controlWindow,
599
(control->buttonQueue[objectr]).buttonX,
600
(control->buttonQueue[objectr]).buttonY,
601
(control->buttonQueue[objectr]).buttonWidth,
602
(control->buttonQueue[objectr]).buttonHeight,Xoption);
603
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
604
XFillRectangle(dsply, control->controlWindow, globalGC1,
605
(control->buttonQueue[originr]).buttonX,
606
(control->buttonQueue[originr]).buttonY,
607
(control->buttonQueue[originr]).buttonWidth,
608
(control->buttonQueue[originr]).buttonHeight);
609
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
610
GDrawRectangle(globalGC1, control->controlWindow,
611
(control->buttonQueue[originr]).buttonX,
612
(control->buttonQueue[originr]).buttonY,
613
(control->buttonQueue[originr]).buttonWidth,
614
(control->buttonQueue[originr]).buttonHeight,Xoption);
615
}
616
s1 = (control->buttonQueue[objectr]).text;
617
strL1 = strlen(s1);
618
s2 = (control->buttonQueue[originr]).text;
619
strL2 = strlen(s2);
620
621
GSetForeground(processGC,
622
(float)monoColor((control->buttonQueue[objectr]).textColor),Xoption);
623
GDrawImageString(processGC,control->controlWindow,
624
(control->buttonQueue[objectr]).buttonX +
625
centerX(processGC,s1,strL1,
626
(control->buttonQueue[objectr]).buttonWidth),
627
(control->buttonQueue[objectr]).buttonY +
628
centerY(processGC,
629
(control->buttonQueue[objectr]).buttonHeight),
630
s1,strL1,Xoption);
631
632
GSetForeground(processGC,
633
(float)monoColor((control->buttonQueue[originr]).textColor),Xoption);
634
GDrawImageString(processGC,control->controlWindow,
635
(control->buttonQueue[originr]).buttonX +
636
centerX(processGC,s2,strL2,
637
(control->buttonQueue[originr]).buttonWidth),
638
(control->buttonQueue[originr]).buttonY +
639
centerY(processGC,
640
(control->buttonQueue[originr]).buttonHeight),
641
s2,strL2,Xoption);
642
clearControlMessage();
643
strcpy(control->message,viewport->title);
644
writeControlMessage();
645
break;
646
647
648
649
case objectr:
650
viewport->objectrOn = yes;
651
(control->buttonQueue[objectr]).textColor = onColor;
652
viewport->originrOn = no;
653
(control->buttonQueue[originr]).textColor = offColor;
654
655
viewport->originFlag = no;
656
if (mono) {
657
XChangeShade(dsply,offShade);
658
XShadeRectangle(dsply,control->controlWindow,
659
(control->buttonQueue[originr]).buttonX,
660
(control->buttonQueue[originr]).buttonY,
661
(control->buttonQueue[originr]).buttonWidth,
662
(control->buttonQueue[originr]).buttonHeight);
663
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
664
GDrawRectangle(globalGC1, control->controlWindow,
665
(control->buttonQueue[originr]).buttonX,
666
(control->buttonQueue[originr]).buttonY,
667
(control->buttonQueue[originr]).buttonWidth,
668
(control->buttonQueue[originr]).buttonHeight,Xoption);
669
GSetForeground(globalGC1,(float)backgroundColor,Xoption);
670
XFillRectangle(dsply, control->controlWindow, globalGC1,
671
(control->buttonQueue[objectr]).buttonX,
672
(control->buttonQueue[objectr]).buttonY,
673
(control->buttonQueue[objectr]).buttonWidth,
674
(control->buttonQueue[objectr]).buttonHeight);
675
GSetForeground(globalGC1,(float)foregroundColor,Xoption);
676
GDrawRectangle(globalGC1, control->controlWindow,
677
(control->buttonQueue[objectr]).buttonX,
678
(control->buttonQueue[objectr]).buttonY,
679
(control->buttonQueue[objectr]).buttonWidth,
680
(control->buttonQueue[objectr]).buttonHeight,Xoption);
681
}
682
s1 = (control->buttonQueue[objectr]).text;
683
strL1 = strlen(s1);
684
s2 = (control->buttonQueue[originr]).text;
685
strL2 = strlen(s2);
686
687
GSetForeground(processGC,
688
(float)monoColor((control->buttonQueue[objectr]).textColor),Xoption);
689
GDrawImageString(processGC,control->controlWindow,
690
(control->buttonQueue[objectr]).buttonX +
691
centerX(processGC,s1,strL1,
692
(control->buttonQueue[objectr]).buttonWidth),
693
(control->buttonQueue[objectr]).buttonY +
694
centerY(processGC,
695
(control->buttonQueue[objectr]).buttonHeight),
696
s1,strL1,Xoption);
697
698
GSetForeground(processGC,
699
(float)monoColor((control->buttonQueue[originr]).textColor),Xoption);
700
GDrawImageString(processGC,control->controlWindow,
701
(control->buttonQueue[originr]).buttonX +
702
centerX(processGC,s2,strL2,
703
(control->buttonQueue[originr]).buttonWidth),
704
(control->buttonQueue[originr]).buttonY +
705
centerY(processGC,
706
(control->buttonQueue[originr]).buttonHeight),
707
s2,strL2,Xoption);
708
clearControlMessage();
709
strcpy(control->message,viewport->title);
710
writeControlMessage();
711
break;
712
713
714
715
case ps:
716
strcpy(control->message," Creating postscript file ... ");
717
writeControlMessage();
718
if (PSInit(viewport->viewWindow, viewport->titleWindow) == psError) {
719
strcpy(control->message," Aborted: PSInit error. ");
720
writeControlMessage();
721
return; /* make new tmpnam for new file */
722
}
723
724
redoSmooth = yes;
725
drawViewport(PSoption); /* draw picture in PS; create ps script file */
726
727
if (PSCreateFile(viewBorderWidth, viewport->viewWindow,
728
viewport->titleWindow, viewport->title) == psError) {
729
strcpy(control->message," Aborted: PSCreateFile error. ");
730
writeControlMessage();
731
return;
732
}
733
734
clearControlMessage();
735
strcpy(control->message,PSfilename);
736
strcat(control->message," in working dir ");
737
writeControlMessage();
738
break;
739
740
741
742
case pixmap:
743
strcpy(control->message," Creating axiom3D.xpm now ... ");
744
writeControlMessage();
745
XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
746
write_pixmap_file(dsply,scrn,"axiom3D.xpm",
747
viewport->titleWindow,0,0,vwInfo.width,
748
vwInfo.height+titleHeight);
749
clearControlMessage();
750
strcpy(control->message," axiom3D.xpm in working dir ");
751
writeControlMessage();
752
break;
753
754
755
756
case transparent:
757
case opaqueMesh:
758
case render:
759
case smooth:
760
clearControlMessage();
761
strcpy(control->message,viewport->title);
762
writeControlMessage();
763
viewData.style = bKey;
764
drawViewport(Xoption); /* draw picture in viewWindow with X routines */
765
break;
766
767
768
case closeAll:
769
clearControlMessage();
770
strcpy(control->message,viewport->title);
771
writeControlMessage();
772
doingPanel = QUITpanel;
773
viewport->closing = yes;
774
XMapWindow(dsply,quitWindow);
775
break;
776
777
778
case quitReturn:
779
XUnmapWindow(dsply,quitWindow);
780
break;
781
782
783
case quitAbort:
784
doingPanel = CONTROLpanel;
785
XUnmapWindow(dsply,quitWindow);
786
break;
787
788
789
case saveit:
790
clearControlMessage();
791
strcpy(control->message,viewport->title);
792
writeControlMessage();
793
saveFlag = yes;
794
doingPanel = SAVEpanel;
795
XMapWindow(dsply,saveWindow);
796
break;
797
798
799
case saveExit:
800
saveFlag = no;
801
doingPanel = CONTROLpanel;
802
XUnmapWindow(dsply,saveWindow);
803
break;
804
805
806
case xy:
807
viewport->theta = pi;
808
viewport->phi = 0.0;
809
viewport->axestheta = pi;
810
viewport->axesphi = 0.0;
811
rotated = yes;
812
viewport->yzOn = viewport->xzOn = no;
813
viewport->xyOn = yes;
814
drawViewport(Xoption);
815
break;
816
817
818
case xz:
819
viewport->theta = pi;
820
viewport->phi = -pi_half;
821
viewport->axestheta = pi;
822
viewport->axesphi = -pi_half;
823
rotated = yes;
824
viewport->yzOn = viewport->xyOn = no;
825
viewport->xzOn = yes;
826
drawViewport(Xoption);
827
break;
828
829
830
case yz:
831
viewport->theta = pi_half;
832
viewport->phi = -pi_half;
833
viewport->axestheta = pi_half;
834
viewport->axesphi = -pi_half;
835
rotated = yes;
836
viewport->xzOn = viewport->xyOn = no;
837
viewport->yzOn = yes;
838
drawViewport(Xoption);
839
break;
840
841
842
default:
843
fprintf(stderr,"Received a non-functioning button request: %d \n",bKey);
844
break;
845
} /* switch (action) */
846
847
} /* processEvents() */
848
849
850
851
/************************** X Event Processing *****************************/
852
void
853
processEvents(void)
854
{
855
856
XEvent *event, tempEvent;
857
Window whichWindow;
858
buttonStruct *controlButton;
859
mouseCoord mouseXY, linearMouseXY;
860
int someInt, mouseW4, mouseH4;
861
int toggleReady =yes;
862
int checkButton = no;
863
int first_time = yes;
864
int changingColor = yes;
865
int gotEvent = 0, exposeView = no;
866
int tempTW, tempTH, tempVW, tempVH;
867
int buttonTablePtr;
868
float f1, f2;
869
int px, py, lx, ly;
870
unsigned int lbuttons;
871
Window dummy;
872
int Xcon,externalControl,len;
873
fd_set rd;
874
875
externalControl = 0;
876
Xcon = ConnectionNumber(dsply);
877
878
/** assign lightPointer for light panel **/
879
lightPointer[0] = tempLightPointer[0] = viewport->lightVector[0];
880
lightPointer[1] = tempLightPointer[1] = viewport->lightVector[1];
881
lightPointer[2] = tempLightPointer[2] = viewport->lightVector[2];
882
883
if (!(event = (XEvent *)saymem("process.c",1,sizeof(XEvent)))) {
884
fprintf(stderr,"Ran out of memory initializing event processing.\n");
885
exitWithAck(RootWindow(dsply,scrn),Window,-1);
886
}
887
888
controlButton = 0;
889
890
while(1) {
891
892
/* Store old viewport window size attributes for resizing comparison. */
893
XGetWindowAttributes(dsply,viewport->titleWindow,&graphWindowAttrib);
894
tempTW = graphWindowAttrib.width;
895
tempTH = graphWindowAttrib.height;
896
XGetWindowAttributes(dsply,viewport->viewWindow,&graphWindowAttrib);
897
tempVW = graphWindowAttrib.width;
898
tempVH = graphWindowAttrib.height;
899
900
/* Get the next X event. The check for pending events is so that
901
a held down mouse button is interpreted as an event
902
even if nothing is pending. */
903
904
len=0;
905
while(len<=0) {
906
FD_ZERO(&rd);
907
if (externalControl==0) FD_SET(0, &rd);
908
FD_SET(Xcon,&rd);
909
910
if (XEventsQueued(dsply, QueuedAlready)) {
911
len=1;
912
break;
913
}
914
if (!followMouse)
915
len=select(FD_SETSIZE, &rd,0,0,0);
916
else
917
len=1;
918
}
919
920
if (FD_ISSET(Xcon,&rd)||
921
XEventsQueued(dsply, QueuedAfterFlush) ||
922
followMouse) {
923
924
if (followMouse) {
925
if (XPending(dsply))
926
XNextEvent(dsply,event);
927
gotEvent++;
928
} else {
929
XNextEvent(dsply,event);
930
gotEvent++;
931
}
932
933
if (gotToggle || !followMouse)
934
checkButton = no;
935
936
if (gotEvent) {
937
whichWindow = ((XButtonEvent *)event)->window;
938
first_time = no;
939
940
switch(((XEvent *)event)->type) {
941
case ClientMessage:
942
if (event->xclient.data.l[0] == wm_delete_window) {
943
goodbye(-1);
944
}
945
else {
946
fprintf(stderr,"Unknown Client Message ...\n");
947
}
948
break;
949
case Expose:
950
if (whichWindow == viewport->titleWindow) {
951
exposeView = yes;
952
followMouse = no;
953
XSync(dsply,0);
954
/* get rid of redundant exposure events */
955
XCheckWindowEvent(dsply,viewport->titleWindow,
956
ExposureMask,&tempEvent);
957
writeTitle();
958
XGetWindowAttributes(dsply,viewport->titleWindow,
959
&graphWindowAttrib);
960
if ((graphWindowAttrib.width!=tempTW) ||
961
((graphWindowAttrib.height)!=tempTH)) {
962
XResizeWindow(dsply,viewport->viewWindow,
963
graphWindowAttrib.width, graphWindowAttrib.height);
964
redoSmooth = yes; /* recompute smooth image pixmap if resized */
965
}
966
} else if (whichWindow == viewport->viewWindow) {
967
exposeView = yes;
968
followMouse = no;
969
XSync(dsply,0);
970
XCheckWindowEvent(dsply,viewport->viewWindow,ExposureMask,
971
&tempEvent);
972
XGetWindowAttributes(dsply,viewport->viewWindow,&graphWindowAttrib);
973
if ((graphWindowAttrib.width!=tempVW) ||
974
((graphWindowAttrib.height)!=tempVH)) {
975
XResizeWindow(dsply,viewport->viewWindow,graphWindowAttrib.width,
976
graphWindowAttrib.height);
977
redoSmooth = yes; /* recompute smooth image pixmap if resized */
978
}
979
drawViewport(Xoption);
980
XMapWindow(dsply,whichWindow);
981
} else if (whichWindow == lightingWindow) {
982
XGetWindowAttributes(dsply,control->controlWindow,
983
&graphWindowAttrib);
984
/* do not allow resizing of control panel */
985
if ((graphWindowAttrib.width!=controlWidth) ||
986
(graphWindowAttrib.height!=controlHeight)) {
987
XResizeWindow(dsply,control->controlWindow,controlWidth,
988
controlHeight);
989
}
990
drawLightingPanel();
991
} else if (whichWindow == volumeWindow) {
992
XGetWindowAttributes(dsply,control->controlWindow,
993
&graphWindowAttrib);
994
/* do not allow resizing of control panel */
995
if ((graphWindowAttrib.width!=controlWidth) ||
996
(graphWindowAttrib.height!=controlHeight)) {
997
XResizeWindow(dsply,control->controlWindow,controlWidth,
998
controlHeight);
999
}
1000
drawVolumePanel();
1001
if (redrawView) {
1002
redrawView = no;
1003
drawViewport(Xoption);
1004
}
1005
} else if (whichWindow == quitWindow) {
1006
XGetWindowAttributes(dsply,control->controlWindow,
1007
&graphWindowAttrib);
1008
/* do not allow resizing of control panel */
1009
if ((graphWindowAttrib.width!=controlWidth) ||
1010
(graphWindowAttrib.height!=controlHeight)) {
1011
XResizeWindow(dsply,control->controlWindow,controlWidth,
1012
controlHeight);
1013
}
1014
drawQuitPanel();
1015
} else if (whichWindow == saveWindow) {
1016
XGetWindowAttributes(dsply,control->controlWindow,
1017
&graphWindowAttrib);
1018
/* do not allow resizing of control panel */
1019
if ((graphWindowAttrib.width!=controlWidth) ||
1020
(graphWindowAttrib.height!=controlHeight)) {
1021
XResizeWindow(dsply,control->controlWindow,controlWidth,
1022
controlHeight);
1023
}
1024
drawSavePanel();
1025
} else if (whichWindow == control->controlWindow) {
1026
XGetWindowAttributes(dsply,control->controlWindow,
1027
&graphWindowAttrib);
1028
/* do not allow resizing of control panel */
1029
if ((graphWindowAttrib.width != controlWidth) ||
1030
(graphWindowAttrib.height != controlHeight)) {
1031
XResizeWindow(dsply,control->controlWindow,
1032
controlWidth,controlHeight);
1033
}
1034
if (viewport->haveControl) drawControlPanel();
1035
followMouse = no;
1036
if (redrawView || exposeView) {
1037
redrawView = no;
1038
drawViewport(Xoption);
1039
}
1040
exposeView = no;
1041
} else {
1042
fprintf(stderr,"Not a valid window.\n");
1043
}
1044
1045
XFlush(dsply);
1046
while(XCheckTypedWindowEvent(dsply, whichWindow, Expose, &tempEvent));
1047
break;
1048
1049
1050
case MotionNotify:
1051
exposeView = no;
1052
if (followMouse) {
1053
if (whichWindow == control->colormapWindow) {
1054
while (XCheckMaskEvent(dsply,ButtonMotionMask,event));
1055
first_time = checkButton = followMouse = changingColor = yes;
1056
gotToggle = no;
1057
} else if (whichWindow != control->controlWindow) {
1058
if (controlButton->pot) {
1059
while (XCheckMaskEvent(dsply,ButtonMotionMask,event));
1060
mouseXY = getPotValue(((XButtonEvent *)event)->x,
1061
((XButtonEvent *)event)->y,
1062
controlButton->xHalf,
1063
controlButton->yHalf);
1064
linearMouseXY = getLinearPotValue(((XButtonEvent *)event)->x,
1065
((XButtonEvent *)event)->y,
1066
controlButton->xHalf,
1067
controlButton->yHalf);
1068
first_time = checkButton = followMouse = yes;
1069
gotToggle = no;
1070
}
1071
}
1072
}
1073
break;
1074
1075
case ButtonRelease:
1076
exposeView = followMouse = no;
1077
toggleReady = yes; gotToggle = yes;
1078
break;
1079
1080
case LeaveNotify:
1081
XQueryPointer(dsply,rtWindow,&dummy,&dummy,&px,&py,&lx,&ly,&lbuttons);
1082
if ( (controlButton) &&
1083
((whichWindow == control->colormapWindow) ||
1084
(controlButton->pot)) &&
1085
(lbuttons & Button1Mask ||
1086
lbuttons & Button2Mask ||
1087
lbuttons & Button3Mask)) {
1088
followMouse = yes;
1089
if (whichWindow == control->colormapWindow)
1090
changingColor = yes;
1091
}
1092
else {
1093
followMouse = no;
1094
changingColor = no;
1095
}
1096
toggleReady = yes;
1097
checkButton = exposeView = no;
1098
break;
1099
1100
case ButtonPress:
1101
exposeView = no; changingColor = no;
1102
if (whichWindow == viewport->viewWindow) {
1103
/* find out where the mouse button is pressed on the viewport,
1104
this determines where to put the control panel */
1105
XGetWindowAttributes(dsply,whichWindow,&graphWindowAttrib);
1106
mouseW4 = graphWindowAttrib.width/4;
1107
if (((XButtonEvent *)event)->x > (graphWindowAttrib.width-mouseW4))
1108
someInt = 1;
1109
else {
1110
mouseH4 = graphWindowAttrib.height/4;
1111
if (((XButtonEvent *)event)->y >
1112
(graphWindowAttrib.height - mouseH4)) someInt = 2;
1113
else if (((XButtonEvent *)event)->x < mouseW4) someInt = 3;
1114
else if (((XButtonEvent *)event)->y < mouseH4) someInt = 4;
1115
else someInt = 0;
1116
}
1117
if (viewport->haveControl) {
1118
XUnmapWindow(dsply,control->controlWindow);
1119
}
1120
putControlPanelSomewhere(someInt);
1121
writeControlMessage();
1122
XSync(dsply,0);
1123
} else if (whichWindow == control->colormapWindow) {
1124
gotToggle = no;
1125
first_time = checkButton = followMouse = changingColor = yes;
1126
} else if (whichWindow != control->controlWindow) {
1127
/* mouse clicked on one of the buttons */
1128
if (!controlButton || (controlButton->self != whichWindow)) {
1129
buttonTablePtr = *((int *)XLookUpAssoc(dsply,table,whichWindow));
1130
/** lighting buttons have indices greater than 100 **/
1131
/** all buttons share the same array now **/
1132
controlButton = &(control->buttonQueue[buttonTablePtr]);
1133
}
1134
if (controlButton->pot) {
1135
/* figure out [x,y] for this button in the range [-1..1,-1..1] */
1136
mouseXY = getPotValue(((XButtonEvent *)event)->x,
1137
((XButtonEvent *)event)->y,
1138
controlButton->xHalf,controlButton->yHalf);
1139
linearMouseXY = getLinearPotValue(((XButtonEvent *)event)->x,
1140
((XButtonEvent *)event)->y,
1141
controlButton->xHalf,
1142
controlButton->yHalf);
1143
followMouse = yes;
1144
gotToggle = no;
1145
} else {
1146
followMouse = no;
1147
gotToggle = yes; /* auto-repeat of toggle buttons not allowed */
1148
if (toggleReady) toggleReady = no;
1149
}
1150
checkButton = yes;
1151
first_time = yes;
1152
}
1153
break;
1154
1155
default:
1156
toggleReady = gotToggle = yes;
1157
exposeView = changingColor = checkButton = followMouse = no;
1158
break;
1159
1160
} /* switch */
1161
gotEvent--;
1162
} /* if gotEvent */
1163
1164
/* Allow a pressed mouse button on a potentiometer to poll repeatedly. */
1165
if (followMouse && !first_time && (followMouse++ > mouseWait)) {
1166
/* reset for next timing loop */
1167
followMouse = yes;
1168
checkButton = yes;
1169
}
1170
if (checkButton) {
1171
if (viewport->closing && (controlButton->buttonKey == quitReturn)) {
1172
goodbye(-1);
1173
} else if (changingColor) {
1174
viewport->closing = no;
1175
/* moving top color map pointer */
1176
if (((XButtonEvent *)event)->y < colorOffsetY) {
1177
if (((XButtonEvent *)event)->x < (colorOffset+colorWidth)) {
1178
/* decreasing top hue number */
1179
if (viewport->hueTop > 0) viewport->hueTop--;
1180
} else if (((XButtonEvent *)event)->x >=
1181
(colorOffsetX + totalHues*colorWidth + colorWidth)) {
1182
if (viewport->hueTop < totalHues) viewport->hueTop++;
1183
} else {
1184
viewport->hueTop =
1185
(((XButtonEvent *)event)->x -
1186
colorOffsetX + colorWidth/2 - 13) / colorWidth;
1187
}
1188
} else if (((XButtonEvent *)event)->y >
1189
(colorOffsetY + colorHeight)) {
1190
/* moving bottom color map pointer */
1191
if (((XButtonEvent *)event)->x < (colorOffset+colorWidth)) {
1192
/* decreasing offset number */
1193
if (viewport->hueOffset > 0) viewport->hueOffset--;
1194
} else if (((XButtonEvent *)event)->x >=
1195
(colorOffsetX + totalHues*colorWidth + colorWidth)) {
1196
if (viewport->hueOffset < totalHues) viewport->hueOffset++;
1197
} else {
1198
viewport->hueOffset =
1199
(((XButtonEvent *)event)->x -
1200
colorOffsetX + colorWidth/2 - 13) / colorWidth;
1201
}
1202
}
1203
/* color map pointer does not wrap around */
1204
if (viewport->hueOffset < 0) viewport->hueOffset = 0;
1205
if (viewport->hueTop < 0) viewport->hueTop = 0;
1206
if (viewport->hueOffset >= totalHues)
1207
viewport->hueOffset = totalHues-1;
1208
if (viewport->hueTop >= totalHues) viewport->hueTop = totalHues-1;
1209
viewport->numberOfHues = viewport->hueTop - viewport->hueOffset;
1210
if ((viewport->hueTop == viewport->hueOffset) && !viewport->monoOn) {
1211
redoColor = yes;
1212
redoDither = no;
1213
} else {
1214
redoColor = no;
1215
redoDither = yes;
1216
}
1217
/* update color map changes on control panel */
1218
drawColorMap();
1219
} else {
1220
viewport->closing = no;
1221
clearControlMessage();
1222
/* reset all the things that might affect a recalculation for
1223
redrawing removing hidden surfaces */
1224
1225
/* determine what type of button has been pressed */
1226
switch(controlButton->buttonKey) {
1227
1228
/*** Potentiometers ***/
1229
case rotate:
1230
if (!((viewport->originrOn) && (viewport->objectrOn))) {
1231
/* update the amount of rotation around the object center
1232
of volume */
1233
if (viewport->objectrOn) {
1234
viewport->thetaObj += mouseXY.x * rotateFactor;
1235
viewport->phiObj -= mouseXY.y * rotateFactor;
1236
while (viewport->thetaObj >= two_pi) {
1237
viewport->thetaObj -= two_pi;
1238
}
1239
while (viewport->thetaObj < 0.0) {
1240
viewport->thetaObj += two_pi;
1241
}
1242
while (viewport->phiObj > pi) {
1243
viewport->phiObj -= two_pi;
1244
}
1245
while (viewport->phiObj <= -pi) {
1246
viewport->phiObj += two_pi;
1247
}
1248
}
1249
/* update amount of rotation around the world space origin */
1250
if (viewport->originrOn) {
1251
viewport->theta += mouseXY.x * rotateFactor;
1252
viewport->phi -= mouseXY.y * rotateFactor;
1253
while (viewport->theta >= two_pi) {
1254
viewport->theta -= two_pi;
1255
}
1256
while (viewport->theta < 0.0) {
1257
viewport->theta += two_pi;
1258
}
1259
while (viewport->phi > pi) {
1260
viewport->phi -= two_pi;
1261
}
1262
while (viewport->phi <= -pi) {
1263
viewport->phi += two_pi;
1264
}
1265
viewport->axestheta += mouseXY.x * rotateFactor;
1266
viewport->axesphi -= mouseXY.y * rotateFactor;
1267
while (viewport->axestheta >= two_pi) {
1268
viewport->axestheta -= two_pi;
1269
}
1270
while (viewport->axestheta < 0.0) {
1271
viewport->axestheta += two_pi;
1272
}
1273
while (viewport->axesphi > pi) {
1274
viewport->axesphi -= two_pi;
1275
}
1276
while (viewport->axesphi <= -pi) {
1277
viewport->axesphi += two_pi;
1278
}
1279
}
1280
rotated = yes;
1281
viewport->yzOn = viewport->xzOn = viewport->xyOn = no;
1282
clearControlMessage();
1283
strcpy(control->message,viewport->title);
1284
writeControlMessage();
1285
drawViewport(Xoption);
1286
}
1287
break;
1288
1289
case zoom:
1290
/* if uniform scaling */
1291
if ((viewport->zoomXOn) &&
1292
(viewport->zoomYOn) &&
1293
(viewport->zoomZOn)) {
1294
viewport->scale *= 1 - mouseXY.y * scaleFactor;
1295
} else { /* else scale axes independently */
1296
if (viewport->zoomXOn) viewport->scaleX *= (1 - mouseXY.y);
1297
if (viewport->zoomYOn) viewport->scaleY *= (1 - mouseXY.y);
1298
if (viewport->zoomZOn) viewport->scaleZ *= (1 - mouseXY.y);
1299
}
1300
if (viewport->scale > maxScale) viewport->scale = maxScale;
1301
else if (viewport->scale < minScale) viewport->scale = minScale;
1302
if (viewport->scaleX > maxScale) viewport->scaleX = maxScale;
1303
else if (viewport->scaleX < minScale) viewport->scaleX = minScale;
1304
if (viewport->scaleY > maxScale) viewport->scaleY = maxScale;
1305
else if (viewport->scaleY < minScale) viewport->scaleY = minScale;
1306
if (viewport->scaleZ > maxScale) viewport->scaleZ = maxScale;
1307
else if (viewport->scaleZ < minScale) viewport->scaleZ = minScale;
1308
zoomed = yes;
1309
clearControlMessage();
1310
strcpy(control->message,viewport->title);
1311
writeControlMessage();
1312
if ((viewport->zoomXOn) ||
1313
(viewport->zoomYOn) ||
1314
(viewport->zoomZOn))
1315
drawViewport(Xoption);
1316
break;
1317
1318
case translate:
1319
viewport->deltaX += mouseXY.x * translateFactor;
1320
viewport->deltaY += mouseXY.y * translateFactor;
1321
if (viewport->deltaX > maxDeltaX) viewport->deltaX = maxDeltaX;
1322
else if (viewport->deltaX < -maxDeltaX) viewport->deltaX = -maxDeltaX;
1323
1324
if (viewport->deltaY > maxDeltaY) viewport->deltaY = maxDeltaY;
1325
else if (viewport->deltaY < -maxDeltaY) viewport->deltaY = -maxDeltaY;
1326
translated = yes;
1327
clearControlMessage();
1328
strcpy(control->message,viewport->title);
1329
writeControlMessage();
1330
drawViewport(Xoption);
1331
break;
1332
1333
/*** Lighting panel ***/
1334
case lightMoveXY:
1335
tempLightPointer[0] = linearMouseXY.x;
1336
tempLightPointer[1] = linearMouseXY.y;
1337
if (tempLightPointer[0] > 1) tempLightPointer[0] = 1;
1338
else if (tempLightPointer[0] < -1) tempLightPointer[0] = -1;
1339
if (tempLightPointer[1] > 1) tempLightPointer[1] = 1;
1340
else if (tempLightPointer[1] < -1) tempLightPointer[1] = -1;
1341
movingLight = yes;
1342
drawLightingAxes();
1343
break;
1344
1345
case lightMoveZ:
1346
tempLightPointer[2] = linearMouseXY.y;
1347
/* linearMouse => no checking necessary */
1348
if (tempLightPointer[2] > 1) tempLightPointer[2] = 1;
1349
else if (tempLightPointer[2] < -1) tempLightPointer[2] = -1;
1350
movingLight = yes;
1351
drawLightingAxes();
1352
break;
1353
1354
/* changes the light intensity */
1355
case lightTranslucent:
1356
tempLightIntensity = (linearMouseXY.y+1)/2;
1357
if (tempLightIntensity > 1) tempLightIntensity = 1;
1358
else if (tempLightIntensity < 0) tempLightIntensity = 0;
1359
changedIntensity = yes;
1360
drawLightTransArrow();
1361
break;
1362
1363
/*** volume panel ***/
1364
case frustrumBut:
1365
screenX = ((XButtonEvent *)event)->x;
1366
if inside(eyeMinX,eyeMaxX) {
1367
/* object coordinate */
1368
f2 = mouseXY.x * (maxEyeDistance - minEyeDistance) +
1369
minEyeDistance;
1370
if (f2 != viewData.eyeDistance) {
1371
doingVolume = 2; /* flag for using screenX */
1372
changedEyeDistance = yes;
1373
viewData.eyeDistance = f2;
1374
drawFrustrum();
1375
drawViewport(Xoption);
1376
}
1377
}
1378
else if inside(hitherMinX,hitherMaxX) {
1379
f1 = ((float)hitherMaxX - ((XButtonEvent *)event)->x) /
1380
(hitherMaxX - hitherMinX);
1381
/* object coordinate */
1382
f2 = f1 * (clipPlaneMax - clipPlaneMin) + clipPlaneMin;
1383
if (f2 != viewData.clipPlane) {
1384
doingVolume = 3; /* flag for using screenX */
1385
viewData.clipPlane = f2;
1386
drawFrustrum();
1387
drawViewport(Xoption);
1388
}
1389
}
1390
else {
1391
doingVolume = 1; /* check out doingVolume */
1392
doingPanel = VOLUMEpanel;
1393
}
1394
break;
1395
1396
case clipXBut: /* this is a horizontal button */
1397
clipValue = linearMouseXY.x * 0.5 + 0.5; /* normalize to 0..1 */
1398
if (lessThan(clipValue,0.0)) clipValue = 0.0;
1399
if (greaterThan(clipValue,1.0)) clipValue = 1.0;
1400
if (lessThan(linearMouseXY.y,0.0)) {
1401
if (!equal(xClipMinN,clipValue)) {
1402
if (greaterThan(xClipMaxN-clipValue,minDistXY))
1403
xClipMinN = clipValue;
1404
else
1405
xClipMinN = xClipMaxN - minDistXY;
1406
viewData.clipXmin = xClipMinN *
1407
(viewData.xmax - viewData.xmin) +
1408
viewData.xmin;
1409
drawClipXBut();
1410
drawClipVolume();
1411
if (viewData.clipbox)
1412
drawViewport(Xoption);
1413
}
1414
} else {
1415
if (!equal(xClipMaxN,clipValue)) {
1416
if (greaterThan(clipValue-xClipMinN,minDistXY))
1417
xClipMaxN = clipValue;
1418
else
1419
xClipMaxN = xClipMinN + minDistXY;
1420
viewData.clipXmax = xClipMaxN *
1421
(viewData.xmax - viewData.xmin) +
1422
viewData.xmin;
1423
drawClipXBut();
1424
drawClipVolume();
1425
if (viewData.clipbox)
1426
drawViewport(Xoption);
1427
}
1428
}
1429
break;
1430
1431
case clipYBut: /* this is a vertical button */
1432
/* normalize to 0..1, bottom up */
1433
clipValue = 1 - (linearMouseXY.y * 0.5 + 0.5);
1434
if (lessThan(clipValue,0.0)) clipValue = 0.0;
1435
if (greaterThan(clipValue,1.0)) clipValue = 1.0;
1436
if (lessThan(linearMouseXY.x,0.0)) {
1437
if (!equal(yClipMinN,clipValue)) {
1438
if (greaterThan(yClipMaxN-clipValue,minDistXY))
1439
yClipMinN = clipValue;
1440
else
1441
yClipMinN = yClipMaxN - minDistXY;
1442
viewData.clipYmin = yClipMinN *
1443
(viewData.ymax - viewData.ymin) +
1444
viewData.ymin;
1445
drawClipYBut();
1446
drawClipVolume();
1447
if (viewData.clipbox)
1448
drawViewport(Xoption);
1449
}
1450
} else {
1451
if (!equal(yClipMaxN,clipValue)) {
1452
if (greaterThan(clipValue-yClipMinN,minDistXY))
1453
yClipMaxN = clipValue;
1454
else
1455
yClipMaxN = yClipMinN + minDistXY;
1456
viewData.clipYmax = yClipMaxN *
1457
(viewData.ymax - viewData.ymin) +
1458
viewData.ymin;
1459
drawClipYBut();
1460
drawClipVolume();
1461
if (viewData.clipbox)
1462
drawViewport(Xoption);
1463
}
1464
}
1465
break;
1466
1467
case clipZBut: /* this is a diagonally aligned button! */
1468
/* f1 is the distance from the center of the button along
1469
the diagonal line with a slope of -1. If f1 is negative,
1470
the direction is downward from the center, if f1 is
1471
positive, the direction is upward from the center.
1472
Note that there ought to be a constant factor, namely
1473
cos(45), multiplied by f1 for the correct normalized value;
1474
however, we exploit this by foreshortening the length of the
1475
diagonal by that same factor (so instead of normalizing the
1476
numbers to, the line we normalize the line to the numbers)
1477
since we need to shorten the line at some point anyway
1478
(both to match the length of the diagonal side of the box
1479
and to allow more area for mouse input. */
1480
1481
/* cos(45), etc => 0.4 */
1482
f1 = (linearMouseXY.x - linearMouseXY.y) * 0.4 + 0.5;
1483
if (lessThan(f1,0.0)) f1 = 0.0;
1484
if (greaterThan(f1,1.0)) f1 = 1.0;
1485
/* note that x<y => moving upward */
1486
if (lessThan(-linearMouseXY.x,linearMouseXY.y)) {
1487
if (!equal(zClipMaxN,f1)) {
1488
if (greaterThan(f1-zClipMinN,minDistZ))
1489
zClipMaxN = f1;
1490
else
1491
zClipMaxN = zClipMinN + minDistZ;
1492
viewData.clipZmax = zClipMaxN *
1493
(viewData.zmax - viewData.zmin) +
1494
viewData.zmin;
1495
drawClipZBut();
1496
drawClipVolume();
1497
if (viewData.clipbox)
1498
drawViewport(Xoption);
1499
}
1500
} else {
1501
if (!equal(zClipMinN,f1)) {
1502
if (greaterThan(zClipMaxN-f1,minDistZ))
1503
zClipMinN = f1;
1504
else
1505
zClipMinN = zClipMaxN - minDistZ;
1506
viewData.clipZmin = zClipMinN *
1507
(viewData.zmax - viewData.zmin) +
1508
viewData.zmin;
1509
drawClipZBut();
1510
drawClipVolume();
1511
if (viewData.clipbox)
1512
drawViewport(Xoption);
1513
}
1514
} /* if lessThan(x,y) */
1515
break;
1516
1517
case perspectiveBut:
1518
if ((viewData.perspective = !viewData.perspective)) {
1519
switchedPerspective = yes;
1520
GSetForeground(volumeGC,
1521
(float)monoColor((control->buttonQueue[perspectiveBut]).textColor),Xoption);
1522
GDrawString(volumeGC,volumeWindow,
1523
controlButton->buttonX +
1524
centerX(volumeGC,"x",1,controlButton->buttonWidth),
1525
controlButton->buttonY +
1526
centerY(volumeGC,controlButton->buttonHeight),
1527
"x",1,Xoption);
1528
}
1529
else
1530
XClearArea(dsply,volumeWindow,
1531
controlButton->buttonX+1,
1532
controlButton->buttonY+1,
1533
controlButton->buttonHeight-2,
1534
controlButton->buttonWidth-2,
1535
False);
1536
drawViewport(Xoption);
1537
break;
1538
1539
case clipRegionBut:
1540
if ((viewData.clipbox = !viewData.clipbox)) {
1541
GSetForeground(volumeGC,
1542
(float)monoColor((control->buttonQueue[clipRegionBut]).textColor),Xoption);
1543
GDrawString(volumeGC,volumeWindow,
1544
controlButton->buttonX +
1545
centerX(volumeGC,"x",1,controlButton->buttonWidth),
1546
controlButton->buttonY +
1547
centerY(volumeGC,controlButton->buttonHeight),
1548
"x",1,Xoption);
1549
}
1550
else
1551
XClearArea(dsply,volumeWindow,
1552
controlButton->buttonX+1,
1553
controlButton->buttonY+1,
1554
controlButton->buttonWidth-2,
1555
controlButton->buttonHeight-2,
1556
False);
1557
1558
drawViewport(Xoption);
1559
break;
1560
1561
case clipSurfaceBut:
1562
if ((viewData.clipStuff = !viewData.clipStuff)) {
1563
GSetForeground(volumeGC,
1564
(float)monoColor((control->buttonQueue[clipSurfaceBut]).textColor),Xoption);
1565
GDrawString(volumeGC,volumeWindow,
1566
controlButton->buttonX +
1567
centerX(volumeGC,"x",1,controlButton->buttonWidth),
1568
controlButton->buttonY +
1569
centerY(volumeGC,controlButton->buttonHeight),
1570
"x",1,Xoption);
1571
}
1572
else
1573
XClearArea(dsply,volumeWindow,
1574
controlButton->buttonX+1,
1575
controlButton->buttonY+1,
1576
controlButton->buttonWidth-2,
1577
controlButton->buttonHeight-2,
1578
False);
1579
break;
1580
1581
default:
1582
buttonAction(controlButton->buttonKey);
1583
} /* switch on buttonKey */
1584
1585
} /* else - not closing */
1586
} /* if checkButton */
1587
} /* if FD_ISSET(Xcon,.. */
1588
else if (FD_ISSET(0,&rd)) {
1589
externalControl = spadAction();
1590
if (spadDraw && (externalControl==0)) drawViewport(Xoption);
1591
}
1592
} /* for (until closed) */
1593
} /* processEvents() */
1594
1595
1596
1597
1598