home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / plotting / contour / contour.lha / Contour / plotX11.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  19.6 KB  |  614 lines

  1. /*   plotX11.c - all the X11 routines  ***/
  2.  
  3. #include <X11/Xlib.h>
  4. #include <X11/Xutil.h>
  5. #include <X11/Xos.h>
  6. #include <X11/keysym.h>
  7. #include <stdio.h>
  8. #include <strings.h>
  9. #include <math.h>
  10.  
  11. #include "common.h"
  12. #include "contour.h"
  13. #include "plot.h"
  14. #include "Xdefs.h"
  15. #include "Xdefs.h"
  16. #include "iconX11.ic"
  17.  
  18. /* colors */
  19. #define DEFAULT_BORDER_COLOR  "Blue"
  20. #define DEFAULT_BACK_COLOR    "MidNightBlue"
  21. #define DEFAULT_FORE_COLOR    "White"
  22. #define DEFAULT_MOUSE_COLOR   "White"
  23. #define DEFAULT_ICON_COLOR    "Red"
  24. #define BDR_C                 0
  25. #define BACK_C                1
  26. #define FORE_C                2
  27. #define MOUSE_C               3
  28. #define ICON_C                4
  29. #define LINE1_C               5
  30. #define LINE2_C               6
  31. #define LINE3_C               7
  32. #define LINE4_C               8
  33. #define LINE5_C               9
  34. #define MAX_COLORS            10
  35.  
  36. unsigned long     border_pixel;                   /* color of border */
  37. unsigned long     background_pixel;               /* color of background */
  38. unsigned long     foreground_pixel;               /* color of foreground */
  39. unsigned long     mouseground_pixel;              /* mouse cursor color */
  40. unsigned long     icon_pixel;                     /* icon color */
  41. unsigned long     colors[MAX_COLORS];             /* color pixel values */
  42. char              *clr_name[MAX_COLORS];          /* color names */
  43.  
  44. /* line-types */
  45. #  define DOTTED       2
  46. #  define SHORT_DOTTED 2
  47. #  define LONG_DOTTED  2
  48. #  define DASHED       2
  49. #  define DOT_DASHED   4
  50. #  define DASH_DOTTED  4
  51. #  define SHORT_DASHED 2
  52. #  define LONG_DASHED  2
  53. #  define EQUAL_DASHED 2
  54. #  define ODD_DASHED   3
  55.    static unsigned char dash_list_dotted[DOTTED]             = {1,6};
  56.    static unsigned char dash_list_short_dotted[SHORT_DOTTED] = {1,3};
  57.    static unsigned char dash_list_long_dotted[LONG_DOTTED]   = {1,8};
  58.    static unsigned char dash_list_dashed[DASHED]             = {4,4};
  59.    static unsigned char dash_list_dot_dashed[DOT_DASHED]     = {3,4,3,1};
  60.    static unsigned char dash_list_dash_dotted[DASH_DOTTED]   = {4,3,1,3};
  61.    static unsigned char dash_list_short_dashed[SHORT_DASHED] = {3,5};
  62.    static unsigned char dash_list_equal_dashed[EQUAL_DASHED] = {6,6};
  63.    static unsigned char dash_list_long_dashed[LONG_DASHED]   = {7,4};
  64.    static unsigned char dash_list_odd_dashed[ODD_DASHED]     = {1,2,3};
  65.  
  66. /* plot information */
  67. #define X_ORG            5
  68. #define Y_ORG            5
  69. #define X_DIM            800
  70. #define Y_DIM            700
  71. #define DEFAULT_BDR_DIM  100
  72.  
  73. #define X_MKR            4
  74. #define X_LIN            11
  75.  
  76. int Xxmin, Xymin, Xxmax, Xymax;
  77.  
  78. /* Misc */
  79. #define DEFAULT_BORDER_WIDTH  3
  80. #define DEFAULT_FONT          "8x13"
  81. #define SMALL_FONT            "6x10"
  82.  
  83. short gray_bits[16] = {
  84.    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  85.    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  86.    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  87.    0xaaaa, 0x5555, 0xaaaa, 0x5555};
  88.  
  89. Display     *display;                   /* display */
  90. int         screen;                     /* screen */
  91. Window      window;                     /* parent window */
  92. XFontStruct *font_info;                 /* font information */
  93. XFontStruct *lblfont_info;              /* label font information */
  94. XSizeHints  size_hints;                 /* window info for manager */
  95. GC          gc, gcl;                    /* graphics context */
  96.  
  97. InitWindow(argc,argv)
  98. int  argc;
  99. char **argv;
  100. {
  101.    Pixmap     icon_pixmap;
  102.    XGCValues  gcvalues;
  103.    char       *sprintf(), default_geometry[100];
  104.    int        x, y, width, height;
  105.  
  106.    /* Open display first, and get screen info */
  107.    if (!(display = XOpenDisplay(display_name))) {
  108.       fprintf(stderr,"%s:Could not open display %s\n",
  109.               progname,display_name);
  110.       exit(1);
  111.    }
  112.    screen = DefaultScreen(display);
  113.    sprintf(default_geometry,"=%dx%d+%d+%d",X_DIM,Y_DIM,X_ORG,Y_ORG);
  114.  
  115.    /* Merge the options first */
  116.    Merge_Options();
  117.  
  118.    /* allocate the colors */
  119.    Alloc_Colors();
  120.  
  121.    /* Initialize the window */
  122.    if (!XGeometry(display,screen,geometry,default_geometry,border_width,
  123.                  0,0,0,0,&x,&y,&width,&height)) {
  124.       x      = X_ORG;
  125.       y      = Y_ORG;
  126.       width  = X_DIM;
  127.       height = Y_DIM;
  128.    }
  129.    window = XCreateSimpleWindow(display, RootWindow(display,screen),
  130.                                 x, y, width, height, border_width,
  131.                                 border_pixel, background_pixel);
  132.  
  133.    /* Initialize size hint property for window manager */
  134.    size_hints.flags      = PPosition | PSize | PMinSize;
  135.    size_hints.x          = x;
  136.    size_hints.y          = y;
  137.    size_hints.width      = width;
  138.    size_hints.height     = height;
  139.    size_hints.min_width  = X_DIM;
  140.    size_hints.min_height = Y_DIM;
  141.  
  142.    /* Create pixmap of depth 1 (bitmap) for icon */
  143.    icon_pixmap = XCreateBitmapFromData(display, window, icon_bitmap_bits,
  144.                         icon_bitmap_width, icon_bitmap_height);
  145.  
  146.    /* set properties for window manager */
  147.    XSetStandardProperties(display,window, "Contour Program", "Contour",
  148.                           icon_pixmap, argv, argc, &size_hints);
  149.  
  150.    /* Select event types wanted */
  151.    XSelectInput(display,window,ExposureMask | ButtonPressMask  |
  152.                 KeyPressMask | StructureNotifyMask );
  153.  
  154.    /* Create GC for text and drawing */
  155.    gc = XCreateGC(display, window, 0, &gcvalues);
  156.    gcl= XCreateGC(display, window, 0, &gcvalues);
  157.  
  158.    /* Find a font and load it */
  159.    if (!(font_info = XLoadQueryFont(display,font_name))){
  160.       fprintf(stderr,"%s:Could not open font %s\n",progname,font_name);
  161.       exit(1);
  162.    }
  163.    XSetFont(display, gc, font_info->fid);
  164.    if (!(lblfont_info = XLoadQueryFont(display,SMALL_FONT))){
  165.       fprintf(stderr,"%s:Could not open font %s\n",progname,SMALL_FONT);
  166.       exit(1);
  167.    }
  168.    XSetFont(display, gcl, lblfont_info->fid);
  169.  
  170.    /* specify foreground */
  171.    XSetForeground(display, gc, foreground_pixel);
  172.  
  173.    /* Display the window */
  174.    XMapWindow(display, window);
  175. }
  176.  
  177. /* Initialize and merge the various options */
  178. Merge_Options()
  179. {
  180.    char    *option;
  181.  
  182.    /* process the various options */
  183.    if (reverse < 0) {
  184.       if ((option = XGetDefault(display,progname,"ReverseVideo")) != NULL)
  185.          if (strcmp(option,"on")) reverse = 1;
  186.    }
  187.    if (!geometry) {
  188.       option = XGetDefault(display,progname,"Geometry"); 
  189.       geometry = option ? option : "=+5+5";
  190.    }
  191.    if (!font_name) {
  192.       /* option = XGetDefault(display,progname,"BodyFont"); */
  193.       font_name = DEFAULT_FONT;
  194.    }
  195.    if (!border_color) {
  196.       option = XGetDefault(display,progname,"Border");
  197.       border_color = option ? option : DEFAULT_BORDER_COLOR;
  198.    }
  199.    if (!back_color) {
  200.       option = XGetDefault(display,progname,"Background");
  201.       back_color = option ? option : DEFAULT_BACK_COLOR;
  202.    }
  203.    if (!fore_color) {
  204.       option = XGetDefault(display,progname,"Foreground");
  205.       fore_color = option ? option : DEFAULT_FORE_COLOR;
  206.    }
  207.    if (!mouse_color) {
  208.       option = XGetDefault(display,progname,"Mouse");
  209.       mouse_color = option ? option : DEFAULT_MOUSE_COLOR;
  210.    }
  211.    if (!icon_color) {
  212.       option = XGetDefault(display,progname,"Icon");
  213.       icon_color = option ? option : DEFAULT_ICON_COLOR;
  214.    }
  215.    if (border_width <= 0) {
  216.       option = XGetDefault(display,progname,"BorderWidth");
  217.       border_width = option ? atoi(option) : DEFAULT_BORDER_WIDTH;
  218.    }
  219. }
  220.  
  221. /* allocate the colors on color display */
  222. Alloc_Colors()
  223. {
  224.    XColor        cdef;
  225.    Colormap      cmap;
  226.    int           i, depth;
  227.    unsigned long tmp_pixel;
  228.  
  229.    /* get info on depth and colormap */
  230.    depth = DisplayPlanes(display,screen);
  231.    cmap  = DefaultColormap(display,screen);
  232.  
  233.    /* associate named colors with pixel values */
  234.    if (depth == 1) {       /* one-plane monochrome */
  235.       colors[BDR_C]     = BlackPixel(display,screen);
  236.       colors[BACK_C]    = BlackPixel(display,screen);
  237.       colors[FORE_C]    = WhitePixel(display,screen);
  238.       colors[MOUSE_C]   = colors[FORE_C];            
  239.       colors[ICON_C]    = colors[FORE_C];            
  240.       for (i=LINE1_C; i<=LINE5_C; i++) colors[i] = colors[FORE_C];
  241.    } else {                /* color */
  242.       clr_name[BDR_C]   = border_color;
  243.       clr_name[BACK_C]  = back_color;
  244.       clr_name[FORE_C]  = fore_color;
  245.       clr_name[MOUSE_C] = mouse_color;
  246.       clr_name[ICON_C]  = icon_color;
  247.       clr_name[LINE1_C] = "yellow";
  248.       clr_name[LINE2_C] = "cyan";
  249.       clr_name[LINE3_C] = "green";
  250.       clr_name[LINE4_C] = "red";
  251.       clr_name[LINE5_C] = "blue";
  252.       for (i=0; i<MAX_COLORS; i++) 
  253.          if (XAllocNamedColor(display,cmap,clr_name[i],&cdef,&cdef))
  254.             colors[i] = cdef.pixel;
  255.          else {
  256.             fprintf(stderr,"%s: Can't allocate color %s\n",
  257.                     progname, clr_name[i]);
  258.             exit(1);
  259.          } /* end if */
  260.    }  /* end if */
  261.  
  262.    /* assign pixel values */
  263.    border_pixel      = colors[BDR_C];
  264.    background_pixel  = colors[BACK_C];
  265.    foreground_pixel  = colors[FORE_C];
  266.    mouseground_pixel = colors[MOUSE_C];
  267.    icon_pixel        = colors[ICON_C];
  268.  
  269.    /* reverse video */
  270.    if (reverse) {
  271.       tmp_pixel        = background_pixel;
  272.       background_pixel = foreground_pixel;
  273.       foreground_pixel = tmp_pixel;
  274.       if (border_pixel == background_pixel)
  275.          border_pixel = foreground_pixel;
  276.       if (mouseground_pixel == background_pixel) 
  277.          mouseground_pixel = foreground_pixel;
  278.       for (i=LINE1_C; i<=LINE5_C; i++)
  279.          if (colors[i]==background_pixel) colors[i] = foreground_pixel;
  280.    }
  281. }
  282.  
  283. RunOps()
  284. {
  285. #  define   SMALLW 1
  286. #  define   OK     0
  287.    XEvent   event;
  288.    KeySym   keysym;
  289.    XComposeStatus compose;
  290.    char     buffer[1];
  291.    int      bufsize = 1;
  292.    int      window_size = OK;
  293.    int      Width, Height;       
  294.  
  295.    /* Initialize window size */
  296.    Width  = X_DIM;
  297.    Height = Y_DIM;
  298.  
  299.    /* event loop */
  300.    while(1) {
  301.       XNextEvent(display, &event);
  302.       switch (event.type) {
  303.       case Expose:
  304.          /* get rid of all other Expose events on the queue */
  305.          while (XCheckTypedEvent(display, Expose, &event));
  306.          /* window was resized too small to use */
  307.          if (window_size == SMALLW) {
  308.             Width  = X_DIM;
  309.             Height = Y_DIM;
  310.          }
  311.          ShowView(Width, Height);
  312.          break;
  313.       case ConfigureNotify:
  314.          /* window has been resized */
  315.          /* change width and height */
  316.          Width  = event.xconfigure.width;
  317.          Height = event.xconfigure.height;
  318.          if ((Width < size_hints.min_width) ||
  319.              (Height < size_hints.min_height) ) 
  320.             window_size = SMALLW;
  321.          else 
  322.             window_size = OK;
  323.          break;
  324.       case ButtonPress:
  325.          XUnloadFont(display, font_info->fid);
  326.          XUnloadFont(display, lblfont_info->fid);
  327.          XFreeGC(display, gc);
  328.          XFreeGC(display, gcl);
  329.          XCloseDisplay(display);
  330.          return;
  331.          break;
  332.       case KeyPress:
  333.          XLookupString(&event,buffer,bufsize,&keysym,&compose);
  334.          if ((keysym == XK_q) || (keysym == XK_Q)) {
  335.             XUnloadFont(display, font_info->fid);
  336.             XUnloadFont(display, lblfont_info->fid);
  337.             XFreeGC(display, gc);
  338.             XFreeGC(display, gcl);
  339.             XCloseDisplay(display);
  340.             return;
  341.          }
  342.          break;
  343.       default:
  344.          break;
  345.       } /* end switch */
  346.    } /* end while */
  347. }
  348.  
  349. ShowView(Width, Height)
  350. int      Width, Height;       
  351. {
  352.    axesX(Width, Height);
  353.    plotX();
  354. }
  355.  
  356. /* draw the axes */
  357. axesX(Width, Height)
  358. int   Width, Height;       
  359. {
  360.    char   *sprintf();
  361.    extern char    xlabel[MAXCHAR];
  362.    extern char    ylabel[MAXCHAR];
  363.    extern char    toplabel[MAXCHAR];
  364.    extern int     grid,equalscale;
  365.    extern double  xmin, xmax, ymin, ymax;
  366.    extern int     xticks,yticks;
  367.  
  368.    int    Xwid, Ywid;
  369.    double xdx, ydy, vallbl, ratio;
  370.    int    xintv, yintv, xtmp, ytmp;
  371.    char   text[100], c;
  372.    int    text_len, text_width, text_xpos, text_ypos;
  373.    int    font_height, font_width;
  374.    int    i;
  375.  
  376.    /* Initialize */
  377.    xdx = (xmax-xmin)/xticks;
  378.    ydy = (ymax-ymin)/yticks;
  379.  
  380.    Xxmin = DEFAULT_BDR_DIM;
  381.    Xymin = DEFAULT_BDR_DIM;
  382.    Xwid  = Width  - 2*DEFAULT_BDR_DIM;
  383.    Ywid  = Height - 2*DEFAULT_BDR_DIM;
  384.    Xxmax = Xxmin + Xwid;
  385.    Xymax = Xymin + Ywid;
  386.    if (equalscale == ON) {
  387.       /* max Xwid = 400, max Ywid = 300 */
  388.       ratio = (ymax-ymin)/(xmax-xmin);
  389.       if (ratio < ((double)Ywid)/((double)Xwid)) 
  390.          Ywid  = ratio*Xwid;
  391.       else 
  392.          Xwid  = Ywid/ratio;
  393.       Xxmax = Xxmin + Xwid;
  394.       Xymax = Xymin + Ywid;
  395.    }
  396.    xintv = (Xxmax-Xxmin)/xticks;
  397.    yintv = (Xymax-Xymin)/yticks;
  398.  
  399.    /* Draw the main axes */
  400.    XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
  401.    XDrawRectangle(display,window,gc,Xxmin,Xymin,Xwid,Ywid);
  402.  
  403.    /* Labels */
  404.    font_height = font_info->max_bounds.ascent +
  405.                  font_info->max_bounds.descent;
  406.    font_width  = font_info->max_bounds.rbearing -
  407.                  font_info->max_bounds.lbearing;
  408.  
  409.    /* Top Label */
  410.    text_len   = strlen(toplabel);
  411.    text_width = XTextWidth(font_info,toplabel,text_len);
  412.    text_xpos  = (Xxmin + Xxmax - text_width)/2;
  413.    text_ypos  = Xymin - 3*font_height;
  414.    XDrawString(display,window,gc,text_xpos,text_ypos,toplabel,text_len);
  415.  
  416.    /* X-Axis Label */
  417.    text_len   = strlen(xlabel);
  418.    text_width = XTextWidth(font_info,xlabel,text_len);
  419.    text_xpos  = (Xxmin + Xxmax - text_width)/2;
  420.    text_ypos  = Xymax + 4*font_height;
  421.    XDrawString(display,window,gc,text_xpos,text_ypos,xlabel,text_len);
  422.  
  423.    /* Y-Axis Label */
  424.    /* Don't know how to rotate, so print character by character */
  425.    text_len   = strlen(ylabel);
  426.    text_xpos  = Xxmin - 12*font_width;
  427.    text_ypos  = (Xymin + Xymax)/2 - text_len*font_height;
  428.    for (i=0; (c=ylabel[i]) != '\0'; i++) {
  429.       text[0] = c;
  430.       XDrawString(display,window,gc,text_xpos,text_ypos,text,1);
  431.       text_ypos += 2*font_height;
  432.    }
  433.  
  434.    /* side labels */
  435.    sprintf(text,"%s","Minimum");
  436.    text_len  = strlen(text);
  437.    text_width= XTextWidth(font_info,text,text_len);
  438.    text_xpos = Xxmax + 40 - text_width/2;
  439.    text_ypos = (Xymin + Xymax)/2 - 6*font_height;  
  440.    XDrawString(display,window,gc,text_xpos,text_ypos,text,text_len);
  441.    sprintf(text,"%.2f",zmin);
  442.    text_len  = strlen(text);
  443.    text_width= XTextWidth(font_info,text,text_len);
  444.    text_xpos = Xxmax + 40 - text_width/2;
  445.    text_ypos = (Xymin + Xymax)/2 - 4*font_height;  
  446.    XDrawString(display,window,gc,text_xpos,text_ypos,text,text_len);
  447.  
  448.    /* side labels */
  449.    sprintf(text,"%s","Maximum");
  450.    text_len  = strlen(text);
  451.    text_width= XTextWidth(font_info,text,text_len);
  452.    text_xpos = Xxmax + 40 - text_width/2;
  453.    text_ypos = (Xymin + Xymax)/2 + 4*font_height;  
  454.    XDrawString(display,window,gc,text_xpos,text_ypos,text,text_len);
  455.    sprintf(text,"%.2f",zmax);
  456.    text_len  = strlen(text);
  457.    text_width= XTextWidth(font_info,text,text_len);
  458.    text_xpos = Xxmax + 40 - text_width/2;
  459.    text_ypos = (Xymin + Xymax)/2 + 6*font_height;  
  460.    XDrawString(display,window,gc,text_xpos,text_ypos,text,text_len);
  461.  
  462.    /* Draw the tick marks and labels */
  463.    for (i=0; i<=xticks; i++) {
  464.       xtmp = Xxmin + i*(Xxmax-Xxmin)/xticks;
  465.       XDrawLine(display,window,gc,xtmp,Xymin,xtmp,Xymin+10);
  466.       XDrawLine(display,window,gc,xtmp,Xymax,xtmp,Xymax-10);
  467.       vallbl = xmin +i*xdx;
  468.       sprintf(text,"%6.2f",vallbl);
  469.       text_len = strlen(text);
  470.       if (text_len > 8) {
  471.          sprintf(text,"%6.2e",vallbl);
  472.          text_len = strlen(text);
  473.       }
  474.       text_width = XTextWidth(font_info,text,text_len);
  475.       text_xpos = xtmp  - text_width/2;
  476.       text_ypos = Xymax + 2*font_height;
  477.       XDrawString(display,window,gc,text_xpos,text_ypos,text,text_len);
  478.    }
  479.  
  480.    for (i=0; i<=yticks; i++) {
  481.       ytmp = Xymin + i*(Xymax-Xymin)/yticks;
  482.       XDrawLine(display,window,gc,Xxmin,ytmp,Xxmin+10,ytmp);
  483.       XDrawLine(display,window,gc,Xxmax,ytmp,Xxmax-10,ytmp);
  484.       vallbl = ymax -i*ydy;
  485.       sprintf(text,"%6.2f",vallbl);
  486.       text_len = strlen(text);
  487.       if (text_len > 8) {
  488.          sprintf(text,"%6.2e",vallbl);
  489.          text_len = strlen(text);
  490.       }
  491.       text_width = XTextWidth(font_info,text,text_len);
  492.       text_xpos = Xxmin - text_width - font_width;
  493.       text_ypos = ytmp  + font_height/2;
  494.       XDrawString(display,window,gc,text_xpos,text_ypos,text,text_len);
  495.    }
  496.  
  497.    /* Work on the grid */
  498.    if (grid == ON) {
  499.       XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
  500.       XSetDashes(display,gc,0,dash_list_long_dotted,LONG_DOTTED);
  501.       for (i=1; i<xticks; i++) {
  502.          xtmp = Xxmin + xintv*i;
  503.          XDrawLine(display,window,gc,xtmp,Xymin+10,xtmp,Xymax-10);
  504.       }
  505.       for (i=1; i<yticks; i++) {
  506.          ytmp = Xymin + yintv*i;
  507.          XDrawLine(display,window,gc,Xxmin+10,ytmp,Xxmax-10,ytmp);
  508.       }
  509.       XSetLineAttributes(display,gc,0,LineSolid,CapButt,JoinBevel);
  510.    }
  511. }
  512.  
  513. /* draw the plot */
  514. plotX()
  515. {
  516.    char   *sprintf();
  517.    extern int     linetypes, contlabel;
  518.    extern double  xmin, xmax, ymin, ymax;
  519.    extern plotptr plot_listhead;
  520.  
  521.    XPoint  points[MAXPTS];
  522.    nodeptr N;
  523.    plotptr P;
  524.    double  idx,jdy,oldlevel;
  525.    char    text[100];
  526.    int     text_len, text_width, text_xpos, text_ypos, font_height;
  527.    int     drawlbl, npts, j, kl=1;
  528.  
  529.    /* initialize */
  530.    font_height = lblfont_info->max_bounds.ascent +
  531.                  lblfont_info->max_bounds.descent;
  532.    idx = (Xxmax-Xxmin)/(xmax-xmin);
  533.    jdy = (Xymax-Xymin)/(ymin-ymax);  /* because of strange x format */
  534.  
  535.    /* plot */
  536.    if (plot_listhead!=NULL) oldlevel = plot_listhead->level;
  537.    for (P=plot_listhead; P!=NULL; P=P->next) {
  538.       j = 0;
  539.       /* rescale points, save in array */
  540.       for (N=P->nodehead; N!=NULL && j<MAXPTS; N=N->next) {
  541.          points[j].x = (int)((N->pt.x-xmin)*idx) + Xxmin;
  542.          points[j].y = (int)((N->pt.y-ymax)*jdy) + Xymin;
  543.          j++;
  544.       }
  545.       npts = j;
  546.  
  547.       if (j>0) {
  548.          /* plot the points */
  549.          if (oldlevel != P->level) kl++;
  550.          drawlbl = linetypX(kl);
  551.          linecolX(kl);
  552.          XDrawLines(display,window,gc,points,npts,CoordModeOrigin);
  553.          XSetForeground(display,gc,foreground_pixel); 
  554.  
  555.          /* label the contours */
  556.          if (contlabel && drawlbl){
  557.             sprintf(text,"%.2f",P->level);
  558.             text_len   = strlen(text);
  559.             text_width = XTextWidth(lblfont_info,text,text_len);
  560.             text_xpos  = points[(int)(0.5*j)].x - text_width/2;
  561.             text_ypos  = points[(int)(0.5*j)].y - font_height/2;
  562.             XDrawString(display,window,gcl,text_xpos,text_ypos,text,text_len);
  563.          }
  564.       }
  565.       oldlevel = P->level;
  566.    }
  567. }
  568.  
  569. /* set the line type */
  570. linetypX(linetyp)
  571. int linetyp;
  572. {
  573.    int  drawlbl = OFF;
  574.  
  575.    if      (linetypes <= 2) linetyp = linetyp % linetypes;
  576.    else if (linetypes == 3) linetyp = linetyp % 4;
  577.  
  578.    switch (linetyp) {
  579.    case 0 : XSetLineAttributes(display,gc,0,LineSolid,CapButt,JoinBevel);
  580.             drawlbl = ON;
  581.             break;
  582.    case 1 : XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
  583.             XSetDashes(display,gc,0,dash_list_dotted,DOTTED);
  584.             break;
  585.    case 2 : XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
  586.             XSetDashes(display,gc,0,dash_list_dashed,DASHED);
  587.             drawlbl = ON;
  588.             break;
  589.    case 3 : XSetLineAttributes(display,gc,0,LineOnOffDash,CapButt,JoinBevel);
  590.             XSetDashes(display,gc,0,dash_list_dotted,DOTTED);
  591.             break;
  592.    default: XSetLineAttributes(display,gc,0,LineSolid,CapButt,JoinBevel);
  593.             break;
  594.    }
  595.    return(drawlbl);
  596. }
  597.  
  598. /* choose a linecolor */
  599. linecolX(linetyp)
  600. int linetyp;
  601. {
  602.    extern int linetypes;
  603.  
  604.    if      (linetypes <= 2) linetyp = linetyp % linetypes;
  605.    else if (linetypes == 3) linetyp = linetyp % 4;
  606.    switch (linetyp) {
  607.       case 0 : XSetForeground(display,gc,colors[LINE1_C]); break;
  608.       case 1 : XSetForeground(display,gc,colors[LINE2_C]); break;
  609.       case 2 : XSetForeground(display,gc,colors[LINE3_C]); break;
  610.       case 3 : XSetForeground(display,gc,colors[LINE2_C]); break;
  611.       default: XSetForeground(display,gc,colors[LINE1_C]); break;
  612.    }
  613. }
  614.