1 | |
---|
2 | /* file XWCH.C |
---|
3 | * ====== |
---|
4 | * |
---|
5 | * $Revision$, $Date$ |
---|
6 | * |
---|
7 | * XWindow channel for graphics module |
---|
8 | * K. Stammler, 21-AUG-1990 |
---|
9 | */ |
---|
10 | |
---|
11 | #include <stdio.h> |
---|
12 | #include <string.h> |
---|
13 | #include <ctype.h> |
---|
14 | #include BASECNST |
---|
15 | #include <X11/Xlib.h> |
---|
16 | #include <X11/Xatom.h> |
---|
17 | #include <X11/cursorfont.h> |
---|
18 | #include <X11/Xutil.h> |
---|
19 | #include BC_SYSBASE |
---|
20 | #include "graphbas.h" |
---|
21 | #include "xwusrdef.h" |
---|
22 | #include "xwerrors.h" |
---|
23 | #include "../globalparams.h" |
---|
24 | |
---|
25 | |
---|
26 | /* global constants */ |
---|
27 | #define X_PIX_PER_CM 30.0 |
---|
28 | #define Y_PIX_PER_CM 30.0 |
---|
29 | #define MAXSTYLE 10 |
---|
30 | /* number of style blocks (GC's) */ |
---|
31 | #define DEFSTYLE 0 |
---|
32 | /* default style number */ |
---|
33 | #define MAXDEFSTYLE 6 |
---|
34 | /* number of different line styles */ |
---|
35 | #define XWRITEOFF 3 |
---|
36 | #define YWRITEOFF 3 |
---|
37 | /* offsets of write position */ |
---|
38 | #define DEFAULTWIDTH 100.0 |
---|
39 | /* default width of user coo */ |
---|
40 | #define DEFAULTHEIGHT 100.0 |
---|
41 | /* default height of user coo */ |
---|
42 | #define MAXSTRLTH 200 |
---|
43 | #define MAXSTORESTR 512 |
---|
44 | |
---|
45 | /* #define EVENTS (ExposureMask|KeyPressMask|FocusChangeMask) */ |
---|
46 | #define EVENTS (ExposureMask|KeyPressMask) |
---|
47 | /* events to wait for */ |
---|
48 | |
---|
49 | #define XWC_FONTLIST "xfonts.lis" |
---|
50 | /* name of font list file */ |
---|
51 | |
---|
52 | #define NUMMASK 0x0f |
---|
53 | |
---|
54 | /* ASCII codes */ |
---|
55 | #define DEL (char)0x7f |
---|
56 | #define BS (char)8 |
---|
57 | #define CR (char)13 |
---|
58 | #define LF (char)10 |
---|
59 | #define ESC (char)27 |
---|
60 | |
---|
61 | |
---|
62 | /* macros */ |
---|
63 | #define xwh_illegalwdw(w) ((w) >= XWC_MAXWDW) |
---|
64 | /* illegal window number */ |
---|
65 | #define xwh_wdwopen(w) (((w) < XWC_MAXWDW) && ((1 << (w)) & xwv_ison)) |
---|
66 | /* window w is open */ |
---|
67 | #define ASWAP(x,y) if (xwv_arrayswap) {XWCOO tmp;tmp=(x);(x)=(y);(y)=tmp;} |
---|
68 | /* swap coo's in xw_arrayplot */ |
---|
69 | |
---|
70 | |
---|
71 | /* global variables */ |
---|
72 | static BOOLEAN xwv_dspinit={FALSE}; /* Display initialised */ |
---|
73 | static Display *xwv_dsp; /* Display */ |
---|
74 | static Screen *xwv_screen; /* Screen */ |
---|
75 | static Window xwv_wdw[XWC_MAXWDW]; /* window specifiers */ |
---|
76 | static Colormap xwv_cmap; /* colour map */ |
---|
77 | static BOOLEAN xwv_colored; /* coloured screen */ |
---|
78 | static int xwv_ison=0; /* stores open status */ |
---|
79 | static XWCOO xwv_gxpos[XWC_MAXWDW]; /* graphic x-position */ |
---|
80 | static XWCOO xwv_gypos[XWC_MAXWDW]; /* graphic y-position */ |
---|
81 | static int xwv_wxpos[XWC_MAXWDW]; /* text x-position */ |
---|
82 | static int xwv_wypos[XWC_MAXWDW]; /* text y-position */ |
---|
83 | static XWCOO xwv_txoff[XWC_MAXWDW]; /* x-offset in user coordinates */ |
---|
84 | static XWCOO xwv_tyoff[XWC_MAXWDW]; /* y-offset in user coordinates */ |
---|
85 | static float xwv_txfac[XWC_MAXWDW]; /* x-zoom factor in user coo's */ |
---|
86 | static float xwv_tyfac[XWC_MAXWDW]; /* y-zoom factor in user coo's */ |
---|
87 | static GC xwv_gc[MAXSTYLE]; /* style blocks */ |
---|
88 | static GC xwv_default_gc; /* default style */ |
---|
89 | static XFontStruct *xwv_font[MAXSTYLE]; /* font structure */ |
---|
90 | static XFontStruct *xwv_default_font; /* default font */ |
---|
91 | static unsigned long xwv_default_fore; /* default foreground pixel */ |
---|
92 | static unsigned long xwv_default_back; /* default background pixel */ |
---|
93 | static int xwv_laststyle; /* last style used (text) */ |
---|
94 | static XWCOO xwv_userh; /* user height */ |
---|
95 | static BOOLEAN xwv_tomem=TRUE; /* store hardcopy in memory */ |
---|
96 | static char xwv_wstr[XWC_MAXWDW][MAXSTORESTR+1]; |
---|
97 | static BOOLEAN xwv_arrayswap=FALSE; /* swap arrayplot */ |
---|
98 | /* "xw_write"-strings for redraw */ |
---|
99 | static int xwv_lstyle[MAXSTYLE] /* line styles */ |
---|
100 | ={LineSolid,LineSolid,LineSolid,LineSolid,LineSolid,LineSolid, |
---|
101 | LineSolid,LineSolid,LineSolid,LineSolid}; |
---|
102 | static int xwv_lwidth[MAXSTYLE] /* line widths */ |
---|
103 | ={1,1,1,1,1,1,1,1,1,1}; |
---|
104 | static int xwv_defstyle[MAXDEFSTYLE] /* default styles */ |
---|
105 | ={LineSolid,LineDoubleDash,LineOnOffDash,LineDoubleDash,LineOnOffDash, |
---|
106 | LineDoubleDash}; |
---|
107 | static char xwv_inputdir[BC_FILELTH+1]; /* input directory */ |
---|
108 | |
---|
109 | |
---|
110 | /* prototypes of local routines */ |
---|
111 | static void xwh_transform( WDW wdw, XWCOO x, XWCOO y, int *u, int *v ); |
---|
112 | static void xwh_backtrans( WDW wdw, int x, int y, XWCOO *u, XWCOO *v ); |
---|
113 | static void xwh_getwdwsize( WDW wdw, int *ww, int *wh ); |
---|
114 | static int xwh_wdwdepth( WDW wdw ); |
---|
115 | static int xwh_getfontheight( int style ); |
---|
116 | static int xwh_getfontwidth( int style ); |
---|
117 | static void xwh_newline( WDW wdw ); |
---|
118 | static void xwh_scroll( WDW wdw ); |
---|
119 | static void xwh_read_character( char *ch ); |
---|
120 | static void xwh_drawcross( WDW wdw, GC gc, int x, int y ); |
---|
121 | static void xwh_setcolor( int style, char value[], STATUS *status ); |
---|
122 | static WDW xwh_findwdw( Window xwdw ); |
---|
123 | static int xwh_getfontnum( WDW wdw, float size ); |
---|
124 | |
---|
125 | |
---|
126 | /*----------------------------------------------------------------------------*/ |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | void xw_init( WDW wdw, int attribs, float xlo, float ylo, |
---|
131 | float width, float height, STATUS *status ) |
---|
132 | |
---|
133 | /* initialises window |
---|
134 | * |
---|
135 | * parameters of routine |
---|
136 | * WDW wdw; input; channels to be initialised |
---|
137 | * int attribs; input; window attributes |
---|
138 | * float xlo, ylo; input; position of window (in cm) |
---|
139 | * float width, height; input; size of window (in cm) |
---|
140 | * STATUS *status; output; return status |
---|
141 | */ |
---|
142 | { |
---|
143 | /* local variables */ |
---|
144 | int wx, wy; /* position of window */ |
---|
145 | int ww, wh; /* size of window */ |
---|
146 | int i; /* counter */ |
---|
147 | XSetWindowAttributes xswa; /* set attribute block */ |
---|
148 | XSizeHints xsh; /* size hints */ |
---|
149 | XWMHints xwmh; /* window manager hints */ |
---|
150 | char str[MAXSTRLTH+1]; /* scratch string */ |
---|
151 | |
---|
152 | /* executable code */ |
---|
153 | |
---|
154 | if (!xwv_dspinit) { |
---|
155 | |
---|
156 | /* initialise everything ... */ |
---|
157 | xwv_dsp = XOpenDisplay( NULL ); |
---|
158 | if (xwv_dsp == NULL) { |
---|
159 | *status = XWE_OPNDSP; |
---|
160 | return; |
---|
161 | } /*endif*/ |
---|
162 | xwv_screen = XDefaultScreenOfDisplay( xwv_dsp ); |
---|
163 | /* XSynchronize( xwv_dsp, 1 ); only for test !!! */ |
---|
164 | |
---|
165 | /* get colourmap if coloured screen */ |
---|
166 | xwv_colored = ((XDefaultVisualOfScreen(xwv_screen))->class == TrueColor |
---|
167 | || (XDefaultVisualOfScreen(xwv_screen))->class == PseudoColor |
---|
168 | || (XDefaultVisualOfScreen(xwv_screen))->class == DirectColor |
---|
169 | || (XDefaultVisualOfScreen(xwv_screen))->class == StaticColor); |
---|
170 | if (xwv_colored) |
---|
171 | xwv_cmap = XDefaultColormapOfScreen( xwv_screen ); |
---|
172 | |
---|
173 | /* create GC's */ |
---|
174 | xwv_default_gc = XCreateGC( xwv_dsp, XRootWindowOfScreen(xwv_screen), |
---|
175 | 0, NULL ); |
---|
176 | xwv_default_fore = XBlackPixelOfScreen(xwv_screen); |
---|
177 | xwv_default_back = XWhitePixelOfScreen(xwv_screen); |
---|
178 | XSetForeground( xwv_dsp, xwv_default_gc, xwv_default_fore ); |
---|
179 | XSetBackground( xwv_dsp, xwv_default_gc, xwv_default_back ); |
---|
180 | for (i=0; i<MAXSTYLE; i++) { |
---|
181 | xwv_gc[i] = XCreateGC( xwv_dsp, XRootWindowOfScreen(xwv_screen), |
---|
182 | 0, NULL ); |
---|
183 | XSetForeground( xwv_dsp, xwv_gc[i], xwv_default_fore ); |
---|
184 | XSetBackground( xwv_dsp, xwv_gc[i], xwv_default_back ); |
---|
185 | } /*endfor*/ |
---|
186 | xwv_default_font = XQueryFont( xwv_dsp, XGContextFromGC(xwv_gc[0]) ); |
---|
187 | for (i=0; i<MAXSTYLE; i++) |
---|
188 | xwv_font[i] = xwv_default_font; |
---|
189 | |
---|
190 | xwv_dspinit = TRUE; |
---|
191 | } /*endif*/ |
---|
192 | |
---|
193 | wdw &= NUMMASK; |
---|
194 | if (xwh_illegalwdw(wdw)) { |
---|
195 | *status = XWE_ILWDW; |
---|
196 | return; |
---|
197 | } /*endif*/ |
---|
198 | |
---|
199 | if ((1 << wdw) & xwv_ison) { |
---|
200 | *status = XWE_WOPNTWICE; |
---|
201 | return; |
---|
202 | } /*endif*/ |
---|
203 | ww = (int)(width*X_PIX_PER_CM); |
---|
204 | wh = (int)(height*Y_PIX_PER_CM); |
---|
205 | wx = (int)(xlo*X_PIX_PER_CM); |
---|
206 | wy = XHeightOfScreen(xwv_screen) - (int)(ylo*Y_PIX_PER_CM) - wh; |
---|
207 | xswa.event_mask = EVENTS; |
---|
208 | xswa.background_pixel = xwv_default_back; |
---|
209 | xswa.border_pixel = xwv_default_fore; |
---|
210 | xswa.override_redirect = True; |
---|
211 | xswa.save_under = True; |
---|
212 | xswa.backing_store = WhenMapped; |
---|
213 | xswa.border_pixmap = CopyFromParent; |
---|
214 | xwv_wdw[wdw] = XCreateWindow( xwv_dsp, XRootWindowOfScreen(xwv_screen), |
---|
215 | wx, wy, ww, wh, 4, XDefaultDepthOfScreen(xwv_screen), InputOutput, |
---|
216 | XDefaultVisualOfScreen(xwv_screen), |
---|
217 | CWEventMask|CWBackPixel|CWBorderPixel| /*CWOverrideRedirect|*/ |
---|
218 | CWBackingStore|CWSaveUnder|CWBorderPixmap, |
---|
219 | &xswa ); |
---|
220 | xsh.x = wx; xsh.y = wy; xsh.width = ww; xsh.height = wh; |
---|
221 | xsh.flags = PPosition | PSize; |
---|
222 | XSetNormalHints( xwv_dsp, xwv_wdw[wdw], &xsh ); |
---|
223 | xwmh.flags = InputHint; |
---|
224 | xwmh.input = (attribs & XWF_WINPUT); |
---|
225 | XSetWMHints( xwv_dsp, xwv_wdw[wdw], &xwmh ); |
---|
226 | XMapWindow( xwv_dsp, xwv_wdw[wdw] ); |
---|
227 | xwv_wxpos[wdw] = XWRITEOFF; |
---|
228 | xwv_wypos[wdw] = xwh_getfontheight(DEFSTYLE) + YWRITEOFF; |
---|
229 | xwv_ison |= (1 << wdw); |
---|
230 | sprintf( str, "Wdw %d", wdw ); |
---|
231 | XChangeProperty( xwv_dsp, xwv_wdw[wdw], XA_WM_NAME, XA_STRING, 8, |
---|
232 | PropModeReplace, str, strlen(str) ); |
---|
233 | |
---|
234 | xw_setcoo( wdw, 0., 0., DEFAULTWIDTH, DEFAULTHEIGHT, status ); |
---|
235 | |
---|
236 | xw_updatewdw(); |
---|
237 | |
---|
238 | } /* end of xw_init */ |
---|
239 | |
---|
240 | |
---|
241 | |
---|
242 | /*----------------------------------------------------------------------------*/ |
---|
243 | |
---|
244 | |
---|
245 | |
---|
246 | void xw_resizewdw( WDW wdw, float x, float y, float w, float h, |
---|
247 | STATUS *status ) |
---|
248 | |
---|
249 | /* resizes and repositions window |
---|
250 | * |
---|
251 | * parameters of routine |
---|
252 | * WDW wdw; input; window number |
---|
253 | * float x, y; input; new position of window (in cm) |
---|
254 | * float w, h; input; new size of window (in cm) |
---|
255 | * STATUS *status; output; return status |
---|
256 | */ |
---|
257 | { |
---|
258 | /* local variables */ |
---|
259 | int wx, wy; /* new position (window coordinates) */ |
---|
260 | int ww, wh; /* new size (window coordinates) */ |
---|
261 | XSizeHints xsh; /* size hints */ |
---|
262 | |
---|
263 | /* executable code */ |
---|
264 | |
---|
265 | wdw &= NUMMASK; |
---|
266 | if (!xwh_wdwopen(wdw)) return; |
---|
267 | |
---|
268 | ww = (int)(w*X_PIX_PER_CM); |
---|
269 | wh = (int)(h*Y_PIX_PER_CM); |
---|
270 | wx = (int)(x*X_PIX_PER_CM); |
---|
271 | wy = XHeightOfScreen(xwv_screen) - (int)(y*Y_PIX_PER_CM) - wh; |
---|
272 | xsh.x = wx; xsh.y = wy; xsh.width = ww; xsh.height = wh; |
---|
273 | xsh.flags = PPosition | PSize; |
---|
274 | XSetNormalHints( xwv_dsp, xwv_wdw[wdw], &xsh ); |
---|
275 | /* XMoveResizeWindow( xwv_dsp, xwv_wdw[wdw], wx, wy, ww, wh ); */ |
---|
276 | /* XSynchronize( xwv_dsp, 1 ); */ |
---|
277 | |
---|
278 | } /* end of xw_resizewdw */ |
---|
279 | |
---|
280 | |
---|
281 | |
---|
282 | /*----------------------------------------------------------------------------*/ |
---|
283 | |
---|
284 | |
---|
285 | |
---|
286 | void xw_exit( WDW wdw ) |
---|
287 | |
---|
288 | /* closes window |
---|
289 | * |
---|
290 | * parameters of routine |
---|
291 | * WDW wdw; input; window number |
---|
292 | */ |
---|
293 | { |
---|
294 | /* local variables */ |
---|
295 | int dmy=0; |
---|
296 | |
---|
297 | /* executable code */ |
---|
298 | |
---|
299 | wdw &= NUMMASK; |
---|
300 | if ((1<<wdw) & xwv_ison) { |
---|
301 | XUnmapWindow( xwv_dsp, xwv_wdw[wdw] ); |
---|
302 | XDestroyWindow( xwv_dsp, xwv_wdw[wdw] ); |
---|
303 | xwv_ison &= ~(1<<wdw); |
---|
304 | } /*endif*/ |
---|
305 | |
---|
306 | } /* end of xw_exit */ |
---|
307 | |
---|
308 | |
---|
309 | |
---|
310 | /*----------------------------------------------------------------------------*/ |
---|
311 | |
---|
312 | |
---|
313 | |
---|
314 | void xw_finish( void ) |
---|
315 | |
---|
316 | /* closes all open windows |
---|
317 | * |
---|
318 | * no parameters |
---|
319 | */ |
---|
320 | { |
---|
321 | /* executable code */ |
---|
322 | |
---|
323 | if (xwv_dspinit) { |
---|
324 | XCloseDisplay( xwv_dsp ); |
---|
325 | xwv_dspinit = FALSE; |
---|
326 | } /*endif*/ |
---|
327 | |
---|
328 | } /* end of xw_finish */ |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | /*----------------------------------------------------------------------------*/ |
---|
333 | |
---|
334 | |
---|
335 | |
---|
336 | void xw_erase( WDW wdw ) |
---|
337 | |
---|
338 | /* clears window |
---|
339 | * |
---|
340 | * parameters of routine |
---|
341 | * WDW wdw; input; window number |
---|
342 | */ |
---|
343 | { |
---|
344 | /* local variables */ |
---|
345 | int dmy; |
---|
346 | |
---|
347 | /* executable code */ |
---|
348 | |
---|
349 | wdw &= NUMMASK; |
---|
350 | if (xwh_wdwopen(wdw)) { |
---|
351 | XClearWindow( xwv_dsp, xwv_wdw[wdw] ); |
---|
352 | XFlush( xwv_dsp ); |
---|
353 | xwv_wxpos[wdw] = XWRITEOFF; |
---|
354 | xwv_wypos[wdw] = xwh_getfontheight(DEFSTYLE) + YWRITEOFF; |
---|
355 | xwv_wstr[wdw][0] = '\0'; |
---|
356 | } /*endif*/ |
---|
357 | |
---|
358 | } /* end of xw_erase */ |
---|
359 | |
---|
360 | |
---|
361 | |
---|
362 | /*----------------------------------------------------------------------------*/ |
---|
363 | |
---|
364 | |
---|
365 | |
---|
366 | void xw_popwdw( WDW wdw ) |
---|
367 | |
---|
368 | /* pops window on top of the others |
---|
369 | * |
---|
370 | * parameters of routine |
---|
371 | * WDW wdw; input; window number |
---|
372 | */ |
---|
373 | { |
---|
374 | /* local variables */ |
---|
375 | /* XImage *img; */ /* image */ |
---|
376 | /* int ww, wh, depth;*/ /* window size & depth */ |
---|
377 | |
---|
378 | /* executable code */ |
---|
379 | |
---|
380 | wdw &= NUMMASK; |
---|
381 | if (xwh_wdwopen(wdw)) { |
---|
382 | # ifdef KSTEST |
---|
383 | xwh_getwdwsize( wdw, &ww, &wh ); |
---|
384 | depth = xwh_wdwdepth( wdw ); |
---|
385 | img = XGetImage( xwv_dsp, xwv_wdw[wdw], 0, 0, ww, wh, -1, ZPixmap ); |
---|
386 | # endif |
---|
387 | XSynchronize( xwv_dsp, TRUE ); |
---|
388 | XRaiseWindow( xwv_dsp, xwv_wdw[wdw] ); |
---|
389 | XFlush( xwv_dsp ); |
---|
390 | XSynchronize( xwv_dsp, FALSE ); |
---|
391 | # ifdef KSTEST |
---|
392 | XPutImage( xwv_dsp, xwv_wdw[wdw], xwv_gc[wdw], img, 0, 0, 0, 0, ww, wh ); |
---|
393 | XDestroyImage( img ); |
---|
394 | # endif |
---|
395 | } /*endif*/ |
---|
396 | |
---|
397 | } /* end of xw_popwdw */ |
---|
398 | |
---|
399 | |
---|
400 | |
---|
401 | /*----------------------------------------------------------------------------*/ |
---|
402 | |
---|
403 | |
---|
404 | |
---|
405 | void xw_pushwdw( WDW wdw ) |
---|
406 | |
---|
407 | /* pushes window below the others |
---|
408 | * |
---|
409 | * parameters of routine |
---|
410 | * WDW wdw; input; window number |
---|
411 | */ |
---|
412 | { |
---|
413 | /* executable code */ |
---|
414 | |
---|
415 | wdw &= NUMMASK; |
---|
416 | if (xwh_wdwopen(wdw)) { |
---|
417 | XSynchronize( xwv_dsp, TRUE ); |
---|
418 | XLowerWindow( xwv_dsp, xwv_wdw[wdw] ); |
---|
419 | XSynchronize( xwv_dsp, FALSE ); |
---|
420 | } /*endif*/ |
---|
421 | |
---|
422 | } /* end of xw_pushwdw */ |
---|
423 | |
---|
424 | |
---|
425 | |
---|
426 | /*----------------------------------------------------------------------------*/ |
---|
427 | |
---|
428 | |
---|
429 | |
---|
430 | void xw_setwdwname( WDW wdw, char name[] ) |
---|
431 | |
---|
432 | /* set new name of window |
---|
433 | * |
---|
434 | * parameters of routine |
---|
435 | * WDW wdw; input; window number |
---|
436 | * char name[]; input; new name |
---|
437 | */ |
---|
438 | { |
---|
439 | /* executable code */ |
---|
440 | |
---|
441 | wdw &= NUMMASK; |
---|
442 | if xwh_wdwopen(wdw) |
---|
443 | XChangeProperty( xwv_dsp, xwv_wdw[wdw], XA_WM_NAME, XA_STRING, 8, |
---|
444 | PropModeReplace, name, strlen(name) ); |
---|
445 | |
---|
446 | } /* end of xw_setwdwname */ |
---|
447 | |
---|
448 | |
---|
449 | |
---|
450 | /*----------------------------------------------------------------------------*/ |
---|
451 | |
---|
452 | |
---|
453 | |
---|
454 | void xw_setcoo( WDW wdw, XWCOO x, XWCOO y, XWCOO w, XWCOO h, |
---|
455 | STATUS *status ) |
---|
456 | |
---|
457 | /* sets new user coordinate system |
---|
458 | * |
---|
459 | * parameters of routine |
---|
460 | * WDW wdw; input; channel map |
---|
461 | * XWCOO x, y; input; origin of user coordinates |
---|
462 | * XWCOO w, h; input; size of user coordinates |
---|
463 | * STATUS *status; output; return status |
---|
464 | */ |
---|
465 | { |
---|
466 | /* local variables */ |
---|
467 | int ww, wh; /* window size */ |
---|
468 | |
---|
469 | /* executable code */ |
---|
470 | |
---|
471 | wdw &= NUMMASK; |
---|
472 | if (!xwh_wdwopen(wdw)) return; |
---|
473 | |
---|
474 | xwh_getwdwsize( wdw, &ww, &wh ); |
---|
475 | xwv_txfac[wdw] = (float)ww / (float)w; |
---|
476 | xwv_tyfac[wdw] = -(float)wh / (float)h; |
---|
477 | xwv_txoff[wdw] = x * xwv_txfac[wdw]; |
---|
478 | xwv_tyoff[wdw] = xwv_tyfac[wdw]*y - wh; |
---|
479 | |
---|
480 | xwv_userh = h; |
---|
481 | |
---|
482 | } /* end of xw_setcoo */ |
---|
483 | |
---|
484 | |
---|
485 | |
---|
486 | /*----------------------------------------------------------------------------*/ |
---|
487 | |
---|
488 | |
---|
489 | |
---|
490 | void xw_moveto( WDW wdw, XWCOO x, XWCOO y ) |
---|
491 | |
---|
492 | /* moves to position (x,y) in user coordinates |
---|
493 | * |
---|
494 | * parameters of routine |
---|
495 | * WDW wdw; input; window number |
---|
496 | * XWCOO x, y; input; position to be moved to |
---|
497 | */ |
---|
498 | { |
---|
499 | /* local variables */ |
---|
500 | int mfstatus; /* mf return status */ |
---|
501 | |
---|
502 | /* executable code */ |
---|
503 | |
---|
504 | wdw &= NUMMASK; |
---|
505 | if (xwh_wdwopen(wdw)) { |
---|
506 | xwv_gxpos[wdw] = x; |
---|
507 | xwv_gypos[wdw] = y; |
---|
508 | } /*endif*/ |
---|
509 | |
---|
510 | } /* end of xw_moveto */ |
---|
511 | |
---|
512 | |
---|
513 | |
---|
514 | /*----------------------------------------------------------------------------*/ |
---|
515 | |
---|
516 | |
---|
517 | |
---|
518 | void xw_drawto( WDW wdw, int style, XWCOO x, XWCOO y ) |
---|
519 | |
---|
520 | /* moves to position (x,y) in user coordinates |
---|
521 | * |
---|
522 | * parameters of routine |
---|
523 | * WDW wdw; input; window number |
---|
524 | * int style; input; style block number |
---|
525 | * XWCOO x, y; input; position to be moved to |
---|
526 | */ |
---|
527 | { |
---|
528 | /* local variables */ |
---|
529 | int u0, v0; /* start position (wdw coordinates) */ |
---|
530 | int u1, v1; /* end position (wdw coordinates) */ |
---|
531 | int mfstatus; /* mf return status */ |
---|
532 | |
---|
533 | /* executable code */ |
---|
534 | |
---|
535 | wdw &= NUMMASK; |
---|
536 | if (style < 0 || style >= MAXSTYLE) |
---|
537 | style = DEFSTYLE; |
---|
538 | |
---|
539 | if (xwh_wdwopen(wdw)) { |
---|
540 | xwh_transform( wdw, xwv_gxpos[wdw], xwv_gypos[wdw], &u0, &v0 ); |
---|
541 | xwh_transform( wdw, x, y, &u1, &v1 ); |
---|
542 | XDrawLine( xwv_dsp, xwv_wdw[wdw], xwv_gc[style], u0, v0, u1, v1 ); |
---|
543 | /* XSynchronize( xwv_dsp, 1 ); */ |
---|
544 | /* XFlush( xwv_dsp ); */ |
---|
545 | xwv_gxpos[wdw] = x; |
---|
546 | xwv_gypos[wdw] = y; |
---|
547 | } /*endif*/ |
---|
548 | |
---|
549 | } /* end of xw_drawto */ |
---|
550 | |
---|
551 | |
---|
552 | |
---|
553 | /*----------------------------------------------------------------------------*/ |
---|
554 | |
---|
555 | |
---|
556 | |
---|
557 | void xw_arrayplot( WDW wdw, int style, long cnt, int red, XWCOO xoff, |
---|
558 | XWCOO xinc, XWCOO yoff, XWCOO yarr[], XWCOO yzoom, STATUS *status ) |
---|
559 | |
---|
560 | /* plots an array of data |
---|
561 | * |
---|
562 | * parameters of routine |
---|
563 | * WDW wdw; input; window number |
---|
564 | * int style; input; style block number |
---|
565 | * long cnt; input; length of data array |
---|
566 | * int red; input; reduction factor |
---|
567 | * XWCOO xoff; input; x-position of first sample |
---|
568 | * XWCOO xinc; input; x increment |
---|
569 | * XWCOO yoff; input; y-position of first sample |
---|
570 | * XWCOO yarr[]; input; data array |
---|
571 | * float yzoom; input; zoom factor in y-direction |
---|
572 | * STATUS *status; output; return status |
---|
573 | */ |
---|
574 | /* #define MAXPLOT 16000 */ |
---|
575 | #define MAXPLOT 4000 |
---|
576 | { |
---|
577 | /* local variables */ |
---|
578 | XWCOO *yptr; /* moving pointer */ |
---|
579 | XWCOO lx, ly; /* scratch values */ |
---|
580 | XPoint *pxy; /* multiple lines */ |
---|
581 | XPoint *p; /* moving pointer */ |
---|
582 | long drawlth; /* number of points to draw */ |
---|
583 | long currdraw; /* current draw length */ |
---|
584 | long drawn; /* points already drawn */ |
---|
585 | long i; /* counter */ |
---|
586 | int ix, iy; /* window coordinates */ |
---|
587 | |
---|
588 | /* executable code */ |
---|
589 | |
---|
590 | wdw &= NUMMASK; |
---|
591 | if (cnt == 0L) return; |
---|
592 | if (red <= 0) return; |
---|
593 | if (style < 0 || style >= MAXSTYLE) |
---|
594 | style = DEFSTYLE; |
---|
595 | |
---|
596 | drawlth = cnt / red; |
---|
597 | if ((red > 1) && ((cnt % red) != 0)) |
---|
598 | drawlth++; |
---|
599 | |
---|
600 | if (xwh_wdwopen(wdw)) { |
---|
601 | pxy = (XPoint *)sy_allocmem( drawlth, sizeof(XPoint), status ); |
---|
602 | if Severe(status) return; |
---|
603 | yptr = yarr; |
---|
604 | p = pxy; |
---|
605 | for (i=0; i<drawlth; i++) { |
---|
606 | lx = xoff + xinc*(XWCOO)(red*i); |
---|
607 | ly = yoff + yzoom * (*yptr); |
---|
608 | ASWAP(lx,ly) |
---|
609 | xwh_transform( wdw, lx, ly, &ix, &iy ); |
---|
610 | p->x = ix; |
---|
611 | p->y = iy; |
---|
612 | p++; |
---|
613 | yptr += red; |
---|
614 | } /*endwhile*/ |
---|
615 | if (drawlth > MAXPLOT) { |
---|
616 | drawn = 0; |
---|
617 | do { |
---|
618 | currdraw = drawlth - drawn; |
---|
619 | if (currdraw > MAXPLOT) currdraw = MAXPLOT-1; |
---|
620 | if (drawn > 0) { |
---|
621 | XDrawLines( xwv_dsp, xwv_wdw[wdw], xwv_gc[style], |
---|
622 | pxy+drawn-1, currdraw+1, CoordModeOrigin ); |
---|
623 | } else { |
---|
624 | XDrawLines( xwv_dsp, xwv_wdw[wdw], xwv_gc[style], |
---|
625 | pxy, currdraw, CoordModeOrigin ); |
---|
626 | } /*endif*/ |
---|
627 | drawn += currdraw; |
---|
628 | } while (drawn < drawlth); |
---|
629 | } else { |
---|
630 | XDrawLines( xwv_dsp, xwv_wdw[wdw], xwv_gc[style], pxy, drawlth, |
---|
631 | CoordModeOrigin ); |
---|
632 | } /*endif*/ |
---|
633 | sy_deallocmem( pxy ); |
---|
634 | } /*endif*/ |
---|
635 | |
---|
636 | } /* end of xw_arrayplot */ |
---|
637 | |
---|
638 | |
---|
639 | |
---|
640 | /*----------------------------------------------------------------------------*/ |
---|
641 | |
---|
642 | |
---|
643 | |
---|
644 | void xw_text( WDW wdw, int style, XWCOO x, XWCOO y, char text[] ) |
---|
645 | |
---|
646 | /* writes text at position (x,y) |
---|
647 | * |
---|
648 | * parameters of routine |
---|
649 | * WDW wdw; input; window number |
---|
650 | * int style; input; style block number |
---|
651 | * XWCOO x, y; input; position of text |
---|
652 | * char text[]; input; text to be written |
---|
653 | */ |
---|
654 | { |
---|
655 | /* local variables */ |
---|
656 | int wx, wy; /* window coordinates */ |
---|
657 | int mfstatus; /* mf return status */ |
---|
658 | |
---|
659 | /* executable code */ |
---|
660 | |
---|
661 | wdw &= NUMMASK; |
---|
662 | if (style < 0 || style >= MAXSTYLE) |
---|
663 | style = DEFSTYLE; |
---|
664 | |
---|
665 | if (xwh_wdwopen(wdw)) { |
---|
666 | xwh_transform( wdw, x, y, &wx, &wy ); |
---|
667 | XDrawString( xwv_dsp, xwv_wdw[wdw], xwv_gc[style], |
---|
668 | wx, wy, text, (int)strlen(text) ); |
---|
669 | } /*endif*/ |
---|
670 | |
---|
671 | xwv_laststyle = style; |
---|
672 | |
---|
673 | } /* end of xw_text */ |
---|
674 | |
---|
675 | |
---|
676 | |
---|
677 | /*----------------------------------------------------------------------------*/ |
---|
678 | |
---|
679 | |
---|
680 | |
---|
681 | void xw_wrtch( WDW wdw, char ch ) |
---|
682 | |
---|
683 | /* writes single character to current write position |
---|
684 | * |
---|
685 | * parameters of routine |
---|
686 | * WDW wdw; input; window number |
---|
687 | * char ch; input; character to be written |
---|
688 | */ |
---|
689 | { |
---|
690 | /* local variables */ |
---|
691 | char cs[2]; /* "string" */ |
---|
692 | |
---|
693 | /* executable code */ |
---|
694 | |
---|
695 | wdw &= NUMMASK; |
---|
696 | if (xwh_wdwopen(wdw)) { |
---|
697 | *cs = ch; |
---|
698 | cs[1] = '\0'; |
---|
699 | if (ch == DEL) { |
---|
700 | xw_wrtch( wdw, BS ); |
---|
701 | xw_wrtch( wdw, ' ' ); |
---|
702 | xw_wrtch( wdw, BS ); |
---|
703 | } else if (ch == BS) { |
---|
704 | xwv_wxpos[wdw] -= xwh_getfontwidth( DEFSTYLE ); |
---|
705 | } else if (ch == '\n') { |
---|
706 | xwh_newline( wdw ); |
---|
707 | } else { |
---|
708 | XDrawImageString( xwv_dsp, xwv_wdw[wdw], xwv_gc[DEFSTYLE], |
---|
709 | xwv_wxpos[wdw], xwv_wypos[wdw], cs, 1 ); |
---|
710 | xwv_wxpos[wdw] += xwh_getfontwidth( DEFSTYLE ); |
---|
711 | } /*endif*/ |
---|
712 | } /*endif*/ |
---|
713 | |
---|
714 | } /* xw_wrtch */ |
---|
715 | |
---|
716 | |
---|
717 | |
---|
718 | /*----------------------------------------------------------------------------*/ |
---|
719 | |
---|
720 | |
---|
721 | |
---|
722 | void xw_write( WDW wdw, char text[] ) |
---|
723 | |
---|
724 | /* writes text at the current write position |
---|
725 | * |
---|
726 | * parameters of routine |
---|
727 | * WDW wdw; input; window number |
---|
728 | * char text[]; input; text to be written |
---|
729 | */ |
---|
730 | { |
---|
731 | /* local variables */ |
---|
732 | BOOLEAN newline; /* newline at end */ |
---|
733 | int txtlth; /* length of text */ |
---|
734 | |
---|
735 | /* executable code */ |
---|
736 | |
---|
737 | wdw &= NUMMASK; |
---|
738 | if (xwh_wdwopen(wdw)) { |
---|
739 | |
---|
740 | if (*text == '\n') { |
---|
741 | xwh_newline( wdw ); |
---|
742 | text++; |
---|
743 | } /*endif*/ |
---|
744 | |
---|
745 | /* check <CR> at end */ |
---|
746 | txtlth = (int)strlen( text ); |
---|
747 | if (txtlth == 0) return; |
---|
748 | strncpy( xwv_wstr[wdw], text, MAXSTORESTR ); |
---|
749 | newline = (text[txtlth-1] == '\n'); |
---|
750 | if (newline) |
---|
751 | text[--txtlth] = '\0'; |
---|
752 | |
---|
753 | XDrawImageString( xwv_dsp, xwv_wdw[wdw], xwv_gc[DEFSTYLE], |
---|
754 | xwv_wxpos[wdw], xwv_wypos[wdw], text, txtlth ); |
---|
755 | |
---|
756 | if (newline) { |
---|
757 | text[txtlth] = '\n'; |
---|
758 | xwh_newline( wdw ); |
---|
759 | } else { |
---|
760 | xwv_wxpos[wdw] += XTextWidth( xwv_font[DEFSTYLE], text, txtlth ); |
---|
761 | } /*endif*/ |
---|
762 | |
---|
763 | } /*endif*/ |
---|
764 | |
---|
765 | } /* end of xw_write */ |
---|
766 | |
---|
767 | |
---|
768 | |
---|
769 | /*----------------------------------------------------------------------------*/ |
---|
770 | |
---|
771 | |
---|
772 | |
---|
773 | void xw_read( WDW wdw, int maxlth, char text[] ) |
---|
774 | |
---|
775 | /* reads text string from window |
---|
776 | * |
---|
777 | * parameters of routine |
---|
778 | * WDW wdw; input; channel map |
---|
779 | * int maxlth; input; maximum length of string |
---|
780 | * char text[]; output; string read |
---|
781 | */ |
---|
782 | { |
---|
783 | /* local variables */ |
---|
784 | int i; /* counter */ |
---|
785 | |
---|
786 | /* executable code */ |
---|
787 | |
---|
788 | wdw &= NUMMASK; |
---|
789 | if (xwh_wdwopen(wdw)) { |
---|
790 | XGrabKeyboard( xwv_dsp, xwv_wdw[wdw], True, |
---|
791 | GrabModeAsync, GrabModeAsync, CurrentTime ); |
---|
792 | i = 0; |
---|
793 | while (i < maxlth) { |
---|
794 | xwh_read_character( text+i ); |
---|
795 | if ((text[i] == CR) || (text[i] == LF)) { |
---|
796 | text[i] = '\0'; |
---|
797 | break; |
---|
798 | } else if ((text[i] == BS) || (text[i] == DEL)) { |
---|
799 | if (i != 0) { |
---|
800 | xw_wrtch( wdw, DEL ); |
---|
801 | text[i--] = '\0'; |
---|
802 | } /*endif*/ |
---|
803 | } else if (text[i] == '\t') { |
---|
804 | text[i] = ' '; |
---|
805 | xw_wrtch( wdw, text[i++] ); |
---|
806 | } else if (text[i] == ESC) { |
---|
807 | for (;i>0;i--) { |
---|
808 | xw_wrtch( wdw, DEL ); |
---|
809 | text[i] = '\0'; |
---|
810 | } /*endfor*/ |
---|
811 | *text = '\0'; |
---|
812 | } else if (text[i] >= ' ') { |
---|
813 | xw_wrtch( wdw, text[i++] ); |
---|
814 | } /*endif*/ |
---|
815 | } /*endwhile*/ |
---|
816 | xwh_newline( wdw ); |
---|
817 | XUngrabKeyboard( xwv_dsp, CurrentTime ); |
---|
818 | } /*endif*/ |
---|
819 | |
---|
820 | } /* end of xwc_read */ |
---|
821 | |
---|
822 | |
---|
823 | |
---|
824 | /*----------------------------------------------------------------------------*/ |
---|
825 | |
---|
826 | |
---|
827 | |
---|
828 | void xw_getloc( WDW wdw, XWCOO *x, XWCOO *y, char *ch ) |
---|
829 | |
---|
830 | /* returns user selected mouse position and key |
---|
831 | * |
---|
832 | * parameters of routine |
---|
833 | * WDW wdw; input; window number |
---|
834 | * XWCOO *x, *y; output; selected position |
---|
835 | * char *ch; output; selected key (mouse button = '@') |
---|
836 | */ |
---|
837 | { |
---|
838 | /* local variables */ |
---|
839 | XEvent event; /* event */ |
---|
840 | XEvent evcop; /* other event */ |
---|
841 | BOOLEAN quit; /* quit loop */ |
---|
842 | int dmy; /* scratch */ |
---|
843 | int xpos, ypos; /* cursor position */ |
---|
844 | GC cross_gc; /* crosshair cursors's GC */ |
---|
845 | Cursor crsr; /* mouse form */ |
---|
846 | WDW rdw; /* redraw window */ |
---|
847 | int rdmap; /* window redraw map */ |
---|
848 | XColor screen_color, exact_color; /* color values */ |
---|
849 | Status xstatus; /* X return status */ |
---|
850 | |
---|
851 | /* #define REDCROSS */ |
---|
852 | |
---|
853 | /* executable code */ |
---|
854 | |
---|
855 | wdw &= NUMMASK; |
---|
856 | if (xwh_wdwopen(wdw)) { |
---|
857 | |
---|
858 | /* XSynchronize( xwv_dsp, 1 ); */ |
---|
859 | XFlush( xwv_dsp ); |
---|
860 | cross_gc = XCreateGC( xwv_dsp, xwv_wdw[wdw], 0, NULL ); |
---|
861 | if (GpGetBoolean(cGpB_reverse_xors)) { |
---|
862 | XSetForeground( xwv_dsp, cross_gc, xwv_default_back ); |
---|
863 | XSetBackground( xwv_dsp, cross_gc, xwv_default_fore ); |
---|
864 | } else { |
---|
865 | XSetForeground( xwv_dsp, cross_gc, xwv_default_fore ); |
---|
866 | XSetBackground( xwv_dsp, cross_gc, xwv_default_back ); |
---|
867 | } /*endif*/ |
---|
868 | XSetFunction( xwv_dsp, cross_gc, GXxor ); |
---|
869 | XGrabKeyboard( xwv_dsp, xwv_wdw[wdw], True, |
---|
870 | GrabModeAsync, GrabModeAsync, CurrentTime ); |
---|
871 | XSelectInput( xwv_dsp, xwv_wdw[wdw], |
---|
872 | EVENTS|ButtonPressMask|PointerMotionMask ); |
---|
873 | quit = FALSE; |
---|
874 | rdmap = 0; |
---|
875 | |
---|
876 | /* clear keyboard & button press buffer */ |
---|
877 | while (XCheckWindowEvent(xwv_dsp,xwv_wdw[wdw],KeyPressMask,&evcop)); |
---|
878 | while (XCheckWindowEvent(xwv_dsp,xwv_wdw[wdw],ButtonPressMask,&evcop)); |
---|
879 | |
---|
880 | /* change mouse form to cross */ |
---|
881 | crsr = XCreateFontCursor( xwv_dsp, XC_crosshair ); |
---|
882 | XDefineCursor( xwv_dsp, xwv_wdw[wdw], crsr ); |
---|
883 | |
---|
884 | /* draw centered crosshair cursor */ |
---|
885 | xwh_getwdwsize( wdw, &xpos, &ypos ); |
---|
886 | xpos /= 2.0; ypos /= 2.0; |
---|
887 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
888 | |
---|
889 | do { |
---|
890 | |
---|
891 | XNextEvent( xwv_dsp, &event ); |
---|
892 | |
---|
893 | switch (event.type) { |
---|
894 | case Expose: |
---|
895 | /* delete all other Expose events of the same window */ |
---|
896 | while (XCheckWindowEvent(xwv_dsp,event.xexpose.window, |
---|
897 | ExposureMask,&evcop)) |
---|
898 | event = evcop; |
---|
899 | dmy = XWE_NOERROR; |
---|
900 | rdw = xwh_findwdw( event.xexpose.window ); |
---|
901 | if ((rdw >= 0) && !((1<<rdw) & rdmap)) { |
---|
902 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
903 | xw_redraw( rdw, &dmy ); |
---|
904 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
905 | rdmap |= (1<<rdw); |
---|
906 | } /*endif*/ |
---|
907 | break; |
---|
908 | case ButtonPress: |
---|
909 | if (event.xbutton.window == xwv_wdw[wdw]) { |
---|
910 | *ch = '@'; |
---|
911 | xwh_backtrans( wdw, event.xbutton.x, event.xbutton.y, x, y ); |
---|
912 | quit = TRUE; |
---|
913 | } /*endif*/ |
---|
914 | break; |
---|
915 | case KeyPress: |
---|
916 | dmy = XLookupString( &(event.xkey), ch, 1, NULL, NULL ); |
---|
917 | xwh_backtrans( wdw, event.xkey.x, event.xkey.y, x, y ); |
---|
918 | quit = TRUE; |
---|
919 | break; |
---|
920 | case MotionNotify: |
---|
921 | while (XCheckWindowEvent(xwv_dsp,xwv_wdw[wdw], |
---|
922 | PointerMotionMask,&evcop)) { |
---|
923 | event = evcop; |
---|
924 | } /*endwhile*/ |
---|
925 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
926 | xpos = event.xmotion.x; |
---|
927 | ypos = event.xmotion.y; |
---|
928 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
929 | break; |
---|
930 | case FocusIn: |
---|
931 | while (XCheckWindowEvent(xwv_dsp,xwv_wdw[wdw], |
---|
932 | FocusChangeMask,&evcop)) |
---|
933 | event = evcop; |
---|
934 | dmy = XWE_NOERROR; |
---|
935 | rdw = xwh_findwdw( event.xfocus.window ); |
---|
936 | if ((rdw >= 0) && !((1<<rdw) & rdmap)) { |
---|
937 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
938 | xw_redraw( rdw, &dmy ); |
---|
939 | if (dmy != XWE_NOERROR) quit = TRUE; |
---|
940 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
941 | rdmap |= (1 << rdw); |
---|
942 | } /*endif*/ |
---|
943 | break; |
---|
944 | case FocusOut: |
---|
945 | break; |
---|
946 | default: |
---|
947 | break; |
---|
948 | } /*endswitch*/ |
---|
949 | |
---|
950 | } while (!quit); |
---|
951 | |
---|
952 | xwh_drawcross( wdw, cross_gc, xpos, ypos ); |
---|
953 | XFlush( xwv_dsp ); |
---|
954 | XUndefineCursor( xwv_dsp, xwv_wdw[wdw] ); |
---|
955 | XFreeCursor( xwv_dsp, crsr ); |
---|
956 | XSelectInput( xwv_dsp, xwv_wdw[wdw], EVENTS ); |
---|
957 | XUngrabKeyboard( xwv_dsp, CurrentTime ); |
---|
958 | XFreeGC( xwv_dsp, cross_gc ); |
---|
959 | /* XSynchronize( xwv_dsp, 1 ); */ |
---|
960 | XFlush( xwv_dsp ); |
---|
961 | |
---|
962 | } /*endif*/ |
---|
963 | |
---|
964 | } /* end of xw_getloc */ |
---|
965 | |
---|
966 | |
---|
967 | |
---|
968 | /*----------------------------------------------------------------------------*/ |
---|
969 | |
---|
970 | |
---|
971 | |
---|
972 | void xw_setstyle( WDW wdw, int style, char item[], char value[], |
---|
973 | STATUS *status ) |
---|
974 | |
---|
975 | /* sets attribute in style block number "style" |
---|
976 | * |
---|
977 | * parameters of routine |
---|
978 | * WDW wdw; input; window number |
---|
979 | * int style; input; style block number |
---|
980 | * char item[]; input; description of attribute |
---|
981 | * char value[]; input; new value of attribute (as string expression) |
---|
982 | * STATUS *status; output; return status |
---|
983 | */ |
---|
984 | { |
---|
985 | /* local variables */ |
---|
986 | int num, cnt; |
---|
987 | float r; /* scratch */ |
---|
988 | char **fontlist; /* list of font names */ |
---|
989 | BOOLEAN local_item; /* local item (not available on CC) */ |
---|
990 | |
---|
991 | /* executable code */ |
---|
992 | |
---|
993 | if (!xwv_dspinit) return; |
---|
994 | |
---|
995 | if ((style < 0) || (style > MAXSTYLE)) { |
---|
996 | *status = XWE_ILSTYLE; |
---|
997 | return; |
---|
998 | } /*endif*/ |
---|
999 | |
---|
1000 | wdw &= NUMMASK; |
---|
1001 | local_item = FALSE; |
---|
1002 | if (strcmp(item,"FONT") == 0) { |
---|
1003 | if (xwv_font[style] != xwv_default_font) /* unload font */ |
---|
1004 | XFreeFont( xwv_dsp, xwv_font[style] ); |
---|
1005 | if (strcmp(value,"DEFAULT") == 0) { |
---|
1006 | xwv_font[style] = xwv_default_font; |
---|
1007 | XCopyGC( xwv_dsp, xwv_default_gc, GCFont, xwv_gc[style] ); |
---|
1008 | } else { |
---|
1009 | xwv_font[style] = XLoadQueryFont( xwv_dsp, value ); |
---|
1010 | if (xwv_font[style] == NULL) { |
---|
1011 | /* cannot find font, use default */ |
---|
1012 | xwv_font[style] = xwv_default_font; |
---|
1013 | } else { |
---|
1014 | XSetFont( xwv_dsp, xwv_gc[style], xwv_font[style]->fid ); |
---|
1015 | } /*endif*/ |
---|
1016 | } /*endif*/ |
---|
1017 | } else if (strcmp(item,"CHARSIZE") == 0 || |
---|
1018 | strcmp(item,"CHARHEIGHT") == 0) { |
---|
1019 | if (sscanf(value,"%f",&r) != 1) { |
---|
1020 | *status = XWE_ILVALUE; |
---|
1021 | return; |
---|
1022 | } /*endif*/ |
---|
1023 | num = xwh_getfontnum( wdw, r ); |
---|
1024 | if (num <= 0) return; |
---|
1025 | fontlist = XListFonts( xwv_dsp, "*", num+1, &cnt ); |
---|
1026 | xw_setstyle( wdw, style, "FONT", fontlist[cnt-1], status ); |
---|
1027 | XFreeFontNames( fontlist ); |
---|
1028 | } else if (strcmp(item,"FONTNUM") == 0) { |
---|
1029 | local_item = TRUE; |
---|
1030 | if (sscanf(value,"%d",&num) != 1) { |
---|
1031 | *status = XWE_ILVALUE; |
---|
1032 | return; |
---|
1033 | } /*endif*/ |
---|
1034 | if (num < 0) return; |
---|
1035 | fontlist = XListFonts( xwv_dsp, "*", num+1, &cnt ); |
---|
1036 | if (num >= cnt) num = cnt-1; |
---|
1037 | xw_setstyle( wdw, style, "FONT", fontlist[num], status ); |
---|
1038 | XFreeFontNames( fontlist ); |
---|
1039 | } else if (strcmp(item,"COLOR") == 0) { |
---|
1040 | xwh_setcolor( style, value, status ); |
---|
1041 | } else if (strcmp(item,"LINEWIDTH") == 0) { |
---|
1042 | if (sscanf(value,"%d",&num) != 1) { |
---|
1043 | *status = XWE_ILVALUE; |
---|
1044 | return; |
---|
1045 | } /*endif*/ |
---|
1046 | xwv_lwidth[style] = num; |
---|
1047 | XSetLineAttributes( xwv_dsp, xwv_gc[style], xwv_lwidth[style], |
---|
1048 | xwv_lstyle[style], CapRound, JoinRound ); |
---|
1049 | } else if (strcmp(item,"LINESTYLE") == 0) { |
---|
1050 | if (sscanf(value,"%d",&num) != 1) { |
---|
1051 | *status = XWE_ILVALUE; |
---|
1052 | return; |
---|
1053 | } else if (num < 0 || num >= MAXDEFSTYLE) { |
---|
1054 | *status = XWE_ILVALUE; |
---|
1055 | return; |
---|
1056 | } /*endif*/ |
---|
1057 | xwv_lstyle[style] = xwv_defstyle[num]; |
---|
1058 | XSetLineAttributes( xwv_dsp, xwv_gc[style], xwv_lwidth[style], |
---|
1059 | xwv_lstyle[style], CapRound, JoinRound ); |
---|
1060 | } else if (strcmp(item,"WRMODE") == 0) { |
---|
1061 | if (strcmp(value,"REPLACE") == 0) { |
---|
1062 | XSetForeground( xwv_dsp, xwv_gc[style], xwv_default_fore ); |
---|
1063 | XSetBackground( xwv_dsp, xwv_gc[style], xwv_default_back ); |
---|
1064 | XSetFunction( xwv_dsp, xwv_gc[style], GXcopy ); |
---|
1065 | } else if (strcmp(value,"XOR") == 0) { |
---|
1066 | if (GpGetBoolean(cGpB_reverse_xors)) { |
---|
1067 | XSetForeground( xwv_dsp, xwv_gc[style], xwv_default_back ); |
---|
1068 | XSetBackground( xwv_dsp, xwv_gc[style], xwv_default_fore ); |
---|
1069 | } else { |
---|
1070 | XSetForeground( xwv_dsp, xwv_gc[style], xwv_default_fore ); |
---|
1071 | XSetBackground( xwv_dsp, xwv_gc[style], xwv_default_back ); |
---|
1072 | } /*endif*/ |
---|
1073 | XSetFunction( xwv_dsp, xwv_gc[style], GXxor ); |
---|
1074 | } else { |
---|
1075 | *status = XWE_ILVALUE; |
---|
1076 | return; |
---|
1077 | } /*endif*/ |
---|
1078 | } else { |
---|
1079 | *status = XWE_ILSTYATT; |
---|
1080 | return; |
---|
1081 | } /*endif*/ |
---|
1082 | |
---|
1083 | } /* end of xw_setstyle */ |
---|
1084 | |
---|
1085 | |
---|
1086 | |
---|
1087 | /*----------------------------------------------------------------------------*/ |
---|
1088 | |
---|
1089 | |
---|
1090 | |
---|
1091 | void xw_charsize( WDW wdw, int style, float size, STATUS *status ) |
---|
1092 | |
---|
1093 | /* sets character size in units of display height |
---|
1094 | * |
---|
1095 | * parameters of routine |
---|
1096 | * WDW wdw; input; window ID |
---|
1097 | * int style; input; style number |
---|
1098 | * float size; input; size of character in units of display height |
---|
1099 | * STATUS *status; output; return status |
---|
1100 | */ |
---|
1101 | { |
---|
1102 | /* local variables */ |
---|
1103 | int num; /* font number */ |
---|
1104 | int cnt; /* length of font list */ |
---|
1105 | char **fontlist; /* font list */ |
---|
1106 | |
---|
1107 | /* executable code */ |
---|
1108 | |
---|
1109 | wdw &= NUMMASK; |
---|
1110 | |
---|
1111 | if ((style < 0) || (style >= MAXSTYLE)) { |
---|
1112 | *status = XWE_ILSTYLE; |
---|
1113 | return; |
---|
1114 | } /*endif*/ |
---|
1115 | |
---|
1116 | num = xwh_getfontnum( wdw, size ); |
---|
1117 | if (num <= 0) return; |
---|
1118 | fontlist = XListFonts( xwv_dsp, "*", num+1, &cnt ); |
---|
1119 | xw_setstyle( wdw, style, "FONT", fontlist[cnt-1], status ); |
---|
1120 | XFreeFontNames( fontlist ); |
---|
1121 | |
---|
1122 | } /* end of xw_charsize */ |
---|
1123 | |
---|
1124 | |
---|
1125 | |
---|
1126 | /*----------------------------------------------------------------------------*/ |
---|
1127 | |
---|
1128 | |
---|
1129 | |
---|
1130 | void xw_linestyle( WDW wdw, int style, int linestyle, STATUS *status ) |
---|
1131 | |
---|
1132 | /* sets line linestyle in style block number "style" |
---|
1133 | * |
---|
1134 | * parameters of routine |
---|
1135 | * WDW wdw; input; window ID |
---|
1136 | * int style; input; style block number |
---|
1137 | * int linestyle; input; number of line style |
---|
1138 | * STATUS *status; output; return status |
---|
1139 | */ |
---|
1140 | { |
---|
1141 | /* executable code */ |
---|
1142 | |
---|
1143 | wdw &= NUMMASK; |
---|
1144 | |
---|
1145 | if ((style < 0) || (style >= MAXSTYLE)) { |
---|
1146 | *status = XWE_ILSTYLE; |
---|
1147 | return; |
---|
1148 | } else if (linestyle < 0 || linestyle >= MAXDEFSTYLE) { |
---|
1149 | *status = XWE_ILVALUE; |
---|
1150 | return; |
---|
1151 | } /*endif*/ |
---|
1152 | |
---|
1153 | xwv_lstyle[style] = xwv_defstyle[linestyle]; |
---|
1154 | XSetLineAttributes( xwv_dsp, xwv_gc[style], xwv_lwidth[style], |
---|
1155 | xwv_lstyle[style], CapRound, JoinRound ); |
---|
1156 | |
---|
1157 | } /* end of xw_linestyle */ |
---|
1158 | |
---|
1159 | |
---|
1160 | |
---|
1161 | /*----------------------------------------------------------------------------*/ |
---|
1162 | |
---|
1163 | |
---|
1164 | |
---|
1165 | void xw_linewidth( WDW wdw, int style, int width, STATUS *status ) |
---|
1166 | |
---|
1167 | /* sets line width in pixels in style block "style" |
---|
1168 | * |
---|
1169 | * parameters of routine |
---|
1170 | * WDW wdw; input; window number |
---|
1171 | * int style; input; style block number |
---|
1172 | * int width; input; width of line in pixels |
---|
1173 | * STATUS *status; output; return status |
---|
1174 | */ |
---|
1175 | { |
---|
1176 | /* executable code */ |
---|
1177 | |
---|
1178 | wdw &= NUMMASK; |
---|
1179 | |
---|
1180 | if ((style < 0) || (style >= MAXSTYLE)) { |
---|
1181 | *status = XWE_ILSTYLE; |
---|
1182 | return; |
---|
1183 | } /*endif*/ |
---|
1184 | |
---|
1185 | xwv_lwidth[style] = width; |
---|
1186 | XSetLineAttributes( xwv_dsp, xwv_gc[style], xwv_lwidth[style], |
---|
1187 | xwv_lstyle[style], CapRound, JoinRound ); |
---|
1188 | |
---|
1189 | } /* end of xw_linewidth */ |
---|
1190 | |
---|
1191 | |
---|
1192 | |
---|
1193 | /*----------------------------------------------------------------------------*/ |
---|
1194 | |
---|
1195 | |
---|
1196 | |
---|
1197 | void xw_color( WDW wdw, int style, float red, float green, float blue, |
---|
1198 | STATUS *status ) |
---|
1199 | |
---|
1200 | /* sets color of style block "style" |
---|
1201 | * |
---|
1202 | * parameters of routine |
---|
1203 | * WDW wdw; input; window ID |
---|
1204 | * int style; input; style block number |
---|
1205 | * float red, green, blue; input; red, green and blue intensities (0..1) |
---|
1206 | * STATUS *status; output; return status |
---|
1207 | */ |
---|
1208 | { |
---|
1209 | /* local variables */ |
---|
1210 | char valstr[80]; /* value string */ |
---|
1211 | |
---|
1212 | /* executable code */ |
---|
1213 | |
---|
1214 | if ((style < 0) || (style >= MAXSTYLE)) { |
---|
1215 | *status = XWE_ILSTYLE; |
---|
1216 | return; |
---|
1217 | } /*endif*/ |
---|
1218 | |
---|
1219 | wdw &= NUMMASK; |
---|
1220 | |
---|
1221 | if (red < 0.0) *status = XWE_ILVALUE; |
---|
1222 | if (red > 1.0) *status = XWE_ILVALUE; |
---|
1223 | if (green < 0.0) *status = XWE_ILVALUE; |
---|
1224 | if (green > 1.0) *status = XWE_ILVALUE; |
---|
1225 | if (blue < 0.0) *status = XWE_ILVALUE; |
---|
1226 | if (blue > 1.0) *status = XWE_ILVALUE; |
---|
1227 | if (Severe(status)) return; |
---|
1228 | |
---|
1229 | sprintf( valstr, "%5.3f,%5.3f,%5.3f", red, green, blue ); |
---|
1230 | xwh_setcolor( style, valstr, status ); |
---|
1231 | if (Severe(status)) return; |
---|
1232 | |
---|
1233 | } /* end of xw_color */ |
---|
1234 | |
---|
1235 | |
---|
1236 | |
---|
1237 | /*----------------------------------------------------------------------------*/ |
---|
1238 | |
---|
1239 | |
---|
1240 | |
---|
1241 | XWCOO xw_chheight( WDW wdw ) |
---|
1242 | |
---|
1243 | /* returns char height in user coordinates of last used style |
---|
1244 | * |
---|
1245 | * parameters of routine |
---|
1246 | * WDW wdw; input; window number |
---|
1247 | */ |
---|
1248 | { |
---|
1249 | /* local variables */ |
---|
1250 | int iheight; /* height in pixels */ |
---|
1251 | int wh; /* window height */ |
---|
1252 | |
---|
1253 | /* executable code */ |
---|
1254 | |
---|
1255 | wdw &= NUMMASK; |
---|
1256 | if (!xwh_wdwopen(wdw)) return; |
---|
1257 | iheight = xwv_font[xwv_laststyle]->max_bounds.ascent + |
---|
1258 | xwv_font[xwv_laststyle]->max_bounds.descent; |
---|
1259 | xwh_getwdwsize( wdw, NULL, &wh ); |
---|
1260 | return ((float)iheight/(float)wh * xwv_userh); |
---|
1261 | |
---|
1262 | } /* end of xw_cheight */ |
---|
1263 | |
---|
1264 | |
---|
1265 | |
---|
1266 | /*----------------------------------------------------------------------------*/ |
---|
1267 | |
---|
1268 | |
---|
1269 | |
---|
1270 | void xw_redraw( WDW wdw, STATUS *status ) |
---|
1271 | |
---|
1272 | /* redraws window |
---|
1273 | * |
---|
1274 | * parameters of routine |
---|
1275 | * WDW wdw; input; window number |
---|
1276 | * STATUS *status; output; return status |
---|
1277 | */ |
---|
1278 | { |
---|
1279 | /* local variables */ |
---|
1280 | PAINTBOX pb; /* paintbox routines */ |
---|
1281 | |
---|
1282 | /* executable code */ |
---|
1283 | |
---|
1284 | pb.wpb.pbtype = GBC_WPAINT; |
---|
1285 | pb.wpb.prepare = xw_prepare; |
---|
1286 | pb.wpb.moveto = xw_moveto; |
---|
1287 | pb.wpb.drawto = xw_drawto; |
---|
1288 | pb.wpb.arrayplot = xw_arrayplot; |
---|
1289 | pb.wpb.text = xw_text; |
---|
1290 | pb.wpb.setstyle = xw_setstyle; |
---|
1291 | pb.wpb.setcoo = xw_setcoo; |
---|
1292 | pb.wpb.cleanup = xw_cleanup; |
---|
1293 | (*gbv_playback)( wdw, wdw, &pb, NULL, status ); |
---|
1294 | |
---|
1295 | } /* end of xw_redraw */ |
---|
1296 | |
---|
1297 | |
---|
1298 | |
---|
1299 | /*----------------------------------------------------------------------------*/ |
---|
1300 | |
---|
1301 | |
---|
1302 | |
---|
1303 | void xw_prepare( WDW wdw, STATUS *status ) |
---|
1304 | |
---|
1305 | /* prepares window for redraw |
---|
1306 | * |
---|
1307 | * parameters of routine |
---|
1308 | * WDW wdw; input; window number |
---|
1309 | * STATUS *status; output; return status |
---|
1310 | */ |
---|
1311 | { |
---|
1312 | /* executable code */ |
---|
1313 | |
---|
1314 | xw_erase( wdw ); |
---|
1315 | |
---|
1316 | } /* end of xw_prepare */ |
---|
1317 | |
---|
1318 | |
---|
1319 | |
---|
1320 | /*----------------------------------------------------------------------------*/ |
---|
1321 | |
---|
1322 | |
---|
1323 | |
---|
1324 | void xw_cleanup( WDW wdw, char outf[], STATUS *status ) |
---|
1325 | |
---|
1326 | /* cleanup after redraw. not used here |
---|
1327 | * |
---|
1328 | * parameters of routine |
---|
1329 | * WDW wdw; input; window number |
---|
1330 | * char outf[]; output; name of output file |
---|
1331 | * STATUS *status; output; return status |
---|
1332 | */ |
---|
1333 | { |
---|
1334 | |
---|
1335 | } /* end of xw_cleanup */ |
---|
1336 | |
---|
1337 | |
---|
1338 | |
---|
1339 | /*----------------------------------------------------------------------------*/ |
---|
1340 | |
---|
1341 | |
---|
1342 | |
---|
1343 | float xw_aspectratio( WDW wdw ) |
---|
1344 | |
---|
1345 | /* returns ratio of width to height |
---|
1346 | * |
---|
1347 | * parameter of routine |
---|
1348 | * WDW wdw; input; window number |
---|
1349 | */ |
---|
1350 | { |
---|
1351 | /* local variables */ |
---|
1352 | int w, h; /* size of window */ |
---|
1353 | |
---|
1354 | /* executable code */ |
---|
1355 | |
---|
1356 | wdw &= NUMMASK; |
---|
1357 | xwh_getwdwsize( wdw, &w, &h ); |
---|
1358 | return (float)w/(float)h; |
---|
1359 | |
---|
1360 | } /* end of xw_aspectratio */ |
---|
1361 | |
---|
1362 | |
---|
1363 | |
---|
1364 | /*----------------------------------------------------------------------------*/ |
---|
1365 | |
---|
1366 | |
---|
1367 | |
---|
1368 | void xw_updatewdw( void ) |
---|
1369 | |
---|
1370 | /* updates windows if necessary |
---|
1371 | * no parameters |
---|
1372 | */ |
---|
1373 | { |
---|
1374 | /* local variables */ |
---|
1375 | XEvent event; /* event */ |
---|
1376 | int rdw; /* redraw window */ |
---|
1377 | int rdmap; /* redraw window map */ |
---|
1378 | int dmy; |
---|
1379 | |
---|
1380 | /* executable code */ |
---|
1381 | |
---|
1382 | if (xwv_dsp == NULL) return; |
---|
1383 | |
---|
1384 | rdmap = 0; |
---|
1385 | while (XCheckMaskEvent( xwv_dsp, ExposureMask, &event )) { |
---|
1386 | if (event.type != Expose) |
---|
1387 | printf( "*** program error in xw_updatewdw ***\n" ); |
---|
1388 | dmy = XWE_NOERROR; |
---|
1389 | rdw = xwh_findwdw( event.xexpose.window ); |
---|
1390 | if ((rdw >= 0) && !((1<<rdw) & rdmap)) { |
---|
1391 | xw_redraw( rdw, &dmy ); |
---|
1392 | rdmap |= (1<<rdw); |
---|
1393 | } /*endif*/ |
---|
1394 | } /*endwhile*/ |
---|
1395 | |
---|
1396 | } /* end of xw_updatewdw */ |
---|
1397 | |
---|
1398 | |
---|
1399 | |
---|
1400 | /*----------------------------------------------------------------------------*/ |
---|
1401 | |
---|
1402 | |
---|
1403 | |
---|
1404 | void xw_flushbuffers( void ) |
---|
1405 | |
---|
1406 | /* flushes all output buffers of graphic windows |
---|
1407 | * |
---|
1408 | * no parameters |
---|
1409 | */ |
---|
1410 | { |
---|
1411 | /* executable code */ |
---|
1412 | |
---|
1413 | XFlush( xwv_dsp ); |
---|
1414 | |
---|
1415 | } /* end of xw_flushbuffers */ |
---|
1416 | |
---|
1417 | |
---|
1418 | |
---|
1419 | /*----------------------------------------------------------------------------*/ |
---|
1420 | |
---|
1421 | |
---|
1422 | |
---|
1423 | void xw_arrayswap( BOOLEAN on_off ) |
---|
1424 | |
---|
1425 | /* switches arrayswap (swapping of x and y in xw_arrayplot) on or off |
---|
1426 | * |
---|
1427 | * parameters of routine |
---|
1428 | * BOOLEAN on_off; input; TRUE=on, FALSE=off |
---|
1429 | */ |
---|
1430 | { |
---|
1431 | /* executable code */ |
---|
1432 | |
---|
1433 | xwv_arrayswap = on_off; |
---|
1434 | |
---|
1435 | } /* end of xw_arrayswap */ |
---|
1436 | |
---|
1437 | |
---|
1438 | |
---|
1439 | /*----------------------------------------------------------------------------*/ |
---|
1440 | /* local routines */ |
---|
1441 | /*----------------------------------------------------------------------------*/ |
---|
1442 | |
---|
1443 | |
---|
1444 | |
---|
1445 | static void xwh_transform( WDW wdw, XWCOO u, XWCOO v, int *x, int *y ) |
---|
1446 | |
---|
1447 | /* transforms user coordinates into window coordinates |
---|
1448 | * |
---|
1449 | * parameters of routine |
---|
1450 | * WDW wdw; input; window number |
---|
1451 | * XWCOO u, v; input; user coordinates |
---|
1452 | * int *x, *y; output; window coordinates |
---|
1453 | */ |
---|
1454 | { |
---|
1455 | /* executable code */ |
---|
1456 | |
---|
1457 | *x = (int)(u*xwv_txfac[wdw] - xwv_txoff[wdw]); |
---|
1458 | *y = (int)(v*xwv_tyfac[wdw] - xwv_tyoff[wdw]); |
---|
1459 | |
---|
1460 | } /* end of xwh_transform */ |
---|
1461 | |
---|
1462 | |
---|
1463 | |
---|
1464 | /*----------------------------------------------------------------------------*/ |
---|
1465 | |
---|
1466 | |
---|
1467 | |
---|
1468 | static void xwh_backtrans( WDW wdw, int x, int y, XWCOO *u, XWCOO *v ) |
---|
1469 | |
---|
1470 | /* transforms window coordinates into user coordinates |
---|
1471 | * |
---|
1472 | * parameters of routine |
---|
1473 | * WDW wdw; input; window number |
---|
1474 | * int x, y; input; window coordinates |
---|
1475 | * XWCOO *u, *v; output; user coordinates |
---|
1476 | */ |
---|
1477 | { |
---|
1478 | /* executable code */ |
---|
1479 | |
---|
1480 | *u = ((XWCOO)x + xwv_txoff[wdw]) / xwv_txfac[wdw]; |
---|
1481 | *v = ((XWCOO)y + xwv_tyoff[wdw]) / xwv_tyfac[wdw]; |
---|
1482 | |
---|
1483 | } /* end of xwh_backtrans */ |
---|
1484 | |
---|
1485 | |
---|
1486 | |
---|
1487 | /*----------------------------------------------------------------------------*/ |
---|
1488 | |
---|
1489 | |
---|
1490 | |
---|
1491 | static void xwh_getwdwsize( WDW wdw, int *ww, int *wh ) |
---|
1492 | |
---|
1493 | /* returns window size (in window coordinates) |
---|
1494 | * |
---|
1495 | * parameters of routine |
---|
1496 | * int wdw; input; window number |
---|
1497 | * int *ww, *wh; output; window size (if != NULL) |
---|
1498 | */ |
---|
1499 | { |
---|
1500 | /* local variables */ |
---|
1501 | Window root; /* root window */ |
---|
1502 | int x, y; /* window pos */ |
---|
1503 | unsigned w, h; /* window size */ |
---|
1504 | unsigned depth; /* depth of window */ |
---|
1505 | unsigned border; /* border width */ |
---|
1506 | |
---|
1507 | /* executable code */ |
---|
1508 | |
---|
1509 | XGetGeometry( xwv_dsp, xwv_wdw[wdw], &root, &x, &y, &w, &h, |
---|
1510 | &border, &depth ); |
---|
1511 | |
---|
1512 | if (ww != NULL) *ww = (int)w; |
---|
1513 | if (wh != NULL) *wh = (int)h; |
---|
1514 | |
---|
1515 | } /* end of xwh_getwdwsize */ |
---|
1516 | |
---|
1517 | |
---|
1518 | |
---|
1519 | /*----------------------------------------------------------------------------*/ |
---|
1520 | |
---|
1521 | |
---|
1522 | |
---|
1523 | static int xwh_wdwdepth( WDW wdw ) |
---|
1524 | |
---|
1525 | /* returns window depth |
---|
1526 | * |
---|
1527 | * parameters of routine |
---|
1528 | * WDW wdw; input; window number |
---|
1529 | * returns window depth |
---|
1530 | */ |
---|
1531 | { |
---|
1532 | /* local variables */ |
---|
1533 | Window root; /* root window */ |
---|
1534 | int x, y; /* window pos */ |
---|
1535 | unsigned w, h; /* window size */ |
---|
1536 | unsigned depth; /* depth of window */ |
---|
1537 | unsigned border; /* border width */ |
---|
1538 | |
---|
1539 | /* executable code */ |
---|
1540 | |
---|
1541 | XGetGeometry( xwv_dsp, xwv_wdw[wdw], &root, &x, &y, &w, &h, |
---|
1542 | &border, &depth ); |
---|
1543 | |
---|
1544 | return depth; |
---|
1545 | |
---|
1546 | } /* end of xwh_wdwdepth */ |
---|
1547 | |
---|
1548 | |
---|
1549 | |
---|
1550 | /*----------------------------------------------------------------------------*/ |
---|
1551 | |
---|
1552 | |
---|
1553 | |
---|
1554 | static void xwh_newline( WDW wdw ) |
---|
1555 | |
---|
1556 | /* starts new output line in window |
---|
1557 | * |
---|
1558 | * parameters of routine |
---|
1559 | * WDW wdw; input; window number |
---|
1560 | */ |
---|
1561 | { |
---|
1562 | /* local variables */ |
---|
1563 | int wh; /* window height */ |
---|
1564 | int fh; /* font height */ |
---|
1565 | |
---|
1566 | /* executable code */ |
---|
1567 | |
---|
1568 | xwh_getwdwsize( wdw, NULL, &wh ); |
---|
1569 | xwv_wxpos[wdw] = XWRITEOFF; |
---|
1570 | fh = xwh_getfontheight( DEFSTYLE ); |
---|
1571 | if ((xwv_wypos[wdw]+fh+YWRITEOFF) > wh) { |
---|
1572 | xwh_scroll( wdw ); |
---|
1573 | } else { |
---|
1574 | xwv_wypos[wdw] += fh; |
---|
1575 | } /*endif*/ |
---|
1576 | |
---|
1577 | } /* end of xwh_newline */ |
---|
1578 | |
---|
1579 | |
---|
1580 | |
---|
1581 | /*----------------------------------------------------------------------------*/ |
---|
1582 | |
---|
1583 | |
---|
1584 | |
---|
1585 | static void xwh_scroll( WDW wdw ) |
---|
1586 | |
---|
1587 | /* scrolls window up |
---|
1588 | * |
---|
1589 | * parameters of routine |
---|
1590 | * WDW wdw; input; window number |
---|
1591 | */ |
---|
1592 | { |
---|
1593 | /* local variables */ |
---|
1594 | int ww, wh; /* window size */ |
---|
1595 | int fh; /* font height */ |
---|
1596 | |
---|
1597 | /* executable code */ |
---|
1598 | |
---|
1599 | xwh_getwdwsize( wdw, &ww, &wh ); |
---|
1600 | fh = xwh_getfontheight( DEFSTYLE ); |
---|
1601 | XCopyArea( xwv_dsp, xwv_wdw[wdw], xwv_wdw[wdw], xwv_gc[wdw], |
---|
1602 | 0, fh, ww, wh-fh, 0, 0 ); |
---|
1603 | XClearArea( xwv_dsp, xwv_wdw[wdw], 0, wh-fh, ww, fh, False ); |
---|
1604 | |
---|
1605 | } /* end of xwh_scroll */ |
---|
1606 | |
---|
1607 | |
---|
1608 | |
---|
1609 | /*----------------------------------------------------------------------------*/ |
---|
1610 | |
---|
1611 | |
---|
1612 | |
---|
1613 | static int xwh_getfontheight( int style ) |
---|
1614 | |
---|
1615 | /* returns font height of "style" |
---|
1616 | * |
---|
1617 | * parameters of routine |
---|
1618 | * int style; input; attribute block number |
---|
1619 | */ |
---|
1620 | { |
---|
1621 | /* executable code */ |
---|
1622 | |
---|
1623 | return (int)(xwv_font[style]->max_bounds.ascent + |
---|
1624 | xwv_font[style]->max_bounds.descent ); |
---|
1625 | |
---|
1626 | } /* end of xwh_getfontheight */ |
---|
1627 | |
---|
1628 | |
---|
1629 | |
---|
1630 | /*----------------------------------------------------------------------------*/ |
---|
1631 | |
---|
1632 | |
---|
1633 | |
---|
1634 | static int xwh_getfontwidth( int style ) |
---|
1635 | |
---|
1636 | /* returns font width of "style" |
---|
1637 | * |
---|
1638 | * parameters of routine |
---|
1639 | * int style; input; attribute block number |
---|
1640 | */ |
---|
1641 | { |
---|
1642 | /* executable code */ |
---|
1643 | |
---|
1644 | return (int)(xwv_font[style]->max_bounds.rbearing - |
---|
1645 | xwv_font[style]->max_bounds.lbearing ); |
---|
1646 | |
---|
1647 | } /* end of xwh_getfontwidth */ |
---|
1648 | |
---|
1649 | |
---|
1650 | |
---|
1651 | /*----------------------------------------------------------------------------*/ |
---|
1652 | |
---|
1653 | |
---|
1654 | |
---|
1655 | static void xwh_read_character( char *ch ) |
---|
1656 | |
---|
1657 | /* reads a single character from terminal |
---|
1658 | * |
---|
1659 | * parameters of routine |
---|
1660 | * char *ch; output; character read |
---|
1661 | */ |
---|
1662 | { |
---|
1663 | /* local constants */ |
---|
1664 | # define KEYBUFLTH 20 |
---|
1665 | |
---|
1666 | /* local variables */ |
---|
1667 | XEvent event; /* event */ |
---|
1668 | XEvent evcop; /* dummy event */ |
---|
1669 | static char keybuf[KEYBUFLTH+1]; /* keyboard buffer */ |
---|
1670 | static int keylth; /* length of keyboard buffer */ |
---|
1671 | static char *cptr; /* buffer pointer */ |
---|
1672 | BOOLEAN quit; /* quit loop */ |
---|
1673 | WDW rdw; /* redraw window */ |
---|
1674 | int rdmap; /* redraw window map */ |
---|
1675 | int dmy=XWE_NOERROR; |
---|
1676 | |
---|
1677 | /* executable code */ |
---|
1678 | |
---|
1679 | if (keylth > 0) { |
---|
1680 | *ch = *cptr++; |
---|
1681 | keylth--; |
---|
1682 | return; |
---|
1683 | } /*endif*/ |
---|
1684 | |
---|
1685 | rdmap = 0; |
---|
1686 | quit = FALSE; |
---|
1687 | do { |
---|
1688 | |
---|
1689 | XNextEvent( xwv_dsp, &event ); |
---|
1690 | |
---|
1691 | switch (event.type) { |
---|
1692 | case Expose: |
---|
1693 | /* delete all other Expose events of the same window */ |
---|
1694 | while (XCheckWindowEvent(xwv_dsp,event.xexpose.window, |
---|
1695 | ExposureMask,&evcop)) |
---|
1696 | rdw = xwh_findwdw( event.xexpose.window ); |
---|
1697 | /* if ((rdw >= 0) && !((1<<rdw) & rdmap)) { */ |
---|
1698 | if (rdw >= 0) { |
---|
1699 | xw_redraw( rdw, &dmy ); |
---|
1700 | rdmap |= (1<<rdw); |
---|
1701 | } /*endif*/ |
---|
1702 | break; |
---|
1703 | case ButtonPress: |
---|
1704 | break; |
---|
1705 | case KeyPress: |
---|
1706 | keylth = XLookupString( &(event.xkey), keybuf, KEYBUFLTH, NULL, NULL ); |
---|
1707 | if (keylth > 0) { |
---|
1708 | cptr = keybuf; |
---|
1709 | *ch = *cptr++; |
---|
1710 | keylth--; |
---|
1711 | quit = TRUE; |
---|
1712 | } /*endif*/ |
---|
1713 | break; |
---|
1714 | case MotionNotify: |
---|
1715 | break; |
---|
1716 | } /*endswitch*/ |
---|
1717 | |
---|
1718 | } while (!quit); |
---|
1719 | |
---|
1720 | } /* end of xwh_read_character */ |
---|
1721 | |
---|
1722 | |
---|
1723 | |
---|
1724 | /*----------------------------------------------------------------------------*/ |
---|
1725 | |
---|
1726 | |
---|
1727 | |
---|
1728 | static void xwh_drawcross( WDW wdw, GC gc, int x, int y ) |
---|
1729 | |
---|
1730 | /* draws crosshair cursor in window |
---|
1731 | * |
---|
1732 | * parameters of routine |
---|
1733 | * WDW wdw; input; window number |
---|
1734 | * GC gc; input; graphics context |
---|
1735 | * int x, y; input; cross coordinates |
---|
1736 | */ |
---|
1737 | { |
---|
1738 | /* local variables */ |
---|
1739 | int ww, wh; /* size of window */ |
---|
1740 | |
---|
1741 | /* executable code */ |
---|
1742 | |
---|
1743 | xwh_getwdwsize( wdw, &ww, &wh ); |
---|
1744 | XDrawLine( xwv_dsp, xwv_wdw[wdw], gc, 0, y, ww, y ); |
---|
1745 | XDrawLine( xwv_dsp, xwv_wdw[wdw], gc, x, 0, x, wh ); |
---|
1746 | |
---|
1747 | } /* end of xwh_drawcross */ |
---|
1748 | |
---|
1749 | |
---|
1750 | |
---|
1751 | /*----------------------------------------------------------------------------*/ |
---|
1752 | |
---|
1753 | |
---|
1754 | |
---|
1755 | static void xwh_setcolor( int style, char value[], STATUS *status ) |
---|
1756 | |
---|
1757 | /* defines a new foreground color for style number "style" |
---|
1758 | * |
---|
1759 | * parameters of routine |
---|
1760 | * int style; input; style number |
---|
1761 | * char value[]; input; new color value (text or red,green,blue) |
---|
1762 | * STATUS *status; output; return status |
---|
1763 | */ |
---|
1764 | { |
---|
1765 | /* local variables */ |
---|
1766 | XColor screen_color, exact_color; /* color values */ |
---|
1767 | Status xstatus; /* X return status */ |
---|
1768 | float r, g, b; /* red, green, blue */ |
---|
1769 | |
---|
1770 | /* executable code */ |
---|
1771 | |
---|
1772 | if (!xwv_colored) return; |
---|
1773 | |
---|
1774 | if (isdigit(*value) || *value == '.') { |
---|
1775 | if (sscanf( value, "%f,%f,%f", &r, &g, &b ) != 3) { |
---|
1776 | *status = XWE_ILCOLOR; |
---|
1777 | return; |
---|
1778 | } else if ((r < 0.0) || (r > 1.0) || (g < 0.0) || (g > 1.0) || (b < 0.0) |
---|
1779 | || (b > 1.0)) { |
---|
1780 | *status = XWE_ILCOLOR; |
---|
1781 | return; |
---|
1782 | } /*endif*/ |
---|
1783 | screen_color.red = (unsigned short)(r * 65535.0); |
---|
1784 | screen_color.green = (unsigned short)(g * 65535.0); |
---|
1785 | screen_color.blue = (unsigned short)(b * 65535.0); |
---|
1786 | xstatus = XAllocColor( xwv_dsp, xwv_cmap, &screen_color ); |
---|
1787 | } else { |
---|
1788 | xstatus = XAllocNamedColor( xwv_dsp, xwv_cmap, value, &screen_color, |
---|
1789 | &exact_color ); |
---|
1790 | } /*endif*/ |
---|
1791 | XSetForeground( xwv_dsp, xwv_gc[style], screen_color.pixel ); |
---|
1792 | |
---|
1793 | } /* end of xwh_setcolor */ |
---|
1794 | |
---|
1795 | |
---|
1796 | |
---|
1797 | /*----------------------------------------------------------------------------*/ |
---|
1798 | |
---|
1799 | |
---|
1800 | |
---|
1801 | static WDW xwh_findwdw( Window xwdw ) |
---|
1802 | |
---|
1803 | /* returns XW window index from XWindow ID, if not found returns -1 |
---|
1804 | * |
---|
1805 | * parameters of routine |
---|
1806 | * Window xwdw; input; XWindow ID |
---|
1807 | * returns window index |
---|
1808 | */ |
---|
1809 | { |
---|
1810 | /* local variables */ |
---|
1811 | WDW w; /* window counter */ |
---|
1812 | |
---|
1813 | /* executable code */ |
---|
1814 | |
---|
1815 | for (w=0; w<XWC_MAXWDW; w++) |
---|
1816 | if (xwv_wdw[w] == xwdw) |
---|
1817 | return w; |
---|
1818 | |
---|
1819 | return -1; |
---|
1820 | |
---|
1821 | } /* end of xwh_findwdw */ |
---|
1822 | |
---|
1823 | |
---|
1824 | |
---|
1825 | /*----------------------------------------------------------------------------*/ |
---|
1826 | |
---|
1827 | |
---|
1828 | |
---|
1829 | static int xwh_getfontnum( WDW wdw, float size ) |
---|
1830 | |
---|
1831 | /* returns font number |
---|
1832 | * parameters of routine |
---|
1833 | * WDW wdw; input; window number |
---|
1834 | * float size; input; character size |
---|
1835 | * returns font number |
---|
1836 | */ |
---|
1837 | { |
---|
1838 | /* local constants */ |
---|
1839 | # define MINSIZE 9 |
---|
1840 | # define MAXSIZE 40 |
---|
1841 | |
---|
1842 | /* local variables */ |
---|
1843 | int wh; /* window height */ |
---|
1844 | int fh; /* font height */ |
---|
1845 | static int fn[MAXSIZE+1]= /* font numbers */ |
---|
1846 | {0,0,0,0,0,0,0,0,0,37,31,32,407,159,33,256,262,257,275,258,35,35,35, |
---|
1847 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 */ |
---|
1848 | 30,30,36,265,265,397,397,393,393,260,266,266,266,430,430,198,198,394}; |
---|
1849 | /* 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 */ |
---|
1850 | FILE *fp; /* file pointer */ |
---|
1851 | char **fontlist; /* list of fonts */ |
---|
1852 | int cnt; /* number of fonts */ |
---|
1853 | int i; /* counter */ |
---|
1854 | char line[BC_LINELTH+1]; /* current line */ |
---|
1855 | char fname[BC_LINELTH+1]; /* name of font */ |
---|
1856 | int psize; /* size in pixel */ |
---|
1857 | char listfile[BC_FILELTH+1]; /* name of font list file */ |
---|
1858 | |
---|
1859 | /* executable code */ |
---|
1860 | |
---|
1861 | size *= 2; /* don't know why */ |
---|
1862 | |
---|
1863 | xwh_getwdwsize( wdw, NULL, &wh ); |
---|
1864 | /* fh = Nint( size * (float)wh ); */ |
---|
1865 | fh = (int)( size * (float)wh ); |
---|
1866 | if (fh < MINSIZE) fh = MINSIZE; |
---|
1867 | if (fh > MAXSIZE) fh = MAXSIZE; |
---|
1868 | |
---|
1869 | if (strlen(xwv_inputdir)+strlen(XWC_FONTLIST) > BC_FILELTH) { |
---|
1870 | printf( "*** %s + %s : name overflow ***\n", xwv_inputdir, XWC_FONTLIST ); |
---|
1871 | return fn[fh]; |
---|
1872 | } /*endif*/ |
---|
1873 | strcpy( listfile, xwv_inputdir ); |
---|
1874 | strcat( listfile, XWC_FONTLIST ); |
---|
1875 | fp = sy_fopen( listfile, "r" ); |
---|
1876 | if (fp == NULL) { |
---|
1877 | printf( "*** no xfonts.lis ***\n" ); |
---|
1878 | return fn[fh]; |
---|
1879 | } else { |
---|
1880 | do { |
---|
1881 | if (fgets(line,BC_LINELTH,fp) == NULL) { |
---|
1882 | printf( "*** size %d didn't match ***\n", fh ); |
---|
1883 | sy_fclose( fp ); |
---|
1884 | return fn[fh]; |
---|
1885 | } /*endif*/ |
---|
1886 | sscanf(line, "%d %s", &psize, fname ); |
---|
1887 | } while (psize != fh); |
---|
1888 | sy_fclose( fp ); |
---|
1889 | fontlist = XListFonts( xwv_dsp, "*", 1000, &cnt ); |
---|
1890 | for (i=0; i<cnt; i++) |
---|
1891 | if (strcmp(fname,fontlist[i]) == 0) { |
---|
1892 | XFreeFontNames( fontlist ); |
---|
1893 | /*printf("*** font found ***\n" );*/ |
---|
1894 | return i; |
---|
1895 | } /*endif*/ |
---|
1896 | XFreeFontNames( fontlist ); |
---|
1897 | return fn[fh]; |
---|
1898 | } /*endif*/ |
---|
1899 | |
---|
1900 | } /* end of xwh_getfontnum */ |
---|
1901 | |
---|
1902 | |
---|
1903 | |
---|
1904 | /*----------------------------------------------------------------------------*/ |
---|
1905 | |
---|
1906 | |
---|
1907 | |
---|
1908 | void xw_set_inputdir( char dir[], STATUS *status ) |
---|
1909 | |
---|
1910 | /* sets scratch directory |
---|
1911 | * |
---|
1912 | * parameters of routine |
---|
1913 | * char dir[]; input; new directory name |
---|
1914 | * STATUS *status; output; return status |
---|
1915 | */ |
---|
1916 | { |
---|
1917 | /* executable code */ |
---|
1918 | |
---|
1919 | if (strlen(dir) > BC_FILELTH) { |
---|
1920 | *status = XWE_STROVFL; |
---|
1921 | return; |
---|
1922 | } /*endif*/ |
---|
1923 | strcpy( xwv_inputdir, dir ); |
---|
1924 | |
---|
1925 | } /* end of xw_set_inputdir */ |
---|
1926 | |
---|
1927 | |
---|
1928 | |
---|
1929 | /*----------------------------------------------------------------------------*/ |
---|
1930 | |
---|