ftp.nice.ch/pub/next/unix/developer/plplot.3.0.s.tar.gz#/plplot/amiga/src/amiga.c

This is amiga.c in view mode; [Download] [Up]

 /* Amiga PLPLOT window routines. */

#include "plamiga.h"
#include <stdio.h>
#ifdef AZTEC_C
   /* Psuedo-ANSI compatibility */
   #define remove(name)    unlink(name)
   /* Lattice defines these for you */
   struct IntuitionBase *IntuitionBase;
   struct GfxBase *GfxBase;
#endif

int XOffset, YOffset, PLWidth, PLHeight;
int MaxPLWidth, MaxPLHeight;
int InitPLWidth, InitPLHeight;
extern int MaxColors;

FILE *PlotFile;
short fbuffer;
static int CurColor;

void amisetup(xmm, ymm, xpg, ypg)
int xpg, ypg;
double xmm, ymm;
{
}

void amiorient(ori)
int ori;
{
}

void amiselect(file)
FILE *file;
{
}

/* amiini is the PLPLOT window initialization routine.  It opens the
   necessary libraries and the window. */
void amiinit()
{
   double Initdpmx, Initdpmy;

   /* Scan defaults file */
   GetPLDefs();
   /* Open the required libraries. */
   OpenLibs();
   /* Open window for graphics */
   OpenPLWind();
   /* Set up virtual screen width and height */
   /* Virtual screen is 25 times the actual one. */
   MaxPLWidth = PLScreen->Width - PLWindow->BorderLeft - PLWindow->BorderRight - 16;
   MaxPLHeight = PLScreen->Height - PLWindow->BorderTop - PLWindow->BorderBottom - 16;
   InitPLWidth = MaxPLWidth*25;
   InitPLHeight = MaxPLHeight*25;
   Initdpmx = GfxBase->NormalDPMX;
   Initdpmy = GfxBase->NormalDPMY;
   if(PLScreen->ViewPort.Modes & HIRES)
      Initdpmx *= 2.;
   if(PLScreen->ViewPort.Modes & LACE)
      Initdpmy *= 2.;
   setpxl((Initdpmx/40.),(Initdpmy/40.));
   setphy(0, (InitPLWidth-1), 0, (InitPLHeight-1));
   scol(1);
   swid(1);
   smod(1);

   SetAPen(PLWRPort,1);
   SetDrMd(PLWRPort,JAM1);
   setlimits();
}

void setlimits()
{
   XOffset = PLWindow->BorderLeft+8;
   YOffset = PLWindow->BorderTop+8;
   PLWidth = PLWindow->Width - XOffset - PLWindow->BorderRight - 8;
   PLHeight = PLWindow->Height - YOffset - PLWindow->BorderBottom - 8;
   if(PLCurPrefs.WinType & PLASP) {
      if(PLWidth*MaxPLHeight > PLHeight*MaxPLWidth) {
         PLWidth = (MaxPLWidth*PLHeight)/MaxPLHeight;
         XOffset += (PLWindow->Width - PLWidth - PLWindow->BorderLeft -
                    PLWindow->BorderRight)/2;
      }
      else {
         PLHeight = (MaxPLHeight*PLWidth)/MaxPLWidth;
         YOffset += (PLWindow->Height - PLHeight - PLWindow->BorderTop -
                    PLWindow->BorderBottom)/2;
      }
   }
}

void amitidy()
{
   void beepw();

   beepw();
   ClosePLWind();
   CloseLibs();
   if(fbuffer) {
      fclose(PlotFile);
      remove(PLOTBFFR);
   }
}

void OpenLibs()
{
  IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
  if( IntuitionBase == NULL ) {
     puts("\nError opening Intuition library.");
     goto IntError;
  }

  GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  if( GfxBase == NULL ) {
     puts("\nError opening Graphics library.");
     goto GfxError;
  }

  return;

GfxError:
  CloseLibrary((struct Library *)IntuitionBase);
IntError:
  pl_exit();
}

void CloseLibs()
{
   CloseLibrary((struct Library *)GfxBase);
   CloseLibrary((struct Library *)IntuitionBase);
}

void amitext()
{
}

void amigraph()
{
}

void amiclear()
{
   void beepw(), setpen();

   beepw();
   setpen(0);
   RectFill(PLWRPort,XOffset,YOffset,PLWidth+XOffset,PLHeight+YOffset);
   setpen(CurColor);
   if(fbuffer) {
      fclose(PlotFile);
      remove(PLOTBFFR);
   }
}

static int xold, yold;

void amipage()
{
   fbuffer = 0;
   if(PLCurPrefs.WinType & PLBUFF) {
      PlotFile = fopen(PLOTBFFR,"w+");
      if(PlotFile == NULL) {
         fprintf(stderr,"\nError opening plot data storage file.\n");
         ClosePLWind();
         CloseLibs();
         exit(1);
      }
      fbuffer = 1;
   }
   xold = -100000; yold = -100000;
}

void amieop()
{
}

void amiline(x1, y1, x2, y2)
int x1, y1, x2, y2;
{
   short comm, xshrt, yshrt;

   /* Check for intuition messages */
   procmess();
   if(x1 == xold && y1 == yold) {
      comm = PEND;
      xshrt = x2;
      yshrt = y2;
      if(fbuffer) {
         (void)fwrite((char *)&comm,sizeof(short),1,PlotFile);
         (void)fwrite((char *)&xshrt,sizeof(short),1,PlotFile);
         (void)fwrite((char *)&yshrt,sizeof(short),1,PlotFile);
      }
      PLDraw((PLWidth*x2)/InitPLWidth,(PLHeight*y2)/InitPLHeight);
   }
   else {
      comm = PENU;
      xshrt = x1;
      yshrt = y1;
      if(fbuffer) {
         (void)fwrite((char *)&comm,sizeof(short),1,PlotFile);
         (void)fwrite((char *)&xshrt,sizeof(short),1,PlotFile);
         (void)fwrite((char *)&yshrt,sizeof(short),1,PlotFile);
      }
      comm = PEND;
      xshrt = x2;
      yshrt = y2;
      if(fbuffer) {
         (void)fwrite((char *)&comm,sizeof(short),1,PlotFile);
         (void)fwrite((char *)&xshrt,sizeof(short),1,PlotFile);
         (void)fwrite((char *)&yshrt,sizeof(short),1,PlotFile);
      }
      PLMove((PLWidth*x1)/InitPLWidth,(PLHeight*y1)/InitPLHeight);
      PLDraw((PLWidth*x2)/InitPLWidth,(PLHeight*y2)/InitPLHeight);
   }
   xold = x2;
   yold = y2;
}

void PLMove(x, y)
int x, y;
{
   int xsc, ysc;

   xsc = XOffset + x;
   ysc = YOffset + PLHeight - y;
   Move(PLWRPort,xsc,ysc);
}

void PLDraw(x, y)
int x, y;
{
   int xsc, ysc;

   xsc = XOffset + x;
   ysc = YOffset + PLHeight - y;
   Draw(PLWRPort,xsc,ysc);
}

void remakeplot()
{
   long cxy, x1, y1;
   long x, y;
   void setpen();

   setpen(0);
   RectFill(PLWRPort,PLWindow->BorderLeft,PLWindow->BorderTop,
            PLWindow->Width-PLWindow->BorderRight,
            PLWindow->Height-PLWindow->BorderBottom);

   setpen(1);

   if(fbuffer == 0)
      return;
   prepupdate();

   while(!getpoint(&cxy, &x1, &y1)) {
      if(cxy == PENU) {
         x = ((long)PLWidth*(long)x1)/InitPLWidth;
         y = ((long)PLHeight*(long)y1)/InitPLHeight;
         PLMove((int)x, (int)y);
      }
      else if(cxy == PEND) {
         x = ((long)PLWidth*(long)x1)/InitPLWidth;
         y = ((long)PLHeight*(long)y1)/InitPLHeight;
         PLDraw((int)x, (int)y);
      }
      else if(cxy == SPEN) {
         CurColor = x1;
         if(x1 >= MaxColors)
            CurColor = 1;
         setpen((int)CurColor);
      }
   }

   finiupdate();
   DisplayBeep(PLScreen);
}

void amiwidth(width)
int width;
{
   short shwid, comm;

   if(width>=1 && width <=3) {
      comm = PWID;
      shwid = width;
      if(fbuffer) {
         fwrite((char *)&comm,sizeof(short),1,PlotFile);
         fwrite((char *)&shwid,sizeof(short),1,PlotFile);
      }
   }
}

void amicolor(color)
int color;
{
   short shcol, comm;
   void setpen();

   if(color >= 0 && color < 16) {
     shcol = color;
     comm = SPEN;
     if(fbuffer) {
        fwrite((char *)&comm,sizeof(short),1,PlotFile);
        fwrite((char *)&shcol,sizeof(short),1,PlotFile);
     }
     if(color >= MaxColors)
        color = 1;
     CurColor = color;
     setpen(color);
   }
}

void amicwin()
{
}

void amigwin()
{
}

static void setpen(color)
int color;
{
   SetAPen(PLWRPort,color);
}

static void beepw()
{
   DisplayBeep(PLScreen);
   eventwait();
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.