[comp.windows.x] X wide, dashed lines

kearns@elrond.CalComp.COM (Arlene S. Kearns) (02/24/88)

  I am using a Sun 3/160 with the release MIT version of X11V1.
  
  Wide Lines and Dashed Lines do not work with a color frame buffer but do
  with a monochrome frame buffer.

  Also Stipples of size less than 32x32 do not work with a color frame buffer
  but do with a monochrome frame buffer. The image on the displayed
  is correct where the 16x16 box falls but it is rounded up to 32 in the x
  direction. Tile of this size work fine.
 
  Attached are the two programs, the first tests the lines and the second 
  tests stipples.

**************************************************************************
********************************lines*************************************
**************************************************************************

#include <stdio.h>
#include <math.h>
#include <strings.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <sys/time.h>

extern char *getenv();


/* objects */
Display	 *dpy;
Window   theWindow,theInputWindow;
Window   theNextWindow;

#define WIDTH  512
#define HEIGHT 512
#define BORDER 1

XEvent			event;
XSetWindowAttributes	xswa;
XGCValues		xgcv;
GContext		gc;
Visual			visual;

Colormap 	colors;
XColor	xcsd, xced;

/**************/
main(argc, argv)      
    int   argc;
    char *argv[];
/**************/
{

int	x,y;
int	height,width,border;
int	offset;
int ForeColor,BackColor,Color;
char *display = NULL;

char *p;			/* get environment variable */

/*****************************************************/

    /* Open up the display. */

    if ((dpy = XOpenDisplay(display)) == NULL) {
        fprintf(stderr, "%s: Can't open display '%s'\n",argv[0], display);
        exit(1);
    }

    /* Open the main window output. */
    x = 0;
    y = 0;
    width = WIDTH;
    height = HEIGHT;
    border = BORDER;

    xswa.background_pixel = BlackPixel(dpy, DefaultScreen(dpy)); /* */
    xswa.border_pixel = WhitePixel(dpy, DefaultScreen(dpy));
    xswa.event_mask = ExposureMask | ButtonPressMask; /* see what you get */
    visual.visualid = CopyFromParent;
    theWindow = XCreateWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)),
		x, y, width, height, border,
		CopyFromParent, InputOutput, &visual, 
		CWEventMask | CWBackPixel | CWBorderPixel,
		&xswa );

    xgcv.function = GXcopy;
    xgcv.foreground = WhitePixel(dpy, DefaultScreen(dpy));
    xgcv.line_style = LineSolid;
    xgcv.line_width = 0;
    gc = (GContext)XCreateGC(dpy, theWindow, GCFunction|GCLineStyle|GCLineWidth|GCForeground, &xgcv);

    XMapWindow(dpy, theWindow);

    /**************** Main loop *****************/

    while (1) {

        XNextEvent(dpy, &event);

        switch (event.type) {
	case ButtonPress:
	    switch( event.xbutton.button ) {
		case Button1:
		    xgcv.line_width = 0;
		    printf(" line_width %d \n",xgcv.line_width);
		    XChangeGC(dpy, gc, GCLineWidth, &xgcv);
	            break;
		case Button2:
		    xgcv.line_width++;
		    printf(" line_width %d \n",xgcv.line_width);
		    XChangeGC(dpy, gc, GCLineWidth, &xgcv);
	            break;
		case Button3:
		    xgcv.line_width--;
		    printf(" line_width %d \n",xgcv.line_width);
		    XChangeGC(dpy, gc, GCLineWidth, &xgcv);
	            break;
	    }
	    XClearWindow( dpy, theWindow );
	    XDrawLine( dpy, theWindow, gc, x, y, width, height );
	    XDrawLine( dpy, theWindow, gc, x, height, width, y );
	    XDrawLine( dpy, theWindow, gc, x, height/2, width, height/2 );
	    XDrawLine( dpy, theWindow, gc, width/2, y, width/2, height );
            break;
	case Expose:
	    XDrawLine( dpy, theWindow, gc, x, y, width, height );
	    XDrawLine( dpy, theWindow, gc, x, height, width, y );
	    XDrawLine( dpy, theWindow, gc, x, height/2, width, height/2 );
	    XDrawLine( dpy, theWindow, gc, width/2, y, width/2, height );
            break;
        default:
	    break;
        }  /* end of switch */
    }  /* end while loop */
}


/***********************************/


**************************************************************************
******************************stipple*************************************
**************************************************************************


/*
 */

#include <stdio.h>
#include <math.h>
#include <strings.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <sys/time.h>

#include <Xmacro.h>

extern char *getenv();


/* objects */
Display	 *dpy;
Window   theWindow,theInputWindow;
Pixmap   pix;

#define WIDTH  512
#define HEIGHT 512
#define BORDER 1

XEvent			event;
XSetWindowAttributes	xswa;
XGCValues		xgcv;
GC		gc,gc2;
Visual			visual;

Colormap 	colors;
XColor	xcsd, xced;

/**************/
main(argc, argv)      
    int   argc;
    char *argv[];
/**************/
{

int	x,y;
int	height,width,border;
int	offset;
int ForeColor,BackColor,Color;
char *display = NULL;
int XDEBUG;

char *p;			/* get environment variable */

/*****************************************************/

    p = getenv("XDEBUG");
    if(p)
	sscanf(p, "%x", &XDEBUG );
    else
	XDEBUG = 0;

    /* Open up the display. */

    if ((dpy = XOpenDisplay(display)) == NULL) {
        fprintf(stderr, "%s: Can't open display '%s'\n",argv[0], display);
        exit(1);
    }
    XPrintDisplayInfo(dpy,0);

    /* Open the main window output. */
    x = 0;
    y = 0;
    width = WIDTH;
    height = HEIGHT;
    border = BORDER;

    colors = DefaultColormap(dpy, DefaultScreen(dpy));
    XAllocNamedColor(dpy, colors, "red",&xcsd, &xced);
    Color = xcsd.pixel;
    printf("color %d \n",Color);

    pix = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), 16, 16, 1 );

    xgcv.function = GXxor;
    xgcv.background = WhitePixel(dpy, DefaultScreen(dpy)); /* */
    xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
    printf("color %d \n",xgcv.foreground);
    printf("color %d \n",xgcv.background);
    xgcv.line_style = FillSolid;
    gc = XCreateGC(dpy, pix, GCFunction|GCLineStyle|GCForeground|GCBackground, &xgcv);
    XFillRectangle(dpy, pix, gc, 0, 0, 16, 16 );
    XFillArc(dpy, pix, gc, 0, 0, 16, 16, 0, 360*64 );
    XFreeGC( dpy, gc );

    xswa.background_pixel = BlackPixel(dpy, DefaultScreen(dpy)); /* */
    xswa.border_pixel = WhitePixel(dpy, DefaultScreen(dpy));
    xswa.event_mask = ExposureMask|ButtonPressMask;
    visual.visualid = CopyFromParent;
    theWindow = XCreateWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)),
		x, y, width, height, border,
		CopyFromParent, InputOutput, &visual, 
		CWBackPixel | CWBorderPixel | CWEventMask,
		&xswa );
    
    xgcv.function = GXxor /*GXor*/;
    xgcv.foreground = Color; /*color*/
    xgcv.background = BlackPixel(dpy, DefaultScreen(dpy));
    xgcv.stipple = pix; /*color*/
    xgcv.fill_style = FillStippled;
    xgcv.ts_x_origin = 0;
    xgcv.ts_y_origin = 0;
    gc = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)),
	GCFunction|GCForeground|GCBackground|GCStipple|GCFillStyle|GCTileStipXOrigin|GCTileStipYOrigin, &xgcv);

    gc2 = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)),
	GCFunction|GCForeground|GCBackground, &xgcv);


    XMapWindow(dpy, theWindow);

    /**************** Main loop *****************/

    while (1) {
        XNextEvent(dpy, &event);
        XPrintEventType(event);
	XClearWindow(dpy, theWindow );
        XFillRectangle(dpy, theWindow, gc2, WIDTH/4, 0, WIDTH/2, HEIGHT );
	sleep(1);
	XClearWindow(dpy, theWindow );
        XFillRectangle(dpy, theWindow, gc, 0, 0, WIDTH/2, HEIGHT );
    }  /* end while loop */
}


/***********************************/