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 >
Wrap
C/C++ Source or Header
|
1990-01-27
|
7KB
|
320 lines
/* Amiga PLPLOT window routines. */
#include "plplot.h"
#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
PLINT XOffset, YOffset, PLWidth, PLHeight;
PLINT MaxPLWidth, MaxPLHeight;
PLINT InitPLWidth, InitPLHeight;
extern PLINT MaxColors;
FILE *PlotFile;
short fbuffer;
static PLINT CurColor;
void amisetup(xmm, ymm, xpg, ypg)
PLINT xpg, ypg;
PLFLT xmm, ymm;
{
}
void amiselect(ori, file)
PLINT ori;
char *file;
{
}
/* amiini is the PLPLOT window initialization routine. It opens the
necessary libraries and the window. */
void amiinit()
{
PLFLT 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((PLFLT)(Initdpmx/40.),(PLFLT)(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 PLINT 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 amiline(x1, y1, x2, y2)
PLINT 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)
PLINT x, y;
{
PLINT xsc, ysc;
xsc = XOffset + x;
ysc = YOffset + PLHeight - y;
Move(PLWRPort,xsc,ysc);
}
void PLDraw(x, y)
PLINT x, y;
{
PLINT 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((PLINT)x, (PLINT)y);
}
else if(cxy == PEND) {
x = ((long)PLWidth*(long)x1)/InitPLWidth;
y = ((long)PLHeight*(long)y1)/InitPLHeight;
PLDraw((PLINT)x, (PLINT)y);
}
else if(cxy == SPEN) {
CurColor = x1;
if(x1 >= MaxColors)
CurColor = 1;
setpen((PLINT)CurColor);
}
}
finiupdate();
DisplayBeep(PLScreen);
}
void amiwidth(width)
PLINT 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)
PLINT 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);
}
}
static void setpen(color)
PLINT color;
{
SetAPen(PLWRPort,color);
}
static void beepw()
{
DisplayBeep(PLScreen);
eventwait();
}