home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume18 / treepar / part01 / plotX.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-12  |  2.5 KB  |  143 lines

  1. /* plotX.c - plot routines specific to X
  2.  *
  3.  * 30.Jul.87  jimmc  Initial definition
  4.  *  1.Aug.87  jimmc  Add PXText, remove PXBox (use default), change PXInit
  5.  * 12.Aug.87  jimmc  Add XCear in Init
  6.  * 17.Aug.87  jimmc  Add dummy textsize function
  7.  * 19.Aug.87  jimmc  Simplify text function
  8.  * 26.Jan.88  jimmc  Change path to X include files
  9.  *  1.Mar.88  jimmc  Add ifdef X10
  10.  */
  11.  
  12. #ifdef X10
  13.  
  14. #include <X/Xlib.h>
  15. #include <X/Xproto.h>
  16. #include "plot.h"
  17.  
  18. #define NULL 0
  19.  
  20. #define FIXY(y) (y) = (PXwinfo.height-(y));
  21.  
  22. extern char *index();
  23.  
  24. extern char *Progname;
  25.  
  26. static int PXcolor;
  27. static int PXop;
  28. static int PXplanes;
  29. static Window PXw;
  30. static WindowInfo PXwinfo;
  31. static char *PXFontname = "6x10";
  32. static FontInfo *PXFontInfo;
  33.  
  34. #define PXdefwidth 100
  35. #define PXdefheight 100
  36.  
  37. static OpaqueFrame PXframe = {
  38.     0,        /* window ID */
  39.     0,0,        /* origin */
  40.     0,0,        /* size */
  41.     1,        /* border width */
  42.     0,0        /* border and background pixmaps */
  43. };
  44.  
  45. static PXOpenWindow()
  46. {
  47.     PXcolor = 1;
  48.     PXop = GXcopy;
  49.     PXplanes = AllPlanes;
  50.     if (!XOpenDisplay(NULL)) {
  51.         printf("Can't open X display\n");
  52.         return 0;
  53.     }
  54.     PXframe.border = WhitePixmap;
  55.     PXframe.background = BlackPixmap;
  56.     PXw = XCreate(Progname,Progname,"","=840x600+20+20",
  57.         &PXframe,PXdefwidth,PXdefheight);
  58.     if (!PXw) {
  59.         printf("Can't open window\n");
  60.         return 0;
  61.     }
  62.     XStoreName(PXw,Progname);
  63.     XMapWindow(PXw);
  64.  
  65.     PXFontInfo = XOpenFont(PXFontname);
  66.     if (PXFontInfo==0) {
  67.         printf("Can't open font %s",PXFontname);
  68.         return 0;
  69.     }
  70.  
  71.     return 1;
  72. }
  73.  
  74. /* ARGSUSED */
  75. int        /* 1 if OK */
  76. PXInit(filename,lxp,lyp,hxp,hyp)
  77. char *filename;        /* we ignore this arg */
  78. int *lxp,*lyp,*hxp,*hyp;    /* returns bounding box of window */
  79. {
  80.     if (!PXw) {    /* need a window */
  81.         if (!PXOpenWindow()) {
  82.             return 0;
  83.         }
  84.     }
  85.     XClear(PXw);
  86.     XQueryWindow(PXw,&PXwinfo);
  87.     *lxp = 0;
  88.     *lyp = 0;
  89.     *hxp = PXwinfo.width-1;
  90.     *hyp = PXwinfo.height-1;
  91.     XFlush();
  92.     return 1;
  93. }
  94.  
  95. PXDone()
  96. {
  97.     XFlush();
  98. }
  99.  
  100. /* ARGSUSED */
  101. PXTextSize(x,y)
  102. int x,y;
  103. {
  104.     return;        /*** We are ignoring text size at the moment */
  105. }
  106.  
  107. PXLine(lx,ly,hx,hy)
  108. int lx,ly,hx,hy;
  109. {
  110.     FIXY(ly)
  111.     FIXY(hy)
  112.     XLine(PXw,lx,ly,hx,hy,1,1,PXcolor,PXop,PXplanes);
  113. }
  114.  
  115. PXText(x,y,text)
  116. int x,y;    /* lower left corner of text */
  117. char *text;
  118. {
  119.     FIXY(y)
  120.     y -= PXFontInfo->height;
  121.     XTextMaskPad(PXw,x,y,text,strlen(text),PXFontInfo->id,
  122.         0,0,PXcolor,PXop,PXplanes);
  123. }
  124.  
  125. PXSetup()
  126. {
  127. PDevInfo *p;
  128.  
  129.     p = Pnew();
  130.     p->name = "X";
  131.     p->init = PXInit;
  132.     p->done = PXDone;
  133.     p->line = PXLine;
  134.     p->text = PXText;
  135.     p->textsize = PXTextSize;
  136. }
  137.  
  138. #else
  139. static char dummy;    /* avoid "empty symbol table" message */
  140. #endif X10
  141.  
  142. /* end */
  143.