Debian Codegraph @

packages/seacas/libraries/svdi/cgi/x11_vdix11.c

raw
1 /*
2 * Copyright(C) 1999-2021, 2023, 2025 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8 /*
9 * SUN DEC/ULTRIX ALLIANT : C routines must have underscores
10 * SGI CONVEX : C routines must have underscores
11 *
12 * VAX HP IBM/aix : C routines do not have underscores
13 *
14 * CRAY/UNICOS : C routines must be capitalized,
15 * and no underscores
16 */
17
18 /* The following ifdef redefines entry points for use of this X driver
19 as an SVDI driver on systems which require an underscore "_" appended
20 to the routine name for FORTRAN - C interfacing.
21 */
22 #if defined(ADD_) && !defined(COUGAR)
23 #define vdinit vdinit_
24 #define vdterm vdterm_
25 #define vdfram vdfram_
26 #define vdiqdc vdiqdc_
27 #define vdnwpg vdnwpg_
28 #define vdbell vdbell_
29 #define vdwait vdwait_
30 #define vdbufl vdbufl_
31 #define vdstco vdstco_
32 #define vdiqco vdiqco_
33 #define vdescp vdescp_
34 #define vdiqes vdiqes_
35 #define vdiqnd vdiqnd_
36 #define vdmova vdmova_
37 #define vdlina vdlina_
38 #define vdpnta vdpnta_
39 #define vdtext vdtext_
40 #define vdpoly vdpoly_
41 #define vdiqcp vdiqcp_
42 #define vdiqos vdiqos_
43 #define vdstos vdstos_
44 #define vdstfc vdstfc_
45 #define vdstbc vdstbc_
46 #define vdstin vdstin_
47 #define vdstls vdstls_
48 #define vdstlw vdstlw_
49 #define vdstcs vdstcs_
50 #define vdaabu vdaabu_
51 #define vdaloc vdaloc_
52 #define vdabgl vdabgl_
53 #define vdakgl vdakgl_
54 #define vdstla vdstla_
55 #define vdloge vdloge_
56 #define vberrh vberrh_
57 #define vdmoni vdmoni_
58 #define vbpkg vbpkg_
59 #define vbiqpk vbiqpk_
60 #define vbiqdv vbiqdv_
61 #define vbdev vbdev_
62 #endif
63
64 /* The following ifdefs redefine entry points for use of this X driver
65 as a CGI driver via the CGI-SVDI shell .
66 */
67 #if !defined(CRA) && !defined(ADDC_) && !defined(COUGAR)
68 #define vdmova wx11mv
69 #define vdmoni wx11mo
70 #define vdgnam wx11gn
71 #define vbiqdv wx11iv
72 #define vbiqpk wx11qp
73 #define vdlina wx11ln
74 #define vdtext wx11tx
75 #define vdpnta wx11pt
76 #define vdpoly wx11py
77 #define vdiqcp wx11cp
78 #define vdstos wx11os
79 #define vdiqos wx11io
80 #define vdstfc wx11fc
81 #define vdstbc wx11bc
82 #define vdstin wx11in
83 #define vdstls wx11ls
84 #define vdstlw wx11lw
85 #define vdstcs wx11cs
86 #define vdaabu wx11bu
87 #define vdaloc wx11lo
88 #define vdabgl wx11bl
89 #define vdakgl wx11kl
90 #define vdstla wx11la
91 #define vdinit wx11nt
92 #define vdfram wx11fr
93 #define vdterm wx11tr
94 #define vdiqdc wx11dc
95 #define vdnwpg wx11pg
96 #define vdbell wx11be
97 #define vdwait wx11wt
98 #define vdbufl wx11fl
99 #define vdstco wx11co
100 #define vdiqco wx11ic
101 #define vdescp wx11es
102 #define vdiqes wx11ie
103 #define vdiqnd wx11id
104 #define vimova wx11im
105 #define vilina wx11il
106 #define vipnta wx11ip
107 #define vitext wx11ix
108 #define viinit wx11ii
109 #define viterm wx11it
110 #define vinwpg wx11ig
111 #define vcjob vcjob
112 #define vberrh wx11er
113 #define vdloge wx11le
114 #define cdrwfs wx11wf
115 #define cdrrfs wx11rf
116 #define cdrofs wx11of
117 #define cdrof3 wx11o3
118 #define cdrcfs wx11cf
119 #define cdroff wx11ff
120 #define cdroab wx11ab
121 #define bgpbuf wx11bf
122 #define qmsbuf wx11qm
123 #define qmsbu1 wx11bf
124 #define ddcbuf wx11bf
125 #define h75buf wx11bf
126 #define btkbuf wx11bf
127 #define nmtbuf wx11bf
128 #define vbimbf wx11ib
129 #define vbpkg wx11pk
130 #define vbdev wx11dv
131 #define vdiqrs wx11qr
132 #define vdstmp wx11mp
133 #define vdstrs wx11rs
134 #define vdstrv wx11rv
135 #define vdbrgb wx11bg
136 #define vdfrgb wx11fg
137 #define vdpixl wx11px
138 #define vdpixi wx11pi
139 #define vdrpix wx11rp
140 #define vdrpxi wx11ri
141 #define vdrscl wx11rl
142 #define vdiqci wx11ci
143 #define vbstmp wx1101
144 #define vifram wx1102
145 #define vcndcm wx1103
146 #define vcattr wx1104
147 #define vbini1 wx1105
148 #define vb2hls wx1106
149 #define vb2rgb wx1107
150 #define vccolt wx1108
151 #define vccrps wx1109
152 #define vcscal wx1110
153 #define vcddim wx1111
154 #define vipoly wx1112
155 #define vbout wx1113
156 #define cgixxx cgix11
157 #endif
158
159 #if defined(CRA)
160 #define vdmova WX11MV
161 #define vdmoni WX11MO
162 #define vdgnam WX11GN
163 #define vbiqdv WX11IV
164 #define vbiqpk WX11QP
165 #define vdlina WX11LN
166 #define vdtext WX11TX
167 #define vdpnta WX11PT
168 #define vdpoly WX11PY
169 #define vdiqcp WX11CP
170 #define vdstos WX11OS
171 #define vdiqos WX11IO
172 #define vdstfc WX11FC
173 #define vdstbc WX11BC
174 #define vdstin WX11IN
175 #define vdstls WX11LS
176 #define vdstlw WX11LW
177 #define vdstcs WX11CS
178 #define vdaabu WX11BU
179 #define vdaloc WX11LO
180 #define vdabgl WX11BL
181 #define vdakgl WX11KL
182 #define vdstla WX11LA
183 #define vdinit WX11NT
184 #define vdfram WX11FR
185 #define vdterm WX11TR
186 #define vdiqdc WX11DC
187 #define vdnwpg WX11PG
188 #define vdbell WX11BE
189 #define vdwait WX11WT
190 #define vdbufl WX11FL
191 #define vdstco WX11CO
192 #define vdiqco WX11IC
193 #define vdescp WX11ES
194 #define vdiqes WX11IE
195 #define vdiqnd WX11ID
196 #define vimova WX11IM
197 #define vilina WX11IL
198 #define vipnta WX11IP
199 #define vitext WX11IX
200 #define viinit WX11II
201 #define viterm WX11IT
202 #define vinwpg WX11IG
203 #define cdrcom CDRCOM
204 #define vcjob VCJOB
205 #define vconod VCONOD
206 #define vberrh WX11ER
207 #define vdloge WX11LE
208 #define cdrwfs WX11WF
209 #define cdrrfs WX11RF
210 #define cdrofs WX11OF
211 #define cdrof3 WX11O3
212 #define cdrcfs WX11CF
213 #define cdroff WX11FF
214 #define cdroab WX11AB
215 #define bgpbuf WX11BF
216 #define qmsbuf WX11QM
217 #define qmsbu1 WX11BF
218 #define ddcbuf WX11BF
219 #define h75buf WX11BF
220 #define btkbuf WX11BF
221 #define nmtbuf WX11BF
222 #define vbimbf WX11IB
223 #define vbpkg WX11PK
224 #define vbdev WX11DV
225 #define vdiqrs WX11QR
226 #define vdstmp WX11MP
227 #define vdstrs WX11RS
228 #define vdstrv WX11RV
229 #define vdbrgb WX11BG
230 #define vdfrgb WX11FG
231 #define vdpixl WX11PX
232 #define vdpixi WX11PI
233 #define vdrpix WX11RP
234 #define vdrpxi WX11RI
235 #define vdrscl WX11RL
236 #define vdiqci WX11CI
237 #define vbstmp WX1101
238 #define vifram WX1102
239 #define vcndcm WX1103
240 #define vcattr WX1104
241 #define vbini1 WX1105
242 #define vb2hls WX1106
243 #define vb2rgb WX1107
244 #define vccolt WX1108
245 #define vccrps WX1109
246 #define vcscal WX1110
247 #define vcddim WX1111
248 #define vipoly WX1112
249 #define vbout WX1113
250 #define wx11zz WX11ZZ
251 #define cgixxx CGIX11
252 #endif
253
254 #if defined(ADDC_) || defined(COUGAR)
255 #define vdmova wx11mv_
256 #define vdmoni wx11mo_
257 #define vdgnam wx11gn_
258 #define vbiqdv wx11iv_
259 #define vbiqpk wx11qp_
260 #define vdlina wx11ln_
261 #define vdtext wx11tx_
262 #define vdpnta wx11pt_
263 #define vdpoly wx11py_
264 #define vdiqcp wx11cp_
265 #define vdstos wx11os_
266 #define vdiqos wx11io_
267 #define vdstfc wx11fc_
268 #define vdstbc wx11bc_
269 #define vdstin wx11in_
270 #define vdstls wx11ls_
271 #define vdstlw wx11lw_
272 #define vdstcs wx11cs_
273 #define vdaabu wx11bu_
274 #define vdaloc wx11lo_
275 #define vdabgl wx11bl_
276 #define vdakgl wx11kl_
277 #define vdstla wx11la_
278 #define vdinit wx11nt_
279 #define vdfram wx11fr_
280 #define vdterm wx11tr_
281 #define vdiqdc wx11dc_
282 #define vdnwpg wx11pg_
283 #define vdbell wx11be_
284 #define vdwait wx11wt_
285 #define vdbufl wx11fl_
286 #define vdstco wx11co_
287 #define vdiqco wx11ic_
288 #define vdescp wx11es_
289 #define vdiqes wx11ie_
290 #define vdiqnd wx11id_
291 #define vimova wx11im_
292 #define vilina wx11il_
293 #define vipnta wx11ip_
294 #define vitext wx11ix_
295 #define viinit wx11ii_
296 #define viterm wx11it_
297 #define vinwpg wx11ig_
298 #define cdrcom cdrcom_
299 #define vcjob vcjob_
300 #define vconod vconod_
301 #define vberrh wx11er_
302 #define vdloge wx11le_
303 #define cdrwfs wx11wf_
304 #define cdrrfs wx11rf_
305 #define cdrofs wx11of_
306 #define cdrof3 wx11o3_
307 #define cdrcfs wx11cf_
308 #define cdroff wx11ff_
309 #define cdroab wx11ab_
310 #define bgpbuf wx11bf_
311 #define qmsbuf wx11qm_
312 #define qmsbu1 wx11bf_
313 #define ddcbuf wx11bf_
314 #define h75buf wx11bf_
315 #define btkbuf wx11bf_
316 #define nmtbuf wx11bf_
317 #define vbimbf wx11ib_
318 #define vbpkg wx11pk_
319 #define vbdev wx11dv_
320 #define vdiqrs wx11qr_
321 #define vdstmp wx11mp_
322 #define vdstrs wx11rs_
323 #define vdstrv wx11rv_
324 #define vdbrgb wx11bg_
325 #define vdfrgb wx11fg_
326 #define vdpixl wx11px_
327 #define vdpixi wx11pi_
328 #define vdrpix wx11rp_
329 #define vdrpxi wx11ri_
330 #define vdrscl wx11rl_
331 #define vdiqci wx11ci_
332 #define vbstmp wx1101_
333 #define vifram wx1102_
334 #define vcndcm wx1103_
335 #define vcattr wx1104_
336 #define vbini1 wx1105_
337 #define vb2hls wx1106_
338 #define vb2rgb wx1107_
339 #define vccolt wx1108_
340 #define vccrps wx1109_
341 #define vcscal wx1110_
342 #define vcddim wx1111_
343 #define vipoly wx1112_
344 #define vbout wx1113_
345 #define wx11bf wx11bf_
346 #define wx11zz wx11zz_
347 #define cgixxx cgix11_
348 #endif
349
350 void x11_vflush(void);
351 void viinit(float *aspect, int *justif);
352 void x_dynamics(int init);
353 void vifram(int *type);
354 void viterm(void);
355 void vdiqdc(int *index, float *value);
356 void vinwpg(void);
357 void vdbell(void);
358 void vdwait(void);
359 void vdbufl(void);
360 void vdstco(int *num, int index_array[], float color_array[][3], int *color_mod);
361 void vdiqco(int *num, int index_array[], float color_array[][3], int *color_mod);
362 void vdescp(int *escape_code, int *n, float args[]);
363 void vdiqes(int *escape_code, int *support);
364 void vdiqnd(float *x_ndc, float *y_ndc);
365 void vimova(float *x, float *y);
366 void vilina(float *x, float *y);
367 void vipnta(float *x, float *y);
368 void vitext(int *length, int char_array[]);
369 void vipoly(float x_array[], float y_array[], int *npts);
370 void vdiqcp(float *x, float *y);
371 void vdiqos(float attr_array[]);
372 void vdstfc(int *color_index);
373 void vdstbc(int *color_index);
374 void vdstin(float *intensity);
375 void vdstls(int *line_style);
376 void vdstlw(float *line_wid);
377 void vdstcs(float *y_size);
378 void vdaabu(int *button);
379 void vdaloc(float *x, float *y);
380 void vdabgl(int *button, float *x, float *y);
381 void vdakgl(int *charac, float *x, float *y);
382 void vdstla(float *x, float *y);
383 void vdstos(float attr_array[]);
384 void x_check_window(void);
385 void x_clear_pixmap(void);
386 void vdpnta(float *x, float *y);
387 void vdnwpg(void);
388 void vdmova(float *x, float *y);
389 void vdmoni(int *state);
390 void vdloge(int *errnum, int *errsev);
391 void vberrh(int *errnum, int *errsev);
392 void vdlina(float *x, float *y);
393 void vdpoly(float xarray[], float yarray[], int *npts);
394 void vdterm(void);
395 void vdinit(float *aspect, int *justif);
396 void vdtext(int *length, int char_array[]);
397 void vdfram(int *type);
398 void vbpkg(char pkg[]);
399 void vbdev(char dev[]);
400 void vbiqpk(char pkg[]);
401 void vbiqdv(char dev[]);
402 void vdiqrs(void);
403 void vdstmp(void);
404 void vdstrs(void);
405 void vdstrv(void);
406 void vdbrgb(void);
407 void vdfrgb(void);
408 void vdpixl(void);
409 void vdpixi(void);
410 void vdrpix(void);
411 void vdrpxi(void);
412 void vdrscl(void);
413 void vdiqci(void);
414 void vbstmp(void);
415
416 /* ---------------------------- */
417 /*
418 SVDI X Windows driver - X11 version
419 Implemented in C, callable by Fortran
420 (Note: Implements SVDI at the "VI" level -- some routines are "VI"
421 routines, e.g. viinit, viterm, vilina, etc., while others are "VD")
422 Dino Pavlakos Jun 1989
423 */
424
425 #include <stdio.h>
426 #include <stdlib.h>
427 #include <string.h>
428
429 #include <X11/Xlib.h>
430 #include <X11/Xutil.h>
431
432 /* svdi state */
433 /* attributes
434 * vector[0] = foreground color
435 * vector[1] = background color
436 * vector[2] = intensity
437 * vector[3] = line style
438 * vector[4] = line width
439 * vector[5] = character box y
440 * vector[6] = character box x */
441 #define MAX_VECTOR 7
442 static float vector[MAX_VECTOR] = {0., 7., 1., 0., 0., 0., 0.};
443
444 /* current position */
445 static float xcp = 0.;
446 static float ycp = 0.;
447
448 /* device capabilities
449 * 1. Erasability
450 * 2. Scan Type
451 * 3. Intensities (1-N)
452 * 4. Colors (1-N)
453 * 5. Line Widths (1-N)
454 * 6. Line Styles (0-N)
455 * 7. Character Sizes (0-N)
456 * 8. Number of Locator Devices
457 * 9. Number of Valuator Devices
458 * 10. Number of Button Devices
459 * 11. Number of Keyboard Devices
460 * 12. Number of Stroke Devices
461 * 13. Input
462 * 14. Input Timing
463 * 15. X Dimension of View Surface in Device Coordinates
464 * 16. Y Dimension of View Surface in Device Coordinates
465 * 17. X Dimension of View Surface in Physical Units (mm)
466 * 18. Y Dimension of View Surface in Physical Units (mm)
467 * 19. Smallest Line Width (DC) at default intensity
468 * 20. Smallest Point (DC) at default intensity
469 * 21. Smallest Character Size (DC)
470 * 22. Header and Trailer Frames Required (0=no,1=yes)
471 * 23. Device Identifier
472 * 24. Polygon support level
473 * 25. Maximum number of points in a polygon
474 * 26. Setable color table
475 * 27. Device color palette size (1-N)
476 * 28. Direct color space size (0-N)
477 * 29. Vector verses Raster VDI
478 * 30. Maximum character height (DC)
479 * 31. Maximum line width (DC)
480 * 32. Color verses monochrome (greyscale) device
481 * 33. Device pixel aspect */
482
483 #define MAX_DEV_CAP 33
484 #define VBUF_SIZE 1024
485 static float dev_cap[MAX_DEV_CAP] = {4., 1., 1., 256., 1.,
486 3., 1., 1., 1., 1.,
487 1., 1., 2., 0., 0.,
488 0., 0., 0., 1., 1.,
489 0., 0., 35., 3., (float)(VBUF_SIZE - 1),
490 1., 0., 0., 0., 0.,
491 1., 1., 1.};
492
493 /* SVDI internal parameters */
494 /* Maximum NDC Values */
495 static float ndc_xmax = 1.;
496 static float ndc_ymax = 1.;
497
498 /* Logical Color Table */
499 #define MAX_COLORS 256
500 static float color_table[MAX_COLORS][3];
501 static float default_color_table[8][3] = {{0., 0., 0.}, {1., 0., 0.}, {0., 1., 0.}, {1., 1., 0.},
502 {0., 0., 1.}, {1., 0., 1.}, {0., 1., 1.}, {1., 1., 1.}};
503 static int x_colors[MAX_COLORS];
504 static enum CT { MONO, PSEUDO, FULL } color_type;
505 static int def_bc_index, def_fc_index;
506 static int svdicolors_base;
507
508 /* aspect, justification */
509 static float asp;
510 static int just;
511
512 /* transformation parameters*/
513 static int xpad, ypad;
514 static float scale;
515
516 /* Other globals */
517 static Drawable draw_id; /* drawable identifier */
518 static Window window_id; /* window identifier */
519 static int window_stat = 0; /* status indicating whether window
520 has changed (e.g. hidden/exposed,
521 resized, etc.) since new page or
522 since the last time the
523 application checked (vdescp 3501)
524 */
525 static Pixmap pixmap_id; /* pixmap identifier (for drawing
526 into off-screen memory)
527 */
528 static int buf_pic = 0; /* buffer picture off-screen flag */
529 static int all_colors = 0; /* full access to color map flag */
530 static Display *display;
531 static int screen;
532 static Screen *screen_pnt;
533 static GC gc; /* graphics context */
534 static GContext gcontext;
535 static XPoint vlist[VBUF_SIZE]; /* vertex buffer (polyline, polygon) */
536 static int x11_nvert = 0;
537 static unsigned int x_width, x_height; /* window size */
538 static int x_depth; /* window depth */
539 static unsigned int line_width; /* line width in device coord. */
540 static Colormap cmap; /* color map */
541 static Visual *visual;
542 static int ncolors; /* number of colors supported */
543 static int f_color; /* device foreground color */
544 static int b_color; /* device background color */
545 static int line_type; /* device line type */
546 static XFontStruct *font_info; /* text stuff */
547 /* static char *font_name = "9x15"; */
548 static char *font_name = "fixed";
549 static Font font_id;
550 static int font_height, font_width; /* char size in device coord. */
551
552 /* macros which map ndc into X Windows device coords. */
553 #define map_x(xin) ((int)(xpad + scale * (xin)))
554 #define map_y(yin) ((int)(x_height - (ypad + scale * (yin))))
555
556 /* macros which map X Windows coords. into ndc */
557 #define ndc_map_x(xin) ((float)(((xin) - xpad) / scale))
558 #define ndc_map_y(yin) ((float)(((x_height - (yin)) - ypad) / scale))
559
560 /* macro to convert measure in X window units into ndc units */
561 #define ndc_units(in) ((float)((in) / scale))
562 /* macro to convert measure in ndc into X window measure */
563 #define x_units(in) ((int)((in) * scale))
564
565 /* macro to convert ascii(integer) to char (note: machine dependent) */
566 #define a_to_c(ain) ((char)(ain)) /* for ascii machine */
567
568 /* misc macros */
569 #define min(p1, p2) ((p1) < (p2) ? p1 : p2)
570 #define max(p1, p2) ((p1) > (p2) ? p1 : p2)
571
572 /* flush polyline buffer */
573 /* implemented as macro to save the overhead of subroutine call */
574 void x11_vflush(void)
575 {
576 if (x11_nvert > 1) {
577 XDrawLines(display, draw_id, gc, vlist, x11_nvert, CoordModeOrigin);
578 }
579 x11_nvert = 0;
580 }
581
582 void viinit(float *aspect, int *justif)
583 {
584 int i, j, xpos, ypos, depth;
585 unsigned long valuemask;
586 unsigned int d_width, d_height;
587 char *geometry = NULL, *bufferpic = NULL, *allcolors = NULL;
588 XSetWindowAttributes setwinattr;
589 XWindowAttributes winattr;
590 XWMHints wmhints;
591 XSizeHints hints;
592 XEvent x_event;
593 XColor def_cmap[MAX_COLORS];
594 int backing_store = 0;
595
596 VisualID visualid;
597 XVisualInfo visual_template;
598 int matching_visuals;
599
600 asp = *aspect;
601 just = *justif;
602
603 if (asp < 0.) {
604 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 721, 5);
605 asp = 0.;
606 }
607
608 if (just < 0 || just > 9) {
609 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 720, 5);
610 just = 0;
611 }
612
613 /* open the display specified by the env variable DISPLAY */
614 if ((display = XOpenDisplay(NULL)) == NULL) {
615 fprintf(stderr, "svdi_x: cannot create window on %s\n", XDisplayName(NULL));
616 exit(1);
617 }
618 screen = DefaultScreen(display);
619 screen_pnt = DefaultScreenOfDisplay(display);
620
621 /* check for user specified options */
622 if ((bufferpic = XGetDefault(display, "svdi", "BufferPic"))) {
623 if (strcmp(bufferpic, "on") == 0) {
624 buf_pic = 1;
625 }
626 }
627 if ((allcolors = XGetDefault(display, "svdi", "AllColors"))) {
628 if (strcmp(allcolors, "on") == 0) {
629 all_colors = 1;
630 }
631 }
632
633 /* get display dimensions */
634 d_width = DisplayWidth(display, screen);
635 d_height = DisplayHeight(display, screen);
636
637 /* create a window */
638 /* set attribute mask */
639 valuemask = CWBackPixel | CWBorderPixel;
640 /* color attributes */
641 setwinattr.background_pixel = BlackPixel(display, screen);
642 setwinattr.border_pixel = WhitePixel(display, screen);
643 if (DoesBackingStore(screen_pnt)) { /* backing store */
644 valuemask = valuemask | CWBackingStore;
645 setwinattr.backing_store = Always;
646 backing_store = 1;
647 }
648 x_height = .65 * d_height;
649 x_width = x_height * 1.63; /* default size */
650 xpos = 0.3 * d_width;
651 ypos = 0.3 * d_height;
652 /* use user-supplied default geometry if available */
653 geometry = XGetDefault(display, "svdi", "Geometry");
654 if (geometry) {
655 XParseGeometry(geometry, &xpos, &ypos, &x_width, &x_height);
656 }
657
658 /* setup colors */
659 /* first try for a 24 bit visual */
660 visual_template.depth = 24;
661 visual_template.class = TrueColor;
662 XGetVisualInfo(display, VisualDepthMask | VisualClassMask, &visual_template, &matching_visuals);
663 i = XMatchVisualInfo(display, DefaultScreen(display), 24, TrueColor, &visual_template);
664 if (matching_visuals > 0 && i > 0) {
665 depth = 24;
666 visual = visual_template.visual;
667 valuemask |= CWBackPixel | CWColormap | CWBorderPixel;
668 setwinattr.colormap = XCreateColormap(display, XRootWindow(display, screen), visual, AllocNone);
669 cmap = setwinattr.colormap;
670 setwinattr.background_pixel = BlackPixel(display, screen);
671 setwinattr.border_pixel = WhitePixel(display, screen);
672 window_id = XCreateWindow(display, RootWindow(display, screen), xpos, ypos, x_width, x_height,
673 1, depth, InputOutput, visual, valuemask, &setwinattr);
674 }
675 else {
676 /* then try for a 16 bit visual */
677 visual_template.depth = 16;
678 visual_template.class = TrueColor;
679 XGetVisualInfo(display, VisualDepthMask | VisualClassMask, &visual_template, &matching_visuals);
680 i = XMatchVisualInfo(display, DefaultScreen(display), 16, TrueColor, &visual_template);
681 if (matching_visuals > 0 && i > 0) {
682 depth = 16;
683 visual = visual_template.visual;
684 valuemask |= CWBackPixel | CWColormap | CWBorderPixel;
685 setwinattr.colormap =
686 XCreateColormap(display, XRootWindow(display, screen), visual, AllocNone);
687 cmap = setwinattr.colormap;
688 setwinattr.background_pixel = BlackPixel(display, screen);
689 setwinattr.border_pixel = WhitePixel(display, screen);
690 window_id = XCreateWindow(display, RootWindow(display, screen), xpos, ypos, x_width, x_height,
691 1, depth, InputOutput, visual, valuemask, &setwinattr);
692 }
693 else {
694 cmap = DefaultColormap(display, screen);
695 visual = DefaultVisual(display, screen);
696 visualid = XVisualIDFromVisual(visual);
697 visual_template.visualid = visualid;
698 visual_template.depth = 8;
699 visual_template.class = PseudoColor;
700 XGetVisualInfo(display, VisualIDMask | VisualDepthMask | VisualClassMask, &visual_template,
701 &matching_visuals);
702 if (matching_visuals == 0) {
703 fprintf(stderr, "Default visual for this screen must be an ");
704 fprintf(stderr, "8-bit PseudoColor or 24-bit TrueColor visual\n");
705 exit(1);
706 }
707 window_id = XCreateWindow(display, RootWindow(display, screen), xpos, ypos, x_width, x_height,
708 3, 0, InputOutput, CopyFromParent, valuemask, &setwinattr);
709 }
710 }
711 XGetWindowAttributes(display, window_id, &winattr);
712 x_depth = winattr.depth;
713
714 /* by default, set the drawable to be the window */
715 draw_id = window_id;
716
717 /* if buffer picture escape selected, create pixmap, make it the drawable */
718 if (buf_pic) {
719 pixmap_id = XCreatePixmap(display, window_id, x_width, x_height, x_depth);
720 draw_id = pixmap_id;
721 }
722
723 /* setup window properties */
724 hints.flags = PSize | PMinSize;
725 hints.width = x_width;
726 hints.height = x_height;
727 hints.min_width = 100;
728 hints.min_height = 100;
729 XSetStandardProperties(display, window_id, "svdi", "svdi", None, 0, 0, &hints);
730 wmhints.flags = InputHint;
731 wmhints.input = True;
732 XSetWMHints(display, window_id, &wmhints);
733
734 /* setup a graphics context */
735 gc = XCreateGC(display, draw_id, 0, NULL);
736
737 /* setup defaults */
738 line_width = 0; /* line width */
739 line_type = LineSolid; /* line type */
740 XSetLineAttributes(display, gc, line_width, line_type, CapButt, JoinMiter);
741
742 ncolors = DisplayCells(display, screen); /* get size of color map */
743 if (ncolors > MAX_COLORS) {
744 ncolors = MAX_COLORS;
745 }
746
747 if (visual->class == TrueColor || visual->class == DirectColor ||
748 (visual->class == PseudoColor && ncolors >= 8)) {
749 /* setup color */
750 if (visual->class == TrueColor || visual->class == DirectColor) {
751 color_type = FULL;
752 }
753 else {
754 color_type = PSEUDO;
755 /* fprintf(stderr,"SVDI: Using pseudo color visual with %d colors\n",
756 ncolors); */
757 /* For pseudo-color systems, a separate virtual color map is created
758 for use by SVDI. In order to minimize the effect of SVDI color
759 table changes on the rest of the screen colors, the original
760 colors are copied into the new virtual map, and certain entries
761 are preserved (unless all_colors option has been selected).
762 */
763 /* query default colors */
764 for (i = 0; i < ncolors; i++) {
765 def_cmap[i].pixel = (unsigned long)i;
766 }
767 XQueryColors(display, cmap, def_cmap, ncolors);
768 /* setup a virtual colormap */
769 cmap = XCreateColormap(display, window_id, visual, AllocAll);
770 XSetWindowColormap(display, window_id, cmap);
771 /* copy default colors into new color map */
772 XStoreColors(display, cmap, def_cmap, ncolors);
773 if (all_colors) {
774 /* all_colors option has been selected -- let driver use
775 all of them */
776 svdicolors_base = 0;
777 }
778 else if (ncolors < 16) {
779 /* number of colors is between 8 and 16 -- let driver use
780 8 of them */
781 svdicolors_base = ncolors - 8;
782 ncolors = 8;
783 }
784 else {
785 /* number of colors is >= 16 -- preserve a few at each end
786 of table */
787 int nreserve = max(4, ncolors / 16);
788 svdicolors_base = nreserve;
789 ncolors = ncolors - 2 * nreserve;
790 }
791 }
792 dev_cap[3] = ncolors; /* update svdi device capabilities */
793 def_bc_index = 0; /* remember defaults */
794 def_fc_index = 7;
795 /* setup default SVDI colors */
796 int index[8];
797 for (i = 0; i < 8; i++) {
798 index[i] = i;
799 }
800 i = 8;
801 j = 0;
802 vdstco(&i, index, default_color_table, &j); /* color table */
803 i = 0;
804 vdstbc(&i); /* background color */
805 i = 7;
806 vdstfc(&i); /* foreground color */
807 }
808 else {
809 /* default to monochrome */
810 color_type = MONO; /* remember color type */
811 /* printf("** mono color **\n"); */
812 ncolors = 2;
813 dev_cap[3] = 2; /* update svdi device capabilities */
814 def_bc_index = 0; /* remember defaults */
815 def_fc_index = 1;
816 /* setup default colors */
817 color_table[0][0] = 0; /* background */
818 color_table[0][1] = 0;
819 color_table[0][2] = 0;
820 b_color = BlackPixel(display, screen);
821 x_colors[0] = b_color;
822 color_table[1][0] = 1; /* foreground */
823 color_table[1][1] = 1;
824 color_table[1][2] = 1;
825 f_color = WhitePixel(display, screen);
826 x_colors[1] = f_color;
827 }
828
829 /* text stuff */
830 if ((font_info = XLoadQueryFont(display, font_name)) == NULL) {
831 fprintf(stderr, "svdi_x: font request failed, using default\n");
832 gcontext = XGContextFromGC(gc);
833 font_info = XQueryFont(display, gcontext);
834 }
835 else {
836 font_id = (*font_info).fid;
837 XSetFont(display, gc, font_id);
838 }
839 font_height = font_info->max_bounds.ascent + font_info->max_bounds.descent;
840 font_width = font_info->max_bounds.rbearing - font_info->min_bounds.lbearing;
841 /* this gives bounding box width, which seems like what
842 we want ... but for whatever reason, this computation
843 doesn't seem to give correct results on VMS */
844
845 /* setup input event stuff */
846 /* specify what kinds of input events to accept */
847 XSelectInput(display, window_id,
848 ExposureMask | StructureNotifyMask | KeyPressMask | ButtonPressMask);
849
850 /* display the window */
851 XMapWindow(display, window_id);
852
853 /* if no backing store, wait for first expose event before drawing */
854 if (!backing_store) {
855 XWindowEvent(display, window_id, ExposureMask, &x_event);
856 }
857
858 /* if buffer picture mode is on, clear the pixmap */
859 if (buf_pic) {
860 x_clear_pixmap();
861 }
862
863 /* setup parameters which are affected by dynamics */
864 x_dynamics(1);
865
866 /* get synced and flush event queue -- start with a clean slate */
867 XSync(display, True);
868 }
869
870 /* x_dynamics -- setup parameters affected by window dynamics
871 init = initialization flag (1 means called from initialization phase,
872 otherwise 0)
873 */
874 void x_dynamics(int init)
875 {
876 XWindowAttributes win_info;
877 float asp1;
878 int just1, xused, yused;
879
880 /* asp and just remember the requested aspect and justification
881 at initialization */
882 asp1 = asp;
883 just1 = just;
884
885 /* query window information */
886 XGetWindowAttributes(display, window_id, &win_info);
887
888 /* if not initializing and window size hasn't changed, just return */
889 if ((!init) && (x_width == win_info.width) && (x_height == win_info.height)) {
890 return;
891 }
892
893 /* remember size */
894 x_width = win_info.width;
895 x_height = win_info.height;
896
897 /* if buffer picture mode is on, then free old pixmap, allocate new
898 one with new size (if initializing, skip over since we already set
899 up a pixmap in viinit) */
900 if ((buf_pic) && (!init)) {
901 XFreePixmap(display, pixmap_id);
902 pixmap_id = XCreatePixmap(display, window_id, x_width, x_height, x_depth);
903 draw_id = pixmap_id;
904 x_clear_pixmap();
905 }
906
907 /* update SVDI info */
908 dev_cap[14] = (float)x_width;
909 dev_cap[15] = (float)x_height;
910
911 /* handle aspect */
912 if (asp1 == 0.) {
913 asp1 = (float)x_width / (float)x_height;
914 /* note: What to do if the window changes??? If the application
915 requested the entire view surface originally (i.e. aspect = 0.),
916 then, when the window changes, do we recompute aspect, which
917 in turn may result in new ndc maximums, which in turn may result
918 in the application drawing to different limits than currently
919 exist (which means the application may end up trying to draw
920 outside the window)? Or, do we just remember the original
921 resulting aspect */
922 /* In the default case, just use the original aspect so the
923 application is guaranteed to see everything which would draw
924 based on that aspect, regardless of window */
925 asp = asp1;
926 }
927 if (asp1 > 1.) {
928 ndc_xmax = 1.;
929 ndc_ymax = 1. / asp1;
930 }
931 else {
932 ndc_xmax = asp1;
933 ndc_ymax = 1.;
934 }
935 scale = min((x_width - 1) / ndc_xmax, (x_height - 1) / ndc_ymax);
936 xused = (int)(scale * ndc_xmax);
937 yused = (int)(scale * ndc_ymax);
938
939 /* handle justification */
940 if (just1 == 0) {
941 just1 = 5;
942 }
943 /* y offset */
944 if (just1 < 4) {
945 ypad = 0;
946 }
947 else if (just1 < 7) {
948 ypad = (x_height - yused) / 2;
949 }
950 else {
951 ypad = x_height - yused;
952 }
953 /* x offset */
954 if (just1 == 1 || just1 == 4 || just1 == 7) {
955 xpad = 0;
956 }
957 else if (just1 == 2 || just1 == 5 || just1 == 8) {
958 xpad = (x_width - xused) / 2;
959 }
960 else {
961 xpad = x_width - xused;
962 }
963
964 /* spatial attributes */
965 vector[4] = (ndc_units((line_width == 0) ? 1 : line_width) * 100);
966 vector[5] = (ndc_units(font_height));
967 vector[6] = (ndc_units(font_width));
968 }
969
970 void vifram(int *type) {}
971
972 void viterm(void)
973 {
974 x11_vflush(); /* flush polyline buffer */
975
976 /* close window, disconnect display */
977 XDestroyWindow(display, window_id);
978 XCloseDisplay(display); /* frees all associated resources */
979 }
980
981 void vdiqdc(int *index, float *value)
982 {
983 if (*index < 1 || *index > MAX_DEV_CAP) {
984 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 726, 5);
985 }
986 else {
987 *value = dev_cap[*index - 1];
988 }
989 }
990
991 void vinwpg(void)
992 {
993 x11_vflush(); /* flush polyline buffer */
994 x_check_window(); /* check window change */
995 window_stat = 0; /* reset window change indicator */
996
997 /* if buffer picture mode, then flush pixmap to window, clear pixmap */
998 if (buf_pic) {
999 vdbufl();
1000 x_clear_pixmap();
1001
1002 /* else clear window */
1003 }
1004 else {
1005 XClearWindow(display, window_id);
1006 }
1007 }
1008
1009 void vdbell(void)
1010 {
1011 x11_vflush(); /* flush polyline buffer */
1012 XBell(display, 100);
1013 }
1014
1015 void vdwait(void)
1016 {
1017 XEvent x_event;
1018 vdbufl();
1019
1020 XBell(display, 100); /* ring bell */
1021 /* wait for keyboard key or mouse button */
1022 XWindowEvent(display, window_id, KeyPressMask | ButtonPressMask, &x_event);
1023 }
1024
1025 void vdbufl(void)
1026 {
1027 x11_vflush(); /* flush polyline buffer */
1028 /* if buffer picture mode is turned on, then flush pixmap to window */
1029 if (buf_pic) {
1030 XCopyArea(display, pixmap_id, window_id, gc, 0, 0, x_width, x_height, 0, 0);
1031 }
1032 /* flush output buffer, wait for server to do its thing ...
1033 we use Sync instead of Flush to wait for server to finish
1034 processing (versus just sending buffer to server) */
1035 XSync(display, False);
1036 }
1037
1038 void vdstco(int *num, int index_array[], float color_array[][3], int *color_mod)
1039 {
1040 int i;
1041 XColor tcolor;
1042
1043 if (color_type == MONO) {
1044 return;
1045 }
1046
1047 /* check valid number of colors */
1048 if (*num < 1) {
1049 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 723, 5);
1050 }
1051
1052 /* check valid color mod */
1053 if (*color_mod != 0 && *color_mod != 1) {
1054 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 725, 5);
1055 }
1056
1057 /* loop over number of colors passed in */
1058 for (i = 0; i < *num; i++) {
1059 /* check index value */
1060 if (index_array[i] < 0 || index_array[i] > MAX_COLORS - 1) {
1061 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 724, 5);
1062 }
1063
1064 /* check index against color table size */
1065 else if (index_array[i] > ncolors - 1) {
1066 /* ignore */
1067 }
1068
1069 /* if rgb mode */
1070 else if (*color_mod == 0) {
1071 /* check rgb values */
1072 if (color_array[i][0] < 0. || color_array[i][0] > 1. || color_array[i][1] < 0. ||
1073 color_array[i][1] > 1. || color_array[i][2] < 0. || color_array[i][2] > 1.) {
1074 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 727, 5);
1075 }
1076 else /* set colors */
1077 {
1078 color_table[index_array[i]][0] = color_array[i][0];
1079 color_table[index_array[i]][1] = color_array[i][1];
1080 color_table[index_array[i]][2] = color_array[i][2];
1081 tcolor.red = (unsigned int)(65535 * color_array[i][0]);
1082 tcolor.green = (unsigned int)(65535 * color_array[i][1]);
1083 tcolor.blue = (unsigned int)(65535 * color_array[i][2]);
1084 if (color_type == PSEUDO) {
1085 tcolor.pixel = (unsigned int)(svdicolors_base + index_array[i]);
1086 tcolor.flags = DoRed | DoGreen | DoBlue;
1087 XStoreColor(display, cmap, &tcolor);
1088 x_colors[index_array[i]] = tcolor.pixel;
1089 }
1090 else { /* FULL */
1091 if (XAllocColor(display, cmap, &tcolor) == 0) {
1092 fprintf(stderr, "svdi_x: problem doing XAllocColor\n");
1093 }
1094 x_colors[index_array[i]] = tcolor.pixel;
1095 }
1096 }
1097 }
1098
1099 /* hls mode not supported */
1100 else {
1101 fprintf(stderr, " HLS option being phased out - not doing anything\n");
1102 fprintf(stderr, " Contact Computer Graphics Group - Div. 2644\n");
1103 }
1104 }
1105 /* end for loop */
1106 }
1107
1108 void vdiqco(int *num, int index_array[], float color_array[][3], int *color_mod)
1109 {
1110 int i;
1111
1112 /* check valid number of colors */
1113 if (*num < 1) {
1114 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 723, 5);
1115 }
1116
1117 /* check valid color mod */
1118 if (*color_mod != 0 && *color_mod != 1) {
1119 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 725, 5);
1120 }
1121
1122 /* loop over number of colors passed in */
1123 for (i = 0; i < *num; i++) {
1124 /* check valid index value */
1125 if (index_array[i] < 0 || index_array[i] > ncolors - 1) {
1126 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 724, 5);
1127 }
1128
1129 /* check index against color table size */
1130 else if (index_array[i] > ncolors - 1) {
1131 /* unsupported index value */
1132 color_array[i][0] = -1.;
1133 }
1134
1135 /* if rgb mode */
1136 else if (*color_mod == 0) {
1137 color_array[i][0] = color_table[index_array[i]][0];
1138 color_array[i][1] = color_table[index_array[i]][1];
1139 color_array[i][2] = color_table[index_array[i]][2];
1140 }
1141
1142 /* hls mode */
1143 else {
1144 fprintf(stderr, " HLS option being phased out - returning RGB values\n");
1145 fprintf(stderr, " Contact Computer Graphics Group - Div. 2644\n");
1146 color_array[i][0] = color_table[index_array[i]][0];
1147 color_array[i][1] = color_table[index_array[i]][1];
1148 color_array[i][2] = color_table[index_array[i]][2];
1149 }
1150 }
1151 /* end for loop */
1152 }
1153
1154 void vdescp(int *escape_code, int *n, float args[])
1155 {
1156 x11_vflush();
1157
1158 if (*n < 0) {
1159 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 802, 5);
1160 }
1161
1162 switch (*escape_code) {
1163 case 3500: /* sync, flush event queue */ XSync(display, True); break;
1164 case 3501: /* check window change (expose, resize, etc.) --
1165 return change indicator */
1166 x_check_window();
1167 args[0] = (float)window_stat;
1168 window_stat = 0; /* reset window change indicator */
1169 break;
1170 case 3502: /* turn on buffer picture mode (draw off-screen & copy) */ buf_pic = 1; break;
1171 case 3503: /* allow access to full color map */ all_colors = 1; break;
1172 default: break;
1173 }
1174 }
1175
1176 void vdiqes(int *escape_code, int *support)
1177 {
1178 switch (*escape_code) {
1179 case 3500: *support = 1; break;
1180 case 3501: *support = 1; break;
1181 case 3502: *support = 1; break;
1182 case 3503: *support = 1; break;
1183 default: *support = 0; break;
1184 }
1185 }
1186
1187 void vdiqnd(float *x_ndc, float *y_ndc)
1188 {
1189 *x_ndc = ndc_xmax;
1190 *y_ndc = ndc_ymax;
1191 }
1192
1193 void vimova(float *x, float *y)
1194 {
1195 x11_vflush(); /* flush polyline buffer */
1196
1197 /* update current position */
1198 xcp = *x;
1199 ycp = *y;
1200 }
1201
1202 void vilina(float *x, float *y)
1203 {
1204 /* if polyline buffer full, flush it */
1205 if (x11_nvert >= VBUF_SIZE) {
1206 x11_vflush();
1207 }
1208
1209 /* if vertex buffer empty, then start a polyline at the previous
1210 current position */
1211 if (x11_nvert == 0) {
1212 vlist[0].x = (short)map_x(xcp);
1213 vlist[0].y = (short)map_y(ycp);
1214 x11_nvert = 1;
1215 }
1216
1217 /* add point to polyline buffer */
1218 vlist[x11_nvert].x = (short)map_x(*x);
1219 vlist[x11_nvert].y = (short)map_y(*y);
1220 /* add point only if it's not the same as the previous point */
1221 if ((vlist[x11_nvert].x != vlist[x11_nvert - 1].x) ||
1222 (vlist[x11_nvert].y != vlist[x11_nvert - 1].y)) {
1223 x11_nvert++;
1224 }
1225
1226 /* update current position */
1227 xcp = *x;
1228 ycp = *y;
1229 }
1230
1231 void vipnta(float *x, float *y)
1232 {
1233 int xx, yy;
1234
1235 x11_vflush(); /* flush polyline buffer */
1236
1237 /* draw point */
1238 xx = map_x(*x);
1239 yy = map_y(*y);
1240 /* XDrawPoint doesn't seem to work on the HP --
1241 nor does XDrawLine of just a single point */
1242 XDrawLine(display, draw_id, gc, xx, yy, xx + 1, yy);
1243
1244 /* update current position */
1245 xcp = *x;
1246 ycp = *y;
1247 }
1248
1249 void vitext(int *length, int char_array[])
1250 {
1251 int len, lenout, i;
1252 char strout[137];
1253 len = *length;
1254
1255 x11_vflush(); /* flush polyline buffer */
1256
1257 if (len < 1) {
1258 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 212, 5);
1259 }
1260
1261 if (len > 136) {
1262 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 213, 5);
1263 len = 136;
1264 }
1265
1266 lenout = 0; /* count characters in string output buffer "strout" */
1267
1268 for (i = 0; i < len; i++) /* for each character */
1269 {
1270 if (char_array[i] < 32 || char_array[i] > 126) /* if special char */
1271 {
1272 if (lenout != 0) /* flush string output buffer */
1273 {
1274 strout[lenout] = '\0';
1275 XDrawString(display, draw_id, gc, map_x(xcp), map_y(ycp), strout, lenout);
1276 xcp = xcp + ndc_units(XTextWidth(font_info, strout, lenout));
1277 lenout = 0;
1278 }
1279 switch (char_array[i]) /* process special character */
1280 {
1281 case 8: /* backspace */ xcp = xcp - vector[6]; break;
1282 case 10: /* line feed */ ycp = ycp - vector[5]; break;
1283 case 13: /* carriage return */ xcp = 0.; break;
1284 default: /* other */
1285 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 208, 5);
1286 break;
1287 }
1288 }
1289 else /* add char to string output buffer */
1290 {
1291 strout[lenout++] = a_to_c(char_array[i]);
1292 }
1293 }
1294 /* end for */
1295
1296 /* All done, flush string output buffer */
1297 if (lenout != 0) /* flush string output buffer */
1298 {
1299 strout[lenout] = '\0';
1300 XDrawString(display, draw_id, gc, map_x(xcp), map_y(ycp), strout, lenout);
1301 xcp = xcp + ndc_units(XTextWidth(font_info, strout, lenout));
1302 }
1303
1304 /* make sure we end up where we want to be */
1305 vimova(&xcp, &ycp);
1306 }
1307
1308 void vipoly(float x_array[], float y_array[], int *npts)
1309 {
1310 int np, i;
1311 np = *npts;
1312
1313 x11_vflush(); /* flush polyline buffer */
1314
1315 /* check size of polygon ??? */
1316 if (np > VBUF_SIZE) {
1317 np = VBUF_SIZE;
1318 }
1319
1320 /* set up vertex list in X format */
1321 for (i = 0; i < np; i++) {
1322 vlist[i].x = (short)map_x(x_array[i]);
1323 vlist[i].y = (short)map_y(y_array[i]);
1324 }
1325
1326 /* draw polygon */
1327 XFillPolygon(display, draw_id, gc, vlist, np, Complex, CoordModeOrigin);
1328
1329 /* update current position */
1330 /* is this where it really is ??? */
1331 xcp = x_array[0];
1332 ycp = y_array[0];
1333 }
1334
1335 void vdiqcp(float *x, float *y)
1336 {
1337 *x = xcp;
1338 *y = ycp;
1339 }
1340
1341 void vdiqos(float attr_array[])
1342 {
1343 int i;
1344 for (i = 0; i < MAX_VECTOR; i++) {
1345 attr_array[i] = vector[i];
1346 }
1347 }
1348
1349 void vdstfc(int *color_index)
1350 {
1351 int loc_index;
1352 loc_index = *color_index;
1353
1354 x11_vflush(); /* flush polyline buffer */
1355
1356 /* check valid color index */
1357 if (loc_index < 0 || loc_index > 255) {
1358 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 724, 5);
1359 loc_index = def_fc_index;
1360 }
1361
1362 if (loc_index > ncolors - 1) {
1363 loc_index = def_fc_index;
1364 }
1365
1366 f_color = x_colors[loc_index];
1367 XSetForeground(display, gc, f_color);
1368 vector[0] = loc_index;
1369 }
1370
1371 void vdstbc(int *color_index)
1372 {
1373 int loc_index;
1374 loc_index = *color_index;
1375
1376 if (loc_index < 0 || loc_index > 255) {
1377 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 724, 5);
1378 loc_index = def_bc_index;
1379 }
1380
1381 if (loc_index > ncolors - 1) {
1382 loc_index = def_bc_index;
1383 }
1384
1385 b_color = x_colors[loc_index];
1386 XSetWindowBackground(display, window_id, b_color);
1387 vector[1] = loc_index;
1388 }
1389
1390 void vdstin(float *intensity)
1391 {
1392 if (*intensity < 0. || *intensity > 1.) {
1393 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 401, 2);
1394 }
1395 }
1396
1397 void vdstls(int *line_style)
1398 {
1399 char dlist[4]; /* dash pattern list */
1400 int nd = 0;
1401
1402 x11_vflush(); /* flush polyline buffer */
1403
1404 if (*line_style < 0 || *line_style > 5) {
1405 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 401, 3);
1406 }
1407
1408 /* set line type accordingly */
1409 switch (*line_style) {
1410 case 0: line_type = LineSolid; break;
1411 case 1: /* dotted */
1412 line_type = LineOnOffDash;
1413 dlist[0] = 3;
1414 dlist[1] = 1;
1415 nd = 2;
1416 break;
1417 case 5:
1418 line_type = LineOnOffDash;
1419 dlist[0] = 4;
1420 dlist[1] = 4;
1421 nd = 2;
1422 break;
1423 default:
1424 line_type = LineOnOffDash;
1425 dlist[0] = 4;
1426 dlist[1] = 4;
1427 nd = 2;
1428 }
1429 XSetLineAttributes(display, gc, line_width, line_type, CapButt, JoinMiter);
1430 if (line_type != LineSolid) {
1431 XSetDashes(display, gc, 0, dlist, nd);
1432 }
1433
1434 vector[3] = *line_style; /* update state list */
1435 }
1436
1437 void vdstlw(float *line_wid)
1438 {
1439 float slw;
1440
1441 x11_vflush(); /* flush polyline buffer */
1442
1443 if (*line_wid < 0. || *line_wid > 1.) {
1444 fprintf(stderr, " SVDI Error Number %d, Severity Code %d\n", 401, 1);
1445 }
1446
1447 slw = (*line_wid) / 100; /* svdi wants line widths scaled by 100 */
1448 line_width = x_units(slw);
1449 if (line_width < 1) {
1450 line_width = 1;
1451 }
1452 XSetLineAttributes(display, gc, line_width, line_type, CapButt, JoinMiter);
1453 vector[4] = *line_wid;
1454 }
1455
1456 void vdstcs(float *y_size)
1457 {
1458 /* doesn't do anything */
1459 /* character size is fixed for each font */
1460 }
1461
1462 void vdaabu(int *button)
1463 {
1464 vdbufl();
1465 /* not implemented */
1466 }
1467
1468 void vdaloc(float *x, float *y)
1469 {
1470 union {
1471 XEvent x_event;
1472 XButtonEvent x_butp;
1473 } event;
1474
1475 vdbufl();
1476
1477 /* wait for button pressed, pull coordinates out of event report */
1478 XWindowEvent(display, window_id, ButtonPressMask, &event.x_event);
1479 *x = ndc_map_x(event.x_butp.x);
1480 *y = ndc_map_y(event.x_butp.y);
1481 }
1482
1483 void vdabgl(int *button, float *x, float *y)
1484 {
1485 vdbufl();
1486 /* not implemented */
1487 }
1488
1489 void vdakgl(int *charac, float *x, float *y)
1490 {
1491 union {
1492 XEvent x_event;
1493 XAnyEvent any;
1494 XKeyEvent x_keyp;
1495 XButtonEvent x_butp;
1496 } event;
1497 char key;
1498
1499 vdbufl();
1500 /* Flush out previous button press events in case any in queue */
1501 XSync(display, True);
1502
1503 /* wait for key pressed, pull coordinates, key out of event report */
1504 XWindowEvent(display, window_id, KeyPressMask | ButtonPressMask, &event.x_event);
1505 switch (event.any.type) {
1506 case ButtonPress: {
1507 *x = ndc_map_x(event.x_butp.x);
1508 *y = ndc_map_y(event.x_butp.y);
1509 *charac = 32; /* treat it like a space */
1510 break;
1511 }
1512 case KeyPress: {
1513 *x = ndc_map_x(event.x_keyp.x);
1514 *y = ndc_map_y(event.x_keyp.y);
1515 XLookupString(&event.x_keyp, &key, 1, NULL, NULL); /* lookup which key */
1516 *charac = (int)key; /* convert to integer ascii */
1517 break;
1518 }
1519 } /* note: XLookupString presumably returns key in ASCII, so we
1520 just need to repackage as integer */
1521 }
1522
1523 void vdstla(float *x, float *y)
1524 {
1525 XWarpPointer(display, None, window_id, 0, 0, 0, 0, map_x(*x), map_y(*y));
1526 }
1527
1528 void vdstos(float attr_array[])
1529 {
1530 /* attr_array[0] is equivalent to *attr_array,
1531 attr_array[1] is equivalent to *(attr_array+1),
1532 etc. */
1533 int i;
1534
1535 i = (int)attr_array[0];
1536 vdstfc(&i);
1537 i = (int)attr_array[1];
1538 vdstbc(&i);
1539 vdstin(attr_array + 2);
1540 i = (int)attr_array[3];
1541 vdstls(&i);
1542 vdstlw(attr_array + 4);
1543 vdstcs(attr_array + 5);
1544 }
1545
1546 void x_check_window(void)
1547 {
1548 int change;
1549 XEvent x_event;
1550
1551 change = 0;
1552 /* pick up any window change events */
1553 while (XCheckWindowEvent(display, window_id, ExposureMask | StructureNotifyMask, &x_event)) {
1554 change = 1;
1555 };
1556
1557 /* if we found any of the ones we care about, then recompute
1558 dynamic parameters, record change */
1559 if (change == 1) {
1560 x_dynamics(0);
1561 window_stat = 1; /* set window change indicator */
1562 }
1563 }
1564
1565 void x_clear_pixmap(void)
1566 {
1567 /* temporarily set foreground color to the background color and draw a
1568 big fill rectangle to clear the pixmap,
1569 then restore the foreground color
1570 */
1571 XSetForeground(display, gc, b_color);
1572 XFillRectangle(display, pixmap_id, gc, 0, 0, x_width + 1, x_height + 1);
1573 XSetForeground(display, gc, f_color);
1574 }
1575
1576 void vdpnta(float *x, float *y) { vipnta(x, y); }
1577 void vdnwpg(void) { vinwpg(); }
1578 void vdmova(float *x, float *y) { vimova(x, y); }
1579 void vdmoni(int *state) {}
1580 void vdloge(int *errnum, int *errsev) {}
1581 void vberrh(int *errnum, int *errsev) {}
1582 void vdlina(float *x, float *y) { vilina(x, y); }
1583 void vdpoly(float xarray[], float yarray[], int *npts) { vipoly(xarray, yarray, npts); }
1584 void vdterm(void) { viterm(); }
1585 void vdinit(float *aspect, int *justif) { viinit(aspect, justif); }
1586 void vdtext(int *length, int char_array[]) { vitext(length, char_array); }
1587 void vdfram(int *type) { vifram(type); }
1588 void vbpkg(char pkg[]) {}
1589 void vbdev(char dev[]) {}
1590 void vbiqpk(char pkg[]) {}
1591 void vbiqdv(char dev[]) {}
1592
1593 /* null entry points for raster */
1594
1595 void vdiqrs(void) {}
1596
1597 void vdstmp(void) {}
1598
1599 void vdstrs(void) {}
1600
1601 void vdstrv(void) {}
1602
1603 void vdbrgb(void) {}
1604
1605 void vdfrgb(void) {}
1606
1607 void vdpixl(void) {}
1608
1609 void vdpixi(void) {}
1610
1611 void vdrpix(void) {}
1612
1613 void vdrpxi(void) {}
1614
1615 void vdrscl(void) {}
1616
1617 void vdiqci(void) {}
1618
1619 void vbstmp(void) {}