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 _PROCESS2D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <string.h>
40
#include <stdio.h>
41
#include <stdlib.h>
42
#include <unistd.h>
43
#include <sys/types.h>
44
#include <sys/time.h>
45
#ifdef RIOSplatform
46
#include <sys/select.h>
47
#endif
48
49
#include "cfuns.h"
50
#include "header2.h"
51
#include "all_2d.H1"
52
#include "util.H1"
53
#include "Gfun.H1"
54
#include "XSpadFill.h"
55
56
using namespace OpenAxiom;
57
58
59
static int doit=0; /* globish variable for picking/dropping/clearing - all sorts of
60
2 button sequence events (command & graph #). */
61
62
63
void
64
doPick (int i,int bKey)
65
{
66
int vCommand=pick2D;
67
68
picking = no;
69
/* reset indicator so that we're not in pick/drop/query mode anymore */
70
doit = 0;
71
if (graphArray[currentGraph].key) {
72
check(write(Socket,&vCommand,intSize));
73
check(write(Socket,&(graphArray[currentGraph].key),intSize));
74
check(write(Socket,&(graphStateArray[currentGraph]),
75
sizeof(graphStateStruct)));
76
sprintf(control->message,"%s%d","Picked up graph ",currentGraph+1);
77
} else
78
sprintf(control->message,"%s","This graph is empty!");
79
writeControlMessage();
80
81
82
}
83
84
85
void
86
doDrop (int i,int bKey)
87
{
88
int vCommand=drop2D;
89
int viewGoAhead;
90
91
dropping = no;
92
/* reset indicator so that we're not in pick/drop/query mode anymore */
93
doit = 0;
94
check(write(Socket,&(vCommand),intSize));
95
readViewman(&viewGoAhead,intSize);
96
if (viewGoAhead < 0) {
97
sprintf(control->message,"%s%d","Couldn't drop to graph ",currentGraph+1);
98
writeControlMessage();
99
} else {
100
sprintf(control->message,"%s%d","Dropped onto graph ",currentGraph+1);
101
writeControlMessage();
102
freeGraph(currentGraph);
103
readViewman(&(graphArray[currentGraph].key),intSize);
104
getGraphFromViewman(currentGraph);
105
/* simulate a button press to turn display number on and select on */
106
/* need !yes since it will be inverted */
107
graphStateArray[currentGraph].selected = no;
108
graphStateArray[currentGraph].showing =
109
!(graphStateArray[currentGraph].showing);
110
clickedOnGraph(currentGraph,currentGraph+graphStart);
111
clickedOnGraphSelect(currentGraph,currentGraph+graphSelectStart);
112
}
113
}
114
115
void
116
clickedOnGraphSelect (int i,int bKey)
117
{
118
int strlength;
119
120
switch (doit) {
121
case pick2D:
122
currentGraph = i;
123
doPick(i,bKey);
124
break;
125
case drop2D:
126
currentGraph = i;
127
doDrop(i,bKey);
128
break;
129
case query2D:
130
queriedGraph = i;
131
makeMessageFromData(queriedGraph);
132
writeControlMessage();
133
/* reset indicator so that we're not in pick/drop/query mode anymore */
134
doit = 0;
135
break;
136
default:
137
graphStateArray[i].selected = !(graphStateArray[i].selected);
138
if (graphStateArray[i].selected) {
139
GSetForeground(graphGC,(float)graphBarSelectColor,Xoption);
140
strcpy(control->buttonQueue[bKey].text,"^");
141
strlength = strlen(control->buttonQueue[bKey].text);
142
} else {
143
GSetForeground(graphGC,(float)graphBarNotSelectColor,Xoption);
144
strcpy(control->buttonQueue[bKey].text,"-");
145
strlength = strlen(control->buttonQueue[bKey].text);
146
}
147
/* just to make sure the background is reset from clickedOnGraph */
148
if (mono) {
149
GSetForeground(graphGC,(float)foregroundColor,Xoption);
150
GSetBackground(graphGC,(float)backgroundColor,Xoption);
151
}
152
153
GDrawImageString(graphGC,control->controlWindow,
154
control->buttonQueue[bKey].buttonX +
155
centerX(graphGC,
156
control->buttonQueue[bKey].text,strlength,
157
control->buttonQueue[bKey].buttonWidth),
158
control->buttonQueue[bKey].buttonY +
159
centerY(graphGC,
160
control->buttonQueue[bKey].buttonHeight),
161
control->buttonQueue[bKey].text,strlength,Xoption);
162
GSetForeground(trashGC,(float)foregroundColor,Xoption);
163
GSetLineAttributes(trashGC,2,LineSolid,CapButt,JoinMiter,Xoption);
164
GDrawLine(trashGC,control->controlWindow,0,286,controlWidth,286,Xoption);
165
break;
166
} /* switch doit */
167
168
}
169
170
171
static void
172
drawControlPushButton(int isOn, int index)
173
{
174
GDrawPushButton(dsply, processGC, processGC, processGC,
175
control->controlWindow,
176
(control->buttonQueue[index]).buttonX,
177
(control->buttonQueue[index]).buttonY,
178
(control->buttonQueue[index]).buttonWidth,
179
(control->buttonQueue[index]).buttonHeight,
180
isOn,
181
(control->buttonQueue[index]).text,
182
buttonColor,
183
monoColor((control->buttonQueue[index]).textColor), Xoption);
184
XSync(dsply,False);
185
}
186
187
188
189
void
190
buttonAction (int bKey)
191
{
192
int i;
193
194
switch (bKey) {
195
196
case pick2D:
197
if (viewAloned) {
198
sprintf(control->message,"%s","Cannot pick without OpenAxiom!");
199
writeControlMessage();
200
XSync(dsply,False);
201
}
202
else {
203
doit = pick2D;
204
sprintf(control->message,"%s","Click on the graph to pick");
205
writeControlMessage();
206
XSync(dsply,False);
207
}
208
break;
209
210
case drop2D:
211
if (viewAloned) {
212
sprintf(control->message,"%s","Cannot drop without OpenAxiom!");
213
writeControlMessage();
214
XSync(dsply,False);
215
} else {
216
doit = drop2D;
217
sprintf(control->message,"%s","Click on the graph to drop");
218
writeControlMessage();
219
XSync(dsply,False);
220
}
221
break;
222
223
case query2D:
224
doit = query2D;
225
sprintf(control->message,"%s","Click on the graph to query");
226
writeControlMessage();
227
XSync(dsply,False);
228
break;
229
230
231
case zoom2Dx:
232
if (zoomXON)
233
strcpy((control->buttonQueue[zoom2Dx]).text ,
234
"X Off");
235
else
236
strcpy((control->buttonQueue[zoom2Dx]).text ,
237
"X On ");
238
zoomXON = !zoomXON;
239
240
drawControlPushButton(zoomXON, zoom2Dx);
241
XSync(dsply,False);
242
break;
243
244
case zoom2Dy:
245
if (zoomYON) strcpy((control->buttonQueue[zoom2Dy]).text,
246
"Y Off");
247
else strcpy((control->buttonQueue[zoom2Dy]).text ,
248
"Y On ");
249
zoomYON = !zoomYON;
250
drawControlPushButton(zoomYON, zoom2Dy);
251
XSync(dsply,False);
252
break;
253
254
255
case translate2Dx:
256
if (transXON) strcpy((control->buttonQueue[translate2Dx]).text,
257
"X Off");
258
else strcpy( (control->buttonQueue[translate2Dx]).text,
259
"X On ");
260
transXON = !transXON;
261
drawControlPushButton(transXON, translate2Dx);
262
XSync(dsply,False);
263
break;
264
265
case translate2Dy:
266
if (transYON) strcpy((control->buttonQueue[translate2Dy]).text,
267
"Y Off");
268
else strcpy( (control->buttonQueue[translate2Dy]).text,
269
"Y On");
270
transYON = !transYON;
271
drawControlPushButton(transYON, translate2Dy);
272
XSync(dsply,False);
273
break;
274
275
case pointsOnOff:
276
if (pointsON) strcpy((control->buttonQueue[pointsOnOff]).text,
277
"Pts Off");
278
else strcpy( (control->buttonQueue[pointsOnOff]).text,
279
"Pts On ");
280
pointsON = !pointsON;
281
for (i=0; i<maxGraphs; i++)
282
if (graphStateArray[i].showing && graphStateArray[i].selected)
283
graphStateArray[i].pointsOn = pointsON;
284
285
drawControlPushButton(pointsON, pointsOnOff);
286
drawViewport(Xoption);
287
break;
288
289
case connectOnOff:
290
if (connectON) strcpy((control->buttonQueue[connectOnOff]).text,
291
"Lines Off");
292
else strcpy( (control->buttonQueue[connectOnOff]).text,
293
"Lines On ");
294
connectON = !connectON;
295
for (i=0; i<maxGraphs; i++)
296
if (graphStateArray[i].showing && graphStateArray[i].selected)
297
graphStateArray[i].connectOn = connectON;
298
299
drawControlPushButton(connectON, connectOnOff);
300
drawViewport(Xoption);
301
break;
302
303
case spline2D:
304
if (splineON) strcpy((control->buttonQueue[spline2D]).text,
305
"Box Off");
306
else strcpy ((control->buttonQueue[spline2D]).text ,
307
"Box On ");
308
splineON = !splineON;
309
for (i=0; i<maxGraphs; i++)
310
if (graphStateArray[i].showing && graphStateArray[i].selected)
311
graphStateArray[i].splineOn = splineON;
312
313
drawControlPushButton(splineON, spline2D);
314
drawViewport(Xoption);
315
break;
316
317
case axesOnOff2D:
318
if (axesON)
319
strcpy ((control->buttonQueue[axesOnOff2D]).text,
320
"Axes Off");
321
else
322
strcpy ((control->buttonQueue[axesOnOff2D]).text ,
323
"Axes On ");
324
axesON = !axesON;
325
for (i=0; i<maxGraphs; i++)
326
if (graphStateArray[i].showing && graphStateArray[i].selected)
327
graphStateArray[i].axesOn = axesON;
328
329
drawControlPushButton(axesON, axesOnOff2D);
330
drawViewport(Xoption);
331
break;
332
333
case unitsOnOff2D:
334
if (unitsON)
335
strcpy( (control->buttonQueue[unitsOnOff2D]).text,
336
"Units Off");
337
else
338
strcpy ((control->buttonQueue[unitsOnOff2D]).text,
339
"Units On ");
340
unitsON = !unitsON;
341
for (i=0; i<maxGraphs; i++)
342
if (graphStateArray[i].showing && graphStateArray[i].selected)
343
graphStateArray[i].unitsOn = unitsON;
344
345
drawControlPushButton(unitsON, unitsOnOff2D);
346
drawViewport(Xoption);
347
break;
348
349
case ps2D:
350
strcpy(control->message,"Creating postscript now ...");
351
writeControlMessage();
352
drawControlPushButton(1, ps2D);
353
354
if (PSInit(viewport->viewWindow, viewport->titleWindow) == psError) {
355
strcpy(control->message,"Aborted: PSInit error.");
356
writeControlMessage();
357
drawControlPushButton(0, ps2D);
358
XSync(dsply,False);
359
return; /* make new temp name for new file */
360
}
361
362
drawViewport(PSoption); /* draw picture in PS; create ps script file */
363
364
if (PSCreateFile(viewBorderWidth,
365
viewport->viewWindow,
366
viewport->titleWindow,
367
viewport->title) == psError) {
368
strcpy(control->message,"Aborted: PSCreateFile error.");
369
writeControlMessage();
370
drawControlPushButton(0, ps2D);
371
XSync(dsply,False);
372
return;
373
}
374
375
clearControlMessage();
376
strcpy(control->message,PSfilename);
377
strcat(control->message," in working dir ");
378
writeControlMessage();
379
drawControlPushButton(0, ps2D);
380
XSync(dsply,False);
381
break;
382
383
case hideControl2D:
384
if (viewport->haveControl) {
385
viewport->haveControl = no;
386
XUnmapWindow(dsply,control->controlWindow);
387
XSync(dsply,False);
388
}
389
break;
390
391
case reset2D:
392
/* reset view */
393
for (i=0; i<maxGraphs; i++)
394
if (graphStateArray[i].showing && graphStateArray[i].selected)
395
graphStateArray[i] = graphStateBackupArray[i];
396
397
unitsON = no;
398
strcpy( (control->buttonQueue[unitsOnOff2D]).text,s = "Units Off");
399
for (i=0; i<maxGraphs; i++)
400
if (graphStateArray[i].showing && graphStateArray[i].selected)
401
graphStateArray[i].unitsOn = no;
402
drawControlPushButton(unitsON, unitsOnOff2D);
403
404
pointsON = yes;
405
strcpy ((control->buttonQueue[pointsOnOff]).text ,"Pts On ");
406
for (i=0; i<maxGraphs; i++)
407
if (graphStateArray[i].showing && graphStateArray[i].selected)
408
graphStateArray[i].pointsOn = yes;
409
drawControlPushButton(pointsON, pointsOnOff);
410
411
axesON = yes;
412
strcpy ((control->buttonQueue[axesOnOff2D]).text,"Axes On ");
413
for (i=0; i<maxGraphs; i++)
414
if (graphStateArray[i].showing && graphStateArray[i].selected)
415
graphStateArray[i].axesOn = yes;
416
drawControlPushButton(axesON, axesOnOff2D);
417
418
connectON = yes;
419
strcpy((control->buttonQueue[connectOnOff]).text,"Lines On ");
420
for (i=0; i<maxGraphs; i++)
421
if (graphStateArray[i].showing && graphStateArray[i].selected)
422
graphStateArray[i].connectOn = yes;
423
drawControlPushButton(connectON, connectOnOff);
424
425
splineON = no;
426
strcpy( (control->buttonQueue[connectOnOff]).text ,"Box Off");
427
for (i=0; i<maxGraphs; i++)
428
if (graphStateArray[i].showing && graphStateArray[i].selected)
429
graphStateArray[i].splineOn = splineON;
430
drawControlPushButton(splineON, spline2D);
431
drawViewport(Xoption);
432
433
break;
434
435
case closeAll2D:
436
strcpy(control->message," Click again to confirm ");
437
writeControlMessage();
438
drawControlPushButton(1, closeAll2D);
439
XSync(dsply,False);
440
viewport->closing = yes;
441
break;
442
443
case clear2D:
444
for (i=0; i<maxGraphs; i++) graphStateArray[i].selected = 1;
445
clickedOnGraphSelect(0,graphSelect1);
446
clickedOnGraphSelect(1,graphSelect2);
447
clickedOnGraphSelect(2,graphSelect3);
448
clickedOnGraphSelect(3,graphSelect4);
449
clickedOnGraphSelect(4,graphSelect5);
450
clickedOnGraphSelect(5,graphSelect6);
451
clickedOnGraphSelect(6,graphSelect7);
452
clickedOnGraphSelect(7,graphSelect8);
453
clickedOnGraphSelect(8,graphSelect9);
454
XSync(dsply,False);
455
break;
456
457
case graph1:
458
case graph2:
459
case graph3:
460
case graph4:
461
case graph5:
462
case graph6:
463
case graph7:
464
case graph8:
465
case graph9:
466
clickedOnGraph(bKey-graphStart,bKey);
467
XSync(dsply,False);
468
break;
469
470
case graphSelect1:
471
case graphSelect2:
472
case graphSelect3:
473
case graphSelect4:
474
case graphSelect5:
475
case graphSelect6:
476
case graphSelect7:
477
case graphSelect8:
478
case graphSelect9:
479
clickedOnGraphSelect(bKey-graphSelectStart,bKey);
480
XSync(dsply,False);
481
break;
482
483
} /* switch (action) */
484
}
485
486
/*********************** X Event Processing ***************************/
487
void
488
processEvents(void)
489
{
490
491
XEvent *event,
492
tempEvent;
493
Window whichWindow;
494
XWindowAttributes graphWindowAttrib;
495
buttonStruct *controlButton;
496
mouseCoord mouseXY;
497
int i,
498
someInt,
499
mouseW4,
500
mouseH4,
501
toggleReady,
502
gotToggle = no,
503
checkButton = no,
504
firstTime = yes,
505
gotEvent = 0,
506
buttonTablePtr,
507
Xcon,
508
len,
509
externalControl;
510
fd_set rd;
511
512
513
externalControl=0;
514
Xcon = ConnectionNumber(dsply);
515
516
517
if (!(event = (XEvent *)malloc(sizeof(XEvent)))) {
518
fprintf(stderr,"Ran out of memory initializing event processing.\n");
519
exitWithAck(RootWindow(dsply,scrn),Window,-1);
520
}
521
522
controlButton = control->buttonQueue;
523
524
while(1) {
525
526
len=0;
527
while(len<=0) {
528
FD_ZERO(&rd);
529
if (externalControl==0) FD_SET(0, &rd);
530
FD_SET(Xcon,&rd);
531
532
if (XEventsQueued(dsply, QueuedAlready)) {
533
len=1;
534
break;
535
}
536
if (!followMouse)
537
len=select(FD_SETSIZE, &rd,0,0,0);
538
else
539
len=1;
540
}
541
if (FD_ISSET(Xcon,&rd)||
542
XEventsQueued(dsply, QueuedAfterFlush) ||
543
followMouse) {
544
545
if (followMouse) {
546
if (XPending(dsply))
547
XNextEvent(dsply,event);
548
gotEvent++;
549
} else {
550
XNextEvent(dsply,event);
551
gotEvent++;
552
}
553
554
if (gotToggle || !followMouse)
555
checkButton = no;
556
557
if (gotEvent) {
558
whichWindow = ((XButtonEvent *)event)->window;
559
firstTime = no;
560
561
switch(((XEvent *)event)->type) {
562
563
case ClientMessage:
564
if (event->xclient.data.l[0] == wm_delete_window) {
565
goodbye(-1);
566
}
567
else {
568
fprintf(stderr,"Unknown Client Message ...\n");
569
}
570
break;
571
case Expose:
572
if (whichWindow == viewport->titleWindow) {
573
/* get rid of redundant events */
574
XCheckWindowEvent(dsply,
575
viewport->titleWindow,
576
ExposureMask,
577
&tempEvent);
578
writeTitle();
579
XGetWindowAttributes(dsply,
580
whichWindow,
581
&graphWindowAttrib);
582
XResizeWindow(dsply,
583
viewport->viewWindow,
584
graphWindowAttrib.width,
585
graphWindowAttrib.height-titleHeight);
586
XSync(dsply,False);
587
break;
588
} else if (whichWindow == viewport->viewWindow) {
589
XCheckWindowEvent(dsply,
590
viewport->viewWindow,
591
ExposureMask,
592
&tempEvent);
593
XGetWindowAttributes(dsply,
594
viewport->titleWindow,
595
&graphWindowAttrib);
596
XResizeWindow(dsply,
597
viewport->viewWindow,
598
graphWindowAttrib.width,
599
graphWindowAttrib.height-titleHeight);
600
drawViewport(Xoption);
601
XMapWindow(dsply,whichWindow);
602
XSync(dsply,False);
603
break;
604
} else { /* it's gotta be the control panel */
605
XGetWindowAttributes(dsply,
606
control->controlWindow,
607
&graphWindowAttrib);
608
/* do not allow resizing of control panel */
609
if ((graphWindowAttrib.width != controlWidth) ||
610
(graphWindowAttrib.height != controlHeight)) {
611
XResizeWindow(dsply,
612
control->controlWindow,
613
controlWidth,
614
controlHeight);
615
}
616
drawControlPanel();
617
XSync(dsply,False);
618
break;
619
}
620
break;
621
622
case MotionNotify:
623
if (followMouse) {
624
while (XCheckMaskEvent(dsply,
625
ButtonMotionMask,
626
event));
627
mouseXY = getPotValue(((XButtonEvent *)event)->x,
628
((XButtonEvent *)event)->y,
629
controlButton->xHalf,
630
controlButton->yHalf);
631
}
632
if (controlButton->pot) {
633
gotToggle = no;
634
checkButton = yes;
635
}
636
break;
637
638
case ButtonRelease:
639
if (followMouse==yes) {
640
followMouse = no;
641
toggleReady = yes;
642
checkButton = no;
643
drawViewport(Xoption);
644
} else {
645
followMouse = no;
646
toggleReady = yes;
647
checkButton = no;
648
}
649
break;
650
651
case LeaveNotify:
652
/*
653
We still follow the mouse when we leave the pots.
654
*/
655
/*
656
followMouse = no;
657
toggleReady = yes;
658
checkButton = no;
659
*/
660
661
break;
662
663
case ButtonPress:
664
if (whichWindow == viewport->viewWindow) {
665
666
/* mouse clicked on viewport */
667
668
switch (((XButtonEvent *)event)->button) {
669
case Button3:
670
671
/* print out (x,y) object-space coordinates in message area */
672
673
XGetWindowAttributes(dsply,whichWindow,&graphWindowAttrib);
674
sprintf(viewport->controlPanel->message,
675
" >%d<: [%6.2f,%6.2f] ",
676
queriedGraph+1,
677
projX((((XButtonEvent *)event)->x),
678
graphWindowAttrib.width,queriedGraph),
679
projY((((XButtonEvent *)event)->y),
680
graphWindowAttrib.height,queriedGraph));
681
writeControlMessage();
682
XFlush(dsply);
683
break;
684
default:
685
686
/* Find where mouse is on the viewport => where to put the CP */
687
688
XGetWindowAttributes(dsply,
689
whichWindow,
690
&graphWindowAttrib);
691
mouseW4 = graphWindowAttrib.width/4;
692
if (((XButtonEvent *)event)->x >
693
(graphWindowAttrib.width - mouseW4))
694
someInt = 1;
695
else {
696
mouseH4 = graphWindowAttrib.height/4;
697
if (((XButtonEvent *)event)->y >
698
(graphWindowAttrib.height - mouseH4))
699
someInt = 2;
700
else if (((XButtonEvent *)event)->x < mouseW4)
701
someInt = 3;
702
else if (((XButtonEvent *)event)->y < mouseH4)
703
someInt = 4;
704
else someInt = 0;
705
}
706
if (viewport->haveControl) {
707
XUnmapWindow(dsply,control->controlWindow);
708
}
709
putControlPanelSomewhere(someInt);
710
XMapWindow(dsply,control->controlWindow);
711
XSync(dsply,False);
712
break;
713
} /* switch on mouse button */
714
} else if (whichWindow == control->colormapWindow) {
715
716
/* mouse clicked on colormap */
717
718
followMouse = yes;
719
gotToggle = no;
720
checkButton = yes;
721
firstTime = yes;
722
} else if (whichWindow != control->controlWindow) {
723
724
/* mouse clicked on control window (not colormap) */
725
726
if (controlButton->self != whichWindow) {
727
buttonTablePtr = *((int *)XLookUpAssoc(dsply,table,whichWindow));
728
controlButton = &(control->buttonQueue[buttonTablePtr]);
729
}
730
731
if (controlButton->pot) {
732
/* figure out [x,y] for this button in the range [-1..1,-1..1] */
733
mouseXY = getPotValue(((XButtonEvent *)event)->x,
734
((XButtonEvent *)event)->y,
735
controlButton->xHalf,
736
controlButton->yHalf);
737
followMouse = yes;
738
gotToggle = no;
739
} else {
740
followMouse = no;
741
gotToggle = yes; /* auto-repeat on toggle buttons not allowed */
742
if (toggleReady) {
743
toggleReady = no;
744
}
745
}
746
checkButton = yes;
747
firstTime = yes;
748
}
749
break;
750
751
} /* switch */
752
gotEvent--;
753
} /* if gotEvent */
754
755
756
/* Allow repeat polling when mouse button clicked on a potentiometer. */
757
758
if (followMouse && !firstTime && (followMouse++ > mouseWait)) {
759
followMouse = yes; /* reset for next timing loop */
760
checkButton = yes;
761
}
762
if (checkButton) {
763
if (viewport->closing && (controlButton->buttonKey == closeAll2D)) {
764
goodbye(-1);
765
} else {
766
clearControlMessage();
767
viewport->closing = no;
768
drawControlPushButton(0, closeAll2D);
769
if ((doit) &&
770
((controlButton->buttonKey < graphStart) &&
771
(controlButton->buttonKey > (graphSelectStart + maxGraphs))))
772
doit = 0;
773
774
switch(controlButton->buttonKey) {
775
776
case translate2D:
777
for (i=0; i<maxGraphs; i++) {
778
if (graphStateArray[i].showing && graphStateArray[i].selected) {
779
if (transXON) {
780
graphStateArray[i].centerX -= mouseXY.x * 0.1;
781
if (graphStateArray[i].centerX > maxDelta)
782
graphStateArray[i].centerX = maxDelta;
783
else if (graphStateArray[i].centerX < -maxDelta)
784
graphStateArray[i].centerX = maxDelta;
785
}
786
if (transYON) {
787
graphStateArray[i].centerY -= mouseXY.y * 0.1;
788
if (graphStateArray[i].centerY > maxDelta)
789
graphStateArray[i].centerY = maxDelta;
790
else if (graphStateArray[i].centerY < -maxDelta)
791
graphStateArray[i].centerY = maxDelta;
792
}
793
} /* graph showing or selected */
794
} /* for graphs */
795
drawViewport(Xoption);
796
break;
797
798
case scale2D:
799
for (i=0; i<maxGraphs; i++) {
800
if (graphStateArray[i].showing && graphStateArray[i].selected) {
801
if (zoomXON) {
802
graphStateArray[i].scaleX *= (1 - mouseXY.y * 0.3);
803
if (graphStateArray[i].scaleX > maxScale)
804
graphStateArray[i].scaleX = maxScale;
805
else if (graphStateArray[i].scaleX < minScale)
806
graphStateArray[i].scaleX = minScale;
807
}
808
if (zoomYON) {
809
graphStateArray[i].scaleY *= (1 - mouseXY.y * 0.3);
810
if (graphStateArray[i].scaleY > maxScale)
811
graphStateArray[i].scaleY = maxScale;
812
else if (graphStateArray[i].scaleY < minScale)
813
graphStateArray[i].scaleY = minScale;
814
}
815
} /* graph showing or selected */
816
} /* for graphs */
817
drawViewport(Xoption);
818
break;
819
820
default:
821
buttonAction(controlButton->buttonKey);
822
} /* switch on buttonKey */
823
} /* else - not closing */
824
} /* if checkButton */
825
} /* if FD_ISSET(Xcon.... */
826
else if (FD_ISSET(0,&rd)) {
827
externalControl=spadAction(); /* returns (-1) if broken ,0 if success */
828
if (spadDraw && (externalControl==0)) drawViewport(Xoption);
829
}
830
} /* while */
831
} /* processEvents() */
832
833
834
835
836
837
838
void
839
clickedOnGraph (int i,int bKey)
840
{
841
842
switch (doit) {
843
case pick2D:
844
currentGraph = queriedGraph = i;
845
doPick(i,bKey);
846
break;
847
case drop2D:
848
currentGraph = queriedGraph = i;
849
doDrop(i,bKey);
850
break;
851
case query2D:
852
queriedGraph = i;
853
makeMessageFromData(queriedGraph);
854
writeControlMessage();
855
/* reset indicator so that we're not in pick/drop/query mode anymore */
856
doit = 0;
857
break;
858
default:
859
graphStateArray[i].showing = !(graphStateArray[i].showing);
860
if (mono) {
861
if (graphStateArray[i].showing) {
862
GSetForeground(graphGC,(float)backgroundColor,Xoption);
863
GSetBackground(graphGC,(float)foregroundColor,Xoption);
864
} else {
865
GSetForeground(graphGC,(float)foregroundColor,Xoption);
866
GSetBackground(graphGC,(float)backgroundColor,Xoption);
867
}
868
GDrawImageString(graphGC,
869
control->controlWindow,
870
(control->buttonQueue[bKey]).buttonX +
871
centerX(graphGC,(control->buttonQueue[bKey]).text,1,
872
(control->buttonQueue[bKey]).buttonWidth),
873
(control->buttonQueue[bKey]).buttonY +
874
centerY(graphGC,(control->buttonQueue[bKey]).buttonHeight),
875
(control->buttonQueue[bKey]).text,
876
1,
877
Xoption);
878
} else {
879
if (graphStateArray[i].showing)
880
GSetForeground(graphGC,(float)graphBarShowingColor,Xoption);
881
else
882
GSetForeground(graphGC,(float)graphBarHiddenColor,Xoption);
883
GDrawString(graphGC,
884
control->controlWindow,
885
(control->buttonQueue[bKey]).buttonX +
886
centerX(graphGC,(control->buttonQueue[bKey]).text,1,
887
(control->buttonQueue[bKey]).buttonWidth),
888
(control->buttonQueue[bKey]).buttonY +
889
centerY(graphGC,(control->buttonQueue[bKey]).buttonHeight),
890
(control->buttonQueue[bKey]).text,1,Xoption);
891
}
892
drawViewport(Xoption);
893
break;
894
} /* switch doit */
895
896
}
897
898
899
900
901
902
903
904
905
906
907