annotate glib/X.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
rev   line source
tomwalters@0 1
tomwalters@0 2 /*
tomwalters@0 3 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
tomwalters@0 4 ===========================================================================
tomwalters@0 5
tomwalters@0 6 Permission to use, copy, modify, and distribute this software without fee
tomwalters@0 7 is hereby granted for research purposes, provided that this copyright
tomwalters@0 8 notice appears in all copies and in all supporting documentation, and that
tomwalters@0 9 the software is not redistributed for any fee (except for a nominal shipping
tomwalters@0 10 charge). Anyone wanting to incorporate all or part of this software in a
tomwalters@0 11 commercial product must obtain a license from the Medical Research Council.
tomwalters@0 12
tomwalters@0 13 The MRC makes no representations about the suitability of this
tomwalters@0 14 software for any purpose. It is provided "as is" without express or implied
tomwalters@0 15 warranty.
tomwalters@0 16 */
tomwalters@0 17
tomwalters@0 18 /*******************************************************************************************
tomwalters@0 19
tomwalters@0 20 X.c A GENERIC X-WINDOWS REAR-END FOR THE WINDOWS.H INTERFACE.
tomwalters@0 21
tomwalters@0 22
tomwalters@0 23 This module is derived from the x10.c module, written by John Holdsworth, and the subsequent
tomwalters@0 24 x11.c module, which was ported by Paul Manson. It attempts to combine the x10/x11 code in
tomwalters@0 25 such a way as to provide a single uniform application with the minimal amount of #ifdef
tomwalters@0 26 "noise". It expects to have either X10 or X11 defined as symbols by the preprocessor -- in the
tomwalters@0 27 event that neither of these is defined, it produces an error message and causes the compiler
tomwalters@0 28 to exit; ie. there is NO DEFAULT.
tomwalters@0 29
tomwalters@0 30 Written: May 3rd. by Paul Manson (but see credits above)
tomwalters@0 31
tomwalters@0 32 Edited:
tomwalters@0 33
tomwalters@0 34 15 May 1989 (Paul Manson) -- Altered the <pixels> argument to use <pixels>-1 in the
tomwalters@0 35 newDisplay window call. On X11, pixels of 0 means "use
tomwalters@0 36 thin lines", which always work correctly. Values greater
tomwalters@0 37 than 0 imply "thick lines", which appear to over-write
tomwalters@0 38 each other.
tomwalters@0 39
tomwalters@0 40 05 June 1989 (Paul Manson) -- Removed the offending "warning" message from axes();.
tomwalters@0 41
tomwalters@0 42 27 July 1989 (Johh Holdsworth) -- put in addition loops to segment line drawing
tomwalters@0 43 operations for very long lines and put XFlush() in
tomwalters@0 44 before pausing. A bug remains in the segentation of
tomwalters@0 45 hidden line removal. The Fill operation Paint to hide
tomwalters@0 46 lines lower than that just drawn can remove part of
tomwalters@0 47 that line - very tricky to avoid. The same problem
tomwalters@0 48 seem to be present in ps.c.
tomwalters@0 49
tomwalters@0 50 18 August 1989 (Paul Manson) -- Altered to accomodate the Pixmap/newWindowWindow entry
tomwalters@0 51 which forces un-resizable windows on us with X11.
tomwalters@0 52
tomwalters@0 53 21 August 1989 (Paul Manson) -- Also altered "Clear" so that it does a FillRectangle in
tomwalters@0 54 preference to a ClearWindow. The latter call doesn't work
tomwalters@0 55 for Pixmaps (see newWindowWindow, etc).
tomwalters@0 56
tomwalters@0 57 22 August 1989 (Paul Manson) -- In a similar vein to the above, I have altered X.c so that
tomwalters@0 58 two global variables Foreground and Background are used to
tomwalters@0 59 determine the colours for drawing and filling.
tomwalters@0 60
tomwalters@0 61 04 September 1989 (Paul Manson) - Altered so that the GXmodes are used to modify the GC for
tomwalters@0 62 clear, draw, etc operations. This seems to be a much more
tomwalters@0 63 reliable way in which to manipulate these settings.
tomwalters@0 64
tomwalters@0 65 31 July 1990 (John Holdsworth) - Extensive changes to remove previous change. GXcopy
tomwalters@0 66 now used with foreground appropiately set. This has
tomwalters@0 67 proved more portable particularly for Multiplane displays.
tomwalters@0 68
tomwalters@0 69
tomwalters@0 70 26th May 1993 (Mitch d'Souza & M Akeroyd) - added an extra include - sys/types.h - so that the
tomwalters@0 71 gcc would work on a decstation.
tomwalters@0 72
tomwalters@0 73 3rd August 1993 (M. Akeroyd) - Removed the 'XAllPlanes' bist of the XGetImage routines,
tomwalters@0 74 so that monochrome bitmaps could be made on colour
tomwalters@0 75 computers.
tomwalters@0 76 Also included new SilentOptions :
tomwalters@0 77 mono_ctn
tomwalters@0 78 colour_ctn
tomwalters@0 79 planemask_ctn
tomwalters@0 80
tomwalters@0 81 20th August 1993 (M.Akeroyd) - First attempt at colour images: two new options fg_col and
tomwalters@0 82 bg_col, and a complementary procedure define_colour().
tomwalters@0 83 These do NOT work with view=grayscale.
tomwalters@0 84
tomwalters@0 85 ********************************************************************************************/
tomwalters@0 86
tomwalters@0 87
tomwalters@0 88 #if !defined(X11) && !defined(X10)
tomwalters@0 89 #define X11
tomwalters@0 90 #endif
tomwalters@0 91
tomwalters@0 92 #if !defined(X10) && !defined(X11)
tomwalters@0 93 #include "-- YOU MUST DEFINE EITHER X10 or X11 TO USE THIS MODULE"
tomwalters@0 94 #endif
tomwalters@0 95
tomwalters@0 96 #include <stdio.h>
tomwalters@0 97 #include <malloc.h>
tomwalters@0 98 #include <sys/types.h>
tomwalters@0 99 #include "options.h" /* Added: MAA 3-8-1993 */
tomwalters@0 100 #if defined(X11)
tomwalters@0 101 #include <X11/X.h>
tomwalters@0 102 #include <X11/Xlib.h>
tomwalters@0 103 #include <X11/Xutil.h> /* MAA: 20-8-1993. For colour */
tomwalters@0 104 #include <X11/Xos.h> /* MAA: 20-8-1993. For colour */
tomwalters@0 105
tomwalters@0 106
tomwalters@0 107 #else
tomwalters@0 108 #if defined(X10)
tomwalters@0 109 #include <X/Xlib.h>
tomwalters@0 110 #endif
tomwalters@0 111 #endif
tomwalters@0 112
tomwalters@0 113 #include "windows.h"
tomwalters@0 114 #include "grey.h"
tomwalters@0 115
tomwalters@0 116 #define FALSE (0)
tomwalters@0 117 #define TRUE (1)
tomwalters@0 118 #define MAX_FILES (20)
tomwalters@0 119 #define MAX_SEGMENT (5000)
tomwalters@0 120 #define MAX_ROW (100)
tomwalters@0 121 #define MAX_COL (1000)
tomwalters@0 122 #define MAX_IMAGE (1500)
tomwalters@0 123 #define DITHER_SIZE (8)
tomwalters@0 124
tomwalters@0 125 extern char *monostr, *colourstr, *planemaskstr; /* Added: MAA 3-8-1993 */
tomwalters@0 126 int planemask;
tomwalters@0 127
tomwalters@0 128 static Display *theDisplay = (Display *) 0; /* The Display Variable */
tomwalters@0 129 static int theWidth, theHeight; /* The Width and Height of the Screen in Pixels */
tomwalters@0 130
tomwalters@0 131 #define MIN(X,Y) (((X) < (Y)) ? (X) : (Y))
tomwalters@0 132
tomwalters@0 133 #define USE_PIXMAPS
tomwalters@0 134
tomwalters@0 135 #if defined(X11)
tomwalters@0 136 static int theScreen ; /* The associated screen no. */
tomwalters@0 137 static int synchronous = FALSE ;
tomwalters@0 138 static unsigned long theForeground, theBackground;
tomwalters@0 139 #else
tomwalters@0 140 static char *marker_font_name = "6x10" ;
tomwalters@0 141 static FontInfo *marker_font = ( FontInfo * ) 0 ;
tomwalters@0 142 #endif
tomwalters@0 143
tomwalters@0 144 typedef struct {
tomwalters@0 145 windowEntries *entries ;
tomwalters@0 146 Window w ;
tomwalters@0 147 int pixels, width, height, hide ;
tomwalters@0 148 int x, y ;
tomwalters@0 149 #if defined(X11)
tomwalters@0 150 GC foregroundGC ;
tomwalters@0 151 GC backgroundGC ;
tomwalters@0 152 int isMapped ;
tomwalters@0 153 #ifdef USE_PIXMAPS
tomwalters@0 154 Pixmap imageData[ MAX_IMAGE ];
tomwalters@0 155 #else
tomwalters@0 156 XImage *imageData[ MAX_IMAGE ];
tomwalters@0 157 #endif
tomwalters@0 158 XImage *theImage; /* Used only for Read operations; The wind__write */
tomwalters@0 159 /* entry point actually creates & destroys images */
tomwalters@0 160 XImage *rowImage, *colImage ;
tomwalters@0 161 #else
tomwalters@0 162 int foreground, background ;
tomwalters@0 163 short *imageData[ MAX_IMAGE ];
tomwalters@0 164 short *theImage ;
tomwalters@0 165 #endif
tomwalters@0 166 struct _lookup *lookup ; /* Dithering */
tomwalters@0 167 int **diths ; /* Dithering */
tomwalters@0 168 short *data ; /* Dithering */
tomwalters@0 169 int greylength ;
tomwalters@0 170 int imageNum ;
tomwalters@0 171 int imageSize;
tomwalters@0 172 } *XWindowObject ;
tomwalters@0 173
tomwalters@0 174 #ifndef lint
tomwalters@0 175 static char *sccs_id = "@(#)X.c 1.38 Paul Manson, John Holdsworth (MRC-APU) 5/31/91" ;
tomwalters@0 176 #endif
tomwalters@0 177
tomwalters@0 178 #if defined(X11)
tomwalters@0 179
tomwalters@0 180
tomwalters@0 181
tomwalters@0 182
tomwalters@0 183 /* MAA: Added 20-8-1993
tomwalters@0 184 * Colour ....
tomwalters@0 185 * Copied off example 7.2 of Xlib Vol 1.
tomwalters@0 186 */
tomwalters@0 187
tomwalters@0 188 extern char *fgcolourstr;
tomwalters@0 189 extern char *bgcolourstr;
tomwalters@0 190
tomwalters@0 191 void define_colours()
tomwalters@0 192 {
tomwalters@0 193 int default_depth;
tomwalters@0 194 Visual *default_visual;
tomwalters@0 195 XColor exact_def;
tomwalters@0 196 Colormap default_cmap;
tomwalters@0 197 int i=5;
tomwalters@0 198 XVisualInfo visual_info;
tomwalters@0 199
tomwalters@0 200
tomwalters@0 201 default_depth = DefaultDepth(theDisplay, theScreen);
tomwalters@0 202 default_visual = DefaultVisual(theDisplay, theScreen);
tomwalters@0 203 default_cmap = DefaultColormap(theDisplay, theScreen);
tomwalters@0 204
tomwalters@0 205 /* MAA: Removed this. */
tomwalters@0 206 /* if (default_depth == 1) {*/
tomwalters@0 207 /* Black-White Only */
tomwalters@0 208 /* theForeground = BlackPixel(theDisplay, theScreen);*/
tomwalters@0 209 /* theBackground = WhitePixel(theDisplay, theScreen);}*/
tomwalters@0 210
tomwalters@0 211 /* i = visual class */
tomwalters@0 212 while (!XMatchVisualInfo(theDisplay, theScreen, default_depth, i--, &visual_info))
tomwalters@0 213 ;
tomwalters@0 214
tomwalters@0 215 if (i<StaticColor) {
tomwalters@0 216 theForeground = BlackPixel(theDisplay, theScreen);
tomwalters@0 217 theBackground = WhitePixel(theDisplay, theScreen);}
tomwalters@0 218
tomwalters@0 219 else {
tomwalters@0 220
tomwalters@0 221 /* Foreground */
tomwalters@0 222 if (!XParseColor(theDisplay, default_cmap, fgcolourstr, &exact_def)){
tomwalters@0 223 fprintf(stderr, "Unable to find colour %s in database. Using Black instead. \n", fgcolourstr);
tomwalters@0 224 theForeground = BlackPixel(theDisplay, theScreen);}
tomwalters@0 225 else
tomwalters@0 226 if (XAllocColor(theDisplay, default_cmap, &exact_def))
tomwalters@0 227 theForeground = exact_def.pixel;
tomwalters@0 228 else {
tomwalters@0 229 fprintf(stderr, "Unable to alloc colour %s. Using Black instead. \n", fgcolourstr);
tomwalters@0 230 theForeground = BlackPixel(theDisplay, theScreen);}
tomwalters@0 231
tomwalters@0 232 /* Background */
tomwalters@0 233 if (!XParseColor(theDisplay, default_cmap, bgcolourstr, &exact_def)){
tomwalters@0 234 fprintf(stderr, "Unable to find colour %s in database. Using White instead. \n", bgcolourstr);
tomwalters@0 235 theBackground = WhitePixel(theDisplay, theScreen);}
tomwalters@0 236 else
tomwalters@0 237 if (XAllocColor(theDisplay, default_cmap, &exact_def))
tomwalters@0 238 theBackground = exact_def.pixel;
tomwalters@0 239 else {
tomwalters@0 240 fprintf(stderr, "Unable to alloc colour %s. Using White instead. \n", bgcolourstr);
tomwalters@0 241 theBackground = WhitePixel(theDisplay, theScreen);}
tomwalters@0 242 }
tomwalters@0 243 }
tomwalters@0 244
tomwalters@0 245
tomwalters@0 246
tomwalters@0 247
tomwalters@0 248 extern void InitializeX(display, screen, foreground, background)
tomwalters@0 249 Display *display ;
tomwalters@0 250 int screen ;
tomwalters@0 251 unsigned long foreground;
tomwalters@0 252 unsigned long background;
tomwalters@0 253 {
tomwalters@0 254 if (theDisplay == (Display *) 0) {
tomwalters@0 255 theDisplay = display ;
tomwalters@0 256 theScreen = screen ;
tomwalters@0 257 theForeground = foreground;
tomwalters@0 258 theBackground = background;
tomwalters@0 259 }
tomwalters@0 260 else {
tomwalters@0 261 (void) fprintf(stderr, "Error! The X.c Display Variable has already been set...\nIt is invalid to call InitializeX after this has happened (eg. by a call to newDisplayWindow).\n");
tomwalters@0 262 exit(1);
tomwalters@0 263 }
tomwalters@0 264 }
tomwalters@0 265
tomwalters@0 266 /* not a nice routine to wait untill window is actually mapped before returning it's size */
tomwalters@0 267
tomwalters@0 268 static void waitTillMapped( info )
tomwalters@0 269 XWindowObject info ;
tomwalters@0 270 {
tomwalters@0 271 XWindowAttributes at ;
tomwalters@0 272
tomwalters@0 273 if( !info->isMapped ) {
tomwalters@0 274 do
tomwalters@0 275 XGetWindowAttributes( theDisplay, info->w, &at ) ;
tomwalters@0 276 while ( at.map_state == IsUnmapped ) ;
tomwalters@0 277
tomwalters@0 278 info->isMapped = 1 ;
tomwalters@0 279
tomwalters@0 280 info->width = at.width ;
tomwalters@0 281 info->height = at.height ;
tomwalters@0 282 }
tomwalters@0 283
tomwalters@0 284 return ;
tomwalters@0 285 }
tomwalters@0 286
tomwalters@0 287 /* ---------------- Beware! This function may be the most dangerous thing ---------------
tomwalters@0 288 ---------------- to ever appear on a DecStation... it makes ---------------
tomwalters@0 289 ---------------- sweeping assumptions about the way that data ---------------
tomwalters@0 290 ---------------- is stored in the X server. If it EVER happens ---------------
tomwalters@0 291 ---------------- that the X Consortium write routines for I/O ---------------
tomwalters@0 292 ---------------- of Screen Images, THROW THIS AWAY! --------------- */
tomwalters@0 293 static int ImageSizeInBytes(image)
tomwalters@0 294 XImage *image;
tomwalters@0 295 {
tomwalters@0 296
tomwalters@0 297 /* Cribbed from X11R3/.../xwd.c */
tomwalters@0 298
tomwalters@0 299 return(image->bytes_per_line * image->height * image->depth);
tomwalters@0 300
tomwalters@0 301 }
tomwalters@0 302
tomwalters@0 303
tomwalters@0 304 static setupImage( w )
tomwalters@0 305 XWindowObject w ;
tomwalters@0 306 {
tomwalters@0 307 if( w->theImage == ( XImage * ) 0 ) {
tomwalters@0 308 w->theImage = XGetImage(theDisplay, w->w, 0, 0, w->entries->width(w),
tomwalters@0 309 w->entries->height(w), planemask, XYPixmap);
tomwalters@0 310 w->imageSize = ImageSizeInBytes(w->theImage);
tomwalters@0 311 }
tomwalters@0 312 }
tomwalters@0 313
tomwalters@0 314
tomwalters@0 315
tomwalters@0 316 #endif
tomwalters@0 317
tomwalters@0 318 static short window__x( info )
tomwalters@0 319 XWindowObject info ;
tomwalters@0 320 {
tomwalters@0 321 #if defined(OldX11)
tomwalters@0 322 XWindowAttributes winfo;
tomwalters@0 323
tomwalters@0 324 (void) XGetWindowAttributes( theDisplay, info->w, &winfo );
tomwalters@0 325
tomwalters@0 326 return ((short) winfo.x);
tomwalters@0 327 #else
tomwalters@0 328 #if defined(X11)
tomwalters@0 329 return ((short) info->x);
tomwalters@0 330 #else
tomwalters@0 331 WindowInfo winfo;
tomwalters@0 332
tomwalters@0 333 XQueryWindow(info->w, &winfo);
tomwalters@0 334
tomwalters@0 335 return (winfo.x);
tomwalters@0 336 #endif
tomwalters@0 337 #endif
tomwalters@0 338 }
tomwalters@0 339
tomwalters@0 340 static short window__y( info )
tomwalters@0 341 XWindowObject info ;
tomwalters@0 342 {
tomwalters@0 343 #if defined(OldX11)
tomwalters@0 344 XWindowAttributes winfo;
tomwalters@0 345
tomwalters@0 346 (void) XGetWindowAttributes( theDisplay, info->w, &winfo );
tomwalters@0 347
tomwalters@0 348 return ((short) winfo.y);
tomwalters@0 349 #else
tomwalters@0 350 #if defined(X11)
tomwalters@0 351 return ((short) info->y);
tomwalters@0 352 #else
tomwalters@0 353 WindowInfo winfo;
tomwalters@0 354
tomwalters@0 355 XQueryWindow(info->w, &winfo);
tomwalters@0 356
tomwalters@0 357 return (winfo.y);
tomwalters@0 358 #endif
tomwalters@0 359 #endif
tomwalters@0 360 }
tomwalters@0 361
tomwalters@0 362 static short window__width( info )
tomwalters@0 363 XWindowObject info ;
tomwalters@0 364 {
tomwalters@0 365 #if defined(X11)
tomwalters@0 366 waitTillMapped(info) ;
tomwalters@0 367 #endif
tomwalters@0 368
tomwalters@0 369 return( info->width ) ;
tomwalters@0 370 }
tomwalters@0 371
tomwalters@0 372 static short window__height( info )
tomwalters@0 373 XWindowObject info ;
tomwalters@0 374 {
tomwalters@0 375 #if defined(X11)
tomwalters@0 376 waitTillMapped(info) ;
tomwalters@0 377 #endif
tomwalters@0 378
tomwalters@0 379 return( info->height ) ;
tomwalters@0 380 }
tomwalters@0 381
tomwalters@0 382 static void window__draw( info, xs, ys, pointsFlag )
tomwalters@0 383 XWindowObject info ;
tomwalters@0 384 short xs[], ys[] ;
tomwalters@0 385 int pointsFlag ;
tomwalters@0 386 {
tomwalters@0 387 #if defined(X11)
tomwalters@0 388 XPoint vs[MAX_SEGMENT], *vptr;
tomwalters@0 389 #else
tomwalters@0 390 Vertex vs[MAX_SEGMENT], *vptr;
tomwalters@0 391 #endif
tomwalters@0 392 register int point, count ;
tomwalters@0 393 register int points = abs( pointsFlag ) ;
tomwalters@0 394 register short h ;
tomwalters@0 395
tomwalters@0 396 #if defined(X11)
tomwalters@0 397 if (synchronous) {
tomwalters@0 398 (void) XSynchronize(theDisplay, FALSE);
tomwalters@0 399 XFlush(theDisplay);
tomwalters@0 400 synchronous = FALSE;
tomwalters@0 401 }
tomwalters@0 402
tomwalters@0 403 waitTillMapped(info) ;
tomwalters@0 404 #else
tomwalters@0 405 int i ;
tomwalters@0 406 #endif
tomwalters@0 407
tomwalters@0 408 h = info->entries->height( info );
tomwalters@0 409
tomwalters@0 410 for( point = 0 ; point < points - 1 ; point += count - 1 ) {
tomwalters@0 411
tomwalters@0 412 vptr = vs ;
tomwalters@0 413
tomwalters@0 414 for( count=0 ; count < MAX_SEGMENT && point + count < points ; count++ ) {
tomwalters@0 415
tomwalters@0 416 vptr->x = xs[ point+count ] ;
tomwalters@0 417 vptr->y = h - ys[ point+count ] ;
tomwalters@0 418 #if defined(X10)
tomwalters@0 419 vptr->flags = pointsFlag > 0 ? 0 : 0 ;
tomwalters@0 420 #endif
tomwalters@0 421 vptr++;
tomwalters@0 422 }
tomwalters@0 423
tomwalters@0 424 if( info->hide && pointsFlag > 0 && vs[0].x == vptr[-1].x &&
tomwalters@0 425 vs[0].y == vptr[-1].y )
tomwalters@0 426 #if defined(X11)
tomwalters@0 427 XFillPolygon( theDisplay, info->w, info->backgroundGC, vs, vptr-vs, Complex, CoordModeOrigin);
tomwalters@0 428
tomwalters@0 429 if( pointsFlag > 0 )
tomwalters@0 430 XDrawLines( theDisplay, info->w, info->foregroundGC, vs, vptr-vs, CoordModeOrigin);
tomwalters@0 431 else
tomwalters@0 432 XDrawPoints(theDisplay, info->w, info->foregroundGC, vs, vptr-vs, CoordModeOrigin);
tomwalters@0 433
tomwalters@0 434 XFlush(theDisplay);
tomwalters@0 435 #else
tomwalters@0 436 XDrawFilled( info->w, vs, vptr-vs, info->background, GXcopy, AllPlanes ) ;
tomwalters@0 437
tomwalters@0 438 if( pointsFlag > 0 )
tomwalters@0 439 XDraw(info->w, vs, vptr-vs, info->pixels, info->pixels, info->foreground, GXcopy, AllPlanes);
tomwalters@0 440 else
tomwalters@0 441 for( i=0 ; i<count ; i++ )
tomwalters@0 442 XPixSet( info->w, vs[i].x, vs[i].y, info->pixels, info->pixels, info->foreground ) ;
tomwalters@0 443 #endif
tomwalters@0 444 }
tomwalters@0 445
tomwalters@0 446 return;
tomwalters@0 447 }
tomwalters@0 448
tomwalters@0 449 static void checkGeometry( info )
tomwalters@0 450 XWindowObject info ;
tomwalters@0 451 {
tomwalters@0 452 #if defined(X11)
tomwalters@0 453 return;
tomwalters@0 454 #else
tomwalters@0 455 #if defined(OldX11)
tomwalters@0 456 XWindowAttributes winfo;
tomwalters@0 457
tomwalters@0 458 (void) XGetWindowAttributes( theDisplay, info->w, &winfo );
tomwalters@0 459 #else
tomwalters@0 460 WindowInfo winfo;
tomwalters@0 461
tomwalters@0 462 XQueryWindow(info->w, &winfo);
tomwalters@0 463 #endif
tomwalters@0 464
tomwalters@0 465 info->width = winfo.width ;
tomwalters@0 466 info->height = winfo.height ;
tomwalters@0 467
tomwalters@0 468 return ;
tomwalters@0 469 #endif
tomwalters@0 470 }
tomwalters@0 471
tomwalters@0 472 static void window__clear( info )
tomwalters@0 473 XWindowObject info ;
tomwalters@0 474 {
tomwalters@0 475
tomwalters@0 476 checkGeometry( info ) ;
tomwalters@0 477
tomwalters@0 478 #if defined(OldX11)
tomwalters@0 479 XClearWindow(theDisplay, info->w);
tomwalters@0 480 XFlush(theDisplay);
tomwalters@0 481 #else
tomwalters@0 482 #if defined(X11)
tomwalters@0 483 XFlush(theDisplay);
tomwalters@0 484 XFillRectangle( theDisplay, info->w, info->backgroundGC, 0, 0, info->width, info->height ) ;
tomwalters@0 485 XFlush(theDisplay);
tomwalters@0 486 #else
tomwalters@0 487 XClear(info->w);
tomwalters@0 488 #endif
tomwalters@0 489 #endif
tomwalters@0 490
tomwalters@0 491 return ;
tomwalters@0 492 }
tomwalters@0 493
tomwalters@0 494 static void window__close( info )
tomwalters@0 495 XWindowObject info ;
tomwalters@0 496 {
tomwalters@0 497 if (info != (XWindowObject )0)
tomwalters@0 498 #if defined(X11)
tomwalters@0 499 XFreeGC( theDisplay, info->foregroundGC ) ;
tomwalters@0 500 XFreeGC( theDisplay, info->backgroundGC ) ;
tomwalters@0 501 XDestroyWindow(theDisplay, info->w);
tomwalters@0 502 #else
tomwalters@0 503 XDestroyWindow(info->w);
tomwalters@0 504 #endif
tomwalters@0 505 free( (char *) info ) ;
tomwalters@0 506
tomwalters@0 507 return ;
tomwalters@0 508 }
tomwalters@0 509
tomwalters@0 510 static int window__store( info )
tomwalters@0 511 XWindowObject info ;
tomwalters@0 512 {
tomwalters@0 513 if (info->imageNum > MAX_IMAGE) {
tomwalters@0 514 (void) fprintf(stderr,
tomwalters@0 515 "windows: Sorry, you can currently store only %i images per window.\n",
tomwalters@0 516 MAX_IMAGE);
tomwalters@0 517 return(FALSE);
tomwalters@0 518 }
tomwalters@0 519 #if defined(X11)
tomwalters@0 520 if (!synchronous) {
tomwalters@0 521 (void) XSynchronize(theDisplay, TRUE);
tomwalters@0 522 XFlush(theDisplay);
tomwalters@0 523 synchronous = TRUE;
tomwalters@0 524 }
tomwalters@0 525
tomwalters@0 526 waitTillMapped(info) ;
tomwalters@0 527
tomwalters@0 528 #ifdef USE_PIXMAPS
tomwalters@0 529 info->imageData[ info->imageNum ] = XCreatePixmap(theDisplay, info->w, Width( info ), Height( info ), DisplayPlanes( theDisplay, theScreen ) ) ;
tomwalters@0 530 XCopyArea( theDisplay, info->w, info->imageData[ info->imageNum ], info->foregroundGC, 0, 0, Width( info), Height( info ), 0, 0 ) ;
tomwalters@0 531 #else
tomwalters@0 532 info->imageData[ info->imageNum ] = XGetImage(theDisplay, info->w, 0, 0,
tomwalters@0 533 info->entries->width(info),
tomwalters@0 534 info->entries->height(info),
tomwalters@0 535 planemask,
tomwalters@0 536 XYPixmap);
tomwalters@0 537 #endif
tomwalters@0 538 #else
tomwalters@0 539 if((info->imageData[info->imageNum] = (short *) malloc(info->imageSize)) == (short *) 0) {
tomwalters@0 540 (void) fprintf(stderr, "Insufficient memory to store %dth image of size %d\n",
tomwalters@0 541 info->imageNum+1, info->imageSize);
tomwalters@0 542 return(FALSE);
tomwalters@0 543 }
tomwalters@0 544 else
tomwalters@0 545 XPixmapGetXY( info->w, 0, 0, info->entries->width(info),
tomwalters@0 546 info->entries->height(info), info->imageData[ info->imageNum ] ) ;
tomwalters@0 547 #endif
tomwalters@0 548 info->imageNum++;
tomwalters@0 549
tomwalters@0 550 return ( info->imageNum ) ;
tomwalters@0 551 }
tomwalters@0 552
tomwalters@0 553 WindowImage window__current_image( info )
tomwalters@0 554 XWindowObject info ;
tomwalters@0 555 {
tomwalters@0 556 static struct _window_image image_info ;
tomwalters@0 557 #if defined(X11)
tomwalters@0 558 #if !defined( USE_PIXMAPS)
tomwalters@0 559 XImage *image_ptr = info->imageData[ info->imageNum-1 ] ;
tomwalters@0 560
tomwalters@0 561 image_info.data = image_ptr->data ;
tomwalters@0 562 image_info.bytes_per_line = image_ptr->bytes_per_line ;
tomwalters@0 563 image_info.height = image_ptr->height ;
tomwalters@0 564
tomwalters@0 565 image_info.left_bit = 1<<0 ;
tomwalters@0 566 image_info.right_bit = 1<<7 ;
tomwalters@0 567 image_info.start_bit = image_info.left_bit<<image_ptr->xoffset ;
tomwalters@0 568 #endif
tomwalters@0 569 #else
tomwalters@0 570 short *image_ptr = info->imageData[ info->imageNum-1 ] ;
tomwalters@0 571
tomwalters@0 572 image_info.data = ( char *) image_ptr ;
tomwalters@0 573 image_info.height = info->height ;
tomwalters@0 574 image_info.bytes_per_line = ( info->width + 15 ) / 16 * sizeof (*image_ptr) ;
tomwalters@0 575
tomwalters@0 576 image_info.left_bit = 1<<0 ;
tomwalters@0 577 image_info.right_bit = 1<<7 ;
tomwalters@0 578 image_info.start_bit = image_info.left_bit ;
tomwalters@0 579
tomwalters@0 580 #endif
tomwalters@0 581
tomwalters@0 582 return ( &image_info ) ;
tomwalters@0 583 }
tomwalters@0 584
tomwalters@0 585 static void window__recall( info, which )
tomwalters@0 586 XWindowObject info ;
tomwalters@0 587 int which ;
tomwalters@0 588 {
tomwalters@0 589
tomwalters@0 590 #if defined(X11)
tomwalters@0 591 if (synchronous) {
tomwalters@0 592 (void) XSynchronize(theDisplay, FALSE);
tomwalters@0 593 XFlush(theDisplay);
tomwalters@0 594 synchronous = FALSE;
tomwalters@0 595 }
tomwalters@0 596 #endif
tomwalters@0 597 if( which > info->imageNum )
tomwalters@0 598 (void) fprintf( stderr, "Invalid Pixmap number %d(%d)\n", which, info->imageNum ) ;
tomwalters@0 599 else
tomwalters@0 600 #if defined(X11)
tomwalters@0 601 #ifdef USE_PIXMAPS
tomwalters@0 602 XCopyArea( theDisplay, info->imageData[ which-1 ], info->w, info->foregroundGC,
tomwalters@0 603 0, 0, Width( info), Height( info ), 0, 0 ) ;
tomwalters@0 604 #else
tomwalters@0 605 XPutImage(theDisplay, info->w, info->foregroundGC, info->imageData[which-1], 0, 0, 0, 0,
tomwalters@0 606 info->entries->width(info), info->entries->height(info));
tomwalters@0 607 #endif
tomwalters@0 608 XFlush(theDisplay) ;
tomwalters@0 609 #else
tomwalters@0 610 XPixmapBitsPutXY(info->w, 0, 0, info->entries->width(info), info->entries->height(info),
tomwalters@0 611 info->imageData[ which-1 ], (Bitmap) 0, GXcopy, AllPlanes);
tomwalters@0 612 #endif
tomwalters@0 613 return ;
tomwalters@0 614 }
tomwalters@0 615
tomwalters@0 616 #define MAX_COLORS 62
tomwalters@0 617
tomwalters@0 618 static char *cmap( npixels )
tomwalters@0 619 int *npixels ;
tomwalters@0 620 {
tomwalters@0 621 int plane_masks[1], pix_num ;
tomwalters@0 622 char *pixvals ;
tomwalters@0 623 #if defined(X11)
tomwalters@0 624 Visual *visual = DefaultVisual( theDisplay, theScreen ) ;
tomwalters@0 625 Colormap theColormap = DefaultColormap( theDisplay, theScreen ) ;
tomwalters@0 626 XColor exact_defs[MAX_COLORS] ;
tomwalters@0 627 unsigned long colors[MAX_COLORS] ;
tomwalters@0 628
tomwalters@0 629 switch( visual->class ) {
tomwalters@0 630 case StaticGray :
tomwalters@0 631
tomwalters@0 632 *npixels = 1 << DisplayPlanes( theDisplay, theScreen ) ;
tomwalters@0 633 pixvals = malloc( (unsigned) *npixels ) ;
tomwalters@0 634
tomwalters@0 635 for( pix_num=0 ; pix_num < *npixels ; pix_num++ )
tomwalters@0 636 pixvals[pix_num] = pix_num ;
tomwalters@0 637
tomwalters@0 638 break ;
tomwalters@0 639
tomwalters@0 640 case PseudoColor :
tomwalters@0 641
tomwalters@0 642 for( *npixels=MAX_COLORS; *npixels > 2 ; (*npixels)-- )
tomwalters@0 643 if( XAllocColorCells( theDisplay, theColormap, False, plane_masks, 0, colors, *npixels ) )
tomwalters@0 644 break ;
tomwalters@0 645
tomwalters@0 646 pixvals = malloc( (unsigned) *npixels + 2 ) ;
tomwalters@0 647
tomwalters@0 648 pixvals[0] = BlackPixel( theDisplay, theScreen ) ;
tomwalters@0 649
tomwalters@0 650 for( pix_num=0 ; pix_num < *npixels ; pix_num++ ) {
tomwalters@0 651 pixvals[pix_num+1] =
tomwalters@0 652 exact_defs[pix_num].pixel = colors[ pix_num ] ;
tomwalters@0 653
tomwalters@0 654 exact_defs[pix_num].red =
tomwalters@0 655 exact_defs[pix_num].green =
tomwalters@0 656 exact_defs[pix_num].blue = 65535 * ( pix_num + 1 ) / ( *npixels + 1 ) ;
tomwalters@0 657
tomwalters@0 658 exact_defs[pix_num].flags = DoRed | DoGreen | DoBlue ;
tomwalters@0 659 }
tomwalters@0 660
tomwalters@0 661 pixvals[*npixels+1] = WhitePixel( theDisplay, theScreen ) ;
tomwalters@0 662
tomwalters@0 663 XStoreColors( theDisplay, theColormap, exact_defs, *npixels ) ;
tomwalters@0 664
tomwalters@0 665 XFreeColors( theDisplay, theColormap, colors, *npixels, 0l ) ;
tomwalters@0 666
tomwalters@0 667 *npixels += 2 ;
tomwalters@0 668
tomwalters@0 669 break ;
tomwalters@0 670 }
tomwalters@0 671 #else
tomwalters@0 672 Color defs[256] ;
tomwalters@0 673 int pixels[256] ;
tomwalters@0 674 int planes ;
tomwalters@0 675
tomwalters@0 676 *npixels = ( 1 << DisplayPlanes() ) - 2 ;
tomwalters@0 677
tomwalters@0 678 while( !XGetColorCells( 0, *npixels, 0, & planes, pixels ) && *npixels > 0 )
tomwalters@0 679 *npixels-- ;
tomwalters@0 680
tomwalters@0 681 pixvals = malloc( (unsigned) *npixels + 2 ) ;
tomwalters@0 682
tomwalters@0 683 pixvals[ 0 ] = BlackPixel ;
tomwalters@0 684
tomwalters@0 685 for( pix_num=0 ; pix_num < *npixels ; pix_num++ ) {
tomwalters@0 686
tomwalters@0 687 pixvals[pix_num+1] =
tomwalters@0 688
tomwalters@0 689 defs[pix_num].pixel = pixels[pix_num] ;
tomwalters@0 690
tomwalters@0 691 defs[pix_num].red = 0 ;
tomwalters@0 692 defs[pix_num].green = 65535 * (pix_num+1) / (*npixels+1) ;
tomwalters@0 693 defs[pix_num].blue = 0 ;
tomwalters@0 694
tomwalters@0 695 }
tomwalters@0 696
tomwalters@0 697 pixvals[ *npixels+1 ] = WhitePixel ;
tomwalters@0 698
tomwalters@0 699 XStoreColors( *npixels, defs ) ;
tomwalters@0 700
tomwalters@0 701 XFreeColors( pixels, *npixels, planes ) ;
tomwalters@0 702
tomwalters@0 703 XFlush() ;
tomwalters@0 704
tomwalters@0 705 *npixels += 2 ;
tomwalters@0 706 #endif
tomwalters@0 707 return ( pixvals ) ;
tomwalters@0 708 }
tomwalters@0 709
tomwalters@0 710 static void ColorColumn( info, col, input, black, white, match, length, row_flag )
tomwalters@0 711 XWindowObject info ;
tomwalters@0 712 int col ;
tomwalters@0 713 short *input ;
tomwalters@0 714 int black, white ;
tomwalters@0 715 int *match, length ;
tomwalters@0 716 int row_flag ;
tomwalters@0 717 {
tomwalters@0 718 register int i ;
tomwalters@0 719 char *data ;
tomwalters@0 720
tomwalters@0 721 if( info->lookup == 0 || length != info->greylength ) {
tomwalters@0 722
tomwalters@0 723 if( info->lookup != 0 )
tomwalters@0 724 freeLookup( info->lookup ) ;
tomwalters@0 725
tomwalters@0 726 info->lookup = makeLookup( cmap, black, white, length ) ;
tomwalters@0 727
tomwalters@0 728 #if defined(X11)
tomwalters@0 729 if( row_flag )
tomwalters@0 730 info->rowImage = XGetImage( theDisplay, info->w, 0, 0, Width(info), 1, planemask, ZPixmap );
tomwalters@0 731 else
tomwalters@0 732 info->colImage = XGetImage( theDisplay, info->w, 0, 0, 1, Height(info), planemask, ZPixmap );
tomwalters@0 733
tomwalters@0 734 info->greylength = length ;
tomwalters@0 735 #endif
tomwalters@0 736 }
tomwalters@0 737
tomwalters@0 738 data = Lookup( col, info->lookup, input, match, length ) ;
tomwalters@0 739
tomwalters@0 740 #if defined(X11)
tomwalters@0 741 if( row_flag ) {
tomwalters@0 742 for( i=0 ; i<Width(info) ; i++ )
tomwalters@0 743 XPutPixel( info->rowImage, i, 0, (unsigned long) data[i] ) ;
tomwalters@0 744
tomwalters@0 745 XPutImage(theDisplay, info->w, info->foregroundGC, info->rowImage, 0, 0, 0, col-1, Width(info), 1 );
tomwalters@0 746 }
tomwalters@0 747 else {
tomwalters@0 748 for( i=0 ; i<Height(info) ; i++)
tomwalters@0 749 XPutPixel( info->colImage, 0, i, (unsigned long) data[i] ) ;
tomwalters@0 750
tomwalters@0 751 XPutImage(theDisplay, info->w, info->foregroundGC, info->colImage, 0, 0, col-1, 0, 1, Height(info) );
tomwalters@0 752 }
tomwalters@0 753 #else
tomwalters@0 754 if( row_flag )
tomwalters@0 755 XPixmapBitsPutZ( info->w, 0, col, length, 1, data, (Bitmap) 0, GXcopy, AllPlanes ) ;
tomwalters@0 756 else
tomwalters@0 757 XPixmapBitsPutZ( info->w, col, 0, 1, length, data, (Bitmap) 0, GXcopy, AllPlanes ) ;
tomwalters@0 758 XFlush() ;
tomwalters@0 759 #endif
tomwalters@0 760 return ;
tomwalters@0 761 }
tomwalters@0 762
tomwalters@0 763 static void DitherColumn( info, col, input, black, white, match, length, row_flag )
tomwalters@0 764 XWindowObject info ;
tomwalters@0 765 int col ;
tomwalters@0 766 short *input ;
tomwalters@0 767 int black, white ;
tomwalters@0 768 int *match, length ;
tomwalters@0 769 int row_flag ;
tomwalters@0 770 {
tomwalters@0 771 register int *mptr = match ;
tomwalters@0 772 register int *mend = match + length ;
tomwalters@0 773 register int x, bit, *dptr ;
tomwalters@0 774 #if defined(X11)
tomwalters@0 775 XPoint pts[2000] ;
tomwalters@0 776 int count = 0 ;
tomwalters@0 777 #endif
tomwalters@0 778
tomwalters@0 779 if( info->data == ( short * ) 0 || length != info->greylength ) {
tomwalters@0 780
tomwalters@0 781 if( info->data != ( short * ) 0 ) {
tomwalters@0 782 free( ( char * ) info->data ) ;
tomwalters@0 783 FreeDithers( info->diths, DITHER_SIZE ) ;
tomwalters@0 784 }
tomwalters@0 785
tomwalters@0 786 info->data = (short *) malloc( (unsigned) length * sizeof( *info->data ) ) ;
tomwalters@0 787 info->diths = Dithers( DITHER_SIZE, length, black, white ) ;
tomwalters@0 788
tomwalters@0 789 info->greylength = length ;
tomwalters@0 790 }
tomwalters@0 791
tomwalters@0 792 dptr = info->diths[ col%DITHER_SIZE ] ;
tomwalters@0 793
tomwalters@0 794 #if defined(X11)
tomwalters@0 795 if( row_flag ) {
tomwalters@0 796 while( mptr < mend )
tomwalters@0 797 if( input[ *mptr++ ] > *dptr++ ) {
tomwalters@0 798 pts[count].x = mptr - match ;
tomwalters@0 799 pts[count].y = col-1 ;
tomwalters@0 800 count++ ;
tomwalters@0 801 }
tomwalters@0 802 }
tomwalters@0 803 else {
tomwalters@0 804 while( mptr < mend )
tomwalters@0 805 if( input[ *mptr++ ] > *dptr++ ) {
tomwalters@0 806 pts[count].x = col-1 ;
tomwalters@0 807 pts[count].y = mptr - match ;
tomwalters@0 808 count++ ;
tomwalters@0 809 }
tomwalters@0 810 }
tomwalters@0 811
tomwalters@0 812 XDrawPoints(theDisplay, info->w, info->foregroundGC, pts, count, CoordModeOrigin ) ;
tomwalters@0 813 #else
tomwalters@0 814 if( row_flag ) {
tomwalters@0 815 while( mptr < mend ) {
tomwalters@0 816
tomwalters@0 817 x = mptr - match ;
tomwalters@0 818
tomwalters@0 819 if( x%16 == 0 )
tomwalters@0 820 info->data[x/16] = 0 ;
tomwalters@0 821
tomwalters@0 822 if( input[ *mptr++ ] <= *dptr++ )
tomwalters@0 823 info->data[x/16] |= 1<<x%16 ;
tomwalters@0 824 }
tomwalters@0 825
tomwalters@0 826 XPixmapBitsPutXY( info->w, 0, col, length, 1, info->data, (Bitmap) 0, GXcopy, AllPlanes ) ;
tomwalters@0 827 }
tomwalters@0 828 else {
tomwalters@0 829 while( mptr < mend )
tomwalters@0 830 info->data[mptr-match] = input[ *mptr++ ] <= *dptr++ ;
tomwalters@0 831
tomwalters@0 832 XPixmapBitsPutXY( info->w, col, 0, 1, length, info->data, (Bitmap) 0, GXcopy, AllPlanes ) ;
tomwalters@0 833 }
tomwalters@0 834 #endif
tomwalters@0 835
tomwalters@0 836 return ;
tomwalters@0 837 }
tomwalters@0 838
tomwalters@0 839
tomwalters@0 840 static void window__fill( info, col, input, black, white, match, length, row_flag )
tomwalters@0 841 XWindowObject info ;
tomwalters@0 842 int col;
tomwalters@0 843 short *input;
tomwalters@0 844 int black, white ;
tomwalters@0 845 int *match, length ;
tomwalters@0 846 int row_flag ;
tomwalters@0 847 {
tomwalters@0 848 int chans, chan, y, blacky;
tomwalters@0 849
tomwalters@0 850 #if defined(X11)
tomwalters@0 851 waitTillMapped(info) ;
tomwalters@0 852 #endif
tomwalters@0 853
tomwalters@0 854 if (info->pixels == 0 || 1 )
tomwalters@0 855
tomwalters@0 856 #if !defined(X11)
tomwalters@0 857 if (DisplayPlanes() > 1)
tomwalters@0 858 #else
tomwalters@0 859 if( DisplayPlanes( theDisplay, theScreen ) > 1 &&
tomwalters@0 860 DisplayPlanes( theDisplay, theScreen ) != 4 )
tomwalters@0 861 #endif
tomwalters@0 862 ColorColumn( info, col, input, black, white, match, length, row_flag );
tomwalters@0 863 else
tomwalters@0 864 DitherColumn( info, col, input, black, white, match, length, row_flag );
tomwalters@0 865
tomwalters@0 866 else { /* old line drawing simulation code to be removed */
tomwalters@0 867 chans = match[length - 1] + 1;
tomwalters@0 868
tomwalters@0 869 blacky = length;
tomwalters@0 870
tomwalters@0 871 for (chan = 0; chan < chans; chan++) {
tomwalters@0 872 y = length - length * chan / chans;
tomwalters@0 873 y -= (input[chan] - black) * length / (white - black) / chans;
tomwalters@0 874
tomwalters@0 875 if( y < blacky || !info->hide ) {
tomwalters@0 876 #if defined(X11)
tomwalters@0 877 XDrawPoint(theDisplay, info->w, info->foregroundGC, col, y);
tomwalters@0 878 #else
tomwalters@0 879 XPixSet(info->w, col, y, info->pixels, info->pixels, info->foreground ) ;
tomwalters@0 880 #endif
tomwalters@0 881 blacky = y;
tomwalters@0 882 }
tomwalters@0 883 }
tomwalters@0 884 }
tomwalters@0 885
tomwalters@0 886 return;
tomwalters@0 887 }
tomwalters@0 888
tomwalters@0 889 static void window__fillCol( info, col, input, black, white, match, length)
tomwalters@0 890 XWindowObject info ;
tomwalters@0 891 int col;
tomwalters@0 892 short *input ;
tomwalters@0 893 int black, white ;
tomwalters@0 894 int *match, length ;
tomwalters@0 895 {
tomwalters@0 896 window__fill( info, col, input, black, white, match, length, 0 ) ;
tomwalters@0 897
tomwalters@0 898 return ;
tomwalters@0 899 }
tomwalters@0 900
tomwalters@0 901 static void window__fillRow( info, col, input, black, white, match, length)
tomwalters@0 902 XWindowObject info ;
tomwalters@0 903 int col;
tomwalters@0 904 short *input;
tomwalters@0 905 int black, white ;
tomwalters@0 906 int *match, length ;
tomwalters@0 907 {
tomwalters@0 908 window__fill( info, col, input, black, white, match, length, 1 ) ;
tomwalters@0 909
tomwalters@0 910 return ;
tomwalters@0 911 }
tomwalters@0 912
tomwalters@0 913 static void window__function( info, ys, segment, skip, offset, yspan, start, points )
tomwalters@0 914 XWindowObject info ;
tomwalters@0 915 short *ys ;
tomwalters@0 916 int segment, skip ;
tomwalters@0 917 double offset, yspan ;
tomwalters@0 918 int start, points ;
tomwalters@0 919 {
tomwalters@0 920 #if defined(X11)
tomwalters@0 921 XPoint vs[ MAX_SEGMENT+4 ], *vptr ;
tomwalters@0 922 #else
tomwalters@0 923 Vertex vs[ MAX_SEGMENT+4 ], *vptr ;
tomwalters@0 924 #endif
tomwalters@0 925 register long x, dx, yscale ;
tomwalters@0 926 register int yoffset, point, count ;
tomwalters@0 927 register short *yptr ;
tomwalters@0 928 static long shift = 16 ;
tomwalters@0 929 static long round = 1l << 15 ;
tomwalters@0 930
tomwalters@0 931 #if defined(X11)
tomwalters@0 932 if (synchronous) {
tomwalters@0 933 (void) XSynchronize(theDisplay, FALSE);
tomwalters@0 934 XFlush(theDisplay);
tomwalters@0 935 synchronous = FALSE;
tomwalters@0 936 }
tomwalters@0 937
tomwalters@0 938 waitTillMapped(info) ;
tomwalters@0 939 #endif
tomwalters@0 940
tomwalters@0 941 points = abs(points);
tomwalters@0 942
tomwalters@0 943 if( points <= 1 )
tomwalters@0 944 return ;
tomwalters@0 945
tomwalters@0 946 yoffset = info->entries->height( info ) - offset ;
tomwalters@0 947
tomwalters@0 948 dx = ( double ) ( ( info->entries->width( info ) - 1 ) << shift ) / ( points - 1 ) + 0.5 ;
tomwalters@0 949 x = dx * start + ( 1 << shift ) + round ;
tomwalters@0 950
tomwalters@0 951 yscale = ( ( info->entries->height( info ) ) << shift ) / yspan + 0.5 ;
tomwalters@0 952
tomwalters@0 953 yptr = ys ;
tomwalters@0 954
tomwalters@0 955 for( point=0 ; point < segment-1 ; point += count-1 ) {
tomwalters@0 956
tomwalters@0 957 vptr = vs ;
tomwalters@0 958
tomwalters@0 959 for( count=0 ; count < MAX_SEGMENT && point + count < segment ; count++ ) {
tomwalters@0 960
tomwalters@0 961 vptr->x = x >> shift ;
tomwalters@0 962 vptr->y = yoffset - ( *yptr * yscale + round >> shift ) ;
tomwalters@0 963 #if defined(X10)
tomwalters@0 964 vptr->flags = 0;
tomwalters@0 965 #endif
tomwalters@0 966 vptr++ ;
tomwalters@0 967
tomwalters@0 968 if( count+1 < MAX_SEGMENT && point + count+1 < segment ) {
tomwalters@0 969 x += dx ;
tomwalters@0 970 yptr += skip ;
tomwalters@0 971 }
tomwalters@0 972 }
tomwalters@0 973
tomwalters@0 974 if( info->hide ) {
tomwalters@0 975
tomwalters@0 976 vptr->x = vptr[-1].x ;
tomwalters@0 977 vptr->y = 1 + yoffset ;
tomwalters@0 978 #if defined(X10)
tomwalters@0 979 vptr->flags = 0 ;
tomwalters@0 980 #endif
tomwalters@0 981 vptr++ ;
tomwalters@0 982
tomwalters@0 983 vptr->x = vs[0].x ;
tomwalters@0 984 vptr->y = vptr[-1].y ;
tomwalters@0 985 #if defined(X10)
tomwalters@0 986 vptr->flags = 0 ;
tomwalters@0 987 #endif
tomwalters@0 988 vptr++ ;
tomwalters@0 989
tomwalters@0 990 vptr->x = vs[0].x ;
tomwalters@0 991 vptr->y = vs[0].y ;
tomwalters@0 992 #if defined(X10)
tomwalters@0 993 vptr->flags = 0 ;
tomwalters@0 994 #endif
tomwalters@0 995 vptr++ ;
tomwalters@0 996
tomwalters@0 997 #if defined(X11)
tomwalters@0 998 XFillPolygon( theDisplay, info->w, info->backgroundGC, vs, vptr-vs, Complex, CoordModeOrigin);
tomwalters@0 999 }
tomwalters@0 1000
tomwalters@0 1001 XDrawLines(theDisplay, info->w, info->foregroundGC, vs, count, CoordModeOrigin);
tomwalters@0 1002 XFlush(theDisplay);
tomwalters@0 1003 #else
tomwalters@0 1004 XDrawFilled( info->w, vs, vptr-vs, info->background, GXcopy, AllPlanes ) ;
tomwalters@0 1005 }
tomwalters@0 1006
tomwalters@0 1007 XDraw( info->w, vs, count, info->pixels, info->pixels, info->foreground, GXcopy, AllPlanes ) ;
tomwalters@0 1008 #endif
tomwalters@0 1009 }
tomwalters@0 1010
tomwalters@0 1011 return ;
tomwalters@0 1012 }
tomwalters@0 1013
tomwalters@0 1014 typedef struct {
tomwalters@0 1015 FILE *imageFilePtr ; /* The File Pointer */
tomwalters@0 1016 int imageFilePreviousFrame ; /* The last image read */
tomwalters@0 1017 } ReadingData;
tomwalters@0 1018
tomwalters@0 1019 static ReadingData readingFiles[MAX_FILES], *current;
tomwalters@0 1020 static int numReadingFiles = 0 ;
tomwalters@0 1021 static int window__writing = 1 ;
tomwalters@0 1022
tomwalters@0 1023 /* --------------------------------------------------------------------
tomwalters@0 1024
tomwalters@0 1025 Search in the readingFiles[] array for the given filePtr. If found,
tomwalters@0 1026 return its index; otherwise return FAILURE (-1).
tomwalters@0 1027
tomwalters@0 1028 -------------------------------------------------------------------- */
tomwalters@0 1029
tomwalters@0 1030 static int findReadingFile( filePtr )
tomwalters@0 1031 FILE *filePtr;
tomwalters@0 1032 {
tomwalters@0 1033 int i;
tomwalters@0 1034
tomwalters@0 1035 for (i = 0; i < numReadingFiles; i++)
tomwalters@0 1036 if (readingFiles[i].imageFilePtr == filePtr)
tomwalters@0 1037 return (i);
tomwalters@0 1038
tomwalters@0 1039 return (-1);
tomwalters@0 1040
tomwalters@0 1041 }
tomwalters@0 1042
tomwalters@0 1043 static int window__read(w, filePtr, which)
tomwalters@0 1044 XWindowObject w ;
tomwalters@0 1045 FILE *filePtr;
tomwalters@0 1046 int which ;
tomwalters@0 1047 {
tomwalters@0 1048 int readingFileIndex ;
tomwalters@0 1049 long filePosBeforeSeek;
tomwalters@0 1050
tomwalters@0 1051 #if defined(X11)
tomwalters@0 1052 if (!synchronous) {
tomwalters@0 1053 (void) XSynchronize(theDisplay, TRUE);
tomwalters@0 1054 XFlush(theDisplay);
tomwalters@0 1055 synchronous = TRUE;
tomwalters@0 1056 }
tomwalters@0 1057
tomwalters@0 1058 waitTillMapped(w) ;
tomwalters@0 1059
tomwalters@0 1060 setupImage( w ) ;
tomwalters@0 1061 #else
tomwalters@0 1062 if( w->theImage == (short *) 0 ) {
tomwalters@0 1063 if((w->theImage = (short *) malloc(w->imageSize)) == NULL) {
tomwalters@0 1064 (void) fprintf(stderr, "windows: Insufficient memory to malloc %i bytes for a Pixmap.\n",
tomwalters@0 1065 w->imageSize);
tomwalters@0 1066 exit(1);
tomwalters@0 1067 }
tomwalters@0 1068 }
tomwalters@0 1069 #endif
tomwalters@0 1070
tomwalters@0 1071 if (numReadingFiles == 0 || current->imageFilePtr != filePtr) {
tomwalters@0 1072 if (numReadingFiles > 0 &&
tomwalters@0 1073 (readingFileIndex = findReadingFile(filePtr)) >= 0)
tomwalters@0 1074 current = &readingFiles[readingFileIndex];
tomwalters@0 1075 else {
tomwalters@0 1076 /* The First Read Operation (on this file) */
tomwalters@0 1077 if (numReadingFiles >= MAX_FILES) {
tomwalters@0 1078 fprintf(stderr,
tomwalters@0 1079 "windows: Sorry, you can only have %i files open for reading at once.\n",
tomwalters@0 1080 MAX_FILES);
tomwalters@0 1081 fprintf(stderr, " Hit <return> to exit.\n");
tomwalters@0 1082 getchar();
tomwalters@0 1083 exit(1);
tomwalters@0 1084 }
tomwalters@0 1085 current = &readingFiles[numReadingFiles] ;
tomwalters@0 1086 current->imageFilePtr = filePtr;
tomwalters@0 1087 current->imageFilePreviousFrame = 0 ;
tomwalters@0 1088 numReadingFiles++;
tomwalters@0 1089 }
tomwalters@0 1090 }
tomwalters@0 1091
tomwalters@0 1092 filePosBeforeSeek = ftell(current->imageFilePtr);
tomwalters@0 1093
tomwalters@0 1094 /* Now Read and Display it */
tomwalters@0 1095
tomwalters@0 1096 if (fseek(current->imageFilePtr,
tomwalters@0 1097 ((long) which - current->imageFilePreviousFrame - (long) 1) * w->imageSize, 1))
tomwalters@0 1098 return (FALSE);
tomwalters@0 1099
tomwalters@0 1100 #if defined(X11)
tomwalters@0 1101 if (fread(w->theImage->data, 1, w->imageSize, current->imageFilePtr) != w->imageSize) {
tomwalters@0 1102 #else
tomwalters@0 1103 if (fread(w->theImage, 1, w->imageSize, current->imageFilePtr) != w->imageSize) {
tomwalters@0 1104 #endif
tomwalters@0 1105 /* Reposition the filePointer to enable future Reads */
tomwalters@0 1106 if (fseek(current->imageFilePtr, filePosBeforeSeek, 0)) {
tomwalters@0 1107 (void) fprintf(stderr,
tomwalters@0 1108 "windows: Unable to reposition the file after a failed Read.\n");
tomwalters@0 1109 exit(1);
tomwalters@0 1110 }
tomwalters@0 1111 return (FALSE);
tomwalters@0 1112 }
tomwalters@0 1113
tomwalters@0 1114 #if defined(X11)
tomwalters@0 1115 XPutImage(theDisplay, w->w, w->foregroundGC, w->theImage, 0, 0, 0, 0, w->entries->width(w),
tomwalters@0 1116 w->entries->height(w));
tomwalters@0 1117 #else
tomwalters@0 1118 XPixmapBitsPutXY(w->w, 0, 0, w->entries->width(w), w->entries->height(w),
tomwalters@0 1119 w->theImage, (Bitmap) 0, GXcopy, AllPlanes);
tomwalters@0 1120 #endif
tomwalters@0 1121
tomwalters@0 1122 current->imageFilePreviousFrame = which;
tomwalters@0 1123
tomwalters@0 1124 return (TRUE);
tomwalters@0 1125 }
tomwalters@0 1126
tomwalters@0 1127
tomwalters@0 1128 static void window__write(w, filePtr)
tomwalters@0 1129 XWindowObject w;
tomwalters@0 1130 FILE *filePtr;
tomwalters@0 1131 {
tomwalters@0 1132 #if defined(X11)
tomwalters@0 1133 int imageSize;
tomwalters@0 1134 XImage *theImage;
tomwalters@0 1135
tomwalters@0 1136 theImage = XGetImage(theDisplay, w->w, 0, 0, w->entries->width(w), w->entries->height(w),
tomwalters@0 1137 planemask, XYPixmap);
tomwalters@0 1138
tomwalters@0 1139 imageSize = ImageSizeInBytes(theImage);
tomwalters@0 1140
tomwalters@0 1141 if (fwrite(theImage->data, 1, imageSize, filePtr) != imageSize) {
tomwalters@0 1142 fprintf(stderr,
tomwalters@0 1143 "window: WARNING! Failed to write %i bytes to Image File as image number %i.\n",
tomwalters@0 1144 imageSize, window__writing);
tomwalters@0 1145 fprintf(stderr, " Hit <return> to continue.\n");
tomwalters@0 1146 getchar();
tomwalters@0 1147 }
tomwalters@0 1148
tomwalters@0 1149 window__writing++;
tomwalters@0 1150
tomwalters@0 1151 (void) XDestroyImage(theImage);
tomwalters@0 1152 #else
tomwalters@0 1153 if( w->theImage == ( short * ) 0 ) {
tomwalters@0 1154 if((w->theImage = (short *) malloc(w->imageSize)) == NULL) {
tomwalters@0 1155 (void) fprintf(stderr, "windows: Insufficient memory to malloc %i bytes for a Pixmap.\n",
tomwalters@0 1156 w->imageSize);
tomwalters@0 1157 exit(1);
tomwalters@0 1158 }
tomwalters@0 1159 }
tomwalters@0 1160
tomwalters@0 1161 XPixmapGetXY(w->w, 0, 0, w->entries->width(w), w->entries->height(w), w->theImage) ;
tomwalters@0 1162
tomwalters@0 1163 (void) fwrite((char *) w->theImage, 1, (int) w->imageSize/DisplayPlanes(), filePtr) ;
tomwalters@0 1164 #endif
tomwalters@0 1165
tomwalters@0 1166 return;
tomwalters@0 1167 }
tomwalters@0 1168
tomwalters@0 1169
tomwalters@0 1170 static char window__pause(info)
tomwalters@0 1171 XWindowObject info ;
tomwalters@0 1172 {
tomwalters@0 1173 char line[256];
tomwalters@0 1174
tomwalters@0 1175 #if defined(X11)
tomwalters@0 1176 XFlush(theDisplay);
tomwalters@0 1177 #else
tomwalters@0 1178 XFlush();
tomwalters@0 1179 #endif
tomwalters@0 1180
tomwalters@0 1181 (void) gets(line);
tomwalters@0 1182
tomwalters@0 1183 if (line[0] == '\000' || line[0] == '\r' || line[0] == '\n')
tomwalters@0 1184 return (' ');
tomwalters@0 1185 else
tomwalters@0 1186 return (line[0]);
tomwalters@0 1187 }
tomwalters@0 1188
tomwalters@0 1189 static void window__axes(info, title, xmin, xmax, xtitle, ymin, ymax, ytitle)
tomwalters@0 1190 XWindowObject info;
tomwalters@0 1191 char *title, *xtitle, *ytitle;
tomwalters@0 1192 char *xmin, *xmax, *ymin, *ymax;
tomwalters@0 1193 {
tomwalters@0 1194 return;
tomwalters@0 1195 }
tomwalters@0 1196
tomwalters@0 1197 static void window__marker( info, label, p, points )
tomwalters@0 1198 XWindowObject info ;
tomwalters@0 1199 char *label ;
tomwalters@0 1200 int p, points ;
tomwalters@0 1201 {
tomwalters@0 1202 short pos = ( info->entries->width( info ) * p + points / 2 ) / points ;
tomwalters@0 1203
tomwalters@0 1204 #if defined( X11 )
tomwalters@0 1205 XDrawLine(theDisplay, info->w, info->foregroundGC, pos, 1, pos, info->entries->height(info));
tomwalters@0 1206 #else
tomwalters@0 1207 XLine( info->w, pos, 1, pos, info->entries->height( info ), info->pixels, info->pixels, info->foreground, GXcopy, AllPlanes ) ;
tomwalters@0 1208
tomwalters@0 1209 if( marker_font == ( FontInfo * ) 0 )
tomwalters@0 1210 marker_font = XOpenFont( marker_font_name ) ;
tomwalters@0 1211
tomwalters@0 1212 if( marker_font == ( FontInfo * ) 0 )
tomwalters@0 1213 (void) fprintf( stderr, "Unable to use font %s for marker %s\n", marker_font_name, label ) ;
tomwalters@0 1214 else
tomwalters@0 1215 XTextMaskPad( info->w, pos - 1 - XQueryWidth( label, marker_font->id ), 1,
tomwalters@0 1216 label, strlen( label ), marker_font->id, 0, 0, info->foreground, GXxor, AllPlanes ) ;
tomwalters@0 1217 #endif
tomwalters@0 1218
tomwalters@0 1219 return ;
tomwalters@0 1220 }
tomwalters@0 1221
tomwalters@0 1222 static int window__special( info, code, data )
tomwalters@0 1223 XWindowObject info ;
tomwalters@0 1224 int code ;
tomwalters@0 1225 char *data ;
tomwalters@0 1226 {
tomwalters@0 1227 return 0 ;
tomwalters@0 1228 }
tomwalters@0 1229
tomwalters@0 1230
tomwalters@0 1231 WindowObject newWindowWindow( window, default_x, default_y, default_width, default_height, pixels )
tomwalters@0 1232 Window window ;
tomwalters@0 1233 int default_x, default_y, default_width, default_height ;
tomwalters@0 1234 int pixels ;
tomwalters@0 1235 {
tomwalters@0 1236 static windowEntries entries = { window__x, window__y, window__width, window__height,
tomwalters@0 1237 window__draw, window__clear, window__close, window__store,
tomwalters@0 1238 window__recall, window__fillRow, window__fillCol,
tomwalters@0 1239 window__function, window__read, window__write,
tomwalters@0 1240 window__pause, window__axes, window__marker, window__special } ;
tomwalters@0 1241 XWindowObject info ;
tomwalters@0 1242 #if defined( X11 )
tomwalters@0 1243 XGCValues GCTemplate;
tomwalters@0 1244 #endif
tomwalters@0 1245
tomwalters@0 1246 if ((info = (XWindowObject ) malloc( sizeof(*info) )) == (XWindowObject )0) {
tomwalters@0 1247 (void) fprintf(stderr, "windows: Insufficient memory to allocate WindowObject.\n");
tomwalters@0 1248 exit(1);
tomwalters@0 1249 }
tomwalters@0 1250
tomwalters@0 1251 info->entries = &entries ;
tomwalters@0 1252 info->w = window ;
tomwalters@0 1253
tomwalters@0 1254 if( pixels < 0 )
tomwalters@0 1255 info->pixels = -pixels ;
tomwalters@0 1256 else
tomwalters@0 1257 info->pixels = pixels ;
tomwalters@0 1258
tomwalters@0 1259 info->hide = pixels < 0 ;
tomwalters@0 1260
tomwalters@0 1261 #if defined(X11)
tomwalters@0 1262 info->isMapped = 1 ;
tomwalters@0 1263
tomwalters@0 1264 /* Initialise a Graphics Context for lines and points */
tomwalters@0 1265
tomwalters@0 1266 GCTemplate.function = GXcopy ;
tomwalters@0 1267
tomwalters@0 1268 GCTemplate.foreground = theForeground ;
tomwalters@0 1269 GCTemplate.background = theBackground ;
tomwalters@0 1270
tomwalters@0 1271 GCTemplate.line_width = info->pixels ;
tomwalters@0 1272
tomwalters@0 1273 if( GCTemplate.line_width == 1 )
tomwalters@0 1274 GCTemplate.line_width = 0 ; /* use "thin" lines */
tomwalters@0 1275
tomwalters@0 1276 info->foregroundGC = XCreateGC( theDisplay, info->w,
tomwalters@0 1277 GCFunction|GCForeground|GCBackground|GCLineWidth, &GCTemplate ) ;
tomwalters@0 1278
tomwalters@0 1279 /* A second GC for clearing and hiding lines */
tomwalters@0 1280
tomwalters@0 1281 GCTemplate.foreground = theBackground ;
tomwalters@0 1282 GCTemplate.background = theForeground ;
tomwalters@0 1283
tomwalters@0 1284 info->backgroundGC = XCreateGC( theDisplay, info->w,
tomwalters@0 1285 GCFunction|GCForeground|GCBackground|GCLineWidth, &GCTemplate ) ;
tomwalters@0 1286
tomwalters@0 1287 #else
tomwalters@0 1288 info->foreground = WhitePixel ;
tomwalters@0 1289 info->background = BlackPixel ;
tomwalters@0 1290 info->lookup = 0;
tomwalters@0 1291 #endif
tomwalters@0 1292
tomwalters@0 1293 info->data = (short *) 0 ;
tomwalters@0 1294 info->greylength = 0 ;
tomwalters@0 1295
tomwalters@0 1296 /* update width and height fields */
tomwalters@0 1297
tomwalters@0 1298 info->x = default_x ;
tomwalters@0 1299 info->y = default_y ;
tomwalters@0 1300 info->width = default_width ;
tomwalters@0 1301 info->height = default_height;
tomwalters@0 1302
tomwalters@0 1303 checkGeometry( info ) ;
tomwalters@0 1304
tomwalters@0 1305 /* Initialise the Image Data Structure for later read operations */
tomwalters@0 1306
tomwalters@0 1307 #if defined(X11)
tomwalters@0 1308 info->theImage = info->rowImage = info->colImage = (XImage *) 0 ;
tomwalters@0 1309 #else
tomwalters@0 1310 info->imageSize = XYPixmapSize(info->entries->width(info), info->entries->height(info), DisplayPlanes());
tomwalters@0 1311 info->theImage = ( short * ) 0 ;
tomwalters@0 1312 #endif
tomwalters@0 1313
tomwalters@0 1314 info->imageNum = 0 ;
tomwalters@0 1315
tomwalters@0 1316 /* MAA: 3-8-1993
tomwalters@0 1317 * The planemask bits might as well go here as anywhere else
tomwalters@0 1318 */
tomwalters@0 1319
tomwalters@0 1320 if ( isON(colourstr) )
tomwalters@0 1321 planemask = AllPlanes;
tomwalters@0 1322 else
tomwalters@0 1323 planemask = atoi(planemaskstr);
tomwalters@0 1324
tomwalters@0 1325 return ( (WindowObject) info ) ;
tomwalters@0 1326 }
tomwalters@0 1327
tomwalters@0 1328 /* Since the <name> argument is always passed to newDisplayWindow as NULL, and
tomwalters@0 1329 the ASP modules don't have any concept of a configurable <display> option (the
tomwalters@0 1330 display is either ON or OFF), the <name> argument is redundant. The <name> argument
tomwalters@0 1331 still has a sensible use as the name of the Window which is being created, and
tomwalters@0 1332 its use has been modified as such in genbmm, revbmm, gensai and revsai... */
tomwalters@0 1333
tomwalters@0 1334
tomwalters@0 1335 WindowObject newXWindow( name, default_x, default_y, default_width, default_height, pixels )
tomwalters@0 1336 char *name ;
tomwalters@0 1337 int default_x, default_y, default_width, default_height ;
tomwalters@0 1338 int pixels ;
tomwalters@0 1339 {
tomwalters@0 1340 Window w ;
tomwalters@0 1341 XWindowObject info;
tomwalters@0 1342
tomwalters@0 1343 #if defined(X11)
tomwalters@0 1344
tomwalters@0 1345 if (theDisplay == (Display *) 0) {
tomwalters@0 1346 if ((theDisplay = XOpenDisplay(NULL)) == (Display *) 0) { /* Was name */
tomwalters@0 1347 (void) fprintf(stderr, "X11: Unable to do XOpenDisplay of display %s.\n",
tomwalters@0 1348 getenv("DISPLAY"));
tomwalters@0 1349 exit(1);
tomwalters@0 1350 }
tomwalters@0 1351
tomwalters@0 1352 theScreen = XDefaultScreen( theDisplay ) ;
tomwalters@0 1353
tomwalters@0 1354 /* MAA: 20-8-1993
tomwalters@0 1355 * lets put the colour bits here */
tomwalters@0 1356
tomwalters@0 1357 define_colours();
tomwalters@0 1358
tomwalters@0 1359 #ifndef SLAVE
tomwalters@0 1360 if (!synchronous) {
tomwalters@0 1361 (void) XSynchronize(theDisplay, TRUE);
tomwalters@0 1362 XFlush(theDisplay);
tomwalters@0 1363 synchronous = TRUE;
tomwalters@0 1364 }
tomwalters@0 1365 #endif
tomwalters@0 1366 }
tomwalters@0 1367
tomwalters@0 1368 /* Need to reset these every time, in case the screen is initialized
tomwalters@0 1369 independently via InitializeX */
tomwalters@0 1370
tomwalters@0 1371 theWidth = XDisplayWidth (theDisplay, theScreen);
tomwalters@0 1372 theHeight = XDisplayHeight(theDisplay, theScreen);
tomwalters@0 1373
tomwalters@0 1374 /* Perform "centering" calculations */
tomwalters@0 1375
tomwalters@0 1376 if (default_x < 0) {
tomwalters@0 1377 /* Center in the x dimension */
tomwalters@0 1378 default_width = (MIN(default_width, theWidth));
tomwalters@0 1379 default_x = (theWidth - default_width) / 2;
tomwalters@0 1380 }
tomwalters@0 1381
tomwalters@0 1382 if (default_y < 0) {
tomwalters@0 1383 /* Center in the y dimension */
tomwalters@0 1384 default_height = (MIN(default_height, theHeight));
tomwalters@0 1385 default_y = (theHeight - default_height) / 2;
tomwalters@0 1386 }
tomwalters@0 1387
tomwalters@0 1388 /* End of "centering" calculations */
tomwalters@0 1389 #else
tomwalters@0 1390 if( theDisplay == (Display *) 0 )
tomwalters@0 1391 if( ( theDisplay = XOpenDisplay(NULL) ) == (Display *) 0 ) {
tomwalters@0 1392 (void) fprintf(stderr, "Could not open DISPLAY \"%s\"\n", getenv("DISPLAY"));
tomwalters@0 1393 exit(1);
tomwalters@0 1394 }
tomwalters@0 1395
tomwalters@0 1396 #endif
tomwalters@0 1397
tomwalters@0 1398
tomwalters@0 1399
tomwalters@0 1400 #if defined(X11)
tomwalters@0 1401 if( default_width == 0 && default_height == 0 )
tomwalters@0 1402 w = XDefaultRootWindow(theDisplay);
tomwalters@0 1403 else
tomwalters@0 1404 if ((w = XCreateSimpleWindow(theDisplay, XDefaultRootWindow(theDisplay),
tomwalters@0 1405 default_x, default_y,
tomwalters@0 1406 (unsigned) default_width, (unsigned) default_height, 1,
tomwalters@0 1407 theForeground, theBackground)) != (Window) 0) {
tomwalters@0 1408 /*
tomwalters@0 1409 XSizeHints hints ;
tomwalters@0 1410
tomwalters@0 1411 hints.flags = PPosition | PSize ;
tomwalters@0 1412
tomwalters@0 1413 hints.x = default_x ;
tomwalters@0 1414 hints.y = default_y ;
tomwalters@0 1415 hints.width = default_width ;
tomwalters@0 1416 hints.height = default_height ;
tomwalters@0 1417 XSetStrandardProperties( theDisplay, w, name, name, None, name, 1, &hints ) ;
tomwalters@0 1418 */
tomwalters@0 1419 XStoreName(theDisplay, w, name);
tomwalters@0 1420 XMapRaised(theDisplay, w);
tomwalters@0 1421 XFlush( theDisplay);
tomwalters@0 1422 }
tomwalters@0 1423 #else
tomwalters@0 1424 if( default_width == 0 && default_height == 0 )
tomwalters@0 1425 w = RootWindow ;
tomwalters@0 1426 else
tomwalters@0 1427 if( ( w = XCreateWindow( RootWindow, abs( default_x ), abs( default_y ),
tomwalters@0 1428 default_width, default_height, 0, WhitePixmap,
tomwalters@0 1429 BlackPixmap ) ) != ( Window ) 0 ) {
tomwalters@0 1430 XStoreName( w, name ) ;
tomwalters@0 1431 XMapWindow( w ) ;
tomwalters@0 1432 XFlush() ;
tomwalters@0 1433 }
tomwalters@0 1434 #endif
tomwalters@0 1435 else {
tomwalters@0 1436 (void) fprintf( stderr,
tomwalters@0 1437 "Could not create window of size %dx%d at position %d,%d\n",
tomwalters@0 1438 default_width, default_height, default_x, default_y ) ;
tomwalters@0 1439 }
tomwalters@0 1440
tomwalters@0 1441 info = (XWindowObject) newWindowWindow(w, default_x, default_y, default_width, default_height, pixels);
tomwalters@0 1442 #if defined(X11)
tomwalters@0 1443 info->isMapped = 0 ;
tomwalters@0 1444 #endif
tomwalters@0 1445 info->entries->clear(info);
tomwalters@0 1446
tomwalters@0 1447 return((WindowObject)info);
tomwalters@0 1448
tomwalters@0 1449 }
tomwalters@0 1450
tomwalters@0 1451 #ifndef SLAVE
tomwalters@0 1452 WindowObject newDisplayWindow( name, default_x, default_y, default_width, default_height, pixels )
tomwalters@0 1453 char *name ;
tomwalters@0 1454 int default_x, default_y, default_width, default_height ;
tomwalters@0 1455 int pixels ;
tomwalters@0 1456 {
tomwalters@0 1457 return ( newXWindow( name, default_x, default_y, default_width, default_height, pixels ) ) ;
tomwalters@0 1458 }
tomwalters@0 1459 #endif