Debian Codegraph @

libsrc/idi/cidi/x11/idilocal2.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /***********************************************************************
29 *
30 * file idilocal2.c
31 *
32 * IDI Device Dependent Routines
33 * (XWindows version)
34 *
35 * V 1.00 880219 F.Pasian, P.Santin - Trieste Astronomical Observatory
36 * V 2.00 890102 K. Banse ESO - Garching (from now on)
37 *
38 *
39 * crea_win : Create a XWindow
40 * cl_win : Clear a XWindow
41 * set_wcur : Set XWindow cursor shape
42 * sendX : do XFlush
43 * crealph : Create alpha_numerics subwindow;
44 * clalph : Clear the alpha_numerics subwindow;
45 * alprfr : Refresh alpha memory
46 * alptext : Write into alpha_numerics subwindow;
47 * crelutbar : Create LUT/Intensity Bar;
48 * vislutbar : Handle visibility of LUT/Intensity Bar;
49 * updalutbar : update LUT/Intensity Bar;
50 * get_string : get character string from keyboard via X;
51 * get_char : get single character from keyboard via X;
52 * initgra : Initialize Graphics Context;
53 * polyline : Draw Polyline on Display Bitmap;
54 * polyrefr : Redraw graphic stuff
55 * txtline : Draw text string on Display Bitmap;
56 * txtrefr : Redraw text stuff
57 * rd_pllut : get R, G, B values of plot colours
58 * do_misc : do miscellaneous functions
59 *
60
61 * 090424 last modif
62
63 ***********************************************************************/
64
65 /*
66
67 */
68
69 # include <stdlib.h>
70 # include <stdio.h>
71
72
73 # include <idi.h>
74 # include <idistruct.h>
75 # include <x11defs.h>
76 # include <proto_idi.h>
77
78
79 static Bool discard = True;
80
81 static int lutoff;
82 static unsigned long int maska;
83 static unsigned int tmpxdim, tmpydim;
84
85 static int parent_id = -1; /* root window */
86 static int textsiz = -1, lasttxtno = -1, lastplno = -1;
87 static int plotcol = -1; /* foreground color of gcima */
88 static int linewidth = -1;
89 static unsigned int border = 1;
90 static short int *jpntra;
91 static long int Def_Mask = (ExposureMask | StructureNotifyMask);
92
93 static float rval;
94
95 static unsigned char *cpntra;
96
97 /*
98
99 */
100
101 /*
102 crea_win routine : display/graphics window creation
103 synopsis: crea_win (dspno,xoff,yoff,xdim,ydim,dspchar)
104 int dspno; input display no.
105 int xoff; input x offset
106 int yoff; input y offset
107 int xdim; input x display dimension
108 int ydim; input y display dimension
109 char dspchar; input display id_char
110 */
111
112 #ifdef __STDC__
113 int crea_win(int dspno,int xoff,int yoff,unsigned int xdim,unsigned int ydim,
114 char dspchar)
115 #else
116 crea_win(dspno,xoff,yoff,xdim,ydim,dspchar)
117 int dspno, xoff, yoff;
118 unsigned int xdim, ydim;
119 char dspchar;
120 #endif
121
122 {
123 char *argv[1];
124 char win_name[32];
125
126 unsigned long int forgr, backgr;
127 int k, j, no;
128
129
130
131
132 no = ididev[dspno].screen;
133 /* XWindow Y Coordinate Inversion */
134 if (ididev[dspno].devtyp == 'g')
135 {
136 forgr = Xworkst[no].black;
137 backgr = Xworkst[no].white;
138 }
139 else
140 {
141 forgr = Xworkst[no].white;
142 backgr = ididev[dspno].backpix; /* at start, just the index */
143 backgr = fixcolr[no][backgr].pixel;
144 }
145 ididev[dspno].backpix = backgr;
146
147
148 /* handle LUT offsets */
149
150 ididev[dspno].lutoff = 0;
151
152 if (Xworkst[no].ownlut == 1)
153 {
154 if ((Xworkst[no].nolut > 1) && (dspno > 0))
155 {
156 if (dspno < Xworkst[no].nolut)
157 ididev[dspno].lutsect = dspno;
158 else
159 ididev[dspno].lutsect = Xworkst[no].nolut - 1;
160 }
161 if (Xworkst[no].visual == 4)
162 ididev[dspno].lutoff = Xworkst[no].auxcol;
163 else
164 {
165 if (Xworkst[no].lutflag == 0)
166 k = ididev[dspno].lutsect * Xworkst[no].lutsize;
167 else
168 k = Xworkst[no].auxcol;
169 ididev[dspno].lutoff = mycolr[no][k].pixel;
170 }
171 }
172
173 k = ididev[dspno].lutsect;
174 maska = CWBackPixel | CWBorderPixel | CWColormap;
175 sattributes.background_pixel = backgr;
176 sattributes.border_pixel = forgr;
177
178 if (parent_id != -1)
179 {
180 /* printf("parent_w = rw[%d] = %x (= mwndw[%d] = %x)\n",
181 no,rw[no],parent_id,mwndw[parent_id]); */
182
183 ididev[parent_id].link[0] = 1; /* indicate parent window */
184 j = ididev[parent_id].ysize;
185 sattributes.colormap = CopyFromParent;
186 }
187 else
188 {
189 j = Xworkst[no].height;
190 sattributes.colormap = cmap[no][k];
191 }
192 yoff = j - ydim - yoff - border*2;
193 ididev[dspno].link[1] = parent_id;
194
195 /* printf("crea_win: xoff,yoff = %d, %d\n",xoff,yoff); */
196
197 mwndw[dspno] = XCreateWindow(mydisp[no],rw[no],
198 xoff,yoff,xdim,ydim,border,Xworkst[no].depth,
199 InputOutput,myvis[no],maska,&sattributes);
200 if (mwndw[dspno] == 0) return(WINOTOPN);
201
202
203 /* create the GC (Graphics Context) painfully by hand ... */
204
205 maska = GCFunction | GCPlaneMask | GCLineWidth | GCLineStyle;
206 maska |= (GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule);
207 maska |= (GCArcMode | GCSubwindowMode | GCGraphicsExposures);
208 xgcvals.function = GXcopy;
209 xgcvals.plane_mask = 0xffffffff;
210 xgcvals.line_width = 1;
211 xgcvals.line_style = LineSolid;
212 xgcvals.cap_style = CapRound;
213 xgcvals.join_style = JoinRound;
214 xgcvals.fill_style = FillSolid;
215 xgcvals.fill_rule = WindingRule;
216 xgcvals.arc_mode = ArcPieSlice;
217 xgcvals.arc_mode = ClipByChildren;
218 xgcvals.graphics_exposures = False;
219 gcima[dspno] = XCreateGC(mydisp[no],mwndw[dspno],maska,&xgcvals);
220 XSetFunction(mydisp[no],gcima[dspno],GXcopy);
221 XSetBackground(mydisp[no],gcima[dspno],backgr);
222 XSetForeground(mydisp[no],gcima[dspno],forgr);
223 XSetFont(mydisp[no],gcima[dspno],myfont[no][0]->fid);
224
225 gcdraw[dspno] = XCreateGC(mydisp[no],mwndw[dspno],0,&xgcvals);
226 if (ididev[dspno].devtyp == 'c')
227 {
228 XSetFunction(mydisp[no],gcdraw[dspno],GXcopy);
229 XSetBackground(mydisp[no],gcdraw[dspno],forgr);
230 XSetForeground(mydisp[no],gcdraw[dspno],backgr);
231 }
232 else
233 {
234 XSetBackground(mydisp[no],gcdraw[dspno],0);
235 XSetForeground(mydisp[no],gcdraw[dspno],0xffffffff);
236 XSetFunction(mydisp[no],gcdraw[dspno],GXxor);
237 if (ididev[dspno].devtyp == 'g')
238 maska = forgr ^ backgr;
239 else
240 {
241 if (Xworkst[no].visual == 3)
242 maska = 0xffffffff; /* use all 1's */
243 else if (Xworkst[no].visual == 4)
244 maska = 0xffffffff; /* use all 1's */
245 else
246 {
247 if (Xworkst[no].depth == 8)
248 maska = 0xffffff80; /* last byte = 1000 0000 */
249 else if (Xworkst[no].depth == 16)
250 maska = 0xffff8000;
251 else if (Xworkst[no].depth == 32)
252 maska = 0x80000000;
253 else
254 maska = 0xffffffff;
255 }
256 }
257 XSetPlaneMask(mydisp[no],gcdraw[dspno],maska);
258 XSetFunction(mydisp[no],gcdraw[dspno],GXxor);
259 }
260
261
262 XDefineCursor(mydisp[no],mwndw[dspno],mycurs[no][0]);
263
264 event_mask = ButtonPressMask | Def_Mask;
265 XSync(mydisp[no],discard);
266
267 XSelectInput(mydisp[no],mwndw[dspno],event_mask);
268
269 myhint[dspno].x = xoff;
270 myhint[dspno].y = yoff;
271 myhint[dspno].width = xdim;
272 myhint[dspno].height = ydim;
273 myhint[dspno].flags = USPosition | USSize; /* like this we force position */
274
275 if (ididev[dspno].devtyp == 'g')
276 {
277 if (ididev[dspno].ref != '\0')
278 (void) sprintf(win_name,"MIDAS_%s shadow(%c),graph_%c",
279 Xworkst[no].miduni,dspchar,ididev[dspno].ref);
280 else
281 (void) sprintf(win_name,"MIDAS_%s graph_%c",Xworkst[no].miduni,dspchar);
282 }
283 else if (ididev[dspno].devtyp == 'z')
284 (void) sprintf(win_name,"MIDAS_%s zoom_%c",Xworkst[no].miduni,dspchar);
285 else if (ididev[dspno].devtyp == 'c')
286 (void) sprintf(win_name,"cursor_%c_window",dspchar);
287 else
288 {
289 if (ididev[dspno].ref != '\0')
290 (void) sprintf(win_name,"MIDAS_%s shadow(%c),display_%c",
291 Xworkst[no].miduni,dspchar,ididev[dspno].ref);
292 else
293 (void) sprintf(win_name,"MIDAS_%s display_%c",Xworkst[no].miduni,dspchar);
294 }
295
296 argv[0] = win_name;
297 XSetStandardProperties(mydisp[no],mwndw[dspno],win_name,win_name,
298 None,argv,1,&myhint[dspno]);
299
300 xwmh.flags = InputHint | StateHint;
301 xwmh.initial_state = NormalState;
302 xwmh.input = True;
303 XSetWMHints(mydisp[no],mwndw[dspno],&xwmh);
304 XMapRaised (mydisp[no],mwndw[dspno]);
305
306 /*
307 printf(
308 "crea_win: XMapRaised of window %d (mwndw[%d] = %x), parent = %x\n",
309 dspno,dspno,mwndw[dspno],rw[no]) ;
310 */
311
312 return (II_SUCCESS);
313 }
314
315 /*
316
317 */
318
319 void cl_win(dspno,colval)
320 int dspno, colval;
321
322 {
323 int no;
324
325
326
327 no = ididev[dspno].screen;
328 plotcol = -1; /* init plotting color again */
329
330 if ((colval > 0) && (colval < 9)) /* update background color */
331 {
332 unsigned long maska;
333
334 ididev[dspno].backpix = fixcolr[no][colval].pixel;
335
336 maska = CWBackPixel;
337 sattributes.background_pixel = ididev[dspno].backpix;
338 XChangeWindowAttributes(mydisp[no],mwndw[dspno],maska,&sattributes);
339 }
340
341 XClearWindow (mydisp[no],mwndw[dspno]);
342 }
343
344 /*
345
346 */
347
348 void set_wcur(dspno,nz)
349 int dspno, nz;
350
351 {
352 int no;
353 static int oldno = -1, oldnz = -1;
354
355
356 if ((oldno == dspno) && (oldnz == nz))
357 return; /* nothing to do */
358 else
359 {
360 oldno = dspno;
361 oldnz = nz;
362 }
363
364 no = ididev[dspno].screen;
365
366 if (nz == -1)
367 {
368 mycurs[no][0] = XCreateFontCursor(mydisp[no],XC_arrow);
369 mycurs[no][1] = XCreateFontCursor(mydisp[no],XC_pirate); /* end symbol */
370 mycurs[no][2] = XCreateFontCursor(mydisp[no],XC_right_ptr);
371 mycurs[no][3] = XCreateFontCursor(mydisp[no],XC_circle);
372 }
373 else
374 XDefineCursor(mydisp[no],mwndw[dspno],mycurs[no][nz]);
375
376 }
377
378 /*
379
380 */
381
382 void sendX(dspno)
383 int dspno;
384
385 {
386 XFlush(mydisp[ididev[dspno].screen]);
387 }
388
389 /*
390
391 */
392
393 int crealph(dspno,dysize)
394 int dspno, dysize;
395
396 {
397 int no;
398 int tmpx, np;
399
400 tmpx = 0;
401 np = 1;
402 no = ididev[dspno].screen;
403
404 alphwnd[dspno] =
405 XCreateSimpleWindow (mydisp[no],mwndw[dspno],tmpx,dysize,ididev[dspno].alphx,
406 ididev[dspno].alphy,np,Xworkst[no].white,
407 Xworkst[no].black);
408 if (alphwnd[dspno] != (Window)0)
409 {
410 gcalph[dspno] = XCreateGC(mydisp[no],alphwnd[dspno],0,&xgcvals);
411 maska = Xworkst[no].black ^ Xworkst[no].white ;
412 XSetPlaneMask(mydisp[no],gcalph[dspno],maska);
413 XSetFunction(mydisp[no],gcalph[dspno],GXcopy);
414 XMapRaised (mydisp[no],alphwnd[dspno]);
415 XSetFont(mydisp[no],gcalph[dspno],myfont[no][0]->fid); /* use small font */
416 return(II_SUCCESS);
417 }
418 else
419 return(WINOTOPN);
420 }
421
422 /*
423
424 */
425
426 void clalph(dspno,flag,x,y,dim)
427 int dspno, flag, x, y, dim;
428
429 {
430 int no;
431 int tmpx, tmpy;
432
433 if (flag == 0)
434 {
435 tmpx = 0;
436 tmpy = 0;
437 tmpxdim = ididev[dspno].alphx;
438 tmpydim = ididev[dspno].alphy;
439 }
440 else
441 {
442 tmpx = x;
443 tmpy = y - ididev[dspno].alphlinsz + 1;
444 tmpxdim = dim * 8;
445 tmpydim = ididev[dspno].alphlinsz;
446 }
447
448 no = ididev[dspno].screen;
449 XSetForeground(mydisp[no],gcalph[dspno],Xworkst[no].black);
450 XFillRectangle(mydisp[no],alphwnd[dspno],gcalph[dspno],
451 tmpx,tmpy,tmpxdim,tmpydim);
452 XSetForeground(mydisp[no],gcalph[dspno],Xworkst[no].white);
453 }
454
455 /*
456
457 */
458
459 void alprfr(dspno,alph)
460 int dspno;
461 ALPH_DATA *alph;
462
463 {
464 int no, x0, y0, j, np;
465 register int loopi;
466
467 char texto[32]; /* alpha text segments now 30 chars long */
468
469
470 no = ididev[dspno].screen;
471
472 XSetForeground(mydisp[no],gcalph[dspno],Xworkst[no].black);
473 XFillRectangle(mydisp[no],alphwnd[dspno],gcalph[dspno],
474 0,0,ididev[dspno].alphx,ididev[dspno].alphy);
475 XSetForeground(mydisp[no],gcalph[dspno],Xworkst[no].white);
476
477 for (loopi=0; loopi<16; loopi++)
478 {
479 x0 = alph->savx[loopi];
480 if (x0 > -1)
481 {
482 y0 = alph->savy[loopi];
483 j = loopi * 30;
484 (void) memcpy(texto,&alph->savtxt[j],(size_t)30);
485 texto[30] = '\0';
486
487 np = (int) strlen(texto);
488 if (np > 0)
489 {
490 rval = x0 * ididev[dspno].alphxscal;
491 x0 = rval + 1;
492 y0 = (y0 +1) * ididev[dspno].alphlinsz;
493 XDrawString(mydisp[no],alphwnd[dspno],gcalph[dspno],x0,y0,texto,np);
494 }
495 }
496 }
497 }
498
499 /*
500
501 */
502
503 void alptext(flag,dspno,alph,txt,x0,y0)
504 int flag, dspno, x0, y0;
505 char *txt;
506 ALPH_DATA *alph;
507
508 {
509 int no, fnd, i, np;
510 register int loopi;
511
512
513
514 /* find corresponding `save' slot */
515
516 no = ididev[dspno].screen;
517 for (loopi=0; loopi<16; loopi++)
518 {
519 if ((x0 == alph->savx[loopi]) && (y0 == alph->savy[loopi]))
520 {
521 fnd = loopi;
522 goto slot_found;
523 }
524 }
525
526 for (loopi=0; loopi<16; loopi++)
527 {
528 if (alph->savx[loopi] < 0)
529 {
530 fnd = loopi;
531 alph->savx[fnd] = x0;
532 alph->savy[fnd] = y0;
533 goto slot_found;
534 }
535 }
536 goto just_do_it;
537
538 slot_found:
539 i = fnd * 30;
540 (void) memcpy(&alph->savtxt[i],txt,(size_t)30);
541 if (flag == 0) return; /* flag == 0, then only store data */
542
543
544 just_do_it:
545 np = (int) strlen(txt);
546 rval = x0 * ididev[dspno].alphxscal;
547 x0 = rval + 1;
548 y0 = (y0 +1) * ididev[dspno].alphlinsz;
549
550 for (loopi=0; loopi<np; loopi++)
551 {
552 if (txt[loopi] != ' ')
553 {
554 XDrawString(mydisp[no],alphwnd[dspno],gcalph[dspno],x0,y0,txt,np);
555 return;
556 }
557 }
558
559 /* text string all blanks, so we want to clear ... */
560
561 clalph(dspno,1,x0,y0,np);
562 }
563
564 /*
565
566 */
567
568 int crelutbar(dspno,bar)
569 int dspno;
570 INTBAR *bar;
571
572 {
573 float fa, fb, fc;
574
575 int total, *ipntra;
576 int ioff, no, np, k;
577 register int nr, mr;
578
579
580
581
582 bar->xsize = ididev[dspno].xsize;
583 bar->ysize = 20;
584 bar->xoff = 0;
585 bar->yoff = ididev[dspno].ysize - bar->ysize - (border*2);
586
587 lutoff = ididev[dspno].lutoff;
588 np = 1;
589 no = ididev[dspno].screen;
590 lutwnd[dspno] = XCreateSimpleWindow (mydisp[no],mwndw[dspno],
591 bar->xoff,bar->yoff,bar->xsize,bar->ysize,np,
592 Xworkst[no].black,Xworkst[no].white);
593 if (lutwnd[dspno] == 0) return(WINOTOPN);
594
595 gclut[dspno] = XCreateGC(mydisp[no],lutwnd[dspno],0,&xgcvals);
596 XSetFunction(mydisp[no],gclut[dspno],GXcopy);
597
598 XMapRaised (mydisp[no],lutwnd[dspno]);
599
600 bar->wp = 1; /* indicate that we already created the window */
601
602 if (Xworkst[no].depth < 16)
603 np = 8;
604 else
605 np = 32;
606 myima = XCreateImage(mydisp[no],myvis[no],Xworkst[no].depth,ZPixmap,
607 0,0,bar->xsize,bar->ysize,np,np*bar->xsize/8);
608
609 lutxima[dspno] = myima;
610 total = myima->bytes_per_line * bar->ysize;
611
612 myima->data = malloc((size_t)total);
613 if (myima->data == 0) return (MEMALLERR);
614
615
616 /* branch according to memory depth */
617
618 fa = Xworkst[no].lutlen;
619 fb = bar->xsize;
620 fc = fa / fb;
621 ioff = ididev[dspno].lutsect * Xworkst[no].lutsize;
622
623 if (Xworkst[no].visual == 2) /* PseudoColor */
624 {
625 if (Xworkst[no].nobyt == 1)
626 {
627 unsigned char *cpntrb;
628
629 cpntra = (unsigned char *) myima->data;
630 cpntrb = cpntra + bar->xsize; /* point to next line */
631
632 for (mr=0; mr<bar->xsize; mr++)
633 {
634 fa = mr*fc + 0.5; /* scale to LUTsize */
635 np = ((int)fa) + ioff;
636 *cpntra++ = (unsigned char) Xworkst[no].mapin[np];
637 }
638 for (nr=1; nr<bar->ysize; nr++)
639 {
640 cpntra = (unsigned char *) myima->data;
641 for (mr=0; mr<bar->xsize; mr++) *cpntrb++ = *cpntra++;
642 }
643 }
644
645 else if (Xworkst[no].nobyt == 2)
646 {
647 jpntra = (short int *) myima->data;
648 for (nr=0; nr<bar->ysize; nr++)
649 {
650 for (mr=0; mr<bar->xsize; mr++)
651 {
652 fa = mr*fc + 0.5;
653 np = ((int)fa) + ioff; /* scale to LUTsize */
654 *jpntra++ = (short int) Xworkst[no].mapin[np];
655 }
656 }
657 }
658 }
659
660 else /* DirectColor/TrueColor => 3 bytes per pixel */
661 {
662 int *jpntr;
663
664 ipntra = (int *) myima->data;
665 jpntr = ipntra + bar->xsize; /* point to next line */
666
667 if (Xworkst[no].visual == 3)
668 {
669 int pixi;
670
671 for (mr=0; mr<bar->xsize; mr++)
672 {
673 fa = mr*fc + 0.5;
674 np = ((int)fa) + ioff; /* scale to LUTsize */
675 pixi = np << 8;
676 np += pixi;
677 pixi = pixi << 8;
678 *ipntra++ = (np + pixi);
679 }
680 }
681 else /* PseudoColor on Direct/TrueColor */
682 {
683 for (mr=0; mr<bar->xsize; mr++)
684 {
685 fa = mr*fc + 0.5;
686 np = ((int)fa) + ioff; /* scale to LUTsize */
687 np += Xworkst[no].auxcol;
688 *ipntra++ = Xworkst[no].mapin[np];
689 }
690 }
691
692 for (nr=1; nr<bar->ysize; nr++)
693 {
694 ipntra = (int *) myima->data;
695 for (mr=0; mr<bar->xsize; mr++) *jpntr++ = *ipntra++;
696 }
697 }
698
699
700 idi_putimage(mydisp[no],lutwnd[dspno],gclut[dspno],lutxima[dspno],
701 0,0,0,0,bar->xsize,bar->ysize);
702 k = ididev[dspno].lutsect;
703 XSetWindowColormap(mydisp[no],lutwnd[dspno],cmap[no][k]);
704
705 return 0;
706 }
707
708 /*
709
710 */
711
712 void vislutbar(dspno,bar,vis)
713 INTBAR *bar;
714 int dspno, vis;
715
716 {
717 int no, k, tmpx, tmpy;
718
719
720 no = ididev[dspno].screen;
721 k = ididev[dspno].lutsect;
722
723 if (vis == 0)
724 {
725 tmpx = 0; tmpy = ididev[dspno].ysize;
726 tmpxdim = 1; tmpydim = 1;
727 XMoveResizeWindow(mydisp[no],lutwnd[dspno],tmpx,tmpy,tmpxdim,tmpydim);
728 XSetWindowColormap(mydisp[no],mwndw[dspno],cmap[no][k]);
729 }
730
731 else
732 {
733 XMoveResizeWindow(mydisp[no],lutwnd[dspno],bar->xoff,bar->yoff,
734 bar->xsize,bar->ysize);
735 idi_putimage(mydisp[no],lutwnd[dspno],gclut[dspno],lutxima[dspno],
736 0,0,0,0,bar->xsize,bar->ysize);
737 XSetWindowColormap(mydisp[no],lutwnd[dspno],cmap[no][k]);
738 }
739 }
740
741 /*
742
743 */
744
745 void updalutbar(dspno,bar)
746 INTBAR *bar;
747 int dspno;
748
749 {
750 int no, k, *ipntra, *jpntr;
751 register int mr, nr, ioff;
752
753 float fa, fb, fc;
754
755
756
757 no = ididev[dspno].screen;
758 k = ididev[dspno].lutsect;
759
760
761 /* this is needed for PseudoColor on TrueColor */
762
763 ipntra = (int *) lutxima[dspno]->data;
764 jpntr = ipntra + bar->xsize; /* point to next line */
765
766 fa = Xworkst[no].lutlen;
767 fb = bar->xsize;
768 fc = fa / fb;
769 ioff = ididev[dspno].lutsect * Xworkst[no].lutsize;
770
771 for (mr=0; mr<bar->xsize; mr++)
772 {
773 fa = mr*fc + 0.5;
774 k = ((int)fa) + ioff; /* scale to LUTsize */
775 k += Xworkst[no].auxcol;
776 *ipntra++ = Xworkst[no].mapin[k];
777 }
778
779 for (nr=1; nr<bar->ysize; nr++)
780 {
781 ipntra = (int *) lutxima[dspno]->data;
782 for (mr=0; mr<bar->xsize; mr++) *jpntr++ = *ipntra++;
783 }
784 }
785
786 /*
787
788 */
789
790 /* set up event loop for input from keyboard + send character string back */
791
792 void get_string(dspno,outbuf,lout)
793 int dspno, *lout;
794 char *outbuf;
795
796 {
797 int no, k, i;
798
799 char cbuf[10];
800
801
802
803 no = ididev[dspno].screen;
804 ididev[dspno].inter_mask |= (KeyPressMask | Def_Mask);
805 XSelectInput(mydisp[no],mwndw[dspno],ididev[dspno].inter_mask);
806 k = 0;
807
808 wait_for_events:
809 XWindowEvent(mydisp[no],mwndw[dspno],ididev[dspno].inter_mask,&myevent);
810
811 if (myevent.type == Expose)
812 exposed(no,dspno); /* refresh */
813
814 else if (myevent.type == KeyPress)
815 {
816 i = XLookupString(&myevent.xkey,cbuf,10,&mykey,&xcstat);
817 if (mykey != XK_Return)
818 {
819 outbuf[k++] = cbuf[0];
820 if (k < 79) goto wait_for_events; /* IDI doc. => max. 80 chars... */
821 }
822 int_disable(dspno); /* disable other interactions */
823 cbuf[k] = '\0';
824 *lout = k;
825 return;
826 }
827
828 goto wait_for_events; /* loop more */
829 }
830
831 /*
832
833 */
834
835 /* set up event loop for input from keyboard + send single character back */
836
837 void get_char(dspno,outbuf)
838 int dspno;
839 char *outbuf;
840
841 {
842 int no, i;
843
844
845 no = ididev[dspno].screen;
846
847 ididev[dspno].inter_mask |= (KeyPressMask | Def_Mask);
848 XSelectInput(mydisp[no],mwndw[dspno],ididev[dspno].inter_mask);
849
850 wait_for_events:
851 XWindowEvent(mydisp[no],mwndw[dspno],ididev[dspno].inter_mask,&myevent);
852
853 if (myevent.type == Expose)
854 exposed(no,dspno); /* refresh */
855
856 else if (myevent.type == KeyPress)
857 {
858 i = XLookupString(&myevent.xkey,outbuf,10,&mykey,&xcstat);
859 if (i == 1)
860 {
861 outbuf[1] = '\0';
862 int_disable(dspno); /* disable other interactions */
863 return;
864 }
865 }
866
867 goto wait_for_events;
868 }
869
870 /*
871
872 */
873
874 /* ---- Init graphics for display window --------------------------- */
875
876 void initgra(dspno)
877 int dspno;
878
879 {
880 int no;
881
882 no = ididev[dspno].screen;
883 plotcol = -1; /* init plotting color again */
884
885 XSetFunction(mydisp[no],gcima[dspno],GXcopy);
886 XSetBackground(mydisp[no],gcima[dspno],ididev[dspno].backpix);
887 XSetForeground(mydisp[no],gcima[dspno],Xworkst[no].white);
888
889 }
890
891 /*
892
893 */
894
895 /* ---- Polyline on display bitmap ----------------------------------- */
896
897 void polyline(dspno,dysize,mem,col,style,xs,ys,np)
898 int dspno, dysize, col, style, *xs, *ys, np;
899 MEM_DATA *mem;
900
901 {
902 int no, kindx, koff, lstyle, last, rem;
903 int j, k, x, y;
904 int lastx, lasty;
905 int *gx, *gy;
906 register int loopi;
907
908 GLIST *gp;
909
910
911
912 if (lastplno != dspno)
913 {
914 lastplno = dspno;
915 plotcol = -1; /* force to new beginning */
916 }
917
918 no = ididev[dspno].screen;
919 x = y = 0;
920 rem = 0;
921 lstyle = 0;
922
923
924 /* check out the given color */
925
926 if (col == 99)
927 goto just_plot; /* we don't save this polygon */
928
929
930 if ((col > 10) && (col < 19)) /* colors in [11,18] mean XORing */
931 {
932 col -= 10;
933 lstyle = 10;
934 }
935 else if (col > 8)
936 {
937 if (ididev[dspno].devtyp == 'g')
938 col = 1; /* default to black */
939 else
940 col = 2; /* default to white */
941 }
942
943 if (plotcol != col)
944 {
945 plotcol = col;
946 XSetForeground(mydisp[no],gcima[dspno],fixcolr[no][plotcol].pixel);
947 }
948
949
950 if (lstyle != 0)
951 XSetFunction(mydisp[no],gcima[dspno],GXxor);
952 /*
953 else
954 XSetFunction(mydisp[no],gcima[dspno],GXcopy);
955 */
956
957
958 if (style >= 10) /* thickness is the power of 10 ... */
959 {
960 k = style / 10;
961 /*
962 if (k == 1) k = 0; XFree has problems with linewidth = 1
963 Not true anymore! 060802
964 */
965 }
966 else
967 k = 0;
968
969 if (linewidth != k)
970 {
971 linewidth = k;
972 XSetLineAttributes(mydisp[no],gcima[dspno],(unsigned int)linewidth,
973 LineSolid, CapProjecting, JoinMiter);
974 }
975
976 gp = mem->gpntr;
977 if (gp == (GLIST *)0) goto just_plot;
978
979 kindx = gp->geln;
980 if (kindx >= gp->maxpnt/2) goto just_plot;
981
982 koff = *(gp->off+kindx);
983 last = koff + np;
984 if (last > gp->maxpnt) goto just_plot;
985
986 *(gp->color+kindx) = col + lstyle;
987 *(gp->lwidth+kindx) = linewidth;
988 *(gp->count+kindx) = np;
989 *(gp->off+kindx+1) = last;
990
991
992 lastx = *xs;
993 lasty = dysize - *ys;
994
995
996 loop:
997 j = np - rem; /* j from 0 to (np-1) in steps of MAX_PTS */
998 if (j < 1) return;
999
1000 if (j > MAX_PTS) j = MAX_PTS;
1001
1002 gx = gp->x + koff + rem;
1003 gy = gp->y + koff + rem;
1004
1005
1006 mypoint[0].x = (short int) lastx;
1007 mypoint[0].y = (short int) lasty;
1008
1009 for (loopi=1; loopi<(j+1); loopi++)
1010 { /* fill j points */
1011 x = *xs++;
1012 y = dysize - (*ys++);
1013 *gx++ = x;
1014 *gy++ = y;
1015 mypoint[loopi].x = (short int) x;
1016 mypoint[loopi].y = (short int) y;
1017 }
1018 lastx = x;
1019 lasty = y;
1020
1021 /*
1022 if (np > 2)
1023 {
1024 printf("polyline: col = %d, style = %d, np = %d, linewidth = %d, visibility = %d\n",
1025 col,style,np,linewidth,mem->visibility);
1026 for (loopi=0; loopi<=j; loopi++)
1027 printf("no: %d x = %d, y = %d\n",loopi,
1028 mypoint[loopi].x,mypoint[loopi].y);
1029 }
1030 */
1031
1032 if (mem->visibility == 1) /* always draw last point again */
1033 {
1034 XDrawLines(mydisp[no],mwndw[dspno],gcima[dspno],
1035 mypoint,(j+1),CoordModeOrigin);
1036 if (linewidth == 0) /* only needed with width = 0 */
1037 XDrawPoint(mydisp[no],mwndw[dspno],gcima[dspno],lastx,lasty);
1038 }
1039
1040
1041 if ((rem+j) < np)
1042 {
1043 rem += j;
1044 goto loop;
1045 }
1046
1047 gp->geln ++ ;
1048 goto flush_it;
1049
1050
1051 /* overflow in our structures, so we just plot and do not save... */
1052
1053 just_plot:
1054 if (mem->visibility != 1) return;
1055
1056
1057
1058 lastx = *xs;
1059 lasty = dysize - *ys;
1060
1061
1062 plot_loop:
1063 j = np - rem; /* j moves from 0 to np in steps of MAX_PTS */
1064 if (j < 1) return;
1065
1066 if (j > MAX_PTS) j = MAX_PTS;
1067
1068 mypoint[0].x = (short) lastx;
1069 mypoint[0].y = (short) lasty;
1070
1071 for (loopi=1; loopi<(j+1); loopi++)
1072 {
1073 x = *xs++;
1074 y = dysize - (*ys++);
1075 mypoint[loopi].x = (short) x;
1076 mypoint[loopi].y = (short) y;
1077 }
1078 lastx = x;
1079 lasty = y;
1080
1081 if (col == 99)
1082 {
1083 XDrawLines(mydisp[no],mwndw[dspno],gcdraw[dspno],
1084 mypoint,j+1,CoordModeOrigin);
1085 if (linewidth == 0) /* only needed with width = 0 */
1086 XDrawPoint(mydisp[no],mwndw[dspno],gcima[dspno],lastx,lasty);
1087 }
1088 else
1089 {
1090 XDrawLines(mydisp[no],mwndw[dspno],gcima[dspno],
1091 mypoint,j+1,CoordModeOrigin);
1092 if (linewidth == 0) /* only needed with width = 0 */
1093 XDrawPoint(mydisp[no],mwndw[dspno],gcima[dspno],lastx,lasty);
1094 }
1095
1096 if ((rem+j) < np) /* still more to draw */
1097 {
1098 rem += j;
1099 goto plot_loop;
1100 }
1101
1102
1103 flush_it:
1104 if (lstyle != 0) /* we must reset the GC for images */
1105 XSetFunction(mydisp[no],gcima[dspno],GXcopy);
1106 }
1107
1108 /*
1109
1110 */
1111
1112 /* ---- Refresh graphics ----------------------------------- */
1113
1114 void polyrefr(dspno,mem,flag,memid)
1115 int dspno, flag, memid;
1116 MEM_DATA *mem;
1117
1118 {
1119 int no, kindx, koff, rem, lstyle, jj, jk, np, k;
1120 int *goff, *gx, *gy, *gcount, *gcol, *gwidth;
1121 int lastx, lasty;
1122 register int loopi, loopj;
1123
1124 GLIST *gp;
1125
1126
1127 if (mem->visibility != 1) return;
1128
1129
1130 /* if flag = 1, we also have to pass the memory no. and draw the stuff
1131 in the Pixmap (if available) instead of the window */
1132
1133 if ( (flag == 1) && (mem->pixmap == 1) )
1134 xdrawable = mxpix[dspno][memid];
1135 else
1136 xdrawable = mwndw[dspno];
1137
1138
1139 no = ididev[dspno].screen;
1140 if (lastplno != dspno)
1141 {
1142 lastplno = dspno;
1143 plotcol = -1; /* force to new beginning */
1144 }
1145
1146 gp = mem->gpntr;
1147 if (gp == (GLIST *)0) return;
1148
1149 kindx = gp->geln;
1150
1151 goff = gp->off;
1152 gcol = gp->color;
1153 gwidth = gp->lwidth;
1154 gcount = gp->count;
1155 lstyle = 0; /* GC should be set to GXcopy */
1156
1157 for (loopi=0; loopi<kindx; loopi++)
1158 {
1159 koff = *goff++;
1160 jk = *gcol++;
1161 if (jk > 10)
1162 {
1163 jk -= 10;
1164 jj = 10;
1165 }
1166 else
1167 jj = 0;
1168
1169 if (plotcol != jk)
1170 {
1171 plotcol = jk;
1172 XSetForeground(mydisp[no],gcima[dspno],fixcolr[no][plotcol].pixel);
1173 }
1174 if (jj != lstyle)
1175 {
1176 if (lstyle != 0)
1177 XSetFunction(mydisp[no],gcima[dspno],GXxor);
1178 /*
1179 else
1180 XSetFunction(mydisp[no],gcima[dspno],GXcopy);
1181 */
1182 }
1183
1184 jj = *gwidth++;
1185 if (jj != linewidth)
1186 {
1187 linewidth = jj;
1188 XSetLineAttributes(mydisp[no],gcima[dspno],(unsigned int)linewidth,
1189 LineSolid,CapProjecting,JoinMiter);
1190 }
1191
1192
1193
1194 np = *gcount++; /* no. of points to connect */
1195 rem = 0;
1196 gx = gp->x + koff;
1197 gy = gp->y + koff;
1198 lastx = *gx;
1199 lasty = *gy;
1200
1201
1202 loop:
1203 k = koff + rem;
1204 jk = np - rem; /* jk moves from 0 to np in steps of MAX_PTS */
1205 if (jk > MAX_PTS) jk = MAX_PTS;
1206
1207 gx = gp->x + k;
1208 gy = gp->y + k;
1209
1210
1211
1212 mypoint[0].x = (short int) lastx;
1213 mypoint[0].y = (short int) lasty;
1214
1215 for (loopj=1; loopj<(jk+1); loopj++)
1216 {
1217 mypoint[loopj].x = (short int) *gx++;
1218 mypoint[loopj].y = (short int) *gy++;
1219 }
1220 lastx = *(gx - 1);
1221 lasty = *(gy - 1);
1222
1223 XDrawLines(mydisp[no],xdrawable,gcima[dspno],
1224 mypoint,(jk+1),CoordModeOrigin);
1225 if (linewidth == 0) /* only needed with width = 0 */
1226 XDrawPoint(mydisp[no],mwndw[dspno],gcima[dspno],lastx,lasty);
1227
1228
1229 if ((rem+jk) < np) /* still more to draw */
1230 {
1231 rem += jk;
1232 goto loop;
1233 }
1234 }
1235
1236 if (lstyle != 0) XSetFunction(mydisp[no],gcima[dspno],GXcopy);
1237 }
1238
1239 /*
1240
1241 */
1242
1243 /* ---- text on display bitmap ----------------------------------- */
1244
1245 void txtline(dspno,dysize,mem,txt,x0,y0,path,orient,col,size)
1246 int dspno, dysize, x0, y0, path, orient, col, size;
1247 char txt[];
1248 MEM_DATA *mem;
1249
1250 {
1251 int x, y, np, no, tindx, toff, last;
1252 register int loopi;
1253
1254 char *cpntr;
1255
1256 TLIST *tp;
1257
1258
1259
1260 /* check text size, and if necessary use different font */
1261
1262 no = ididev[dspno].screen;
1263 if (size > 3)
1264 size = 0;
1265 else if (size < 0) /* read Font from x11fonts.dat */
1266 {
1267 if (font_load(1,no,&size) == -1) /* problems reading Font file */
1268 {
1269 myfont[no][3] = XLoadQueryFont(mydisp[no],"fixed");
1270 (void) printf("Use Font `fixed' instead\n");
1271 }
1272 size = 3;
1273 textsiz = -1; /* force to new beginning */
1274 }
1275
1276 if (lasttxtno != dspno)
1277 {
1278 lasttxtno = dspno;
1279 textsiz = -1; /* force to new beginning */
1280 }
1281
1282 if (textsiz != size)
1283 {
1284 textsiz = size;
1285 XSetFont(mydisp[no],gcima[dspno],myfont[no][textsiz]->fid);
1286 }
1287
1288 if (plotcol != col)
1289 {
1290 plotcol = col;
1291 XSetForeground(mydisp[no],gcima[dspno],fixcolr[no][plotcol].pixel);
1292 }
1293
1294 np = (int) strlen(txt);
1295 x = x0; y = dysize - y0;
1296
1297 tp = mem->tpntr;
1298 if (tp == (TLIST *)0) goto just_text;
1299
1300 tindx = tp->teln;
1301 if (tindx >= MAX_TXT) goto just_text;
1302
1303 if (tindx < 0)
1304 {
1305 (void) printf("txtline: dspno = %d, image = %s, tindx = %d\n",
1306 dspno,mem->frame,tindx);
1307 tindx = 0;
1308 }
1309
1310 toff = tp->off[tindx];
1311 last = toff + np;
1312 if (last > MAX_TXTLEN) goto just_text;
1313
1314 tp->x[tindx] = x;
1315 tp->y[tindx] = y;
1316 tp->size[tindx] = size;
1317 tp->color[tindx] = col;
1318 tp->count[tindx] = np;
1319 tp->off[tindx+1] = last;
1320
1321 cpntr = &(tp->text[toff]);
1322 for (loopi=0; loopi<np; loopi++) *cpntr ++ = txt[loopi];
1323
1324 tp->teln ++ ;
1325
1326 just_text:
1327 if (mem->visibility == 1)
1328 XDrawString(mydisp[no],mwndw[dspno],gcima[dspno],x,y,txt,np);
1329 }
1330
1331 /*
1332
1333 */
1334
1335 /* ---- Refresh Text ----------------------------------- */
1336
1337 void txtrefr(dspno,mem,flag,memid)
1338 int dspno, flag, memid;
1339 MEM_DATA *mem;
1340
1341 {
1342 int no, tindx, toff, x, y, np;
1343 register int loopi;
1344
1345 char *cpntr;
1346
1347 TLIST *tp;
1348
1349
1350 if (mem->visibility != 1) return;
1351
1352
1353 /* if flag = 1, we also have to pass the memory no. and draw the text
1354 in the Pixmap (if available) instead of the window */
1355
1356 if ( (flag == 1) && (mem->pixmap == 1) )
1357 xdrawable = mxpix[dspno][memid];
1358 else
1359 xdrawable = mwndw[dspno];
1360
1361 tp = mem->tpntr;
1362 if (tp == (TLIST *)0) return;
1363
1364 tindx = tp->teln;
1365 no = ididev[dspno].screen;
1366
1367 for (loopi=0; loopi<tindx; loopi++)
1368 {
1369 toff = tp->off[loopi];
1370 np = tp->count[loopi];
1371 x = tp->x[loopi];
1372 y = tp->y[loopi];
1373 if (textsiz != tp->size[loopi])
1374 {
1375 textsiz = tp->size[loopi];
1376 XSetFont(mydisp[no],gcima[dspno],myfont[no][textsiz]->fid);
1377 }
1378 if (plotcol != tp->color[loopi])
1379 {
1380 plotcol = tp->color[loopi];
1381 XSetForeground(mydisp[no],gcima[dspno],fixcolr[no][plotcol].pixel);
1382 }
1383 cpntr = & (tp->text[toff]);
1384
1385 XDrawString(mydisp[no],xdrawable,gcima[dspno],x,y,cpntr,np);
1386 }
1387 }
1388
1389 /*
1390
1391 */
1392
1393 /* ---- get plot colour values --------------------------------------- */
1394
1395 void rd_pllut (dspno,plut)
1396 int dspno;
1397 LUT_DATA *plut;
1398
1399 {
1400 register int loop;
1401 int no;
1402
1403 no = ididev[dspno].screen;
1404
1405 for (loop=0; loop<PLOT_COLOURS; loop++)
1406 {
1407 plut->lutr[loop] = fixcolr[no][loop].red;
1408 plut->lutg[loop] = fixcolr[no][loop].green;
1409 plut->lutb[loop] = fixcolr[no][loop].blue;
1410 }
1411 }
1412
1413 /*
1414
1415 */
1416
1417 /* ---- do miscellaneous stuff --------------------------------------- */
1418
1419 void do_misc(dspno,flag,auxid,cbuf,ibuf,rbuf)
1420 int dspno, flag, auxid, *ibuf;
1421 float *rbuf;
1422 char *cbuf;
1423
1424 {
1425 int no;
1426
1427
1428
1429 no = ididev[dspno].screen;
1430
1431
1432 /* flag = 1 is currently the only "officially" used flag */
1433
1434 if (flag == 1)
1435 {
1436 if (auxid < 0) /* reset to root window */
1437 {
1438 rw[no] = XRootWindow(mydisp[no],myscreen);
1439 dspno = -1; /* just to be on the safe side */
1440 }
1441 else
1442 rw[no] = mwndw[dspno];
1443 parent_id = dspno;
1444
1445 /*
1446 printf("rw[%d] = %x will be set to mwndw[%d] = %x, parent_id = %d\n",
1447 no,rw[no],dspno,mwndw[dspno],dspno);
1448 */
1449
1450 return;
1451 }
1452
1453
1454
1455
1456 /*
1457 (void) printf
1458 ("do_misc: flag = %d, mwndw[%d] = %x \n",flag,dspno,mwndw[dspno]);
1459 */
1460
1461
1462 if (flag == 2)
1463 {
1464 Window root, parent, *children;
1465 unsigned int nochld;
1466
1467 XQueryTree(mydisp[no],mwndw[dspno],
1468 &root,&parent,&children,&nochld);
1469
1470 /*
1471 (void) printf("XQueryTree for window %d returned:\n",dspno);
1472 (void) printf("root_w = %x, parent_w = %x, no. children = %d\n",
1473 root,parent,nochld);
1474 */
1475
1476 XFree(children);
1477 }
1478
1479 else if (flag == 3)
1480 {
1481 XMapSubwindows(mydisp[no],mwndw[dspno]);
1482
1483 printf("XMapSubwindows was called...\n");
1484 }
1485
1486 else if (flag == 4)
1487 {
1488 Window root;
1489 int x, y;
1490 unsigned int wd, he, bw, dep;
1491
1492
1493 XWindowAttributes attribs;
1494
1495 XGetWindowAttributes(mydisp[no],mwndw[dspno],&attribs);
1496
1497 /*
1498 (void) printf("XGetWindowAttributes for window %d returned:\n",dspno);
1499 (void) printf(
1500 "xpos, ypos = %d, %d width, height = %d, %d, borderw = %d, depth = %d\n",
1501 attribs.x,attribs.y,attribs.width,attribs.height,
1502 attribs.border_width,attribs.depth);
1503
1504 (void) printf("associated Visual = %x\n",attribs.visual);
1505 */
1506
1507 if (attribs.map_state == IsUnmapped)
1508 (void) printf("window is unmapped ...\n");
1509 else if (attribs.map_state == IsUnviewable)
1510 (void) printf("window is unviewable ...\n");
1511 else if (attribs.map_state == IsViewable)
1512 (void) printf("window is viewable ...\n");
1513 if (attribs.map_installed)
1514 (void) printf("color map is installed ...\n");
1515 else
1516 (void) printf("color map is NOT installed ...\n");
1517
1518 XGetGeometry(mydisp[no],mwndw[dspno],&root,&x,&y,&wd,&he,&bw,&dep);
1519 /*
1520 (void) printf("XGetGeometry returned:\n");
1521 (void) printf
1522 ("root = %x, x, y = %d, %d wd, he = %d, %d, bw = %d, dep = %d\n",
1523 root,x,y,wd,he,bw,dep);
1524 */
1525 }
1526 }
1527