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

  1. #include <stdio.h>
  2. #include <exec/types.h>
  3. #include "struct.h"
  4. #include "plot.h"
  5. #include "Axes.h"
  6.  
  7. extern struct Window *FrontWindow;
  8. extern struct Screen *screen;
  9.  
  10. extern struct NewWindow NewFrontWindow;
  11. extern struct RastPort *p;
  12. extern struct ViewPort *vp;
  13. extern struct Pict *Pict;
  14.  
  15.  
  16. #define GO 1
  17. #define STOP 0
  18. #define XREGION 0
  19. #define YREGION 1
  20. #define ON TRUE
  21. int QuitAxisFlag=GO;
  22. FFP increment;
  23.  
  24. EditAxes(axis,ticno,minval,maxval,array)
  25. char axis;
  26. short *ticno;
  27. FFP *minval, *maxval, *array;
  28. {
  29. struct IntuiMessage  *a_message;         /* pointer to message */
  30. void ProcAxisMes();
  31. FFP GetIncriment();
  32.  
  33.  
  34.   NewFrontWindow.Screen = screen;
  35.   if (axis=='x')
  36.     {
  37.       NewFrontWindow.Title ="                     X Axis                      ";
  38.       strcpy(AxisLabelSIBuff,Pict->XLabel->String);
  39.     }
  40.   else
  41.     {
  42.        NewFrontWindow.Title ="                     Y Axis                      ";
  43.        strcpy(AxisLabelSIBuff,Pict->YLabel->String);
  44.     }
  45.  
  46.   TicNumberSInfo.LongInt = *ticno;
  47.   stci_d(TicNumberSIBuff,TicNumberSInfo.LongInt);
  48.   /*gcvt(*minval,4,MinValueSIBuff);*/
  49.   /*gcvt(*maxval,4,MaxValueSIBuff);*/
  50.    GetString(MinValueSIBuff,*minval);
  51.    GetString(MaxValueSIBuff,*maxval);
  52.  
  53.   increment = GetIncriment(*minval,*maxval,TicNumberSInfo.LongInt);
  54.  
  55.   NewFrontWindow.FirstGadget = &AxisContinue;
  56.  
  57.   if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
  58.     {
  59.        ErrorAlert(0);
  60.        CloseScreen(screen);
  61.        sexit(FALSE);
  62.     }
  63.   p = FrontWindow->RPort;
  64.   PrintIText(p,&AxisText1,0,0);
  65.   QuitAxisFlag=GO;     /*** RESET FLAG IN CASE NOT FIRST TIME ***/
  66.  
  67.   while (QuitAxisFlag !=STOP)
  68.    {
  69.      Wait(1l<<FrontWindow->UserPort->mp_SigBit);        /* wait for a message */
  70.      while (a_message = (struct IntuiMessage *)GetMsg(FrontWindow->UserPort))
  71.        ProcAxisMes(a_message);
  72.    }
  73.   CloseWindow(FrontWindow);
  74.  
  75.   if (axis=='x') strcpy(Pict->XLabel->String,AxisLabelSIBuff);
  76.   else strcpy(Pict->YLabel->String,AxisLabelSIBuff);
  77.  
  78.   *ticno  = TicNumberSInfo.LongInt;
  79.   *minval = atof(MinValueSIBuff);
  80.   *maxval = atof(MaxValueSIBuff);
  81.   AdjustTics(minval,maxval,*ticno,array);
  82.   return(0);
  83. }
  84.  
  85.  
  86. void ProcAxisMes(p_message)
  87. struct IntuiMessage *p_message;
  88. {
  89. ULONG MesClass;        /*     Fields for storing      */
  90. USHORT MesCode;        /*     intuimessage data       */
  91. APTR Pointer;          /*                             */
  92. int HandleAxisEvent();
  93.  
  94.    MesClass = p_message->Class;             /* Store values */
  95.    MesCode = p_message->Code;
  96.    Pointer = p_message->IAddress;
  97.    ReplyMsg(p_message);                     /* Reply to message */
  98.    HandleAxisEvent(MesClass,MesCode,Pointer);
  99. }
  100.  
  101. int HandleAxisEvent(MesClass,MesCode,Pointer)
  102. ULONG MesClass;        /*     Fields for storing      */
  103. USHORT MesCode;        /*     intuimessage data       */
  104. APTR Pointer;          /*                             */
  105. {
  106. FFP temp;
  107. short len;
  108.  
  109.   if ( MesClass == GADGETDOWN)
  110.     {
  111.       if (Pointer == (APTR)&TicDown)
  112.          {
  113.             RemoveGadget(FrontWindow,&TicNumber);
  114.             if (TicNumberSInfo.LongInt<2) {Message("  Tic Number Must Exceed 0  ");}
  115.             else TicNumberSInfo.LongInt=TicNumberSInfo.LongInt-1;
  116.             stci_d(TicNumberSIBuff,TicNumberSInfo.LongInt);
  117.             len =strlen(TicNumberSIBuff);
  118.             TicNumberSInfo.BufferPos=len;
  119.             TicNumberSInfo.DispPos=0;
  120.             AddGadget(FrontWindow,&TicNumber,-1L);
  121.             RefreshGadgets(&TicNumber,FrontWindow,NULL);
  122. /*            ActivateGadget(&TicNumber,FrontWindow,NULL);  */
  123.          }
  124.       if (Pointer == (APTR)&TicUp)
  125.          {
  126.             RemoveGadget(FrontWindow,&TicNumber);
  127.             TicNumberSInfo.LongInt=TicNumberSInfo.LongInt+1;
  128.             stci_d(TicNumberSIBuff,TicNumberSInfo.LongInt);
  129.             len =strlen(TicNumberSIBuff);
  130.             TicNumberSInfo.BufferPos=len;
  131.             TicNumberSInfo.DispPos=0;
  132.             AddGadget(FrontWindow,&TicNumber,-1L);
  133.             RefreshGadgets(&TicNumber,FrontWindow,NULL);
  134. /*            ActivateGadget(&TicNumber,FrontWindow,NULL);  */
  135.  
  136.          }
  137.       if (Pointer == (APTR)&MinUp)
  138.          {
  139.             RemoveGadget(FrontWindow,&MinValue);
  140.             temp = atof(MinValueSIBuff);
  141.             temp+=increment;
  142.             GetString(MinValueSIBuff,temp);
  143.             len =strlen(MinValueSIBuff);
  144.             MinValueSInfo.BufferPos=len;
  145.             MinValueSInfo.DispPos=0;
  146.             AddGadget(FrontWindow,&MinValue,-1L);
  147.             RefreshGadgets(&MinValue,FrontWindow,NULL);
  148. /*            ActivateGadget(&MinValue,FrontWindow,NULL);  */
  149.  
  150.          }
  151.       if (Pointer == (APTR)&MaxUp)
  152.          {
  153.             RemoveGadget(FrontWindow,&MaxValue);
  154.             temp = atof(MaxValueSIBuff);
  155.             temp+=increment;
  156.             GetString(MaxValueSIBuff,temp);
  157.             len =strlen(MaxValueSIBuff);
  158.             MaxValueSInfo.BufferPos=len;
  159.             MaxValueSInfo.DispPos=0;
  160.             AddGadget(FrontWindow,&MaxValue,-1L);
  161.             RefreshGadgets(&MaxValue,FrontWindow,NULL);
  162. /*            ActivateGadget(&MaxValue,FrontWindow,NULL);  */
  163.          }
  164.       if (Pointer == (APTR)&MinDown)
  165.          {
  166.             RemoveGadget(FrontWindow,&MinValue);
  167.             temp = atof(MinValueSIBuff);
  168.             temp-=increment;
  169.             GetString(MinValueSIBuff,temp);
  170.             len =strlen(MinValueSIBuff);
  171.             MinValueSInfo.BufferPos=len;
  172.             MinValueSInfo.DispPos=0;
  173.             AddGadget(FrontWindow,&MinValue,-1L);
  174.             RefreshGadgets(&MinValue,FrontWindow,NULL);
  175. /*            ActivateGadget(&MinValue,FrontWindow,NULL);  */
  176.          }
  177.       if (Pointer == (APTR)&MaxDown)
  178.          {
  179.             RemoveGadget(FrontWindow,&MaxValue);
  180.             temp = atof(MaxValueSIBuff);
  181.             temp-=increment;
  182.             GetString(MaxValueSIBuff,temp);
  183.             len =strlen(MaxValueSIBuff);
  184.             MaxValueSInfo.BufferPos=len;
  185.             MaxValueSInfo.DispPos=0;
  186.             AddGadget(FrontWindow,&MaxValue,-1L);
  187.             RefreshGadgets(&MaxValue,FrontWindow,NULL);
  188. /*            ActivateGadget(&MaxValue,FrontWindow,NULL);  */
  189.          }
  190.  
  191.       if (Pointer == (APTR)&AxisContinue)
  192.          {
  193.             if (TicNumberSInfo.LongInt<1) {Message("  Tic Number Must Exceed 0  "); return(0);}
  194.             QuitAxisFlag = STOP;
  195.             return(1);
  196.          }
  197.     }
  198.   if ( MesClass == RAWKEY)
  199.     {
  200.       if (MesCode ==196)  /* RETURN key RELEASED */
  201.          {
  202.             if (TicNumberSInfo.LongInt<1) {Message("  Tic Number Must Exceed 0  "); return(0);}
  203.             QuitAxisFlag = STOP;
  204.             return(1);
  205.          }
  206.      }
  207.   return(0);
  208. }
  209.  
  210.  
  211. AdjustTics(dmin, dmax, ntics, tics)
  212. FFP *dmin, *dmax, *tics;
  213. short ntics;
  214. {
  215.    FFP tmp, f_ntics;
  216.    short i;
  217.  
  218.    f_ntics = (FFP)(ntics);
  219.    tmp = (*dmax - *dmin) / f_ntics;
  220.    tics[0]=*dmin;
  221.    for (i=1; i<ntics; i++) {
  222.       tics[i] = tics[i-1] + tmp;
  223.    }
  224.    return(0);
  225. }
  226.  
  227.  
  228. FFP GetIncriment(min,max,ticno)
  229. FFP min, max;
  230. short ticno;
  231. {
  232.    FFP f_ticno;
  233.  
  234.    f_ticno = (FFP)(ticno);
  235.    return((max - min) / f_ticno);
  236. }
  237.  
  238.  
  239.  
  240.  
  241.