home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / drivers / preferences.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  3.1 KB  |  162 lines

  1. #include "plplot.h"
  2. #include <stdio.h>
  3.  
  4. static int orient, select=0, curwid;
  5. static long bmapx, bmapy, bmapxmax, bmapymax, xdpi, ydpi;
  6. static long dwidth, dheight;
  7.  
  8. void prefsetup(xddpi, yddpi, xwid, ywid)
  9. PLINT xwid, ywid;
  10. PLFLT xddpi, yddpi;
  11. {
  12.    /* Ignore these and use preferences data instead. */
  13. }
  14.  
  15. void prefselect(ori, name)
  16. PLINT ori;
  17. char *name;
  18. {
  19.    orient = ori;
  20.    select = 1;
  21. }
  22.  
  23. /* Most of the code is in plsupport.c  where it is shared with the menu
  24.    selection printer dump. */
  25. void prefinit()
  26. {
  27.    char line[10];
  28.    int mode, openprinter(), mapinit(), queryprint();
  29.    void closeprinter();
  30.  
  31.    if(!select) {
  32.       printf("Landscape or portrait orientation? (0 or 1) ");
  33.       fgets(line,sizeof(line),stdin);
  34.       if(sscanf(line,"%d",&orient) != 1)
  35.          orient = 0;
  36.    }
  37.    select = 0;
  38.  
  39.    if(openprinter()) plexit("");
  40.  
  41.    mode = queryprint(&bmapx, &bmapy, &bmapxmax, &bmapymax, &xdpi, &ydpi);
  42.  
  43.    /* If mode == 1 we want to adjust the bitmap size so that the aspect
  44.       ratio is maintained. */
  45.    if(mode) {
  46.       if((float)bmapxmax*bmapy > (float)bmapymax*bmapx)
  47.          bmapy = (int)(((float)bmapx*bmapymax)/bmapxmax + .5);
  48.       else
  49.          bmapx = (int)(((float)bmapy*bmapxmax)/bmapymax + .5);
  50.    }
  51.  
  52.    /* Leave a little space for pen width. */
  53.    dwidth = bmapx - 2;
  54.    dheight = bmapy - 2;
  55.  
  56.    if(!orient) {
  57.       setpxl((PLFLT)(ydpi/25.4), (PLFLT)(xdpi/25.4));
  58.       setphy(0,bmapymax,0,bmapxmax);
  59.    }
  60.    else {
  61.       setpxl((PLFLT)(xdpi/25.4), (PLFLT)(ydpi/25.4));
  62.       setphy(0,bmapxmax,0,bmapymax);
  63.    }
  64.  
  65.    scol(1);
  66.    swid(1);
  67.    smod(0);
  68.  
  69.    /* Allocate bitmap and initial for line drawing */
  70.    if(mapinit(bmapx, bmapy)) {
  71.       closeprinter();
  72.       plexit("");
  73.    }
  74. }
  75.  
  76. void preftext()
  77. {
  78. }
  79.  
  80. void prefgraph()
  81. {
  82. }
  83.  
  84. void prefclear()
  85. {
  86.    void ejectpage(), dmpport();
  87.  
  88.    dmpport(0L,bmapx,bmapy);
  89.    /* Eject the page. */
  90.    ejectpage();
  91. }
  92.  
  93. void prefpage()
  94. {
  95.    void mapclear();
  96.  
  97.    mapclear();
  98. }
  99.  
  100. void prefwidth(width)
  101. PLINT width;
  102. {
  103.    if(width < 1)
  104.       curwid = 1;
  105.    else if(width > 3)
  106.       curwid = 3;
  107.    else
  108.       curwid = width;
  109. }
  110.  
  111. void prefcolor(color)
  112. PLINT color;
  113. {
  114. }
  115.  
  116. void prefline(x1,y1,x2,y2)
  117. PLINT x1, y1, x2, y2;
  118. {
  119.    long xn1, yn1, xn2, yn2;
  120.    void mapline();
  121.  
  122.    if(!orient) {
  123.       xn1 = (x1*dheight)/bmapymax;
  124.       yn1 = (y1*dwidth)/bmapxmax;
  125.       xn2 = (x2*dheight)/bmapymax;
  126.       yn2 = (y2*dwidth)/bmapxmax;
  127.       switch(curwid) {
  128.          case 3:
  129.             mapline(yn1,xn1,yn2,xn2);
  130.          case 2:
  131.             mapline(yn1+2,xn1+2,yn2+2,xn2+2);
  132.          case 1:
  133.          default:
  134.             mapline(yn1+1,xn1+1,yn2+1,xn2+1);
  135.       }
  136.    }
  137.    else {
  138.       xn1 = (x1*dwidth)/bmapxmax;
  139.       yn1 = (y1*dheight)/bmapymax;
  140.       xn2 = (x2*dwidth)/bmapxmax;
  141.       yn2 = (y2*dheight)/bmapymax;
  142.       switch(curwid) {
  143.          case 3:
  144.             mapline(xn1,dheight-yn1,xn2,dheight-yn2);
  145.          case 2:
  146.             mapline(xn1+2,dheight-yn1+2,xn2+2,dheight-yn2+2);
  147.          case 1:
  148.          default:
  149.             mapline(xn1+1,dheight-yn1+1,xn2+1,dheight-yn2+1);
  150.       }
  151.    }
  152. }
  153.  
  154. void preftidy()
  155. {
  156.    void dmpport(), mapfree(), closeprinter();
  157.  
  158.    dmpport(0L,bmapx,bmapy);
  159.    mapfree();
  160.    closeprinter();
  161. }
  162.