home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk373.lzh / Multiplot / source / mplot_src / src.zoo / gethowto.c < prev    next >
C/C++ Source or Header  |  1990-08-02  |  15KB  |  481 lines

  1. #include <stdio.h>
  2. #include <exec/types.h>
  3. #include "struct.h"
  4. #include "plot.h"
  5. #include "howto2.h"
  6.  
  7. extern char *gets();
  8. extern char *getwrd();
  9. extern struct Window *FrontWindow;
  10. extern struct Screen *screen;
  11. extern struct Selection *Sump;
  12. extern struct Remember *SumpKey;
  13.  
  14. extern struct NewWindow NewFrontWindow;
  15. extern struct NewScreen newscreen;
  16.  
  17. extern struct RastPort *p;
  18. extern struct ViewPort *vp;
  19.  
  20. extern int debug;
  21.  
  22. /*** PLOT TYPES ***/
  23. #define LINEPLOT 0
  24. #define POINTPLOT 1
  25. #define BOTHPLOT 2
  26. #define STEP 3
  27.  
  28. USHORT PlotType;
  29. USHORT PointType;
  30. USHORT Colour;
  31. USHORT PlotPrefs;
  32. USHORT SkipPlot;
  33. USHORT StopPlot;
  34.  
  35.  
  36. #define DEFAULT 0
  37. #define CHOOSE 1
  38. #define STOP 0
  39. #define GO 1
  40. #define KILL 2
  41.  
  42.  
  43. extern int QuitFrontFlag;
  44. short firstcall = TRUE;
  45. extern short SCRIPT_ON;
  46.  
  47. void GetHowTo(Pict)
  48. struct Pict *Pict;
  49. {
  50.    short i;
  51.    struct Plot *Plot;
  52.    void ProcHowMes(), ProcCustMes(), GadMXSel();
  53.    QuitFrontFlag=GO;
  54.  
  55. if (firstcall) {
  56.    firstcall = FALSE;
  57.       /*** ESTABLISH DEFAULTS ***/
  58.    if (!SCRIPT_ON)
  59.      {
  60.         PointType=6;
  61.         Pict->Grid = 0;
  62.         Pict->ShowErr = Pict->ErrBar;
  63.         Pict->Tics->NX = Pict->Tics->NY = 5;
  64.         PlotPrefs=DEFAULT;
  65.      }
  66.    Plot = Pict->Plot;
  67.    if (newscreen.Depth==1) i=1;
  68.    else i = 0;
  69.    while (Plot) {
  70.      if (!SCRIPT_ON)
  71.        {
  72.           Plot->Enabled = TRUE;
  73.           Plot->Color = PLOTCOLORBASE + i;
  74.           Plot->PointType = PointType;
  75.           if (PointType>1) PointType = PointType-1;
  76.           else PointType = 6;
  77.           Plot->PlotType=BOTHPLOT;
  78.           Plot->PointSize = DEFAULT_POINT_SIZE;
  79.           Plot->Lines=TRUE;
  80.         }
  81.      while (Plot->Continued) {
  82.          Plot->NextPlot->Color = Plot->Color;
  83.          Plot->NextPlot->PointType= Plot->PointType;
  84.          Plot->NextPlot->PointSize = Plot->PointSize;
  85.          Plot->NextPlot->Lines = Plot->Lines;
  86.          Plot->NextPlot->Enabled = Plot->Enabled;
  87.          Plot = Plot->NextPlot;
  88.          }
  89.      Plot = Plot->NextPlot;
  90.      switch(newscreen.Depth) {
  91.        case 1:  break;
  92.        case 2:  if ((i==1)||(i==9)) i++;
  93.        case 3:  if (i==5) i++;
  94.        default: i++; if (i>11) i=0; break;
  95.        }
  96.      }
  97.    }
  98.    else
  99.     {            /* GET USER'S INSTRUCTIONS FOR EACH PLOT */
  100.       Plot = Pict->Plot;
  101.       for(i=0;i<Pict->NPlt;i++)
  102.         {
  103.            if (!CustomPlotWindow(Pict,Plot,i)) { StopPlot=FALSE; i=Pict->NPlt; }
  104.            while (Plot->Continued) Plot=Plot->NextPlot;
  105.            Plot = Plot->NextPlot;
  106.         }
  107.    }
  108. }
  109.  
  110.  
  111. void ProcCustMes(p_message)
  112. struct IntuiMessage *p_message;
  113. {
  114. ULONG MesClass;        /*     Fields for storing      */
  115. USHORT MesCode;        /*     intuimessage data       */
  116. APTR Pointer;          /*                             */
  117. void HandleCustEvent();
  118.  
  119.    MesClass = p_message->Class;             /* Store values */
  120.    MesCode = p_message->Code;
  121.    Pointer = p_message->IAddress;
  122.    ReplyMsg(p_message);                     /* Reply to message */
  123.    HandleCustEvent(MesClass,MesCode,Pointer);
  124. }
  125.  
  126. void HandleCustEvent(MesClass,MesCode,Pointer)
  127. ULONG MesClass;        /*     Fields for storing      */
  128. USHORT MesCode;        /*     intuimessage data       */
  129. APTR Pointer;          /*                             */
  130. {
  131.  
  132.    if ( MesClass == GADGETDOWN)
  133.      {
  134.         if (Pointer == (APTR)&Gadget45)
  135.           {
  136.             RemoveGadget(FrontWindow,&Gadget45);
  137.  
  138.             if (Colour2.PlaneOnOff==0xD)
  139.               {
  140.                 Colour2.PlaneOnOff = 0x4;
  141.               }
  142.             else Colour2.PlaneOnOff++;
  143.             AddGadget(FrontWindow,&Gadget45,-1L);
  144.             RefreshGadgets(&Gadget45,FrontWindow,NULL);
  145.           }
  146.         else if (Pointer == (APTR)&SizeDown)
  147.           {
  148.             RemoveGadget(FrontWindow,&Gadget46);
  149.             if (Gadget46SInfo.LongInt<1) {Message("    Point size must be +ve  ");}
  150.             else Gadget46SInfo.LongInt=Gadget46SInfo.LongInt-1;
  151.             stci_d(Gadget46SIBuff,Gadget46SInfo.LongInt);
  152.             AddGadget(FrontWindow,&Gadget46,-1L);
  153.             RefreshGadgets(&Gadget46,FrontWindow,NULL);
  154.           }
  155.         else if (Pointer == (APTR)&SizeUp)
  156.           {
  157.             RemoveGadget(FrontWindow,&Gadget46);
  158.             Gadget46SInfo.LongInt=Gadget46SInfo.LongInt+1;
  159.             stci_d(Gadget46SIBuff,Gadget46SInfo.LongInt);
  160.             AddGadget(FrontWindow,&Gadget46,-1L);
  161.             RefreshGadgets(&Gadget46,FrontWindow,NULL);
  162.          }
  163.         else if (Pointer == (APTR)&Gadget47)
  164.           {
  165.             RemoveGadget(FrontWindow,&Gadget47);
  166.             if (PlotType==LINEPLOT)
  167.               {
  168.                   PlotType=POINTPLOT;
  169.                   Gadget47.GadgetRender = (APTR)&Image6b;
  170.               }
  171.             else if (PlotType==POINTPLOT)
  172.               {
  173.                   PlotType=BOTHPLOT;
  174.                   Gadget47.GadgetRender = (APTR)&Image6c;
  175.               }
  176.             else if (PlotType==BOTHPLOT)
  177.               {
  178.                   PlotType=STEP;
  179.                   Gadget47.GadgetRender = (APTR)&Image6d;
  180.               }
  181.             else
  182.               {
  183.                   PlotType=LINEPLOT;
  184.                   Gadget47.GadgetRender = (APTR)&Image6a;
  185.               }
  186.             AddGadget(FrontWindow,&Gadget47,-1L);
  187.             RefreshGadgets(&Gadget47,FrontWindow,NULL);
  188.           }
  189.         else if (Pointer == (APTR)&LineTypeSel)
  190.           {
  191.             RemoveGadget(FrontWindow,&LineTypeSel);
  192.             if (LineTypeSel.GadgetRender== (APTR)&LineTyIm1)
  193.                   LineTypeSel.GadgetRender= (APTR)&LineTyIm2;
  194.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm2)
  195.                   LineTypeSel.GadgetRender= (APTR)&LineTyIm3;
  196.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm3)
  197.                   LineTypeSel.GadgetRender= (APTR)&LineTyIm4;
  198.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm4)
  199.                   LineTypeSel.GadgetRender= (APTR)&LineTyIm5;
  200.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm5)
  201.                   LineTypeSel.GadgetRender= (APTR)&LineTyIm6;
  202.             else LineTypeSel.GadgetRender= (APTR)&LineTyIm1;
  203.             AddGadget(FrontWindow,&LineTypeSel,-1L);
  204.             RefreshGadgets(&LineTypeSel,FrontWindow,NULL);
  205.           }
  206.         else if (Pointer == (APTR)&GadgPoint6)
  207.           {
  208.               GadMXSel(FrontWindow,&GadgPoint6,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  209.               PointType=6;
  210.           }
  211.         else if (Pointer == (APTR)&GadgPoint5)
  212.           {
  213.               GadMXSel(FrontWindow,&GadgPoint5,&GadgPoint6,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  214.               PointType=5;
  215.           }
  216.         else if (Pointer == (APTR)&GadgPoint4)
  217.           {
  218.               GadMXSel(FrontWindow,&GadgPoint4,&GadgPoint5,&GadgPoint6,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  219.               PointType=4;
  220.           }
  221.         else if (Pointer == (APTR)&GadgPoint3)
  222.           {
  223.               GadMXSel(FrontWindow,&GadgPoint3,&GadgPoint5,&GadgPoint4,&GadgPoint6,&GadgPoint2,&GadgPoint1);
  224.               PointType=3;
  225.           }
  226.         else if (Pointer == (APTR)&GadgPoint2)
  227.           {
  228.               GadMXSel(FrontWindow,&GadgPoint2,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint6,&GadgPoint1);
  229.               PointType=2;
  230.           }
  231.         else if (Pointer == (APTR)&GadgPoint1)
  232.           {
  233.               GadMXSel(FrontWindow,&GadgPoint1,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint6);
  234.               PointType=1;
  235.           }
  236.         else if (Pointer == (APTR)&GadgetSkip)
  237.          {
  238.             QuitFrontFlag = STOP;
  239.             SkipPlot=TRUE;
  240.          }
  241.         else if (Pointer == (APTR)&GadgetKill)
  242.          {
  243.             QuitFrontFlag = STOP;
  244.             SkipPlot=KILL;
  245.          }
  246.         else if (Pointer == (APTR)&GadgetStop)
  247.          {
  248.             QuitFrontFlag = STOP;
  249.             StopPlot=TRUE;
  250.          }
  251.         else if (Pointer == (APTR)&Gadget43) QuitFrontFlag = STOP;
  252.         else ;
  253.      }
  254.    if ( MesClass == RAWKEY)
  255.      {
  256.       if (MesCode ==196)  /* RETURN key RELEASED */
  257.          {
  258.              QuitFrontFlag = STOP;
  259.          }
  260.       else if (MesCode ==69)  /* ESCAPE key PRESSED */
  261.          {
  262.              QuitFrontFlag = STOP;
  263.              StopPlot=TRUE;
  264.  
  265.          }
  266.       else ;
  267.      }
  268.    else ;
  269. }
  270.  
  271. /**
  272. *
  273. *   This routine selects gad1 and deselects the previously selected one.
  274. *   Maximum number of gadgets to be mutually excluded is six, obviously.
  275. *   Extension to more gadgets is obvious, too. This routine assumes that
  276. *   only one gadget is selected at a time.
  277. *
  278. **/
  279.  
  280. void GadMXSel(win,gad1,gad2,gad3,gad4,gad5,gad6)
  281. struct Window *win;
  282. struct Gadget *gad1,*gad2,*gad3,*gad4,*gad5,*gad6;
  283. {
  284. void GadMXSD();
  285. static struct Gadget *gadprev;
  286.  
  287.    gadprev = NULL;
  288.    if (gad1 != NULL)
  289.       if (gad1->Flags & SELECTED) return;
  290.    if (gad2 != NULL)
  291.       if (gad2->Flags & SELECTED) gadprev = gad2;
  292.    if (gad3 != NULL)
  293.       if (gad3->Flags & SELECTED) gadprev = gad3;
  294.    if (gad4 != NULL)
  295.       if (gad4->Flags & SELECTED) gadprev = gad4;
  296.    if (gad5 != NULL)
  297.       if (gad5->Flags & SELECTED) gadprev = gad5;
  298.    if (gad6 != NULL)
  299.       if (gad6->Flags & SELECTED) gadprev = gad6;
  300.  
  301.    GadMXSD(win,gad1,gadprev);
  302.  
  303.    return;
  304. }
  305.  
  306. /**
  307. *
  308. *   This routine selects gad1 and deselects gad2.
  309. *   Notice, that this version removes gadgets from the gadget list and adds
  310. *   them to the end. If you're sensitive to the location of the gadgets
  311. *   in the gadgetlist, you have to use: gadloc = RemoveGadget... and
  312. *   AddGadget(...,...,(long) gadloc), where gadloc is a USHORT. Then you
  313. *   have to refresh all gadgets to make sure the two you changed get
  314. *   refreshed.
  315. *
  316. **/
  317.  
  318. void GadMXSD(win,gad1,gad2)
  319. struct Window *win;
  320. struct Gadget *gad1,*gad2;
  321. {
  322. /*
  323. *   First select gad2 (yes!) and refresh.
  324. */
  325.    if (gad2 != NULL) {
  326.       RemoveGadget(win,gad2);
  327.       gad2->Flags |= SELECTED;
  328.       AddGadget(win,gad2,-1L);
  329.    }
  330.  
  331.    if (gad2 != NULL) RefreshGadgets(gad2,win,NULL);
  332. /*
  333. *   Now select gad1 and deselect gad2 and refresh.
  334. */
  335.    if (gad1 != NULL) {
  336.       RemoveGadget(win,gad1);
  337.       gad1->Flags |= SELECTED;
  338.       AddGadget(win,gad1,-1L);
  339.    }
  340.  
  341.    if (gad2 != NULL) {
  342.       RemoveGadget(win,gad2);
  343.       gad2->Flags &= ~SELECTED;
  344.       AddGadget(win,gad2,-1L);
  345.    }
  346.  
  347.    if (gad1 != NULL) RefreshGadgets(gad1,win,NULL);
  348.  
  349.    return;
  350. }
  351.  
  352.  
  353.  
  354. CustomPlotWindow(Pict,Plot,i)
  355. struct Plot *Plot;
  356. struct Pict *Pict;
  357. int i;
  358. {            /* GET USER'S INSTRUCTIONS FOR A PLOT */
  359. void ProcCustMes(), GadMXSel(), KillPlot();
  360. SHORT border[] ={
  361.                 336, 76,
  362.                 400, 76,
  363.                 400,140,
  364.                 336,140,
  365.                 336, 76
  366.               };
  367. int j;
  368. struct IntuiMessage  *p_message;         /* pointer to message */
  369.  
  370.   j=min(19,i);
  371.   IText16.IText=SetText[j];
  372.   NewFrontWindow.Title = title1;
  373.   NewFrontWindow.FirstGadget = &Gadget43;
  374.   NewFrontWindow.Screen = screen;
  375.  
  376.   Gadget46SInfo.LongInt=Plot->PointSize;
  377.   stci_d(Gadget46SIBuff,Gadget46SInfo.LongInt);
  378.  
  379.   Colour2.PlaneOnOff= Plot->Color;
  380.  
  381.   PlotType=Plot->PlotType;
  382.   if (PlotType==LINEPLOT) { Gadget47.GadgetRender = (APTR)&Image6a;}
  383.   else if (PlotType==POINTPLOT) {Gadget47.GadgetRender = (APTR)&Image6b;}
  384.   else if (PlotType==BOTHPLOT) {Gadget47.GadgetRender = (APTR)&Image6c;}
  385.   else  {Gadget47.GadgetRender = (APTR)&Image6d;}
  386.  
  387.   GadgPoint1.Flags &= ~SELECTED; GadgPoint2.Flags &= ~SELECTED; GadgPoint3.Flags &= ~SELECTED;
  388.   GadgPoint4.Flags &= ~SELECTED; GadgPoint5.Flags &= ~SELECTED; GadgPoint6.Flags &= ~SELECTED;
  389.   PointType= Plot->PointType;
  390.   switch (Plot->PointType) {
  391.     case 1:  GadgPoint1.Flags |= SELECTED; break;
  392.     case 2:  GadgPoint2.Flags |= SELECTED; break;
  393.     case 3:  GadgPoint3.Flags |= SELECTED; break;
  394.     case 4:  GadgPoint4.Flags |= SELECTED; break;
  395.     case 5:  GadgPoint5.Flags |= SELECTED; break;
  396.     case 6:
  397.     default: PointType=6; GadgPoint6.Flags |= SELECTED; break;
  398.     }
  399.  
  400.   switch (Plot->Lines) {
  401.     case 6: LineTypeSel.GadgetRender= (APTR)&LineTyIm6; break;
  402.     case 5: LineTypeSel.GadgetRender= (APTR)&LineTyIm5; break;
  403.     case 4: LineTypeSel.GadgetRender= (APTR)&LineTyIm4; break;
  404.     case 3: LineTypeSel.GadgetRender= (APTR)&LineTyIm3; break;
  405.     case 2: LineTypeSel.GadgetRender= (APTR)&LineTyIm2; break;
  406.     case 1:
  407.     case 0:
  408.     default: LineTypeSel.GadgetRender= (APTR)&LineTyIm1; break;
  409.     }
  410.  
  411.   if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
  412.     {
  413.         ErrorAlert(0);
  414.         CloseScreen(screen);
  415.         sexit(FALSE);
  416.     }
  417.    p = FrontWindow->RPort;
  418.    PrintIText(p,&IText16,0,0);
  419.    Move(p,336,76);
  420.    PolyDraw(p,5,border);
  421.  
  422.    QuitFrontFlag=GO;
  423.    SkipPlot=FALSE;
  424.    StopPlot=FALSE;
  425.  
  426.    while (QuitFrontFlag !=STOP) {
  427.        Wait(1l<<FrontWindow->UserPort->mp_SigBit);        /* wait for a message */
  428.        while (p_message = (struct IntuiMessage *)GetMsg(FrontWindow->UserPort))
  429.        ProcCustMes(p_message);
  430.    }
  431.    if (SkipPlot) {
  432.          if (SkipPlot==KILL) {
  433.             if (Sump) FreeRemember(&SumpKey,TRUE);
  434.             Sump=NULL;
  435.             KillPlot(Pict,Plot);
  436.             SkipPlot=FALSE;
  437.          }
  438.          else  {   /* Temporarily Skip Plot */
  439.             Plot->Enabled = FALSE;
  440.             while (Plot->Continued) {Plot=Plot->NextPlot; Plot->Enabled=FALSE;}
  441.             SkipPlot=FALSE;
  442.          }
  443.    }
  444.    else if (!StopPlot)
  445.       {
  446.          Plot->Enabled = TRUE;
  447.          Plot->PointType=PointType;
  448.          Plot->Color = Colour2.PlaneOnOff;
  449.          if (PlotType==LINEPLOT) Plot->PointSize = 0;
  450.          else Plot->PointSize = Gadget46SInfo.LongInt;
  451.          Plot->PlotType=PlotType;
  452.          if (PlotType==POINTPLOT) {
  453.              Plot->Lines = FALSE;
  454.    /*          if (Plot->PointSize <1) Plot->PointSize=8; */
  455.          }
  456.          else
  457.            {
  458.             if (LineTypeSel.GadgetRender== (APTR)&LineTyIm1) Plot->Lines = 1;
  459.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm2) Plot->Lines = 2;
  460.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm3) Plot->Lines = 3;
  461.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm4) Plot->Lines = 4;
  462.             else if (LineTypeSel.GadgetRender== (APTR)&LineTyIm5) Plot->Lines = 5;
  463.             else Plot->Lines = 6;
  464.            }
  465.          while (Plot->Continued) {
  466.             Plot->NextPlot->Color = Plot->Color;
  467.             Plot->NextPlot->PointType= Plot->PointType;
  468.             Plot->NextPlot->PointSize = Plot->PointSize;
  469.             Plot->NextPlot->Lines = Plot->Lines;
  470.             Plot->NextPlot->Enabled = Plot->Enabled;
  471.             Plot=Plot->NextPlot;
  472.             }
  473.      }
  474.    CloseWindow(FrontWindow);
  475.    if (StopPlot) return(FALSE);
  476.    if (SkipPlot==KILL) return(KILL);
  477.    else return(TRUE);
  478. }
  479.  
  480.  
  481.