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

  1.  /* Amiga PLPLOT window routines. */
  2.  
  3. #include "plplot.h"
  4. #include "plamiga.h"
  5. #include <stdio.h>
  6. #ifdef AZTEC_C
  7.    /* Psuedo-ANSI compatibility */
  8.    #define remove(name)    unlink(name)
  9.    /* Lattice defines these for you */
  10.    struct IntuitionBase *IntuitionBase;
  11.    struct GfxBase *GfxBase;
  12. #endif
  13.  
  14. PLINT XOffset, YOffset, PLWidth, PLHeight;
  15. PLINT MaxPLWidth, MaxPLHeight;
  16. PLINT InitPLWidth, InitPLHeight;
  17. extern PLINT MaxColors;
  18.  
  19. FILE *PlotFile;
  20. short fbuffer;
  21. static PLINT CurColor;
  22.  
  23. void amisetup(xmm, ymm, xpg, ypg)
  24. PLINT xpg, ypg;
  25. PLFLT xmm, ymm;
  26. {
  27. }
  28.  
  29. void amiselect(ori, file)
  30. PLINT ori;
  31. char *file;
  32. {
  33. }
  34.  
  35. /* amiini is the PLPLOT window initialization routine.  It opens the
  36.    necessary libraries and the window. */
  37. void amiinit()
  38. {
  39.    PLFLT Initdpmx, Initdpmy;
  40.  
  41.    /* Scan defaults file */
  42.    GetPLDefs();
  43.    /* Open the required libraries. */
  44.    OpenLibs();
  45.    /* Open window for graphics */
  46.    OpenPLWind();
  47.    /* Set up virtual screen width and height */
  48.    /* Virtual screen is 25 times the actual one. */
  49.    MaxPLWidth = PLScreen->Width - PLWindow->BorderLeft - PLWindow->BorderRight - 16;
  50.    MaxPLHeight = PLScreen->Height - PLWindow->BorderTop - PLWindow->BorderBottom - 16;
  51.    InitPLWidth = MaxPLWidth*25;
  52.    InitPLHeight = MaxPLHeight*25;
  53.    Initdpmx = GfxBase->NormalDPMX;
  54.    Initdpmy = GfxBase->NormalDPMY;
  55.    if(PLScreen->ViewPort.Modes & HIRES)
  56.       Initdpmx *= 2.;
  57.    if(PLScreen->ViewPort.Modes & LACE)
  58.       Initdpmy *= 2.;
  59.    setpxl((PLFLT)(Initdpmx/40.),(PLFLT)(Initdpmy/40.));
  60.    setphy(0, (InitPLWidth-1), 0, (InitPLHeight-1));
  61.    scol(1);
  62.    swid(1);
  63.    smod(1);
  64.  
  65.    SetAPen(PLWRPort,1);
  66.    SetDrMd(PLWRPort,JAM1);
  67.    setlimits();
  68. }
  69.  
  70. void setlimits()
  71. {
  72.    XOffset = PLWindow->BorderLeft+8;
  73.    YOffset = PLWindow->BorderTop+8;
  74.    PLWidth = PLWindow->Width - XOffset - PLWindow->BorderRight - 8;
  75.    PLHeight = PLWindow->Height - YOffset - PLWindow->BorderBottom - 8;
  76.    if(PLCurPrefs.WinType & PLASP) {
  77.       if(PLWidth*MaxPLHeight > PLHeight*MaxPLWidth) {
  78.          PLWidth = (MaxPLWidth*PLHeight)/MaxPLHeight;
  79.          XOffset += (PLWindow->Width - PLWidth - PLWindow->BorderLeft -
  80.                     PLWindow->BorderRight)/2;
  81.       }
  82.       else {
  83.          PLHeight = (MaxPLHeight*PLWidth)/MaxPLWidth;
  84.          YOffset += (PLWindow->Height - PLHeight - PLWindow->BorderTop -
  85.                     PLWindow->BorderBottom)/2;
  86.       }
  87.    }
  88. }
  89.  
  90. void amitidy()
  91. {
  92.    void beepw();
  93.  
  94.    beepw();
  95.    ClosePLWind();
  96.    CloseLibs();
  97.    if(fbuffer) {
  98.       fclose(PlotFile);
  99.       remove(PLOTBFFR);
  100.    }
  101. }
  102.  
  103. void OpenLibs()
  104. {
  105.   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
  106.   if( IntuitionBase == NULL ) {
  107.      puts("\nError opening Intuition library.");
  108.      goto IntError;
  109.   }
  110.  
  111.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  112.   if( GfxBase == NULL ) {
  113.      puts("\nError opening Graphics library.");
  114.      goto GfxError;
  115.   }
  116.  
  117.   return;
  118.  
  119. GfxError:
  120.   CloseLibrary((struct Library *)IntuitionBase);
  121. IntError:
  122.   pl_exit();
  123. }
  124.  
  125. void CloseLibs()
  126. {
  127.    CloseLibrary((struct Library *)GfxBase);
  128.    CloseLibrary((struct Library *)IntuitionBase);
  129. }
  130.  
  131. void amitext()
  132. {
  133. }
  134.  
  135. void amigraph()
  136. {
  137. }
  138.  
  139. void amiclear()
  140. {
  141.    void beepw(), setpen();
  142.  
  143.    beepw();
  144.    setpen(0);
  145.    RectFill(PLWRPort,XOffset,YOffset,PLWidth+XOffset,PLHeight+YOffset);
  146.    setpen(CurColor);
  147.    if(fbuffer) {
  148.       fclose(PlotFile);
  149.       remove(PLOTBFFR);
  150.    }
  151. }
  152.  
  153. static PLINT xold, yold;
  154.  
  155. void amipage()
  156. {
  157.    fbuffer = 0;
  158.    if(PLCurPrefs.WinType & PLBUFF) {
  159.       PlotFile = fopen(PLOTBFFR,"w+");
  160.       if(PlotFile == NULL) {
  161.          fprintf(stderr,"\nError opening plot data storage file.\n");
  162.          ClosePLWind();
  163.          CloseLibs();
  164.          exit(1);
  165.       }
  166.       fbuffer = 1;
  167.    }
  168.    xold = -100000; yold = -100000;
  169. }
  170.  
  171.  
  172. void amiline(x1, y1, x2, y2)
  173. PLINT x1, y1, x2, y2;
  174. {
  175.    short comm, xshrt, yshrt;
  176.  
  177.    /* Check for intuition messages */
  178.    procmess();
  179.    if(x1 == xold && y1 == yold) {
  180.       comm = PEND;
  181.       xshrt = x2;
  182.       yshrt = y2;
  183.       if(fbuffer) {
  184.          (void)fwrite((char *)&comm,sizeof(short),1,PlotFile);
  185.          (void)fwrite((char *)&xshrt,sizeof(short),1,PlotFile);
  186.          (void)fwrite((char *)&yshrt,sizeof(short),1,PlotFile);
  187.       }
  188.       PLDraw((PLWidth*x2)/InitPLWidth,(PLHeight*y2)/InitPLHeight);
  189.    }
  190.    else {
  191.       comm = PENU;
  192.       xshrt = x1;
  193.       yshrt = y1;
  194.       if(fbuffer) {
  195.          (void)fwrite((char *)&comm,sizeof(short),1,PlotFile);
  196.          (void)fwrite((char *)&xshrt,sizeof(short),1,PlotFile);
  197.          (void)fwrite((char *)&yshrt,sizeof(short),1,PlotFile);
  198.       }
  199.       comm = PEND;
  200.       xshrt = x2;
  201.       yshrt = y2;
  202.       if(fbuffer) {
  203.          (void)fwrite((char *)&comm,sizeof(short),1,PlotFile);
  204.          (void)fwrite((char *)&xshrt,sizeof(short),1,PlotFile);
  205.          (void)fwrite((char *)&yshrt,sizeof(short),1,PlotFile);
  206.       }
  207.       PLMove((PLWidth*x1)/InitPLWidth,(PLHeight*y1)/InitPLHeight);
  208.       PLDraw((PLWidth*x2)/InitPLWidth,(PLHeight*y2)/InitPLHeight);
  209.    }
  210.    xold = x2;
  211.    yold = y2;
  212. }
  213.  
  214. void PLMove(x, y)
  215. PLINT x, y;
  216. {
  217.    PLINT xsc, ysc;
  218.  
  219.    xsc = XOffset + x;
  220.    ysc = YOffset + PLHeight - y;
  221.    Move(PLWRPort,xsc,ysc);
  222. }
  223.  
  224. void PLDraw(x, y)
  225. PLINT x, y;
  226. {
  227.    PLINT xsc, ysc;
  228.  
  229.    xsc = XOffset + x;
  230.    ysc = YOffset + PLHeight - y;
  231.    Draw(PLWRPort,xsc,ysc);
  232. }
  233.  
  234. void remakeplot()
  235. {
  236.    long cxy, x1, y1;
  237.    long x, y;
  238.    void setpen();
  239.  
  240.    setpen(0);
  241.    RectFill(PLWRPort,PLWindow->BorderLeft,PLWindow->BorderTop,
  242.             PLWindow->Width-PLWindow->BorderRight,
  243.             PLWindow->Height-PLWindow->BorderBottom);
  244.  
  245.    setpen(1);
  246.  
  247.    if(fbuffer == 0)
  248.       return;
  249.    prepupdate();
  250.  
  251.    while(!getpoint(&cxy, &x1, &y1)) {
  252.       if(cxy == PENU) {
  253.          x = ((long)PLWidth*(long)x1)/InitPLWidth;
  254.          y = ((long)PLHeight*(long)y1)/InitPLHeight;
  255.          PLMove((PLINT)x, (PLINT)y);
  256.       }
  257.       else if(cxy == PEND) {
  258.          x = ((long)PLWidth*(long)x1)/InitPLWidth;
  259.          y = ((long)PLHeight*(long)y1)/InitPLHeight;
  260.          PLDraw((PLINT)x, (PLINT)y);
  261.       }
  262.       else if(cxy == SPEN) {
  263.          CurColor = x1;
  264.          if(x1 >= MaxColors)
  265.             CurColor = 1;
  266.          setpen((PLINT)CurColor);
  267.       }
  268.    }
  269.  
  270.    finiupdate();
  271.    DisplayBeep(PLScreen);
  272. }
  273.  
  274. void amiwidth(width)
  275. PLINT width;
  276. {
  277.    short shwid, comm;
  278.  
  279.    if(width>=1 && width <=3) {
  280.       comm = PWID;
  281.       shwid = width;
  282.       if(fbuffer) {
  283.          fwrite((char *)&comm,sizeof(short),1,PlotFile);
  284.          fwrite((char *)&shwid,sizeof(short),1,PlotFile);
  285.       }
  286.    }
  287. }
  288.  
  289. void amicolor(color)
  290. PLINT color;
  291. {
  292.    short shcol, comm;
  293.    void setpen();
  294.  
  295.    if(color >= 0 && color < 16) {
  296.      shcol = color;
  297.      comm = SPEN;
  298.      if(fbuffer) {
  299.         fwrite((char *)&comm,sizeof(short),1,PlotFile);
  300.         fwrite((char *)&shcol,sizeof(short),1,PlotFile);
  301.      }
  302.      if(color >= MaxColors)
  303.         color = 1;
  304.      CurColor = color;
  305.      setpen(color);
  306.    }
  307. }
  308.  
  309. static void setpen(color)
  310. PLINT color;
  311. {
  312.    SetAPen(PLWRPort,color);
  313. }
  314.  
  315. static void beepw()
  316. {
  317.    DisplayBeep(PLScreen);
  318.    eventwait();
  319. }
  320.