Back to index

radiance  4R0+20100331
Defines | Functions | Variables
x11plot.c File Reference
#include "meta.h"
#include "plot.h"
#include "string.h"
#include <X11/Xlib.h>

Go to the source code of this file.

Defines

#define BORWIDTH   5
#define BlackPix   BlackPixel(dpy,0 )
#define WhitePix   WhitePixel(dpy,0 )
#define mapx(x)   CONV(x,dxsize)
#define mapy(y)   CONV((XYSIZE-1)-(y),dysize)
#define MAXVERT   128
#define MAXCOLOR   65535
#define LONG_DASHED_LIST_LENGTH   2
#define SHORT_DASHED_LIST_LENGTH   2
#define DOTTED_LIST_LENGTH   2

Functions

void replay (int xmin, int ymin, int xmax, int ymax)
static void adjustsize ()
void init (char *name, char *geom)
void endpage ()
void printstr (PRIMITIVE *p)
void plotlseg (PRIMITIVE *p)
void pXFlush ()
void filltri (PRIMITIVE *p)
void fillpoly (PRIMITIVE *p)
void fillrect (PRIMITIVE *p)

Variables

static const char RCSid [] = "$Id: x11plot.c,v 1.4 2007/11/21 18:51:05 greg Exp $"
struct {
char * name
Font id
font []
static int fontmap [16] = {0,3,0,3,1,3,1,3,2,4,2,4,2,4,2,4}
int dash_list_length []
unsigned char long_dashed [LONG_DASHED_LIST_LENGTH] = {4,7}
unsigned char short_dashed [SHORT_DASHED_LIST_LENGTH] = {4,3}
unsigned char dotted [DOTTED_LIST_LENGTH] = {5,2}
unsigned char * Linetypes []
Display * dpy
Window wind
Colormap cmap
GC gc
Font curfont
int curwidth
int curfill
int curcol
int curlinetype
XGCValues gcval
int pixel [4]
int dxsize
int dysize
int debug = False

Define Documentation

#define BlackPix   BlackPixel(dpy,0 )

Definition at line 27 of file x11plot.c.

#define BORWIDTH   5

Definition at line 25 of file x11plot.c.

#define DOTTED_LIST_LENGTH   2

Definition at line 54 of file x11plot.c.

#define LONG_DASHED_LIST_LENGTH   2

Definition at line 52 of file x11plot.c.

#define mapx (   x)    CONV(x,dxsize)

Definition at line 30 of file x11plot.c.

#define mapy (   y)    CONV((XYSIZE-1)-(y),dysize)

Definition at line 31 of file x11plot.c.

#define MAXCOLOR   65535

Definition at line 35 of file x11plot.c.

#define MAXVERT   128

Definition at line 33 of file x11plot.c.

#define SHORT_DASHED_LIST_LENGTH   2

Definition at line 53 of file x11plot.c.

#define WhitePix   WhitePixel(dpy,0 )

Definition at line 28 of file x11plot.c.


Function Documentation

static void adjustsize ( ) [static]

Definition at line 89 of file x11plot.c.

{
       if (dxsize > dysize)
              dxsize = dysize;
       else
              dysize = dxsize;
}

Here is the caller graph for this function:

void endpage ( void  )

Definition at line 179 of file x11plot.c.

{
    XEvent  evnt;
    int    quit=False;

    XFlush(dpy);
    XBell(dpy, 0);
    while ( !quit ) {
       XNextEvent(dpy, &evnt);
       switch (evnt.type) {
         case ConfigureNotify:
              dxsize = evnt.xconfigure.width;
              dysize = evnt.xconfigure.height;
              adjustsize();
              break;
         case Expose:
              replay((int)((long)XYSIZE*evnt.xexpose.x/dxsize),
                 (int)((long)XYSIZE*(dysize-evnt.xexpose.y-evnt.xexpose.height)/dysize),
                 (int)((long)XYSIZE*(evnt.xexpose.x+evnt.xexpose.width)/dxsize),
                 (int)((long)XYSIZE*(dysize-evnt.xexpose.y)/dysize));
              break;
         case ButtonPress:
              quit = True;
              break;
       } /* switch */
    } /* for */
    XClearWindow(dpy, wind);

}

Here is the call graph for this function:

Here is the caller graph for this function:

void fillpoly ( PRIMITIVE *  p)

Definition at line 484 of file x11plot.c.

{}

Here is the caller graph for this function:

void fillrect ( PRIMITIVE *  p)

Definition at line 485 of file x11plot.c.

{}

Here is the caller graph for this function:

void filltri ( PRIMITIVE *  p)

Definition at line 483 of file x11plot.c.

{}

Here is the caller graph for this function:

static void init ( char *  name,
char *  geom 
)

Definition at line 99 of file x11plot.c.

{
    char  defgeom[32];
    XColor  cdef,dum;
    XEvent  evnt;

    curfont = curfill = curcol = -1;
    curlinetype = 0;

    if ((dpy=XOpenDisplay("")) == NULL)
       error(SYSTEM, "can't open display");
    
    /* for debugging so we don't have to flush always */
    if (debug) 
       (void) XSynchronize(dpy, True);

    dxsize = DisplayWidth(dpy,0) - 2*BORWIDTH-4;
    dysize = DisplayHeight(dpy,0) - 2*BORWIDTH-100;
    adjustsize();

    sprintf(defgeom, "=%dx%d+2+25", dxsize, dysize);
    /* XUseGeometry(dpy,0,geom,defgeom,BORWIDTH,100,100,100,100,
              &xoff,&yoff,&dxsize,&dysize); */
    gc = DefaultGC(dpy,0);                /* get default gc */
    cmap = DefaultColormap(dpy,0);        /* and colormap */

    wind = XCreateSimpleWindow(dpy,DefaultRootWindow(dpy),0,0,dxsize,dysize,
              BORWIDTH,BlackPix,WhitePix);
    if (wind == 0)
       error(SYSTEM, "can't create window");
    XStoreName(dpy, wind, name);
    XMapRaised(dpy, wind);
    XSelectInput(dpy, wind, StructureNotifyMask | ButtonPressMask | ExposureMask);
    if (DisplayPlanes(dpy,0) < 2) {       /* less than 2 color planes, use black */
           pixel[0] = pixel[1] = pixel[2] = pixel[3] = BlackPix;
    } else {
       if (XAllocNamedColor(dpy, cmap, "black", &dum, &cdef)==0)
              error(USER,"cannot allocate black!");
       pixel[0] = cdef.pixel;
       if (XAllocNamedColor(dpy, cmap, "red", &dum, &cdef)==0)
              {
              error(WARNING,"cannot allocate red");
              cdef.pixel = BlackPix;
              }
       pixel[1] = cdef.pixel;
       if (XAllocNamedColor(dpy, cmap, "green", &dum, &cdef)==0)
              {
              error(WARNING,"cannot allocate green");
              cdef.pixel = BlackPix;
              }
       pixel[2] = cdef.pixel;
       if (XAllocNamedColor(dpy, cmap, "blue", &dum, &cdef)==0)
              {
              error(WARNING,"cannot allocate blue");
              cdef.pixel = BlackPix;
              }
       pixel[3] = cdef.pixel;
    }

    while (1)
       {
       XNextEvent(dpy, &evnt);
       if (evnt.type == ConfigureNotify) /* wait for first ConfigureNotify */
              break;
       }
    dxsize = evnt.xconfigure.width;
    dysize = evnt.xconfigure.height;
    adjustsize();
    while (1)
       {
       XNextEvent(dpy, &evnt);
       if (evnt.type == Expose)    /* wait for first Expose */
              break;
       }
}

Here is the call graph for this function:

void plotlseg ( PRIMITIVE *  p)

Definition at line 252 of file x11plot.c.

{
    int  x1, y1, x2, y2;
    int  linetype, ps, pw;
    int col;

    linetype = (p->arg0 >> 4) & 03;       /* line style (solid, dashed, etc) */

    col = p->arg0 & 03;                   /* color */

    ps = WIDTH((p->arg0 >> 2) & 03);
    pw = CONV((ps)/2, dxsize);

    x1 = mapx(p->xy[XMN]);
    x2 = mapx(p->xy[XMX]);
    if (p->arg0 & 0100) {          /* reverse slope */
       y1 = mapy(p->xy[YMX]);
       y2 = mapy(p->xy[YMN]);
    } else {
       y1 = mapy(p->xy[YMN]);
       y2 = mapy(p->xy[YMX]);
    }

    if (curcol != col || curwidth != pw)
       {
       curcol = col;
       gcval.foreground = pixel[col];
       curwidth = pw;
       gcval.line_width = pw*2+1;  /* convert to thickness in pixels */
       gcval.join_style = JoinRound;
       XChangeGC(dpy, gc, GCJoinStyle|GCLineWidth|GCForeground, &gcval);
       }
    if (curlinetype != linetype)
       {
       curlinetype = linetype;
       if (linetype==0)
              gcval.line_style = LineSolid;
       else
              {
              gcval.line_style = LineOnOffDash;
              XSetDashes(dpy, gc, 0, Linetypes[linetype], dash_list_length[linetype]);
              }
       XChangeGC(dpy, gc, GCLineStyle, &gcval);
       }
    XDrawLine(dpy,wind,gc,x1,y1,x2,y2);
}
void printstr ( PRIMITIVE *  p)

Definition at line 212 of file x11plot.c.

{
    int  fn;
    int  col;

    fn = fontmap[(p->arg0 >> 2) & 017];          /* get font number */
                                          /* set font */
    if (font[fn].id == 0) 
       {
       font[fn].id = XLoadFont(dpy, font[fn].name);
       if (font[fn].id == 0) 
           {
           sprintf(errmsg, "can't open font \"%s\"", font[fn].name);
           error(SYSTEM, errmsg);
           }
       }
    col = p->arg0 & 03;
    if (curcol != col)
       {
       curcol = col;
       XSetForeground(dpy, gc, pixel[col]);
       }
    if (curfont != font[fn].id) 
       {
       curfont = font[fn].id;
       XSetFont(dpy, gc, curfont);
       }

    XDrawImageString(dpy, wind, gc, mapx(p->xy[XMN]), mapy(p->xy[YMN]),
              p->args, strlen(p->args));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pXFlush ( void  )

Definition at line 304 of file x11plot.c.

{
       XFlush(dpy);
}

Here is the caller graph for this function:

void replay ( int  xmin,
int  ymin,
int  xmax,
int  ymax 
)

Definition at line 157 of file xmeta.c.

{
    register PRIMITIVE  *p;

    unset(SALL);
    set(SALL, NULL);
    for (p = recording.ptop; p != NULL; p = p->pnext)
       if (isprim(p->com)) {
           if (overlap(p, xmin, ymin, xmax, ymax))
              doprim(p, 0);
       } else
           doglobal(p, 0);

}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Colormap cmap

Definition at line 76 of file x11plot.c.

int curcol

Definition at line 81 of file x11plot.c.

int curfill

Definition at line 80 of file x11plot.c.

Font curfont

Definition at line 78 of file x11plot.c.

Definition at line 82 of file x11plot.c.

int curwidth

Definition at line 79 of file x11plot.c.

Initial value:

Definition at line 56 of file x11plot.c.

int debug = False

Definition at line 86 of file x11plot.c.

unsigned char dotted[DOTTED_LIST_LENGTH] = {5,2}

Definition at line 65 of file x11plot.c.

Display* dpy

Definition at line 74 of file x11plot.c.

int dxsize

Definition at line 85 of file x11plot.c.

int dysize

Definition at line 85 of file x11plot.c.

struct { ... } font[] [static]
int fontmap[16] = {0,3,0,3,1,3,1,3,2,4,2,4,2,4,2,4} [static]

Definition at line 50 of file x11plot.c.

GC gc

Definition at line 77 of file x11plot.c.

XGCValues gcval

Definition at line 83 of file x11plot.c.

unsigned char* Linetypes[]
Initial value:

Definition at line 67 of file x11plot.c.

unsigned char long_dashed[LONG_DASHED_LIST_LENGTH] = {4,7}

Definition at line 63 of file x11plot.c.

int pixel[4]

Definition at line 84 of file x11plot.c.

const char RCSid[] = "$Id: x11plot.c,v 1.4 2007/11/21 18:51:05 greg Exp $" [static]

Definition at line 2 of file x11plot.c.

unsigned char short_dashed[SHORT_DASHED_LIST_LENGTH] = {4,3}

Definition at line 64 of file x11plot.c.

Window wind

Definition at line 75 of file x11plot.c.