tomwalters@0: tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal shipping tomwalters@0: charge). Anyone wanting to incorporate all or part of this software in a tomwalters@0: commercial product must obtain a license from the Medical Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or implied tomwalters@0: warranty. tomwalters@0: */ tomwalters@0: tomwalters@0: /******************************************************************************************* tomwalters@0: tomwalters@0: X.c A GENERIC X-WINDOWS REAR-END FOR THE WINDOWS.H INTERFACE. tomwalters@0: tomwalters@0: tomwalters@0: This module is derived from the x10.c module, written by John Holdsworth, and the subsequent tomwalters@0: x11.c module, which was ported by Paul Manson. It attempts to combine the x10/x11 code in tomwalters@0: such a way as to provide a single uniform application with the minimal amount of #ifdef tomwalters@0: "noise". It expects to have either X10 or X11 defined as symbols by the preprocessor -- in the tomwalters@0: event that neither of these is defined, it produces an error message and causes the compiler tomwalters@0: to exit; ie. there is NO DEFAULT. tomwalters@0: tomwalters@0: Written: May 3rd. by Paul Manson (but see credits above) tomwalters@0: tomwalters@0: Edited: tomwalters@0: tomwalters@0: 15 May 1989 (Paul Manson) -- Altered the argument to use -1 in the tomwalters@0: newDisplay window call. On X11, pixels of 0 means "use tomwalters@0: thin lines", which always work correctly. Values greater tomwalters@0: than 0 imply "thick lines", which appear to over-write tomwalters@0: each other. tomwalters@0: tomwalters@0: 05 June 1989 (Paul Manson) -- Removed the offending "warning" message from axes();. tomwalters@0: tomwalters@0: 27 July 1989 (Johh Holdsworth) -- put in addition loops to segment line drawing tomwalters@0: operations for very long lines and put XFlush() in tomwalters@0: before pausing. A bug remains in the segentation of tomwalters@0: hidden line removal. The Fill operation Paint to hide tomwalters@0: lines lower than that just drawn can remove part of tomwalters@0: that line - very tricky to avoid. The same problem tomwalters@0: seem to be present in ps.c. tomwalters@0: tomwalters@0: 18 August 1989 (Paul Manson) -- Altered to accomodate the Pixmap/newWindowWindow entry tomwalters@0: which forces un-resizable windows on us with X11. tomwalters@0: tomwalters@0: 21 August 1989 (Paul Manson) -- Also altered "Clear" so that it does a FillRectangle in tomwalters@0: preference to a ClearWindow. The latter call doesn't work tomwalters@0: for Pixmaps (see newWindowWindow, etc). tomwalters@0: tomwalters@0: 22 August 1989 (Paul Manson) -- In a similar vein to the above, I have altered X.c so that tomwalters@0: two global variables Foreground and Background are used to tomwalters@0: determine the colours for drawing and filling. tomwalters@0: tomwalters@0: 04 September 1989 (Paul Manson) - Altered so that the GXmodes are used to modify the GC for tomwalters@0: clear, draw, etc operations. This seems to be a much more tomwalters@0: reliable way in which to manipulate these settings. tomwalters@0: tomwalters@0: 31 July 1990 (John Holdsworth) - Extensive changes to remove previous change. GXcopy tomwalters@0: now used with foreground appropiately set. This has tomwalters@0: proved more portable particularly for Multiplane displays. tomwalters@0: tomwalters@0: tomwalters@0: 26th May 1993 (Mitch d'Souza & M Akeroyd) - added an extra include - sys/types.h - so that the tomwalters@0: gcc would work on a decstation. tomwalters@0: tomwalters@0: 3rd August 1993 (M. Akeroyd) - Removed the 'XAllPlanes' bist of the XGetImage routines, tomwalters@0: so that monochrome bitmaps could be made on colour tomwalters@0: computers. tomwalters@0: Also included new SilentOptions : tomwalters@0: mono_ctn tomwalters@0: colour_ctn tomwalters@0: planemask_ctn tomwalters@0: tomwalters@0: 20th August 1993 (M.Akeroyd) - First attempt at colour images: two new options fg_col and tomwalters@0: bg_col, and a complementary procedure define_colour(). tomwalters@0: These do NOT work with view=grayscale. tomwalters@0: tomwalters@0: ********************************************************************************************/ tomwalters@0: tomwalters@0: tomwalters@0: #if !defined(X11) && !defined(X10) tomwalters@0: #define X11 tomwalters@0: #endif tomwalters@0: tomwalters@0: #if !defined(X10) && !defined(X11) tomwalters@0: #include "-- YOU MUST DEFINE EITHER X10 or X11 TO USE THIS MODULE" tomwalters@0: #endif tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "options.h" /* Added: MAA 3-8-1993 */ tomwalters@0: #if defined(X11) tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include /* MAA: 20-8-1993. For colour */ tomwalters@0: #include /* MAA: 20-8-1993. For colour */ tomwalters@0: tomwalters@0: tomwalters@0: #else tomwalters@0: #if defined(X10) tomwalters@0: #include tomwalters@0: #endif tomwalters@0: #endif tomwalters@0: tomwalters@0: #include "windows.h" tomwalters@0: #include "grey.h" tomwalters@0: tomwalters@0: #define FALSE (0) tomwalters@0: #define TRUE (1) tomwalters@0: #define MAX_FILES (20) tomwalters@0: #define MAX_SEGMENT (5000) tomwalters@0: #define MAX_ROW (100) tomwalters@0: #define MAX_COL (1000) tomwalters@0: #define MAX_IMAGE (1500) tomwalters@0: #define DITHER_SIZE (8) tomwalters@0: tomwalters@0: extern char *monostr, *colourstr, *planemaskstr; /* Added: MAA 3-8-1993 */ tomwalters@0: int planemask; tomwalters@0: tomwalters@0: static Display *theDisplay = (Display *) 0; /* The Display Variable */ tomwalters@0: static int theWidth, theHeight; /* The Width and Height of the Screen in Pixels */ tomwalters@0: tomwalters@0: #define MIN(X,Y) (((X) < (Y)) ? (X) : (Y)) tomwalters@0: tomwalters@0: #define USE_PIXMAPS tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: static int theScreen ; /* The associated screen no. */ tomwalters@0: static int synchronous = FALSE ; tomwalters@0: static unsigned long theForeground, theBackground; tomwalters@0: #else tomwalters@0: static char *marker_font_name = "6x10" ; tomwalters@0: static FontInfo *marker_font = ( FontInfo * ) 0 ; tomwalters@0: #endif tomwalters@0: tomwalters@0: typedef struct { tomwalters@0: windowEntries *entries ; tomwalters@0: Window w ; tomwalters@0: int pixels, width, height, hide ; tomwalters@0: int x, y ; tomwalters@0: #if defined(X11) tomwalters@0: GC foregroundGC ; tomwalters@0: GC backgroundGC ; tomwalters@0: int isMapped ; tomwalters@0: #ifdef USE_PIXMAPS tomwalters@0: Pixmap imageData[ MAX_IMAGE ]; tomwalters@0: #else tomwalters@0: XImage *imageData[ MAX_IMAGE ]; tomwalters@0: #endif tomwalters@0: XImage *theImage; /* Used only for Read operations; The wind__write */ tomwalters@0: /* entry point actually creates & destroys images */ tomwalters@0: XImage *rowImage, *colImage ; tomwalters@0: #else tomwalters@0: int foreground, background ; tomwalters@0: short *imageData[ MAX_IMAGE ]; tomwalters@0: short *theImage ; tomwalters@0: #endif tomwalters@0: struct _lookup *lookup ; /* Dithering */ tomwalters@0: int **diths ; /* Dithering */ tomwalters@0: short *data ; /* Dithering */ tomwalters@0: int greylength ; tomwalters@0: int imageNum ; tomwalters@0: int imageSize; tomwalters@0: } *XWindowObject ; tomwalters@0: tomwalters@0: #ifndef lint tomwalters@0: static char *sccs_id = "@(#)X.c 1.38 Paul Manson, John Holdsworth (MRC-APU) 5/31/91" ; tomwalters@0: #endif tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* MAA: Added 20-8-1993 tomwalters@0: * Colour .... tomwalters@0: * Copied off example 7.2 of Xlib Vol 1. tomwalters@0: */ tomwalters@0: tomwalters@0: extern char *fgcolourstr; tomwalters@0: extern char *bgcolourstr; tomwalters@0: tomwalters@0: void define_colours() tomwalters@0: { tomwalters@0: int default_depth; tomwalters@0: Visual *default_visual; tomwalters@0: XColor exact_def; tomwalters@0: Colormap default_cmap; tomwalters@0: int i=5; tomwalters@0: XVisualInfo visual_info; tomwalters@0: tomwalters@0: tomwalters@0: default_depth = DefaultDepth(theDisplay, theScreen); tomwalters@0: default_visual = DefaultVisual(theDisplay, theScreen); tomwalters@0: default_cmap = DefaultColormap(theDisplay, theScreen); tomwalters@0: tomwalters@0: /* MAA: Removed this. */ tomwalters@0: /* if (default_depth == 1) {*/ tomwalters@0: /* Black-White Only */ tomwalters@0: /* theForeground = BlackPixel(theDisplay, theScreen);*/ tomwalters@0: /* theBackground = WhitePixel(theDisplay, theScreen);}*/ tomwalters@0: tomwalters@0: /* i = visual class */ tomwalters@0: while (!XMatchVisualInfo(theDisplay, theScreen, default_depth, i--, &visual_info)) tomwalters@0: ; tomwalters@0: tomwalters@0: if (iisMapped ) { tomwalters@0: do tomwalters@0: XGetWindowAttributes( theDisplay, info->w, &at ) ; tomwalters@0: while ( at.map_state == IsUnmapped ) ; tomwalters@0: tomwalters@0: info->isMapped = 1 ; tomwalters@0: tomwalters@0: info->width = at.width ; tomwalters@0: info->height = at.height ; tomwalters@0: } tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: /* ---------------- Beware! This function may be the most dangerous thing --------------- tomwalters@0: ---------------- to ever appear on a DecStation... it makes --------------- tomwalters@0: ---------------- sweeping assumptions about the way that data --------------- tomwalters@0: ---------------- is stored in the X server. If it EVER happens --------------- tomwalters@0: ---------------- that the X Consortium write routines for I/O --------------- tomwalters@0: ---------------- of Screen Images, THROW THIS AWAY! --------------- */ tomwalters@0: static int ImageSizeInBytes(image) tomwalters@0: XImage *image; tomwalters@0: { tomwalters@0: tomwalters@0: /* Cribbed from X11R3/.../xwd.c */ tomwalters@0: tomwalters@0: return(image->bytes_per_line * image->height * image->depth); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: static setupImage( w ) tomwalters@0: XWindowObject w ; tomwalters@0: { tomwalters@0: if( w->theImage == ( XImage * ) 0 ) { tomwalters@0: w->theImage = XGetImage(theDisplay, w->w, 0, 0, w->entries->width(w), tomwalters@0: w->entries->height(w), planemask, XYPixmap); tomwalters@0: w->imageSize = ImageSizeInBytes(w->theImage); tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: #endif tomwalters@0: tomwalters@0: static short window__x( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: #if defined(OldX11) tomwalters@0: XWindowAttributes winfo; tomwalters@0: tomwalters@0: (void) XGetWindowAttributes( theDisplay, info->w, &winfo ); tomwalters@0: tomwalters@0: return ((short) winfo.x); tomwalters@0: #else tomwalters@0: #if defined(X11) tomwalters@0: return ((short) info->x); tomwalters@0: #else tomwalters@0: WindowInfo winfo; tomwalters@0: tomwalters@0: XQueryWindow(info->w, &winfo); tomwalters@0: tomwalters@0: return (winfo.x); tomwalters@0: #endif tomwalters@0: #endif tomwalters@0: } tomwalters@0: tomwalters@0: static short window__y( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: #if defined(OldX11) tomwalters@0: XWindowAttributes winfo; tomwalters@0: tomwalters@0: (void) XGetWindowAttributes( theDisplay, info->w, &winfo ); tomwalters@0: tomwalters@0: return ((short) winfo.y); tomwalters@0: #else tomwalters@0: #if defined(X11) tomwalters@0: return ((short) info->y); tomwalters@0: #else tomwalters@0: WindowInfo winfo; tomwalters@0: tomwalters@0: XQueryWindow(info->w, &winfo); tomwalters@0: tomwalters@0: return (winfo.y); tomwalters@0: #endif tomwalters@0: #endif tomwalters@0: } tomwalters@0: tomwalters@0: static short window__width( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: #if defined(X11) tomwalters@0: waitTillMapped(info) ; tomwalters@0: #endif tomwalters@0: tomwalters@0: return( info->width ) ; tomwalters@0: } tomwalters@0: tomwalters@0: static short window__height( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: #if defined(X11) tomwalters@0: waitTillMapped(info) ; tomwalters@0: #endif tomwalters@0: tomwalters@0: return( info->height ) ; tomwalters@0: } tomwalters@0: tomwalters@0: static void window__draw( info, xs, ys, pointsFlag ) tomwalters@0: XWindowObject info ; tomwalters@0: short xs[], ys[] ; tomwalters@0: int pointsFlag ; tomwalters@0: { tomwalters@0: #if defined(X11) tomwalters@0: XPoint vs[MAX_SEGMENT], *vptr; tomwalters@0: #else tomwalters@0: Vertex vs[MAX_SEGMENT], *vptr; tomwalters@0: #endif tomwalters@0: register int point, count ; tomwalters@0: register int points = abs( pointsFlag ) ; tomwalters@0: register short h ; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if (synchronous) { tomwalters@0: (void) XSynchronize(theDisplay, FALSE); tomwalters@0: XFlush(theDisplay); tomwalters@0: synchronous = FALSE; tomwalters@0: } tomwalters@0: tomwalters@0: waitTillMapped(info) ; tomwalters@0: #else tomwalters@0: int i ; tomwalters@0: #endif tomwalters@0: tomwalters@0: h = info->entries->height( info ); tomwalters@0: tomwalters@0: for( point = 0 ; point < points - 1 ; point += count - 1 ) { tomwalters@0: tomwalters@0: vptr = vs ; tomwalters@0: tomwalters@0: for( count=0 ; count < MAX_SEGMENT && point + count < points ; count++ ) { tomwalters@0: tomwalters@0: vptr->x = xs[ point+count ] ; tomwalters@0: vptr->y = h - ys[ point+count ] ; tomwalters@0: #if defined(X10) tomwalters@0: vptr->flags = pointsFlag > 0 ? 0 : 0 ; tomwalters@0: #endif tomwalters@0: vptr++; tomwalters@0: } tomwalters@0: tomwalters@0: if( info->hide && pointsFlag > 0 && vs[0].x == vptr[-1].x && tomwalters@0: vs[0].y == vptr[-1].y ) tomwalters@0: #if defined(X11) tomwalters@0: XFillPolygon( theDisplay, info->w, info->backgroundGC, vs, vptr-vs, Complex, CoordModeOrigin); tomwalters@0: tomwalters@0: if( pointsFlag > 0 ) tomwalters@0: XDrawLines( theDisplay, info->w, info->foregroundGC, vs, vptr-vs, CoordModeOrigin); tomwalters@0: else tomwalters@0: XDrawPoints(theDisplay, info->w, info->foregroundGC, vs, vptr-vs, CoordModeOrigin); tomwalters@0: tomwalters@0: XFlush(theDisplay); tomwalters@0: #else tomwalters@0: XDrawFilled( info->w, vs, vptr-vs, info->background, GXcopy, AllPlanes ) ; tomwalters@0: tomwalters@0: if( pointsFlag > 0 ) tomwalters@0: XDraw(info->w, vs, vptr-vs, info->pixels, info->pixels, info->foreground, GXcopy, AllPlanes); tomwalters@0: else tomwalters@0: for( i=0 ; iw, vs[i].x, vs[i].y, info->pixels, info->pixels, info->foreground ) ; tomwalters@0: #endif tomwalters@0: } tomwalters@0: tomwalters@0: return; tomwalters@0: } tomwalters@0: tomwalters@0: static void checkGeometry( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: #if defined(X11) tomwalters@0: return; tomwalters@0: #else tomwalters@0: #if defined(OldX11) tomwalters@0: XWindowAttributes winfo; tomwalters@0: tomwalters@0: (void) XGetWindowAttributes( theDisplay, info->w, &winfo ); tomwalters@0: #else tomwalters@0: WindowInfo winfo; tomwalters@0: tomwalters@0: XQueryWindow(info->w, &winfo); tomwalters@0: #endif tomwalters@0: tomwalters@0: info->width = winfo.width ; tomwalters@0: info->height = winfo.height ; tomwalters@0: tomwalters@0: return ; tomwalters@0: #endif tomwalters@0: } tomwalters@0: tomwalters@0: static void window__clear( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: tomwalters@0: checkGeometry( info ) ; tomwalters@0: tomwalters@0: #if defined(OldX11) tomwalters@0: XClearWindow(theDisplay, info->w); tomwalters@0: XFlush(theDisplay); tomwalters@0: #else tomwalters@0: #if defined(X11) tomwalters@0: XFlush(theDisplay); tomwalters@0: XFillRectangle( theDisplay, info->w, info->backgroundGC, 0, 0, info->width, info->height ) ; tomwalters@0: XFlush(theDisplay); tomwalters@0: #else tomwalters@0: XClear(info->w); tomwalters@0: #endif tomwalters@0: #endif tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: static void window__close( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: if (info != (XWindowObject )0) tomwalters@0: #if defined(X11) tomwalters@0: XFreeGC( theDisplay, info->foregroundGC ) ; tomwalters@0: XFreeGC( theDisplay, info->backgroundGC ) ; tomwalters@0: XDestroyWindow(theDisplay, info->w); tomwalters@0: #else tomwalters@0: XDestroyWindow(info->w); tomwalters@0: #endif tomwalters@0: free( (char *) info ) ; tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: static int window__store( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: if (info->imageNum > MAX_IMAGE) { tomwalters@0: (void) fprintf(stderr, tomwalters@0: "windows: Sorry, you can currently store only %i images per window.\n", tomwalters@0: MAX_IMAGE); tomwalters@0: return(FALSE); tomwalters@0: } tomwalters@0: #if defined(X11) tomwalters@0: if (!synchronous) { tomwalters@0: (void) XSynchronize(theDisplay, TRUE); tomwalters@0: XFlush(theDisplay); tomwalters@0: synchronous = TRUE; tomwalters@0: } tomwalters@0: tomwalters@0: waitTillMapped(info) ; tomwalters@0: tomwalters@0: #ifdef USE_PIXMAPS tomwalters@0: info->imageData[ info->imageNum ] = XCreatePixmap(theDisplay, info->w, Width( info ), Height( info ), DisplayPlanes( theDisplay, theScreen ) ) ; tomwalters@0: XCopyArea( theDisplay, info->w, info->imageData[ info->imageNum ], info->foregroundGC, 0, 0, Width( info), Height( info ), 0, 0 ) ; tomwalters@0: #else tomwalters@0: info->imageData[ info->imageNum ] = XGetImage(theDisplay, info->w, 0, 0, tomwalters@0: info->entries->width(info), tomwalters@0: info->entries->height(info), tomwalters@0: planemask, tomwalters@0: XYPixmap); tomwalters@0: #endif tomwalters@0: #else tomwalters@0: if((info->imageData[info->imageNum] = (short *) malloc(info->imageSize)) == (short *) 0) { tomwalters@0: (void) fprintf(stderr, "Insufficient memory to store %dth image of size %d\n", tomwalters@0: info->imageNum+1, info->imageSize); tomwalters@0: return(FALSE); tomwalters@0: } tomwalters@0: else tomwalters@0: XPixmapGetXY( info->w, 0, 0, info->entries->width(info), tomwalters@0: info->entries->height(info), info->imageData[ info->imageNum ] ) ; tomwalters@0: #endif tomwalters@0: info->imageNum++; tomwalters@0: tomwalters@0: return ( info->imageNum ) ; tomwalters@0: } tomwalters@0: tomwalters@0: WindowImage window__current_image( info ) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: static struct _window_image image_info ; tomwalters@0: #if defined(X11) tomwalters@0: #if !defined( USE_PIXMAPS) tomwalters@0: XImage *image_ptr = info->imageData[ info->imageNum-1 ] ; tomwalters@0: tomwalters@0: image_info.data = image_ptr->data ; tomwalters@0: image_info.bytes_per_line = image_ptr->bytes_per_line ; tomwalters@0: image_info.height = image_ptr->height ; tomwalters@0: tomwalters@0: image_info.left_bit = 1<<0 ; tomwalters@0: image_info.right_bit = 1<<7 ; tomwalters@0: image_info.start_bit = image_info.left_bit<xoffset ; tomwalters@0: #endif tomwalters@0: #else tomwalters@0: short *image_ptr = info->imageData[ info->imageNum-1 ] ; tomwalters@0: tomwalters@0: image_info.data = ( char *) image_ptr ; tomwalters@0: image_info.height = info->height ; tomwalters@0: image_info.bytes_per_line = ( info->width + 15 ) / 16 * sizeof (*image_ptr) ; tomwalters@0: tomwalters@0: image_info.left_bit = 1<<0 ; tomwalters@0: image_info.right_bit = 1<<7 ; tomwalters@0: image_info.start_bit = image_info.left_bit ; tomwalters@0: tomwalters@0: #endif tomwalters@0: tomwalters@0: return ( &image_info ) ; tomwalters@0: } tomwalters@0: tomwalters@0: static void window__recall( info, which ) tomwalters@0: XWindowObject info ; tomwalters@0: int which ; tomwalters@0: { tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if (synchronous) { tomwalters@0: (void) XSynchronize(theDisplay, FALSE); tomwalters@0: XFlush(theDisplay); tomwalters@0: synchronous = FALSE; tomwalters@0: } tomwalters@0: #endif tomwalters@0: if( which > info->imageNum ) tomwalters@0: (void) fprintf( stderr, "Invalid Pixmap number %d(%d)\n", which, info->imageNum ) ; tomwalters@0: else tomwalters@0: #if defined(X11) tomwalters@0: #ifdef USE_PIXMAPS tomwalters@0: XCopyArea( theDisplay, info->imageData[ which-1 ], info->w, info->foregroundGC, tomwalters@0: 0, 0, Width( info), Height( info ), 0, 0 ) ; tomwalters@0: #else tomwalters@0: XPutImage(theDisplay, info->w, info->foregroundGC, info->imageData[which-1], 0, 0, 0, 0, tomwalters@0: info->entries->width(info), info->entries->height(info)); tomwalters@0: #endif tomwalters@0: XFlush(theDisplay) ; tomwalters@0: #else tomwalters@0: XPixmapBitsPutXY(info->w, 0, 0, info->entries->width(info), info->entries->height(info), tomwalters@0: info->imageData[ which-1 ], (Bitmap) 0, GXcopy, AllPlanes); tomwalters@0: #endif tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: #define MAX_COLORS 62 tomwalters@0: tomwalters@0: static char *cmap( npixels ) tomwalters@0: int *npixels ; tomwalters@0: { tomwalters@0: int plane_masks[1], pix_num ; tomwalters@0: char *pixvals ; tomwalters@0: #if defined(X11) tomwalters@0: Visual *visual = DefaultVisual( theDisplay, theScreen ) ; tomwalters@0: Colormap theColormap = DefaultColormap( theDisplay, theScreen ) ; tomwalters@0: XColor exact_defs[MAX_COLORS] ; tomwalters@0: unsigned long colors[MAX_COLORS] ; tomwalters@0: tomwalters@0: switch( visual->class ) { tomwalters@0: case StaticGray : tomwalters@0: tomwalters@0: *npixels = 1 << DisplayPlanes( theDisplay, theScreen ) ; tomwalters@0: pixvals = malloc( (unsigned) *npixels ) ; tomwalters@0: tomwalters@0: for( pix_num=0 ; pix_num < *npixels ; pix_num++ ) tomwalters@0: pixvals[pix_num] = pix_num ; tomwalters@0: tomwalters@0: break ; tomwalters@0: tomwalters@0: case PseudoColor : tomwalters@0: tomwalters@0: for( *npixels=MAX_COLORS; *npixels > 2 ; (*npixels)-- ) tomwalters@0: if( XAllocColorCells( theDisplay, theColormap, False, plane_masks, 0, colors, *npixels ) ) tomwalters@0: break ; tomwalters@0: tomwalters@0: pixvals = malloc( (unsigned) *npixels + 2 ) ; tomwalters@0: tomwalters@0: pixvals[0] = BlackPixel( theDisplay, theScreen ) ; tomwalters@0: tomwalters@0: for( pix_num=0 ; pix_num < *npixels ; pix_num++ ) { tomwalters@0: pixvals[pix_num+1] = tomwalters@0: exact_defs[pix_num].pixel = colors[ pix_num ] ; tomwalters@0: tomwalters@0: exact_defs[pix_num].red = tomwalters@0: exact_defs[pix_num].green = tomwalters@0: exact_defs[pix_num].blue = 65535 * ( pix_num + 1 ) / ( *npixels + 1 ) ; tomwalters@0: tomwalters@0: exact_defs[pix_num].flags = DoRed | DoGreen | DoBlue ; tomwalters@0: } tomwalters@0: tomwalters@0: pixvals[*npixels+1] = WhitePixel( theDisplay, theScreen ) ; tomwalters@0: tomwalters@0: XStoreColors( theDisplay, theColormap, exact_defs, *npixels ) ; tomwalters@0: tomwalters@0: XFreeColors( theDisplay, theColormap, colors, *npixels, 0l ) ; tomwalters@0: tomwalters@0: *npixels += 2 ; tomwalters@0: tomwalters@0: break ; tomwalters@0: } tomwalters@0: #else tomwalters@0: Color defs[256] ; tomwalters@0: int pixels[256] ; tomwalters@0: int planes ; tomwalters@0: tomwalters@0: *npixels = ( 1 << DisplayPlanes() ) - 2 ; tomwalters@0: tomwalters@0: while( !XGetColorCells( 0, *npixels, 0, & planes, pixels ) && *npixels > 0 ) tomwalters@0: *npixels-- ; tomwalters@0: tomwalters@0: pixvals = malloc( (unsigned) *npixels + 2 ) ; tomwalters@0: tomwalters@0: pixvals[ 0 ] = BlackPixel ; tomwalters@0: tomwalters@0: for( pix_num=0 ; pix_num < *npixels ; pix_num++ ) { tomwalters@0: tomwalters@0: pixvals[pix_num+1] = tomwalters@0: tomwalters@0: defs[pix_num].pixel = pixels[pix_num] ; tomwalters@0: tomwalters@0: defs[pix_num].red = 0 ; tomwalters@0: defs[pix_num].green = 65535 * (pix_num+1) / (*npixels+1) ; tomwalters@0: defs[pix_num].blue = 0 ; tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: pixvals[ *npixels+1 ] = WhitePixel ; tomwalters@0: tomwalters@0: XStoreColors( *npixels, defs ) ; tomwalters@0: tomwalters@0: XFreeColors( pixels, *npixels, planes ) ; tomwalters@0: tomwalters@0: XFlush() ; tomwalters@0: tomwalters@0: *npixels += 2 ; tomwalters@0: #endif tomwalters@0: return ( pixvals ) ; tomwalters@0: } tomwalters@0: tomwalters@0: static void ColorColumn( info, col, input, black, white, match, length, row_flag ) tomwalters@0: XWindowObject info ; tomwalters@0: int col ; tomwalters@0: short *input ; tomwalters@0: int black, white ; tomwalters@0: int *match, length ; tomwalters@0: int row_flag ; tomwalters@0: { tomwalters@0: register int i ; tomwalters@0: char *data ; tomwalters@0: tomwalters@0: if( info->lookup == 0 || length != info->greylength ) { tomwalters@0: tomwalters@0: if( info->lookup != 0 ) tomwalters@0: freeLookup( info->lookup ) ; tomwalters@0: tomwalters@0: info->lookup = makeLookup( cmap, black, white, length ) ; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if( row_flag ) tomwalters@0: info->rowImage = XGetImage( theDisplay, info->w, 0, 0, Width(info), 1, planemask, ZPixmap ); tomwalters@0: else tomwalters@0: info->colImage = XGetImage( theDisplay, info->w, 0, 0, 1, Height(info), planemask, ZPixmap ); tomwalters@0: tomwalters@0: info->greylength = length ; tomwalters@0: #endif tomwalters@0: } tomwalters@0: tomwalters@0: data = Lookup( col, info->lookup, input, match, length ) ; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if( row_flag ) { tomwalters@0: for( i=0 ; irowImage, i, 0, (unsigned long) data[i] ) ; tomwalters@0: tomwalters@0: XPutImage(theDisplay, info->w, info->foregroundGC, info->rowImage, 0, 0, 0, col-1, Width(info), 1 ); tomwalters@0: } tomwalters@0: else { tomwalters@0: for( i=0 ; icolImage, 0, i, (unsigned long) data[i] ) ; tomwalters@0: tomwalters@0: XPutImage(theDisplay, info->w, info->foregroundGC, info->colImage, 0, 0, col-1, 0, 1, Height(info) ); tomwalters@0: } tomwalters@0: #else tomwalters@0: if( row_flag ) tomwalters@0: XPixmapBitsPutZ( info->w, 0, col, length, 1, data, (Bitmap) 0, GXcopy, AllPlanes ) ; tomwalters@0: else tomwalters@0: XPixmapBitsPutZ( info->w, col, 0, 1, length, data, (Bitmap) 0, GXcopy, AllPlanes ) ; tomwalters@0: XFlush() ; tomwalters@0: #endif tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: static void DitherColumn( info, col, input, black, white, match, length, row_flag ) tomwalters@0: XWindowObject info ; tomwalters@0: int col ; tomwalters@0: short *input ; tomwalters@0: int black, white ; tomwalters@0: int *match, length ; tomwalters@0: int row_flag ; tomwalters@0: { tomwalters@0: register int *mptr = match ; tomwalters@0: register int *mend = match + length ; tomwalters@0: register int x, bit, *dptr ; tomwalters@0: #if defined(X11) tomwalters@0: XPoint pts[2000] ; tomwalters@0: int count = 0 ; tomwalters@0: #endif tomwalters@0: tomwalters@0: if( info->data == ( short * ) 0 || length != info->greylength ) { tomwalters@0: tomwalters@0: if( info->data != ( short * ) 0 ) { tomwalters@0: free( ( char * ) info->data ) ; tomwalters@0: FreeDithers( info->diths, DITHER_SIZE ) ; tomwalters@0: } tomwalters@0: tomwalters@0: info->data = (short *) malloc( (unsigned) length * sizeof( *info->data ) ) ; tomwalters@0: info->diths = Dithers( DITHER_SIZE, length, black, white ) ; tomwalters@0: tomwalters@0: info->greylength = length ; tomwalters@0: } tomwalters@0: tomwalters@0: dptr = info->diths[ col%DITHER_SIZE ] ; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if( row_flag ) { tomwalters@0: while( mptr < mend ) tomwalters@0: if( input[ *mptr++ ] > *dptr++ ) { tomwalters@0: pts[count].x = mptr - match ; tomwalters@0: pts[count].y = col-1 ; tomwalters@0: count++ ; tomwalters@0: } tomwalters@0: } tomwalters@0: else { tomwalters@0: while( mptr < mend ) tomwalters@0: if( input[ *mptr++ ] > *dptr++ ) { tomwalters@0: pts[count].x = col-1 ; tomwalters@0: pts[count].y = mptr - match ; tomwalters@0: count++ ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: XDrawPoints(theDisplay, info->w, info->foregroundGC, pts, count, CoordModeOrigin ) ; tomwalters@0: #else tomwalters@0: if( row_flag ) { tomwalters@0: while( mptr < mend ) { tomwalters@0: tomwalters@0: x = mptr - match ; tomwalters@0: tomwalters@0: if( x%16 == 0 ) tomwalters@0: info->data[x/16] = 0 ; tomwalters@0: tomwalters@0: if( input[ *mptr++ ] <= *dptr++ ) tomwalters@0: info->data[x/16] |= 1<w, 0, col, length, 1, info->data, (Bitmap) 0, GXcopy, AllPlanes ) ; tomwalters@0: } tomwalters@0: else { tomwalters@0: while( mptr < mend ) tomwalters@0: info->data[mptr-match] = input[ *mptr++ ] <= *dptr++ ; tomwalters@0: tomwalters@0: XPixmapBitsPutXY( info->w, col, 0, 1, length, info->data, (Bitmap) 0, GXcopy, AllPlanes ) ; tomwalters@0: } tomwalters@0: #endif tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: static void window__fill( info, col, input, black, white, match, length, row_flag ) tomwalters@0: XWindowObject info ; tomwalters@0: int col; tomwalters@0: short *input; tomwalters@0: int black, white ; tomwalters@0: int *match, length ; tomwalters@0: int row_flag ; tomwalters@0: { tomwalters@0: int chans, chan, y, blacky; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: waitTillMapped(info) ; tomwalters@0: #endif tomwalters@0: tomwalters@0: if (info->pixels == 0 || 1 ) tomwalters@0: tomwalters@0: #if !defined(X11) tomwalters@0: if (DisplayPlanes() > 1) tomwalters@0: #else tomwalters@0: if( DisplayPlanes( theDisplay, theScreen ) > 1 && tomwalters@0: DisplayPlanes( theDisplay, theScreen ) != 4 ) tomwalters@0: #endif tomwalters@0: ColorColumn( info, col, input, black, white, match, length, row_flag ); tomwalters@0: else tomwalters@0: DitherColumn( info, col, input, black, white, match, length, row_flag ); tomwalters@0: tomwalters@0: else { /* old line drawing simulation code to be removed */ tomwalters@0: chans = match[length - 1] + 1; tomwalters@0: tomwalters@0: blacky = length; tomwalters@0: tomwalters@0: for (chan = 0; chan < chans; chan++) { tomwalters@0: y = length - length * chan / chans; tomwalters@0: y -= (input[chan] - black) * length / (white - black) / chans; tomwalters@0: tomwalters@0: if( y < blacky || !info->hide ) { tomwalters@0: #if defined(X11) tomwalters@0: XDrawPoint(theDisplay, info->w, info->foregroundGC, col, y); tomwalters@0: #else tomwalters@0: XPixSet(info->w, col, y, info->pixels, info->pixels, info->foreground ) ; tomwalters@0: #endif tomwalters@0: blacky = y; tomwalters@0: } tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: return; tomwalters@0: } tomwalters@0: tomwalters@0: static void window__fillCol( info, col, input, black, white, match, length) tomwalters@0: XWindowObject info ; tomwalters@0: int col; tomwalters@0: short *input ; tomwalters@0: int black, white ; tomwalters@0: int *match, length ; tomwalters@0: { tomwalters@0: window__fill( info, col, input, black, white, match, length, 0 ) ; tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: static void window__fillRow( info, col, input, black, white, match, length) tomwalters@0: XWindowObject info ; tomwalters@0: int col; tomwalters@0: short *input; tomwalters@0: int black, white ; tomwalters@0: int *match, length ; tomwalters@0: { tomwalters@0: window__fill( info, col, input, black, white, match, length, 1 ) ; tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: static void window__function( info, ys, segment, skip, offset, yspan, start, points ) tomwalters@0: XWindowObject info ; tomwalters@0: short *ys ; tomwalters@0: int segment, skip ; tomwalters@0: double offset, yspan ; tomwalters@0: int start, points ; tomwalters@0: { tomwalters@0: #if defined(X11) tomwalters@0: XPoint vs[ MAX_SEGMENT+4 ], *vptr ; tomwalters@0: #else tomwalters@0: Vertex vs[ MAX_SEGMENT+4 ], *vptr ; tomwalters@0: #endif tomwalters@0: register long x, dx, yscale ; tomwalters@0: register int yoffset, point, count ; tomwalters@0: register short *yptr ; tomwalters@0: static long shift = 16 ; tomwalters@0: static long round = 1l << 15 ; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if (synchronous) { tomwalters@0: (void) XSynchronize(theDisplay, FALSE); tomwalters@0: XFlush(theDisplay); tomwalters@0: synchronous = FALSE; tomwalters@0: } tomwalters@0: tomwalters@0: waitTillMapped(info) ; tomwalters@0: #endif tomwalters@0: tomwalters@0: points = abs(points); tomwalters@0: tomwalters@0: if( points <= 1 ) tomwalters@0: return ; tomwalters@0: tomwalters@0: yoffset = info->entries->height( info ) - offset ; tomwalters@0: tomwalters@0: dx = ( double ) ( ( info->entries->width( info ) - 1 ) << shift ) / ( points - 1 ) + 0.5 ; tomwalters@0: x = dx * start + ( 1 << shift ) + round ; tomwalters@0: tomwalters@0: yscale = ( ( info->entries->height( info ) ) << shift ) / yspan + 0.5 ; tomwalters@0: tomwalters@0: yptr = ys ; tomwalters@0: tomwalters@0: for( point=0 ; point < segment-1 ; point += count-1 ) { tomwalters@0: tomwalters@0: vptr = vs ; tomwalters@0: tomwalters@0: for( count=0 ; count < MAX_SEGMENT && point + count < segment ; count++ ) { tomwalters@0: tomwalters@0: vptr->x = x >> shift ; tomwalters@0: vptr->y = yoffset - ( *yptr * yscale + round >> shift ) ; tomwalters@0: #if defined(X10) tomwalters@0: vptr->flags = 0; tomwalters@0: #endif tomwalters@0: vptr++ ; tomwalters@0: tomwalters@0: if( count+1 < MAX_SEGMENT && point + count+1 < segment ) { tomwalters@0: x += dx ; tomwalters@0: yptr += skip ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: if( info->hide ) { tomwalters@0: tomwalters@0: vptr->x = vptr[-1].x ; tomwalters@0: vptr->y = 1 + yoffset ; tomwalters@0: #if defined(X10) tomwalters@0: vptr->flags = 0 ; tomwalters@0: #endif tomwalters@0: vptr++ ; tomwalters@0: tomwalters@0: vptr->x = vs[0].x ; tomwalters@0: vptr->y = vptr[-1].y ; tomwalters@0: #if defined(X10) tomwalters@0: vptr->flags = 0 ; tomwalters@0: #endif tomwalters@0: vptr++ ; tomwalters@0: tomwalters@0: vptr->x = vs[0].x ; tomwalters@0: vptr->y = vs[0].y ; tomwalters@0: #if defined(X10) tomwalters@0: vptr->flags = 0 ; tomwalters@0: #endif tomwalters@0: vptr++ ; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: XFillPolygon( theDisplay, info->w, info->backgroundGC, vs, vptr-vs, Complex, CoordModeOrigin); tomwalters@0: } tomwalters@0: tomwalters@0: XDrawLines(theDisplay, info->w, info->foregroundGC, vs, count, CoordModeOrigin); tomwalters@0: XFlush(theDisplay); tomwalters@0: #else tomwalters@0: XDrawFilled( info->w, vs, vptr-vs, info->background, GXcopy, AllPlanes ) ; tomwalters@0: } tomwalters@0: tomwalters@0: XDraw( info->w, vs, count, info->pixels, info->pixels, info->foreground, GXcopy, AllPlanes ) ; tomwalters@0: #endif tomwalters@0: } tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: typedef struct { tomwalters@0: FILE *imageFilePtr ; /* The File Pointer */ tomwalters@0: int imageFilePreviousFrame ; /* The last image read */ tomwalters@0: } ReadingData; tomwalters@0: tomwalters@0: static ReadingData readingFiles[MAX_FILES], *current; tomwalters@0: static int numReadingFiles = 0 ; tomwalters@0: static int window__writing = 1 ; tomwalters@0: tomwalters@0: /* -------------------------------------------------------------------- tomwalters@0: tomwalters@0: Search in the readingFiles[] array for the given filePtr. If found, tomwalters@0: return its index; otherwise return FAILURE (-1). tomwalters@0: tomwalters@0: -------------------------------------------------------------------- */ tomwalters@0: tomwalters@0: static int findReadingFile( filePtr ) tomwalters@0: FILE *filePtr; tomwalters@0: { tomwalters@0: int i; tomwalters@0: tomwalters@0: for (i = 0; i < numReadingFiles; i++) tomwalters@0: if (readingFiles[i].imageFilePtr == filePtr) tomwalters@0: return (i); tomwalters@0: tomwalters@0: return (-1); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: static int window__read(w, filePtr, which) tomwalters@0: XWindowObject w ; tomwalters@0: FILE *filePtr; tomwalters@0: int which ; tomwalters@0: { tomwalters@0: int readingFileIndex ; tomwalters@0: long filePosBeforeSeek; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if (!synchronous) { tomwalters@0: (void) XSynchronize(theDisplay, TRUE); tomwalters@0: XFlush(theDisplay); tomwalters@0: synchronous = TRUE; tomwalters@0: } tomwalters@0: tomwalters@0: waitTillMapped(w) ; tomwalters@0: tomwalters@0: setupImage( w ) ; tomwalters@0: #else tomwalters@0: if( w->theImage == (short *) 0 ) { tomwalters@0: if((w->theImage = (short *) malloc(w->imageSize)) == NULL) { tomwalters@0: (void) fprintf(stderr, "windows: Insufficient memory to malloc %i bytes for a Pixmap.\n", tomwalters@0: w->imageSize); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: } tomwalters@0: #endif tomwalters@0: tomwalters@0: if (numReadingFiles == 0 || current->imageFilePtr != filePtr) { tomwalters@0: if (numReadingFiles > 0 && tomwalters@0: (readingFileIndex = findReadingFile(filePtr)) >= 0) tomwalters@0: current = &readingFiles[readingFileIndex]; tomwalters@0: else { tomwalters@0: /* The First Read Operation (on this file) */ tomwalters@0: if (numReadingFiles >= MAX_FILES) { tomwalters@0: fprintf(stderr, tomwalters@0: "windows: Sorry, you can only have %i files open for reading at once.\n", tomwalters@0: MAX_FILES); tomwalters@0: fprintf(stderr, " Hit to exit.\n"); tomwalters@0: getchar(); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: current = &readingFiles[numReadingFiles] ; tomwalters@0: current->imageFilePtr = filePtr; tomwalters@0: current->imageFilePreviousFrame = 0 ; tomwalters@0: numReadingFiles++; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: filePosBeforeSeek = ftell(current->imageFilePtr); tomwalters@0: tomwalters@0: /* Now Read and Display it */ tomwalters@0: tomwalters@0: if (fseek(current->imageFilePtr, tomwalters@0: ((long) which - current->imageFilePreviousFrame - (long) 1) * w->imageSize, 1)) tomwalters@0: return (FALSE); tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if (fread(w->theImage->data, 1, w->imageSize, current->imageFilePtr) != w->imageSize) { tomwalters@0: #else tomwalters@0: if (fread(w->theImage, 1, w->imageSize, current->imageFilePtr) != w->imageSize) { tomwalters@0: #endif tomwalters@0: /* Reposition the filePointer to enable future Reads */ tomwalters@0: if (fseek(current->imageFilePtr, filePosBeforeSeek, 0)) { tomwalters@0: (void) fprintf(stderr, tomwalters@0: "windows: Unable to reposition the file after a failed Read.\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: return (FALSE); tomwalters@0: } tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: XPutImage(theDisplay, w->w, w->foregroundGC, w->theImage, 0, 0, 0, 0, w->entries->width(w), tomwalters@0: w->entries->height(w)); tomwalters@0: #else tomwalters@0: XPixmapBitsPutXY(w->w, 0, 0, w->entries->width(w), w->entries->height(w), tomwalters@0: w->theImage, (Bitmap) 0, GXcopy, AllPlanes); tomwalters@0: #endif tomwalters@0: tomwalters@0: current->imageFilePreviousFrame = which; tomwalters@0: tomwalters@0: return (TRUE); tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: static void window__write(w, filePtr) tomwalters@0: XWindowObject w; tomwalters@0: FILE *filePtr; tomwalters@0: { tomwalters@0: #if defined(X11) tomwalters@0: int imageSize; tomwalters@0: XImage *theImage; tomwalters@0: tomwalters@0: theImage = XGetImage(theDisplay, w->w, 0, 0, w->entries->width(w), w->entries->height(w), tomwalters@0: planemask, XYPixmap); tomwalters@0: tomwalters@0: imageSize = ImageSizeInBytes(theImage); tomwalters@0: tomwalters@0: if (fwrite(theImage->data, 1, imageSize, filePtr) != imageSize) { tomwalters@0: fprintf(stderr, tomwalters@0: "window: WARNING! Failed to write %i bytes to Image File as image number %i.\n", tomwalters@0: imageSize, window__writing); tomwalters@0: fprintf(stderr, " Hit to continue.\n"); tomwalters@0: getchar(); tomwalters@0: } tomwalters@0: tomwalters@0: window__writing++; tomwalters@0: tomwalters@0: (void) XDestroyImage(theImage); tomwalters@0: #else tomwalters@0: if( w->theImage == ( short * ) 0 ) { tomwalters@0: if((w->theImage = (short *) malloc(w->imageSize)) == NULL) { tomwalters@0: (void) fprintf(stderr, "windows: Insufficient memory to malloc %i bytes for a Pixmap.\n", tomwalters@0: w->imageSize); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: XPixmapGetXY(w->w, 0, 0, w->entries->width(w), w->entries->height(w), w->theImage) ; tomwalters@0: tomwalters@0: (void) fwrite((char *) w->theImage, 1, (int) w->imageSize/DisplayPlanes(), filePtr) ; tomwalters@0: #endif tomwalters@0: tomwalters@0: return; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: static char window__pause(info) tomwalters@0: XWindowObject info ; tomwalters@0: { tomwalters@0: char line[256]; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: XFlush(theDisplay); tomwalters@0: #else tomwalters@0: XFlush(); tomwalters@0: #endif tomwalters@0: tomwalters@0: (void) gets(line); tomwalters@0: tomwalters@0: if (line[0] == '\000' || line[0] == '\r' || line[0] == '\n') tomwalters@0: return (' '); tomwalters@0: else tomwalters@0: return (line[0]); tomwalters@0: } tomwalters@0: tomwalters@0: static void window__axes(info, title, xmin, xmax, xtitle, ymin, ymax, ytitle) tomwalters@0: XWindowObject info; tomwalters@0: char *title, *xtitle, *ytitle; tomwalters@0: char *xmin, *xmax, *ymin, *ymax; tomwalters@0: { tomwalters@0: return; tomwalters@0: } tomwalters@0: tomwalters@0: static void window__marker( info, label, p, points ) tomwalters@0: XWindowObject info ; tomwalters@0: char *label ; tomwalters@0: int p, points ; tomwalters@0: { tomwalters@0: short pos = ( info->entries->width( info ) * p + points / 2 ) / points ; tomwalters@0: tomwalters@0: #if defined( X11 ) tomwalters@0: XDrawLine(theDisplay, info->w, info->foregroundGC, pos, 1, pos, info->entries->height(info)); tomwalters@0: #else tomwalters@0: XLine( info->w, pos, 1, pos, info->entries->height( info ), info->pixels, info->pixels, info->foreground, GXcopy, AllPlanes ) ; tomwalters@0: tomwalters@0: if( marker_font == ( FontInfo * ) 0 ) tomwalters@0: marker_font = XOpenFont( marker_font_name ) ; tomwalters@0: tomwalters@0: if( marker_font == ( FontInfo * ) 0 ) tomwalters@0: (void) fprintf( stderr, "Unable to use font %s for marker %s\n", marker_font_name, label ) ; tomwalters@0: else tomwalters@0: XTextMaskPad( info->w, pos - 1 - XQueryWidth( label, marker_font->id ), 1, tomwalters@0: label, strlen( label ), marker_font->id, 0, 0, info->foreground, GXxor, AllPlanes ) ; tomwalters@0: #endif tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: static int window__special( info, code, data ) tomwalters@0: XWindowObject info ; tomwalters@0: int code ; tomwalters@0: char *data ; tomwalters@0: { tomwalters@0: return 0 ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: WindowObject newWindowWindow( window, default_x, default_y, default_width, default_height, pixels ) tomwalters@0: Window window ; tomwalters@0: int default_x, default_y, default_width, default_height ; tomwalters@0: int pixels ; tomwalters@0: { tomwalters@0: static windowEntries entries = { window__x, window__y, window__width, window__height, tomwalters@0: window__draw, window__clear, window__close, window__store, tomwalters@0: window__recall, window__fillRow, window__fillCol, tomwalters@0: window__function, window__read, window__write, tomwalters@0: window__pause, window__axes, window__marker, window__special } ; tomwalters@0: XWindowObject info ; tomwalters@0: #if defined( X11 ) tomwalters@0: XGCValues GCTemplate; tomwalters@0: #endif tomwalters@0: tomwalters@0: if ((info = (XWindowObject ) malloc( sizeof(*info) )) == (XWindowObject )0) { tomwalters@0: (void) fprintf(stderr, "windows: Insufficient memory to allocate WindowObject.\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: info->entries = &entries ; tomwalters@0: info->w = window ; tomwalters@0: tomwalters@0: if( pixels < 0 ) tomwalters@0: info->pixels = -pixels ; tomwalters@0: else tomwalters@0: info->pixels = pixels ; tomwalters@0: tomwalters@0: info->hide = pixels < 0 ; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: info->isMapped = 1 ; tomwalters@0: tomwalters@0: /* Initialise a Graphics Context for lines and points */ tomwalters@0: tomwalters@0: GCTemplate.function = GXcopy ; tomwalters@0: tomwalters@0: GCTemplate.foreground = theForeground ; tomwalters@0: GCTemplate.background = theBackground ; tomwalters@0: tomwalters@0: GCTemplate.line_width = info->pixels ; tomwalters@0: tomwalters@0: if( GCTemplate.line_width == 1 ) tomwalters@0: GCTemplate.line_width = 0 ; /* use "thin" lines */ tomwalters@0: tomwalters@0: info->foregroundGC = XCreateGC( theDisplay, info->w, tomwalters@0: GCFunction|GCForeground|GCBackground|GCLineWidth, &GCTemplate ) ; tomwalters@0: tomwalters@0: /* A second GC for clearing and hiding lines */ tomwalters@0: tomwalters@0: GCTemplate.foreground = theBackground ; tomwalters@0: GCTemplate.background = theForeground ; tomwalters@0: tomwalters@0: info->backgroundGC = XCreateGC( theDisplay, info->w, tomwalters@0: GCFunction|GCForeground|GCBackground|GCLineWidth, &GCTemplate ) ; tomwalters@0: tomwalters@0: #else tomwalters@0: info->foreground = WhitePixel ; tomwalters@0: info->background = BlackPixel ; tomwalters@0: info->lookup = 0; tomwalters@0: #endif tomwalters@0: tomwalters@0: info->data = (short *) 0 ; tomwalters@0: info->greylength = 0 ; tomwalters@0: tomwalters@0: /* update width and height fields */ tomwalters@0: tomwalters@0: info->x = default_x ; tomwalters@0: info->y = default_y ; tomwalters@0: info->width = default_width ; tomwalters@0: info->height = default_height; tomwalters@0: tomwalters@0: checkGeometry( info ) ; tomwalters@0: tomwalters@0: /* Initialise the Image Data Structure for later read operations */ tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: info->theImage = info->rowImage = info->colImage = (XImage *) 0 ; tomwalters@0: #else tomwalters@0: info->imageSize = XYPixmapSize(info->entries->width(info), info->entries->height(info), DisplayPlanes()); tomwalters@0: info->theImage = ( short * ) 0 ; tomwalters@0: #endif tomwalters@0: tomwalters@0: info->imageNum = 0 ; tomwalters@0: tomwalters@0: /* MAA: 3-8-1993 tomwalters@0: * The planemask bits might as well go here as anywhere else tomwalters@0: */ tomwalters@0: tomwalters@0: if ( isON(colourstr) ) tomwalters@0: planemask = AllPlanes; tomwalters@0: else tomwalters@0: planemask = atoi(planemaskstr); tomwalters@0: tomwalters@0: return ( (WindowObject) info ) ; tomwalters@0: } tomwalters@0: tomwalters@0: /* Since the argument is always passed to newDisplayWindow as NULL, and tomwalters@0: the ASP modules don't have any concept of a configurable option (the tomwalters@0: display is either ON or OFF), the argument is redundant. The argument tomwalters@0: still has a sensible use as the name of the Window which is being created, and tomwalters@0: its use has been modified as such in genbmm, revbmm, gensai and revsai... */ tomwalters@0: tomwalters@0: tomwalters@0: WindowObject newXWindow( name, default_x, default_y, default_width, default_height, pixels ) tomwalters@0: char *name ; tomwalters@0: int default_x, default_y, default_width, default_height ; tomwalters@0: int pixels ; tomwalters@0: { tomwalters@0: Window w ; tomwalters@0: XWindowObject info; tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: tomwalters@0: if (theDisplay == (Display *) 0) { tomwalters@0: if ((theDisplay = XOpenDisplay(NULL)) == (Display *) 0) { /* Was name */ tomwalters@0: (void) fprintf(stderr, "X11: Unable to do XOpenDisplay of display %s.\n", tomwalters@0: getenv("DISPLAY")); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: theScreen = XDefaultScreen( theDisplay ) ; tomwalters@0: tomwalters@0: /* MAA: 20-8-1993 tomwalters@0: * lets put the colour bits here */ tomwalters@0: tomwalters@0: define_colours(); tomwalters@0: tomwalters@0: #ifndef SLAVE tomwalters@0: if (!synchronous) { tomwalters@0: (void) XSynchronize(theDisplay, TRUE); tomwalters@0: XFlush(theDisplay); tomwalters@0: synchronous = TRUE; tomwalters@0: } tomwalters@0: #endif tomwalters@0: } tomwalters@0: tomwalters@0: /* Need to reset these every time, in case the screen is initialized tomwalters@0: independently via InitializeX */ tomwalters@0: tomwalters@0: theWidth = XDisplayWidth (theDisplay, theScreen); tomwalters@0: theHeight = XDisplayHeight(theDisplay, theScreen); tomwalters@0: tomwalters@0: /* Perform "centering" calculations */ tomwalters@0: tomwalters@0: if (default_x < 0) { tomwalters@0: /* Center in the x dimension */ tomwalters@0: default_width = (MIN(default_width, theWidth)); tomwalters@0: default_x = (theWidth - default_width) / 2; tomwalters@0: } tomwalters@0: tomwalters@0: if (default_y < 0) { tomwalters@0: /* Center in the y dimension */ tomwalters@0: default_height = (MIN(default_height, theHeight)); tomwalters@0: default_y = (theHeight - default_height) / 2; tomwalters@0: } tomwalters@0: tomwalters@0: /* End of "centering" calculations */ tomwalters@0: #else tomwalters@0: if( theDisplay == (Display *) 0 ) tomwalters@0: if( ( theDisplay = XOpenDisplay(NULL) ) == (Display *) 0 ) { tomwalters@0: (void) fprintf(stderr, "Could not open DISPLAY \"%s\"\n", getenv("DISPLAY")); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: #endif tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: #if defined(X11) tomwalters@0: if( default_width == 0 && default_height == 0 ) tomwalters@0: w = XDefaultRootWindow(theDisplay); tomwalters@0: else tomwalters@0: if ((w = XCreateSimpleWindow(theDisplay, XDefaultRootWindow(theDisplay), tomwalters@0: default_x, default_y, tomwalters@0: (unsigned) default_width, (unsigned) default_height, 1, tomwalters@0: theForeground, theBackground)) != (Window) 0) { tomwalters@0: /* tomwalters@0: XSizeHints hints ; tomwalters@0: tomwalters@0: hints.flags = PPosition | PSize ; tomwalters@0: tomwalters@0: hints.x = default_x ; tomwalters@0: hints.y = default_y ; tomwalters@0: hints.width = default_width ; tomwalters@0: hints.height = default_height ; tomwalters@0: XSetStrandardProperties( theDisplay, w, name, name, None, name, 1, &hints ) ; tomwalters@0: */ tomwalters@0: XStoreName(theDisplay, w, name); tomwalters@0: XMapRaised(theDisplay, w); tomwalters@0: XFlush( theDisplay); tomwalters@0: } tomwalters@0: #else tomwalters@0: if( default_width == 0 && default_height == 0 ) tomwalters@0: w = RootWindow ; tomwalters@0: else tomwalters@0: if( ( w = XCreateWindow( RootWindow, abs( default_x ), abs( default_y ), tomwalters@0: default_width, default_height, 0, WhitePixmap, tomwalters@0: BlackPixmap ) ) != ( Window ) 0 ) { tomwalters@0: XStoreName( w, name ) ; tomwalters@0: XMapWindow( w ) ; tomwalters@0: XFlush() ; tomwalters@0: } tomwalters@0: #endif tomwalters@0: else { tomwalters@0: (void) fprintf( stderr, tomwalters@0: "Could not create window of size %dx%d at position %d,%d\n", tomwalters@0: default_width, default_height, default_x, default_y ) ; tomwalters@0: } tomwalters@0: tomwalters@0: info = (XWindowObject) newWindowWindow(w, default_x, default_y, default_width, default_height, pixels); tomwalters@0: #if defined(X11) tomwalters@0: info->isMapped = 0 ; tomwalters@0: #endif tomwalters@0: info->entries->clear(info); tomwalters@0: tomwalters@0: return((WindowObject)info); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: #ifndef SLAVE tomwalters@0: WindowObject newDisplayWindow( name, default_x, default_y, default_width, default_height, pixels ) tomwalters@0: char *name ; tomwalters@0: int default_x, default_y, default_width, default_height ; tomwalters@0: int pixels ; tomwalters@0: { tomwalters@0: return ( newXWindow( name, default_x, default_y, default_width, default_height, pixels ) ) ; tomwalters@0: } tomwalters@0: #endif