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-2010, 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 _CONTROL3D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <string.h>
40
#include <stdio.h>
41
#include <unistd.h>
42
#include <stdlib.h>
43
44
#include "mouse11.bitmap"
45
#include "mouse11.mask"
46
47
#include "header.h"
48
#include "cpanel.h"
49
50
#include "util.H1"
51
#include "XShade.h"
52
#include "XSpadFill.h"
53
#include "Gfun.H1"
54
#include "all_3d.H1"
55
56
/* Defines the pixmap for the arrow displayed in the scale window */
57
#define zoomArrowN 11
58
static XPoint zoomArrow[zoomArrowN] = {
59
{29,14},{38,23},{33,23},
60
{40,45},{53,45},
61
{29,69},
62
{5,45},{18,45},
63
{25,23},{20,23},{29,14} };
64
65
/* Defines the pixmap for the arrows displayed in the translate window */
66
#define translateArrowN 25
67
static XPoint translateArrow[translateArrowN] = {
68
{55,2},{60,10},{58,10},{58,37},
69
{85,37},{85,35},{93,40},{85,45},{85,43},{58,43},
70
{58,70},{60,70},{55,78},{50,70},{52,70},{52,43},
71
{25,43},{25,45},{17,40},{25,35},{25,37},{52,37},
72
{52,10},{50,10},{55,2} };
73
74
static int rotateX, rotateY, rotateR;
75
76
/*
77
void drawColorMap ()
78
*/
79
80
void
81
drawColorMap (void)
82
{
83
84
controlPanelStruct *cp;
85
int i,shadeWidth;
86
87
/* Draw the color map window */
88
89
cp = viewport->controlPanel;
90
91
XClearArea(dsply,cp->controlWindow,5,colormapY,colormapW,colormapH,False);
92
93
/* if window is grayscale, show the grayscale colormap */
94
if (mono || (viewport->monoOn)) {
95
shadeWidth = 230/maxGreyShade;
96
for (i=0; i<maxGreyShade; i++) {
97
XChangeShade(dsply, i);
98
XShadeRectangle(dsply,cp->controlWindow,
99
colormapX + colorOffsetX + i*shadeWidth,
100
colormapY + colorOffsetY - 10, shadeWidth, 40);
101
}
102
} else {
103
GDrawString(globalGC2,cp->controlWindow,colorWidth,
104
colormapY + 13,"-",1,Xoption);
105
GDrawString(globalGC2,cp->controlWindow,30*colorWidth + 40,
106
colormapY + 13,"+",1,Xoption);
107
GDrawString(globalGC2,cp->controlWindow,colorWidth,
108
colormapY + 46,"-",1,Xoption);
109
GDrawString(globalGC2,cp->controlWindow,30*colorWidth + 40,
110
colormapY + 46,"+",1,Xoption);
111
for (i=0; i<totalHues; i++) {
112
GSetForeground(anotherGC, (float)XSolidColor(i,2), Xoption);
113
GDrawLine(anotherGC,cp->controlWindow,
114
colormapX + i*colorWidth + colorOffsetX,
115
colormapY + colorOffsetY,
116
colormapX + i*colorWidth + colorOffsetX,
117
colormapY + colorOffsetY + colorHeight,Xoption);
118
}
119
120
if (viewport->hueTop > totalHues-1) viewport->hueTop = totalHues-1;
121
if (viewport->hueOffset > totalHues-1) viewport->hueOffset = totalHues-1;
122
123
GSetForeground(globGC, (float)monoColor(7), Xoption);
124
/* Bottom (zmin) color indicator */
125
GDrawLine(globGC,cp->controlWindow,
126
colormapX + viewport->hueOffset * colorWidth + colorOffsetX,
127
colormapY + colorOffsetY+colorHeight,
128
colormapX + viewport->hueOffset * colorWidth + colorOffsetX,
129
colormapY + colorOffsetY+colorHeight+colorPointer,Xoption);
130
131
/* Top (zmax) color indicator */
132
GDrawLine(globGC,cp->controlWindow,
133
colormapX + viewport->hueTop * colorWidth+colorOffsetX,
134
colormapY + colorOffsetY,
135
colormapX + viewport->hueTop * colorWidth+colorOffsetX,
136
colormapY + colorOffsetY-colorPointer,Xoption);
137
138
/* Connect the bottom and top color indicator bars */
139
GSetForeground(globGC, (float)monoColor(0), Xoption);
140
GDrawLine(globGC,cp->controlWindow,
141
colormapX + viewport->hueOffset * colorWidth + colorOffsetX,
142
colormapY + colorOffsetY+colorHeight,
143
colormapX + viewport->hueTop * colorWidth+colorOffsetX,
144
colormapY + colorOffsetY,Xoption);
145
}
146
XSync(dsply,0);
147
148
} /* drawColorMap() */
149
150
151
/*******************************
152
* void writeControlTitle(w) *
153
* *
154
* We need the window argument *
155
* here because there are *
156
* multiple control panels in *
157
* 3D. *
158
*******************************/
159
160
void
161
writeControlTitle (Window w)
162
{
163
int strlength;
164
165
s = viewport->title;
166
strlength = strlen(s);
167
XClearArea(dsply,w,0,0,controlWidth,potA,False);
168
169
GSetForeground(anotherGC,(float)controlTitleColor,Xoption);
170
GDrawString(anotherGC,w,centerX(anotherGC,s,strlength,controlWidth),
171
15,s,strlength,Xoption);
172
173
} /* writeControlTitle() */
174
175
176
/************************************/
177
/*** void clearControlMessage() ***/
178
/************************************/
179
180
void
181
clearControlMessage (void)
182
{
183
int strlength;
184
185
strcpy(viewport->controlPanel->message," ");
186
strlength = strlen(viewport->controlPanel->message);
187
GDrawImageString(globalGC1,viewport->controlPanel->controlWindow,
188
centerX(globalGC1,viewport->controlPanel->message,
189
strlength,controlWidth),
190
controlMessageY + globalFont->max_bounds.ascent + 8,
191
viewport->controlPanel->message,strlength,Xoption);
192
193
}
194
195
/************************************/
196
/*** void writeControlMessage() ***/
197
/************************************/
198
199
void
200
writeControlMessage (void)
201
{
202
203
int strlength;
204
controlPanelStruct *cp;
205
206
cp = viewport->controlPanel;
207
strlength = strlen(cp->message);
208
XClearArea(dsply,cp->controlWindow,
209
0,controlMessageY+ globalFont->max_bounds.ascent + 8,
210
0,controlMessageHeight,False);
211
GSetForeground(globalGC1, (float)controlMessageColor, Xoption);
212
GDrawImageString(globalGC1,cp->controlWindow,
213
centerX(globalGC1,cp->message,strlength,controlWidth),
214
controlMessageY + globalFont->max_bounds.ascent + 8,
215
cp->message,strlength,Xoption);
216
217
XFlush(dsply);
218
219
}
220
221
/*********************************/
222
/*** void drawControlPanel() ***/
223
/*********************************/
224
225
void
226
drawControlPanel(void )
227
{
228
229
int offShade=14;
230
controlPanelStruct *cp;
231
int i, strlength;
232
const char* s;
233
234
cp = viewport->controlPanel;
235
236
GSetForeground(trashGC, (float)foregroundColor, Xoption);
237
238
/* Draw border lines to separate the potentiometer, message, colormap and
239
button regions of the control panel. */
240
GSetLineAttributes(trashGC, 2, LineSolid, CapButt, JoinMiter, Xoption);
241
242
/* Draw a horizontal white line below the potentiometer area. */
243
GDrawLine(trashGC, cp->controlWindow, 0, potB-1, controlWidth, potB-1, Xoption);
244
245
/* Draw a horizontal white line above the rendering mode buttons. */
246
GDrawLine(trashGC, cp->controlWindow, 0, butA, controlWidth, butA, Xoption);
247
248
/* Draw a horizontal white line above the color mapping area. */
249
GDrawLine(trashGC, cp->controlWindow, 0, cmapA, controlWidth, cmapA, Xoption);
250
251
GSetLineAttributes(trashGC, 3, LineSolid, CapButt, JoinMiter, Xoption);
252
/* Draw a horizontal white line above the potentiometer area. */
253
GDrawLine(trashGC, cp->controlWindow, 0, potA, controlWidth, potA, Xoption);
254
255
/* Set the line width as 1 here because it is used below as well. */
256
GSetLineAttributes(trashGC, 1, LineSolid, CapButt, JoinMiter, Xoption);
257
258
/* Draw inner white lines around quit, hide panel, and reset buttons. */
259
GDrawLine(trashGC, cp->controlWindow, closeL, butA, closeL, butA+110, Xoption);
260
261
/* Write potentiometer titles on the control panel. */
262
263
writeControlTitle(cp->controlWindow);
264
GSetForeground(globGC, (float)controlPotHeaderColor, Xoption);
265
266
s = "Rotate";
267
GDrawString(globGC,cp->controlWindow,35,31+headerHeight,s,strlen(s),Xoption);
268
s = "Translate";
269
GDrawString(globGC,cp->controlWindow,202,31+headerHeight,s,strlen(s),Xoption);
270
s = "Scale";
271
GDrawString(globGC,cp->controlWindow,126,31+headerHeight,s,strlen(s),Xoption);
272
273
GSetForeground(globGC, (float)controlColorColor, Xoption);
274
275
/* Write labels on regular buttons, draw pixmaps on the potentiometers. */
276
277
GSetForeground(globalGC1, (float)monoColor(buttonColor), Xoption);
278
279
for (i=controlButtonsStart3D; i<(controlButtonsEnd3D); i++) {
280
/* special cases depending on initial conditions */
281
282
/* check if axes are set on or off */
283
284
if (((cp->buttonQueue[i]).buttonKey == axesOnOff) &&
285
(viewport->axesOn)) {
286
(cp->buttonQueue[i]).textColor = onColor;
287
if (mono) {
288
GSetForeground(globalGC1, (float)backgroundColor, Xoption);
289
XFillRectangle(dsply, control->controlWindow, globalGC1,
290
(control->buttonQueue[axesOnOff]).buttonX,
291
(control->buttonQueue[axesOnOff]).buttonY,
292
(control->buttonQueue[axesOnOff]).buttonWidth,
293
(control->buttonQueue[axesOnOff]).buttonHeight);
294
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
295
GDrawRectangle(globalGC1,control->controlWindow,
296
(control->buttonQueue[axesOnOff]).buttonX,
297
(control->buttonQueue[axesOnOff]).buttonY,
298
(control->buttonQueue[axesOnOff]).buttonWidth,
299
(control->buttonQueue[axesOnOff]).buttonHeight,Xoption);
300
}
301
} else {
302
if (((cp->buttonQueue[i]).buttonKey == axesOnOff) &&
303
(!viewport->axesOn)) {
304
(cp->buttonQueue[i]).textColor = offColor;
305
if (mono) {
306
XChangeShade(dsply,offShade);
307
XShadeRectangle(dsply,cp->controlWindow,
308
(cp->buttonQueue[i]).buttonX,
309
(cp->buttonQueue[i]).buttonY,
310
(cp->buttonQueue[i]).buttonWidth,
311
(cp->buttonQueue[i]).buttonHeight);
312
s = (control->buttonQueue[axesOnOff]).text;
313
strlength = strlen(s);
314
GSetForeground(processGC,
315
(float)monoColor((control->buttonQueue[axesOnOff]).textColor),Xoption);
316
GDrawImageString(processGC,control->controlWindow,
317
(control->buttonQueue[axesOnOff]).buttonX +
318
centerX(processGC,s,strlength,
319
(control->buttonQueue[axesOnOff]).buttonWidth),
320
(control->buttonQueue[axesOnOff]).buttonY +
321
centerY(processGC,
322
(control->buttonQueue[axesOnOff]).buttonHeight),
323
s,strlength,Xoption);
324
} /* if mono */
325
}
326
} /* if axes */
327
328
/* check if bounding region is set on or off */
329
330
if (((cp->buttonQueue[i]).buttonKey == region3D) &&
331
(viewport->regionOn)) {
332
(cp->buttonQueue[i]).textColor = onColor;
333
if (mono) {
334
GSetForeground(globalGC1, (float)backgroundColor, Xoption);
335
XFillRectangle(dsply, control->controlWindow, globalGC1,
336
(control->buttonQueue[region3D]).buttonX,
337
(control->buttonQueue[region3D]).buttonY,
338
(control->buttonQueue[region3D]).buttonWidth,
339
(control->buttonQueue[region3D]).buttonHeight);
340
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
341
GDrawRectangle(globalGC1,control->controlWindow,
342
(control->buttonQueue[region3D]).buttonX,
343
(control->buttonQueue[region3D]).buttonY,
344
(control->buttonQueue[region3D]).buttonWidth,
345
(control->buttonQueue[region3D]).buttonHeight,Xoption);
346
}
347
} else {
348
if (((cp->buttonQueue[i]).buttonKey == region3D) &&
349
(!viewport->regionOn)) {
350
(cp->buttonQueue[i]).textColor = offColor;
351
if (mono) {
352
XChangeShade(dsply,offShade);
353
XShadeRectangle(dsply,cp->controlWindow,
354
(cp->buttonQueue[i]).buttonX,
355
(cp->buttonQueue[i]).buttonY,
356
(cp->buttonQueue[i]).buttonWidth,
357
(cp->buttonQueue[i]).buttonHeight);
358
s = (control->buttonQueue[region3D]).text;
359
strlength = strlen(s);
360
GSetForeground(processGC,
361
(float)monoColor((control->buttonQueue[region3D]).textColor),Xoption);
362
GDrawImageString(processGC,control->controlWindow,
363
(control->buttonQueue[region3D]).buttonX +
364
centerX(processGC,s,strlength,
365
(control->buttonQueue[region3D]).buttonWidth),
366
(control->buttonQueue[region3D]).buttonY +
367
centerY(processGC,
368
(control->buttonQueue[region3D]).buttonHeight),
369
s,strlength,Xoption);
370
} /* if mono */
371
}
372
} /* if bounding region */
373
374
/* check if black and white is set on or off */
375
376
if (((cp->buttonQueue[i]).buttonKey == bwColor) && (mono)) {
377
(cp->buttonQueue[i]).text = " ";
378
XChangeShade(dsply,offShade);
379
XShadeRectangle(dsply,cp->controlWindow,
380
(cp->buttonQueue[i]).buttonX,
381
(cp->buttonQueue[i]).buttonY,
382
(cp->buttonQueue[i]).buttonWidth,
383
(cp->buttonQueue[i]).buttonHeight);
384
} else {
385
if (((cp->buttonQueue[i]).buttonKey == bwColor) && viewport->monoOn) {
386
(cp->buttonQueue[i]).textColor = onColor;
387
s = (control->buttonQueue[bwColor]).text;
388
strlength = strlen(s);
389
390
GSetForeground(processGC,
391
(float)monoColor((control->buttonQueue[bwColor]).textColor),Xoption);
392
GDrawImageString(processGC,control->controlWindow,
393
(control->buttonQueue[bwColor]).buttonX +
394
centerX(processGC,s,strlength,
395
(control->buttonQueue[bwColor]).buttonWidth),
396
(control->buttonQueue[bwColor]).buttonY +
397
centerY(processGC,
398
(control->buttonQueue[bwColor]).buttonHeight),
399
s,strlength,Xoption);
400
} else {
401
if (((cp->buttonQueue[i]).buttonKey == bwColor) && (!viewport->monoOn)) {
402
(cp->buttonQueue[i]).textColor = offColor;
403
s = (control->buttonQueue[bwColor]).text;
404
strlength = strlen(s);
405
406
GSetForeground(processGC,
407
(float)monoColor((control->buttonQueue[bwColor]).textColor),Xoption);
408
GDrawImageString(processGC,control->controlWindow,
409
(control->buttonQueue[bwColor]).buttonX +
410
centerX(processGC,s,strlength,
411
(control->buttonQueue[bwColor]).buttonWidth),
412
(control->buttonQueue[bwColor]).buttonY +
413
centerY(processGC,
414
(control->buttonQueue[bwColor]).buttonHeight),
415
s,strlength,Xoption);
416
}
417
}
418
} /* if black and white */
419
420
/* check if object rotation is set on or off */
421
422
if (((cp->buttonQueue[i]).buttonKey == objectr) &&
423
(viewport->objectrOn)) {
424
(control->buttonQueue[objectr]).textColor = onColor;
425
if (mono) {
426
GSetForeground(globalGC1, (float)backgroundColor, Xoption);
427
XFillRectangle(dsply, control->controlWindow, globalGC1,
428
(control->buttonQueue[objectr]).buttonX,
429
(control->buttonQueue[objectr]).buttonY,
430
(control->buttonQueue[objectr]).buttonWidth,
431
(control->buttonQueue[objectr]).buttonHeight);
432
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
433
GDrawRectangle(globalGC1,control->controlWindow,
434
(control->buttonQueue[objectr]).buttonX,
435
(control->buttonQueue[objectr]).buttonY,
436
(control->buttonQueue[objectr]).buttonWidth,
437
(control->buttonQueue[objectr]).buttonHeight,Xoption);
438
}
439
} else {
440
if (((cp->buttonQueue[i]).buttonKey == objectr) &&
441
(!viewport->objectrOn)) {
442
(control->buttonQueue[objectr]).textColor = offColor;
443
if (mono) {
444
XChangeShade(dsply,offShade);
445
XShadeRectangle(dsply,control->controlWindow,
446
(control->buttonQueue[objectr]).buttonX,
447
(control->buttonQueue[objectr]).buttonY,
448
(control->buttonQueue[objectr]).buttonWidth,
449
(control->buttonQueue[objectr]).buttonHeight);
450
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
451
GDrawRectangle(globalGC1,control->controlWindow,
452
(control->buttonQueue[objectr]).buttonX,
453
(control->buttonQueue[objectr]).buttonY,
454
(control->buttonQueue[objectr]).buttonWidth,
455
(control->buttonQueue[objectr]).buttonHeight,Xoption);
456
GSetForeground(processGC,
457
(float)monoColor((control->buttonQueue[objectr]).textColor),Xoption);
458
GDrawImageString(processGC,control->controlWindow,
459
(control->buttonQueue[objectr]).buttonX +
460
centerX(processGC,(control->buttonQueue[objectr]).text,
461
strlen((control->buttonQueue[objectr]).text),
462
(control->buttonQueue[objectr]).buttonWidth),
463
(control->buttonQueue[objectr]).buttonY +
464
centerY(processGC,
465
(control->buttonQueue[objectr]).buttonHeight),
466
(control->buttonQueue[objectr]).text,
467
strlen((control->buttonQueue[objectr]).text),Xoption);
468
}
469
} /* else not object rotation */
470
} /* if object rotation */
471
472
/* check if origin rotation is set on or off */
473
474
if (((cp->buttonQueue[i]).buttonKey == originr) &&
475
(viewport->originrOn)) {
476
(control->buttonQueue[originr]).textColor = onColor;
477
if (mono) {
478
GSetForeground(globalGC1, (float)backgroundColor, Xoption);
479
XFillRectangle(dsply, control->controlWindow, globalGC1,
480
(control->buttonQueue[originr]).buttonX,
481
(control->buttonQueue[originr]).buttonY,
482
(control->buttonQueue[originr]).buttonWidth,
483
(control->buttonQueue[originr]).buttonHeight);
484
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
485
GDrawRectangle(globalGC1,control->controlWindow,
486
(control->buttonQueue[originr]).buttonX,
487
(control->buttonQueue[originr]).buttonY,
488
(control->buttonQueue[originr]).buttonWidth,
489
(control->buttonQueue[originr]).buttonHeight,Xoption);
490
}
491
} else {
492
if (((cp->buttonQueue[i]).buttonKey == originr) &&
493
(!viewport->originrOn)) {
494
(control->buttonQueue[originr]).textColor = offColor;
495
if (mono) {
496
XChangeShade(dsply,offShade);
497
XShadeRectangle(dsply,control->controlWindow,
498
(control->buttonQueue[originr]).buttonX,
499
(control->buttonQueue[originr]).buttonY,
500
(control->buttonQueue[originr]).buttonWidth,
501
(control->buttonQueue[originr]).buttonHeight);
502
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
503
GDrawRectangle(globalGC1,control->controlWindow,
504
(control->buttonQueue[originr]).buttonX,
505
(control->buttonQueue[originr]).buttonY,
506
(control->buttonQueue[originr]).buttonWidth,
507
(control->buttonQueue[originr]).buttonHeight,Xoption);
508
509
GSetForeground(processGC,
510
(float)monoColor((control->buttonQueue[originr]).textColor),Xoption);
511
GDrawImageString(processGC,control->controlWindow,
512
(control->buttonQueue[originr]).buttonX +
513
centerX(processGC,(control->buttonQueue[originr]).text,
514
strlen((control->buttonQueue[originr]).text),
515
(control->buttonQueue[originr]).buttonWidth),
516
(control->buttonQueue[originr]).buttonY +
517
centerY(processGC,
518
(control->buttonQueue[originr]).buttonHeight),
519
(control->buttonQueue[originr]).text,
520
strlen((control->buttonQueue[originr]).text),Xoption);
521
}
522
} /* else not origin rotation */
523
} /* if origin rotation */
524
525
/* check if zoom X is set on or off */
526
527
if (((cp->buttonQueue[i]).buttonKey == zoomx) &&
528
(viewport->zoomXOn)) {
529
(control->buttonQueue[zoomx]).textColor = onColor;
530
if (mono) {
531
GSetForeground(globalGC1, (float)backgroundColor, Xoption);
532
XFillRectangle(dsply, control->controlWindow, globalGC1,
533
(control->buttonQueue[zoomx]).buttonX,
534
(control->buttonQueue[zoomx]).buttonY,
535
(control->buttonQueue[zoomx]).buttonWidth,
536
(control->buttonQueue[zoomx]).buttonHeight);
537
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
538
GDrawRectangle(globalGC1,control->controlWindow,
539
(control->buttonQueue[zoomx]).buttonX,
540
(control->buttonQueue[zoomx]).buttonY,
541
(control->buttonQueue[zoomx]).buttonWidth,
542
(control->buttonQueue[zoomx]).buttonHeight,Xoption);
543
}
544
} else {
545
if (((cp->buttonQueue[i]).buttonKey == zoomx) &&
546
(!viewport->zoomXOn)) {
547
(control->buttonQueue[zoomx]).textColor = offColor;
548
if (mono) {
549
XChangeShade(dsply,offShade);
550
XShadeRectangle(dsply,control->controlWindow,
551
(control->buttonQueue[zoomx]).buttonX,
552
(control->buttonQueue[zoomx]).buttonY,
553
(control->buttonQueue[zoomx]).buttonWidth,
554
(control->buttonQueue[zoomx]).buttonHeight);
555
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
556
GDrawRectangle(globalGC1,control->controlWindow,
557
(control->buttonQueue[zoomx]).buttonX,
558
(control->buttonQueue[zoomx]).buttonY,
559
(control->buttonQueue[zoomx]).buttonWidth,
560
(control->buttonQueue[zoomx]).buttonHeight,Xoption);
561
562
GSetForeground(processGC,
563
(float)monoColor((control->buttonQueue[zoomx]).textColor),Xoption);
564
GDrawImageString(processGC,control->controlWindow,
565
(control->buttonQueue[zoomx]).buttonX +
566
centerX(processGC,(control->buttonQueue[zoomx]).text,
567
strlen((control->buttonQueue[zoomx]).text),
568
(control->buttonQueue[zoomx]).buttonWidth),
569
(control->buttonQueue[zoomx]).buttonY +
570
centerY(processGC,
571
(control->buttonQueue[zoomx]).buttonHeight),
572
(control->buttonQueue[zoomx]).text,
573
strlen((control->buttonQueue[zoomx]).text),Xoption);
574
}
575
} /* else not zoom X */
576
} /* if zoom X */
577
578
/* check if zoom Y is set on or off */
579
580
if (((cp->buttonQueue[i]).buttonKey == zoomy) &&
581
(viewport->zoomYOn)) {
582
(control->buttonQueue[zoomy]).textColor = onColor;
583
if (mono) {
584
GSetForeground(globalGC1, (float)backgroundColor, Xoption);
585
XFillRectangle(dsply, control->controlWindow, globalGC1,
586
(control->buttonQueue[zoomy]).buttonX,
587
(control->buttonQueue[zoomy]).buttonY,
588
(control->buttonQueue[zoomy]).buttonWidth,
589
(control->buttonQueue[zoomy]).buttonHeight);
590
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
591
GDrawRectangle(globalGC1, control->controlWindow,
592
(control->buttonQueue[zoomy]).buttonX,
593
(control->buttonQueue[zoomy]).buttonY,
594
(control->buttonQueue[zoomy]).buttonWidth,
595
(control->buttonQueue[zoomy]).buttonHeight,Xoption);
596
}
597
} else {
598
if (((cp->buttonQueue[i]).buttonKey == zoomy) &&
599
(!viewport->zoomYOn)) {
600
(control->buttonQueue[zoomy]).textColor = offColor;
601
if (mono) {
602
XChangeShade(dsply,offShade);
603
XShadeRectangle(dsply,control->controlWindow,
604
(control->buttonQueue[zoomy]).buttonX,
605
(control->buttonQueue[zoomy]).buttonY,
606
(control->buttonQueue[zoomy]).buttonWidth,
607
(control->buttonQueue[zoomy]).buttonHeight);
608
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
609
GDrawRectangle(globalGC1,control->controlWindow,
610
(control->buttonQueue[zoomy]).buttonX,
611
(control->buttonQueue[zoomy]).buttonY,
612
(control->buttonQueue[zoomy]).buttonWidth,
613
(control->buttonQueue[zoomy]).buttonHeight,Xoption);
614
615
GSetForeground(processGC,
616
(float)monoColor((control->buttonQueue[zoomy]).textColor),Xoption);
617
GDrawImageString(processGC,control->controlWindow,
618
(control->buttonQueue[zoomy]).buttonX +
619
centerX(processGC,(control->buttonQueue[zoomy]).text,
620
strlen((control->buttonQueue[zoomy]).text),
621
(control->buttonQueue[zoomy]).buttonWidth),
622
(control->buttonQueue[zoomy]).buttonY +
623
centerY(processGC,
624
(control->buttonQueue[zoomy]).buttonHeight),
625
(control->buttonQueue[zoomy]).text,
626
strlen((control->buttonQueue[zoomy]).text),Xoption);
627
}
628
} /* else not zoom Y */
629
} /* if zoom Y */
630
631
/* check if zoom Z is set on or off */
632
633
if (((cp->buttonQueue[i]).buttonKey == zoomz) &&
634
(viewport->zoomZOn)) {
635
(control->buttonQueue[zoomz]).textColor = onColor;
636
if (mono) {
637
GSetForeground(globalGC1, (float)backgroundColor, Xoption);
638
XFillRectangle(dsply, control->controlWindow, globalGC1,
639
(control->buttonQueue[zoomz]).buttonX,
640
(control->buttonQueue[zoomz]).buttonY,
641
(control->buttonQueue[zoomz]).buttonWidth,
642
(control->buttonQueue[zoomz]).buttonHeight);
643
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
644
GDrawRectangle(globalGC1,control->controlWindow,
645
(control->buttonQueue[zoomz]).buttonX,
646
(control->buttonQueue[zoomz]).buttonY,
647
(control->buttonQueue[zoomz]).buttonWidth,
648
(control->buttonQueue[zoomz]).buttonHeight,Xoption);
649
}
650
} else {
651
if (((cp->buttonQueue[i]).buttonKey == zoomz) &&
652
(!viewport->zoomZOn)) {
653
(control->buttonQueue[zoomz]).textColor = offColor;
654
if (mono) {
655
XChangeShade(dsply,offShade);
656
XShadeRectangle(dsply,control->controlWindow,
657
(control->buttonQueue[zoomz]).buttonX,
658
(control->buttonQueue[zoomz]).buttonY,
659
(control->buttonQueue[zoomz]).buttonWidth,
660
(control->buttonQueue[zoomz]).buttonHeight);
661
GSetForeground(globalGC1, (float)foregroundColor, Xoption);
662
GDrawRectangle(globalGC1,control->controlWindow,
663
(control->buttonQueue[zoomz]).buttonX,
664
(control->buttonQueue[zoomz]).buttonY,
665
(control->buttonQueue[zoomz]).buttonWidth,
666
(control->buttonQueue[zoomz]).buttonHeight,Xoption);
667
668
GSetForeground(processGC,
669
(float)monoColor((control->buttonQueue[zoomz]).textColor),Xoption);
670
GDrawImageString(processGC,control->controlWindow,
671
(control->buttonQueue[zoomz]).buttonX +
672
centerX(processGC,(control->buttonQueue[zoomz]).text,
673
strlen((control->buttonQueue[zoomz]).text),
674
(control->buttonQueue[zoomz]).buttonWidth),
675
(control->buttonQueue[zoomz]).buttonY +
676
centerY(processGC,
677
(control->buttonQueue[zoomz]).buttonHeight),
678
(control->buttonQueue[zoomz]).text,
679
strlen((control->buttonQueue[zoomz]).text),Xoption);
680
}
681
} /* else not zoom Y */
682
} /* if zoom Y */
683
684
/* check if outline is set on or off */
685
686
if (((cp->buttonQueue[i]).buttonKey == outlineOnOff) &&
687
(viewData.outlineRenderOn)) {
688
(cp->buttonQueue[i]).textColor = onColor;
689
} else {
690
if (((cp->buttonQueue[i]).buttonKey == outlineOnOff) &&
691
!(viewData.outlineRenderOn)) {
692
(cp->buttonQueue[i]).textColor = offColor;
693
if (mono) {
694
XChangeShade(dsply,offShade);
695
XShadeRectangle(dsply,cp->controlWindow,
696
(cp->buttonQueue[i]).buttonX,
697
(cp->buttonQueue[i]).buttonY,
698
(cp->buttonQueue[i]).buttonWidth,
699
(cp->buttonQueue[i]).buttonHeight);
700
s = (control->buttonQueue[outlineOnOff]).text;
701
strlength = strlen(s);
702
703
GSetForeground(processGC,
704
(float)monoColor((control->buttonQueue[outlineOnOff]).textColor),Xoption);
705
GDrawImageString(processGC,control->controlWindow,
706
(control->buttonQueue[outlineOnOff]).buttonX +
707
centerX(processGC,s,strlength,
708
(control->buttonQueue[outlineOnOff]).buttonWidth),
709
(control->buttonQueue[outlineOnOff]).buttonY +
710
centerY(processGC,
711
(control->buttonQueue[outlineOnOff]).buttonHeight),
712
s,strlength,Xoption);
713
} /* if mono */
714
} /* outline off */
715
} /* outline on */
716
717
/* Draw the button window border */
718
719
GDraw3DButtonOut(globalGC1,cp->controlWindow,
720
(cp->buttonQueue[i]).buttonX, (cp->buttonQueue[i]).buttonY,
721
(cp->buttonQueue[i]).buttonWidth,
722
(cp->buttonQueue[i]).buttonHeight,Xoption);
723
724
GSetForeground(trashGC,
725
(float)monoColor((cp->buttonQueue[i]).textColor), Xoption);
726
switch (i) {
727
case rotate:
728
GDrawArc(trashGC, cp->controlWindow,
729
rotateX, rotateY, rotateR, rotateR, 0, 360*64, Xoption);
730
break;
731
732
case zoom:
733
GDrawLines(trashGC, cp->controlWindow, zoomArrow, zoomArrowN,
734
CoordModeOrigin, Xoption);
735
break;
736
737
case translate:
738
GDrawLines(trashGC, cp->controlWindow, translateArrow,
739
translateArrowN, CoordModeOrigin, Xoption);
740
break;
741
742
default:
743
s = (cp->buttonQueue[i]).text;
744
strlength = strlen(s);
745
GDrawString(trashGC, cp->controlWindow,
746
(cp->buttonQueue[i]).buttonX +
747
centerX(processGC,s,strlength,
748
(cp->buttonQueue[i]).buttonWidth),
749
(cp->buttonQueue[i]).buttonY +
750
centerY(processGC,
751
(cp->buttonQueue[i]).buttonHeight),s,strlen(s),Xoption);
752
break;
753
};
754
755
if ((cp->buttonQueue[i]).pot) {
756
/* draw horizontal and vertical centerlines */
757
758
GDrawLine(globalGC1,cp->controlWindow,
759
(cp->buttonQueue[i]).buttonX + (cp->buttonQueue[i]).xHalf,
760
(cp->buttonQueue[i]).buttonY,
761
(cp->buttonQueue[i]).buttonX + (cp->buttonQueue[i]).xHalf,
762
(cp->buttonQueue[i]).buttonY + 2*(cp->buttonQueue[i]).yHalf,Xoption);
763
764
GDrawLine(globalGC1,cp->controlWindow,
765
(cp->buttonQueue[i]).buttonX,
766
(cp->buttonQueue[i]).buttonY + (cp->buttonQueue[i]).yHalf,
767
(cp->buttonQueue[i]).buttonX + 2*(cp->buttonQueue[i]).xHalf,
768
(cp->buttonQueue[i]).buttonY + (cp->buttonQueue[i]).yHalf,Xoption);
769
}
770
}
771
772
/* refresh the latest message */
773
clearControlMessage();
774
strcpy(control->message,viewport->title);
775
writeControlMessage();
776
777
/* Draw the color map window */
778
cp = viewport->controlPanel;
779
drawColorMap();
780
XFlush(dsply);
781
782
} /* drawControlPanel() */
783
784
785
/*****************************
786
* void getControlXY() *
787
* *
788
* Determines the x and y *
789
* coordinate where the *
790
* control panel is to be *
791
* placed, based upon where *
792
* the mouse button was *
793
* pressed within the graph *
794
* viewport window. *
795
*****************************/
796
797
controlXY
798
getControlXY (int whereDoYouWantPanel)
799
{
800
801
XWindowAttributes wAttrib;
802
controlXY cXY;
803
int viewX, viewY, viewW, viewH, tmp=1;
804
Window rootW, parentW, *childrenWs, tmpW;
805
unsigned int nChildren;
806
807
tmpW = viewport->titleWindow;
808
while(tmp) {
809
XQueryTree(dsply,tmpW,&rootW,&parentW,&childrenWs,&nChildren);
810
XFree(childrenWs);
811
if (parentW == rtWindow) {
812
tmp = 0;
813
} else {
814
tmpW = parentW;
815
}
816
}
817
XGetWindowAttributes(dsply,tmpW,&wAttrib);
818
819
viewX = wAttrib.x;
820
viewY = wAttrib.y;
821
viewW = wAttrib.width;
822
viewH = wAttrib.height;
823
824
if (whereDoYouWantPanel) {
825
switch (whereDoYouWantPanel) {
826
case 1: /* right */
827
cXY.putX = viewX + viewW;
828
cXY.putY = viewY;
829
break;
830
case 2: /* bottom */
831
cXY.putX = viewX + (viewW - controlWidth)/2; /* center it */
832
cXY.putY = viewY + viewH;
833
break;
834
case 3: /* left */
835
cXY.putX = viewX - controlWidth - borderWidth;
836
cXY.putY = viewY;
837
break;
838
case 4: /* top */
839
cXY.putX = viewX + (viewW - controlWidth)/2; /* center it */
840
cXY.putY = viewY - controlHeight - borderHeight;
841
}
842
} else {
843
if ((physicalWidth - (viewX + viewW)) >= controlWidth) {
844
cXY.putX = viewX + viewW;
845
cXY.putY = viewY;
846
} else if ((physicalHeight - (viewY + viewH)) >= controlHeight) {
847
cXY.putX = viewX + (viewW - controlWidth)/2; /* center it */
848
cXY.putY = viewY + viewH;
849
} else if (viewX >= controlWidth) {
850
cXY.putX = viewX - controlWidth - borderWidth;
851
cXY.putY = viewY;
852
} else if (viewY >= controlHeight) {
853
cXY.putX = viewX + (viewW - controlWidth)/2; /* center it */
854
cXY.putY = viewY - controlHeight - borderHeight;
855
} else { /* put inside of viewport */
856
cXY.putX = viewX + viewW - controlWidth;
857
cXY.putY = viewY + viewH - controlHeight;
858
}
859
}
860
if (cXY.putX < 0) cXY.putX = 0;
861
if (cXY.putY < 0) cXY.putY = 0;
862
return(cXY);
863
864
}
865
866
867
868
/************************************************/
869
/*** controlPanelStruct *makeControlPanel() ***/
870
/************************************************/
871
872
controlPanelStruct *
873
makeControlPanel (void)
874
{
875
876
Window cw;
877
int i;
878
controlPanelStruct *control;
879
buttonStruct *buttons;
880
controlXY cXY;
881
XSetWindowAttributes cwAttrib, controlAttrib;
882
XSizeHints sizehint;
883
Pixmap mousebits, mousemask;
884
XColor foreColor, backColor;
885
886
if (!(control = (controlPanelStruct *)saymem("control.c",1,
887
sizeof(controlPanelStruct)))) {
888
fprintf(stderr,"Ran out of memory trying to create control panel.\n");
889
exitWithAck(RootWindow(dsply,scrn),Window,-1);
890
}
891
892
cXY = getControlXY(0);
893
894
mousebits = XCreateBitmapFromData(dsply,rtWindow,
895
(const char*) mouseBitmap_bits,
896
mouseBitmap_width, mouseBitmap_height);
897
mousemask = XCreateBitmapFromData(dsply,rtWindow,
898
(const char*) mouseMask_bits,
899
mouseMask_width, mouseMask_height);
900
cwAttrib.background_pixel = backgroundColor;
901
cwAttrib.border_pixel = foregroundColor;
902
cwAttrib.event_mask = controlMASK;
903
cwAttrib.colormap = colorMap;
904
cwAttrib.override_redirect = overrideManager;
905
foreColor.pixel = controlCursorForeground;
906
XQueryColor(dsply,colorMap,&foreColor);
907
backColor.pixel = controlCursorBackground;
908
XQueryColor(dsply,colorMap,&backColor);
909
cwAttrib.cursor = XCreatePixmapCursor(dsply,mousebits,
910
mousemask, &foreColor,&backColor,
911
mouseBitmap_x_hot,mouseBitmap_y_hot);
912
cw = XCreateWindow(dsply,rtWindow,
913
cXY.putX,cXY.putY,controlWidth,controlHeight,3,
914
CopyFromParent,InputOutput,CopyFromParent,
915
controlCreateMASK,&cwAttrib);
916
917
sizehint.flags = PPosition | PSize;
918
sizehint.x = cXY.putX;
919
sizehint.y = cXY.putY;
920
sizehint.width = controlWidth;
921
sizehint.height = controlHeight;
922
/*** the None stands for icon pixmap ***/
923
XSetNormalHints(dsply,cw,&sizehint);
924
XSetStandardProperties(dsply,cw,"3D Control Panel","3D Control Panel",
925
None,NULL,0,&sizehint);
926
927
/* Define and assign a mouse cursor */
928
control->controlWindow = cw;
929
930
initButtons(control->buttonQueue);
931
buttons = control->buttonQueue;
932
for (i=controlButtonsStart3D; i<(controlButtonsEnd3D); i++) {
933
controlAttrib.event_mask = (control->buttonQueue[i]).mask;
934
(control->buttonQueue[i]).self = XCreateWindow(dsply,cw,
935
(control->buttonQueue[i]).buttonX,
936
(control->buttonQueue[i]).buttonY,
937
(control->buttonQueue[i]).buttonWidth,
938
(control->buttonQueue[i]).buttonHeight,
939
0,0,InputOnly,CopyFromParent,
940
buttonCreateMASK,&controlAttrib);
941
XMakeAssoc(dsply,table,(control->buttonQueue[i]).self,
942
&((control->buttonQueue[i]).buttonKey));
943
/* use buttonKey and not i because buttonKey has a permanent address */
944
945
XMapWindow(dsply,(control->buttonQueue[i]).self);
946
947
} /* for each button */
948
949
950
/* Set up the potentiometer pixmaps. */
951
for (i=0; i<zoomArrowN; i++) {
952
zoomArrow[i].x += buttons[zoom].buttonX;
953
zoomArrow[i].y += buttons[zoom].buttonY;
954
}
955
for (i=0; i<translateArrowN; i++) {
956
translateArrow[i].x += buttons[translate].buttonX;
957
translateArrow[i].y += buttons[translate].buttonY;
958
}
959
960
rotateX = control->buttonQueue[rotate].buttonX+17;
961
rotateY = control->buttonQueue[rotate].buttonY+2;
962
rotateR = control->buttonQueue[rotate].buttonHeight-4;
963
964
strcpy(control->message," ");
965
966
/* Create the color mapping window */
967
controlAttrib.event_mask = colorMASK;
968
control->colormapWindow = XCreateWindow(dsply,cw, colorWidth,colormapY,
969
colormapW,colormapH,0, 0,InputOnly,
970
CopyFromParent, colormapCreateMASK,
971
&controlAttrib);
972
XMapWindow(dsply,control->colormapWindow);
973
viewport->justMadeControl = yes;
974
975
return(control);
976
977
} /* makeControlPanel() */
978
979
980
981
982
/******************************************
983
* void putControlPanelSomewhere() *
984
* This routine puts up the control panel *
985
* associated with the viewport passed *
986
* in. It first tries to put it to the *
987
* right of the viewport. If there isn't *
988
* enough room, it tries the bottom and *
989
* so on going clockwise. If the viewport *
990
* is too big and there is no room to put *
991
* the control panel outside of it, the *
992
* control panel is placed on the bottom *
993
* right hand corner of the viewport. *
994
*****************************************/
995
996
void
997
putControlPanelSomewhere (int whereDoesPanelGo)
998
{
999
controlPanelStruct *control;
1000
controlXY whereControl;
1001
1002
control = viewport->controlPanel;
1003
whereControl = getControlXY(whereDoesPanelGo);
1004
1005
viewport->haveControl = yes;
1006
1007
XRaiseWindow(dsply,control->controlWindow);
1008
XMoveWindow(dsply, control->controlWindow,
1009
whereControl.putX, whereControl.putY);
1010
1011
drawControlPanel();
1012
XSync(dsply,0);
1013
if (viewport->justMadeControl) {
1014
XMapWindow(dsply,control->controlWindow);
1015
viewport->justMadeControl = no;
1016
}
1017
XMapWindow(dsply,control->controlWindow);
1018
XFlush(dsply);
1019
1020
}
1021
1022
1023
1024
1025