home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <exec/types.h>
- #include "struct.h"
- #include "plot.h"
- #include "howto2.h"
-
- extern char *gets();
- extern char *getwrd();
- extern struct Window *FrontWindow;
- extern struct Screen *screen;
- extern struct Selection *Sump;
- extern struct Remember *SumpKey;
-
- extern struct NewWindow NewFrontWindow;
- extern struct NewScreen newscreen;
-
- extern struct RastPort *p;
- extern struct ViewPort *vp;
-
- extern int debug;
-
- /*** PLOT TYPES ***/
- #define LINEPLOT 0
- #define POINTPLOT 1
- #define BOTHPLOT 2
- #define STEP 3
-
- USHORT PlotType;
- USHORT PointType;
- USHORT Colour;
- USHORT PlotPrefs;
- USHORT SkipPlot;
- USHORT StopPlot;
-
-
- #define DEFAULT 0
- #define CHOOSE 1
- #define STOP 0
- #define GO 1
- #define KILL 2
-
-
- extern int QuitFrontFlag;
- short firstcall = TRUE;
- extern short SCRIPT_ON;
-
- void GetHowTo(Pict)
- struct Pict *Pict;
- {
- short i;
- struct Plot *Plot;
- void ProcHowMes(), ProcCustMes(), GadMXSel();
- QuitFrontFlag=GO;
-
- if (firstcall) {
- firstcall = FALSE;
- /*** ESTABLISH DEFAULTS ***/
- if (!SCRIPT_ON)
- {
- PointType=6;
- Pict->Grid = 0;
- Pict->ShowErr = Pict->ErrBar;
- Pict->Tics->NX = Pict->Tics->NY = 5;
- PlotPrefs=DEFAULT;
- }
- Plot = Pict->Plot;
- if (newscreen.Depth==1) i=1;
- else i = 0;
- while (Plot) {
- if (!SCRIPT_ON)
- {
- Plot->Enabled = TRUE;
- Plot->Color = PLOTCOLORBASE + i;
- Plot->PointType = PointType;
- if (PointType>1) PointType = PointType-1;
- else PointType = 6;
- Plot->PlotType=BOTHPLOT;
- Plot->PointSize = DEFAULT_POINT_SIZE;
- Plot->Lines=TRUE;
- }
- while (Plot->Continued) {
- Plot->NextPlot->Color = Plot->Color;
- Plot->NextPlot->PointType= Plot->PointType;
- Plot->NextPlot->PointSize = Plot->PointSize;
- Plot->NextPlot->Lines = Plot->Lines;
- Plot->NextPlot->Enabled = Plot->Enabled;
- Plot = Plot->NextPlot;
- }
- Plot = Plot->NextPlot;
- switch(newscreen.Depth) {
- case 1: break;
- case 2: if ((i==1)||(i==9)) i++;
- case 3: if (i==5) i++;
- default: i++; if (i>11) i=0; break;
- }
- }
- }
- else
- { /* GET USER'S INSTRUCTIONS FOR EACH PLOT */
- Plot = Pict->Plot;
- for(i=0;i<Pict->NPlt;i++)
- {
- if (!CustomPlotWindow(Pict,Plot,i)) { StopPlot=FALSE; i=Pict->NPlt; }
- while (Plot->Continued) Plot=Plot->NextPlot;
- Plot = Plot->NextPlot;
- }
- }
- }
-
-
- void ProcCustMes(p_message)
- struct IntuiMessage *p_message;
- {
- ULONG MesClass; /* Fields for storing */
- USHORT MesCode; /* intuimessage data */
- APTR Pointer; /* */
- void HandleCustEvent();
-
- MesClass = p_message->Class; /* Store values */
- MesCode = p_message->Code;
- Pointer = p_message->IAddress;
- ReplyMsg(p_message); /* Reply to message */
- HandleCustEvent(MesClass,MesCode,Pointer);
- }
-
- void HandleCustEvent(MesClass,MesCode,Pointer)
- ULONG MesClass; /* Fields for storing */
- USHORT MesCode; /* intuimessage data */
- APTR Pointer; /* */
- {
-
- if ( MesClass == GADGETDOWN)
- {
- if (Pointer == (APTR)&Gadget45)
- {
- RemoveGadget(FrontWindow,&Gadget45);
-
- if (Colour2.PlaneOnOff==0xD)
- {
- Colour2.PlaneOnOff = 0x4;
- }
- else Colour2.PlaneOnOff++;
- AddGadget(FrontWindow,&Gadget45,-1L);
- RefreshGadgets(&Gadget45,FrontWindow,NULL);
- }
- else if (Pointer == (APTR)&SizeDown)
- {
- RemoveGadget(FrontWindow,&Gadget46);
- if (Gadget46SInfo.LongInt<1) {Message(" Point size must be +ve ");}
- else Gadget46SInfo.LongInt=Gadget46SInfo.LongInt-1;
- stci_d(Gadget46SIBuff,Gadget46SInfo.LongInt);
- AddGadget(FrontWindow,&Gadget46,-1L);
- RefreshGadgets(&Gadget46,FrontWindow,NULL);
- }
- else if (Pointer == (APTR)&SizeUp)
- {
- RemoveGadget(FrontWindow,&Gadget46);
- Gadget46SInfo.LongInt=Gadget46SInfo.LongInt+1;
- stci_d(Gadget46SIBuff,Gadget46SInfo.LongInt);
- AddGadget(FrontWindow,&Gadget46,-1L);
- RefreshGadgets(&Gadget46,FrontWindow,NULL);
- }
- else if (Pointer == (APTR)&Gadget47)
- {
- RemoveGadget(FrontWindow,&Gadget47);
- if (PlotType==LINEPLOT)
- {
- PlotType=POINTPLOT;
- Gadget47.GadgetRender = (APTR)&Image6b;
- }
- else if (PlotType==POINTPLOT)
- {
- PlotType=BOTHPLOT;
- Gadget47.GadgetRender = (APTR)&Image6c;
- }
- else if (PlotType==BOTHPLOT)
- {
- PlotType=STEP;
- Gadget47.GadgetRender = (APTR)&Image6d;
- }
- else
- {
- PlotType=LINEPLOT;
- Gadget47.GadgetRender = (APTR)&Image6a;
- }
- AddGadget(FrontWindow,&Gadget47,-1L);
- RefreshGadgets(&Gadget47,FrontWindow,NULL);
- }
- else if (Pointer == (APTR)&LineTypeSel)
- {
- RemoveGadget(FrontWindow,&LineTypeSel);
- if (LineTypeSel.GadgetRender== (APTR)&LineTyIm1)
- LineTypeSel.GadgetRender= (APTR)&LineTyIm2;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm2)
- LineTypeSel.GadgetRender= (APTR)&LineTyIm3;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm3)
- LineTypeSel.GadgetRender= (APTR)&LineTyIm4;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm4)
- LineTypeSel.GadgetRender= (APTR)&LineTyIm5;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm5)
- LineTypeSel.GadgetRender= (APTR)&LineTyIm6;
- else LineTypeSel.GadgetRender= (APTR)&LineTyIm1;
- AddGadget(FrontWindow,&LineTypeSel,-1L);
- RefreshGadgets(&LineTypeSel,FrontWindow,NULL);
- }
- else if (Pointer == (APTR)&GadgPoint6)
- {
- GadMXSel(FrontWindow,&GadgPoint6,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
- PointType=6;
- }
- else if (Pointer == (APTR)&GadgPoint5)
- {
- GadMXSel(FrontWindow,&GadgPoint5,&GadgPoint6,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
- PointType=5;
- }
- else if (Pointer == (APTR)&GadgPoint4)
- {
- GadMXSel(FrontWindow,&GadgPoint4,&GadgPoint5,&GadgPoint6,&GadgPoint3,&GadgPoint2,&GadgPoint1);
- PointType=4;
- }
- else if (Pointer == (APTR)&GadgPoint3)
- {
- GadMXSel(FrontWindow,&GadgPoint3,&GadgPoint5,&GadgPoint4,&GadgPoint6,&GadgPoint2,&GadgPoint1);
- PointType=3;
- }
- else if (Pointer == (APTR)&GadgPoint2)
- {
- GadMXSel(FrontWindow,&GadgPoint2,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint6,&GadgPoint1);
- PointType=2;
- }
- else if (Pointer == (APTR)&GadgPoint1)
- {
- GadMXSel(FrontWindow,&GadgPoint1,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint6);
- PointType=1;
- }
- else if (Pointer == (APTR)&GadgetSkip)
- {
- QuitFrontFlag = STOP;
- SkipPlot=TRUE;
- }
- else if (Pointer == (APTR)&GadgetKill)
- {
- QuitFrontFlag = STOP;
- SkipPlot=KILL;
- }
- else if (Pointer == (APTR)&GadgetStop)
- {
- QuitFrontFlag = STOP;
- StopPlot=TRUE;
- }
- else if (Pointer == (APTR)&Gadget43) QuitFrontFlag = STOP;
- else ;
- }
- if ( MesClass == RAWKEY)
- {
- if (MesCode ==196) /* RETURN key RELEASED */
- {
- QuitFrontFlag = STOP;
- }
- else if (MesCode ==69) /* ESCAPE key PRESSED */
- {
- QuitFrontFlag = STOP;
- StopPlot=TRUE;
-
- }
- else ;
- }
- else ;
- }
-
- /**
- *
- * This routine selects gad1 and deselects the previously selected one.
- * Maximum number of gadgets to be mutually excluded is six, obviously.
- * Extension to more gadgets is obvious, too. This routine assumes that
- * only one gadget is selected at a time.
- *
- **/
-
- void GadMXSel(win,gad1,gad2,gad3,gad4,gad5,gad6)
- struct Window *win;
- struct Gadget *gad1,*gad2,*gad3,*gad4,*gad5,*gad6;
- {
- void GadMXSD();
- static struct Gadget *gadprev;
-
- gadprev = NULL;
- if (gad1 != NULL)
- if (gad1->Flags & SELECTED) return;
- if (gad2 != NULL)
- if (gad2->Flags & SELECTED) gadprev = gad2;
- if (gad3 != NULL)
- if (gad3->Flags & SELECTED) gadprev = gad3;
- if (gad4 != NULL)
- if (gad4->Flags & SELECTED) gadprev = gad4;
- if (gad5 != NULL)
- if (gad5->Flags & SELECTED) gadprev = gad5;
- if (gad6 != NULL)
- if (gad6->Flags & SELECTED) gadprev = gad6;
-
- GadMXSD(win,gad1,gadprev);
-
- return;
- }
-
- /**
- *
- * This routine selects gad1 and deselects gad2.
- * Notice, that this version removes gadgets from the gadget list and adds
- * them to the end. If you're sensitive to the location of the gadgets
- * in the gadgetlist, you have to use: gadloc = RemoveGadget... and
- * AddGadget(...,...,(long) gadloc), where gadloc is a USHORT. Then you
- * have to refresh all gadgets to make sure the two you changed get
- * refreshed.
- *
- **/
-
- void GadMXSD(win,gad1,gad2)
- struct Window *win;
- struct Gadget *gad1,*gad2;
- {
- /*
- * First select gad2 (yes!) and refresh.
- */
- if (gad2 != NULL) {
- RemoveGadget(win,gad2);
- gad2->Flags |= SELECTED;
- AddGadget(win,gad2,-1L);
- }
-
- if (gad2 != NULL) RefreshGadgets(gad2,win,NULL);
- /*
- * Now select gad1 and deselect gad2 and refresh.
- */
- if (gad1 != NULL) {
- RemoveGadget(win,gad1);
- gad1->Flags |= SELECTED;
- AddGadget(win,gad1,-1L);
- }
-
- if (gad2 != NULL) {
- RemoveGadget(win,gad2);
- gad2->Flags &= ~SELECTED;
- AddGadget(win,gad2,-1L);
- }
-
- if (gad1 != NULL) RefreshGadgets(gad1,win,NULL);
-
- return;
- }
-
-
-
- CustomPlotWindow(Pict,Plot,i)
- struct Plot *Plot;
- struct Pict *Pict;
- int i;
- { /* GET USER'S INSTRUCTIONS FOR A PLOT */
- void ProcCustMes(), GadMXSel(), KillPlot();
- SHORT border[] ={
- 336, 76,
- 400, 76,
- 400,140,
- 336,140,
- 336, 76
- };
- int j;
- struct IntuiMessage *p_message; /* pointer to message */
-
- j=min(19,i);
- IText16.IText=SetText[j];
- NewFrontWindow.Title = title1;
- NewFrontWindow.FirstGadget = &Gadget43;
- NewFrontWindow.Screen = screen;
-
- Gadget46SInfo.LongInt=Plot->PointSize;
- stci_d(Gadget46SIBuff,Gadget46SInfo.LongInt);
-
- Colour2.PlaneOnOff= Plot->Color;
-
- PlotType=Plot->PlotType;
- if (PlotType==LINEPLOT) { Gadget47.GadgetRender = (APTR)&Image6a;}
- else if (PlotType==POINTPLOT) {Gadget47.GadgetRender = (APTR)&Image6b;}
- else if (PlotType==BOTHPLOT) {Gadget47.GadgetRender = (APTR)&Image6c;}
- else {Gadget47.GadgetRender = (APTR)&Image6d;}
-
- GadgPoint1.Flags &= ~SELECTED; GadgPoint2.Flags &= ~SELECTED; GadgPoint3.Flags &= ~SELECTED;
- GadgPoint4.Flags &= ~SELECTED; GadgPoint5.Flags &= ~SELECTED; GadgPoint6.Flags &= ~SELECTED;
- PointType= Plot->PointType;
- switch (Plot->PointType) {
- case 1: GadgPoint1.Flags |= SELECTED; break;
- case 2: GadgPoint2.Flags |= SELECTED; break;
- case 3: GadgPoint3.Flags |= SELECTED; break;
- case 4: GadgPoint4.Flags |= SELECTED; break;
- case 5: GadgPoint5.Flags |= SELECTED; break;
- case 6:
- default: PointType=6; GadgPoint6.Flags |= SELECTED; break;
- }
-
- switch (Plot->Lines) {
- case 6: LineTypeSel.GadgetRender= (APTR)&LineTyIm6; break;
- case 5: LineTypeSel.GadgetRender= (APTR)&LineTyIm5; break;
- case 4: LineTypeSel.GadgetRender= (APTR)&LineTyIm4; break;
- case 3: LineTypeSel.GadgetRender= (APTR)&LineTyIm3; break;
- case 2: LineTypeSel.GadgetRender= (APTR)&LineTyIm2; break;
- case 1:
- case 0:
- default: LineTypeSel.GadgetRender= (APTR)&LineTyIm1; break;
- }
-
- if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
- {
- ErrorAlert(0);
- CloseScreen(screen);
- sexit(FALSE);
- }
- p = FrontWindow->RPort;
- PrintIText(p,&IText16,0,0);
- Move(p,336,76);
- PolyDraw(p,5,border);
-
- QuitFrontFlag=GO;
- SkipPlot=FALSE;
- StopPlot=FALSE;
-
- while (QuitFrontFlag !=STOP) {
- Wait(1l<<FrontWindow->UserPort->mp_SigBit); /* wait for a message */
- while (p_message = (struct IntuiMessage *)GetMsg(FrontWindow->UserPort))
- ProcCustMes(p_message);
- }
- if (SkipPlot) {
- if (SkipPlot==KILL) {
- if (Sump) FreeRemember(&SumpKey,TRUE);
- Sump=NULL;
- KillPlot(Pict,Plot);
- SkipPlot=FALSE;
- }
- else { /* Temporarily Skip Plot */
- Plot->Enabled = FALSE;
- while (Plot->Continued) {Plot=Plot->NextPlot; Plot->Enabled=FALSE;}
- SkipPlot=FALSE;
- }
- }
- else if (!StopPlot)
- {
- Plot->Enabled = TRUE;
- Plot->PointType=PointType;
- Plot->Color = Colour2.PlaneOnOff;
- if (PlotType==LINEPLOT) Plot->PointSize = 0;
- else Plot->PointSize = Gadget46SInfo.LongInt;
- Plot->PlotType=PlotType;
- if (PlotType==POINTPLOT) {
- Plot->Lines = FALSE;
- /* if (Plot->PointSize <1) Plot->PointSize=8; */
- }
- else
- {
- if (LineTypeSel.GadgetRender== (APTR)&LineTyIm1) Plot->Lines = 1;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm2) Plot->Lines = 2;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm3) Plot->Lines = 3;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm4) Plot->Lines = 4;
- else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm5) Plot->Lines = 5;
- else Plot->Lines = 6;
- }
- while (Plot->Continued) {
- Plot->NextPlot->Color = Plot->Color;
- Plot->NextPlot->PointType= Plot->PointType;
- Plot->NextPlot->PointSize = Plot->PointSize;
- Plot->NextPlot->Lines = Plot->Lines;
- Plot->NextPlot->Enabled = Plot->Enabled;
- Plot=Plot->NextPlot;
- }
- }
- CloseWindow(FrontWindow);
- if (StopPlot) return(FALSE);
- if (SkipPlot==KILL) return(KILL);
- else return(TRUE);
- }
-
-
-