home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <exec/types.h>
- #include "struct.h"
- #include "plot.h"
- #include "Axes.h"
-
- extern struct Window *FrontWindow;
- extern struct Screen *screen;
-
- extern struct NewWindow NewFrontWindow;
- extern struct RastPort *p;
- extern struct ViewPort *vp;
- extern struct Pict *Pict;
-
-
- #define GO 1
- #define STOP 0
- #define XREGION 0
- #define YREGION 1
- #define ON TRUE
- int QuitAxisFlag=GO;
- FFP increment;
-
- EditAxes(axis,ticno,minval,maxval,array)
- char axis;
- short *ticno;
- FFP *minval, *maxval, *array;
- {
- struct IntuiMessage *a_message; /* pointer to message */
- void ProcAxisMes();
- FFP GetIncriment();
-
-
- NewFrontWindow.Screen = screen;
- if (axis=='x')
- {
- NewFrontWindow.Title =" X Axis ";
- strcpy(AxisLabelSIBuff,Pict->XLabel->String);
- }
- else
- {
- NewFrontWindow.Title =" Y Axis ";
- strcpy(AxisLabelSIBuff,Pict->YLabel->String);
- }
-
- TicNumberSInfo.LongInt = *ticno;
- stci_d(TicNumberSIBuff,TicNumberSInfo.LongInt);
- /*gcvt(*minval,4,MinValueSIBuff);*/
- /*gcvt(*maxval,4,MaxValueSIBuff);*/
- GetString(MinValueSIBuff,*minval);
- GetString(MaxValueSIBuff,*maxval);
-
- increment = GetIncriment(*minval,*maxval,TicNumberSInfo.LongInt);
-
- NewFrontWindow.FirstGadget = &AxisContinue;
-
- if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
- {
- ErrorAlert(0);
- CloseScreen(screen);
- sexit(FALSE);
- }
- p = FrontWindow->RPort;
- PrintIText(p,&AxisText1,0,0);
- QuitAxisFlag=GO; /*** RESET FLAG IN CASE NOT FIRST TIME ***/
-
- while (QuitAxisFlag !=STOP)
- {
- Wait(1l<<FrontWindow->UserPort->mp_SigBit); /* wait for a message */
- while (a_message = (struct IntuiMessage *)GetMsg(FrontWindow->UserPort))
- ProcAxisMes(a_message);
- }
- CloseWindow(FrontWindow);
-
- if (axis=='x') strcpy(Pict->XLabel->String,AxisLabelSIBuff);
- else strcpy(Pict->YLabel->String,AxisLabelSIBuff);
-
- *ticno = TicNumberSInfo.LongInt;
- *minval = atof(MinValueSIBuff);
- *maxval = atof(MaxValueSIBuff);
- AdjustTics(minval,maxval,*ticno,array);
- return(0);
- }
-
-
- void ProcAxisMes(p_message)
- struct IntuiMessage *p_message;
- {
- ULONG MesClass; /* Fields for storing */
- USHORT MesCode; /* intuimessage data */
- APTR Pointer; /* */
- int HandleAxisEvent();
-
- MesClass = p_message->Class; /* Store values */
- MesCode = p_message->Code;
- Pointer = p_message->IAddress;
- ReplyMsg(p_message); /* Reply to message */
- HandleAxisEvent(MesClass,MesCode,Pointer);
- }
-
- int HandleAxisEvent(MesClass,MesCode,Pointer)
- ULONG MesClass; /* Fields for storing */
- USHORT MesCode; /* intuimessage data */
- APTR Pointer; /* */
- {
- FFP temp;
- short len;
-
- if ( MesClass == GADGETDOWN)
- {
- if (Pointer == (APTR)&TicDown)
- {
- RemoveGadget(FrontWindow,&TicNumber);
- if (TicNumberSInfo.LongInt<2) {Message(" Tic Number Must Exceed 0 ");}
- else TicNumberSInfo.LongInt=TicNumberSInfo.LongInt-1;
- stci_d(TicNumberSIBuff,TicNumberSInfo.LongInt);
- len =strlen(TicNumberSIBuff);
- TicNumberSInfo.BufferPos=len;
- TicNumberSInfo.DispPos=0;
- AddGadget(FrontWindow,&TicNumber,-1L);
- RefreshGadgets(&TicNumber,FrontWindow,NULL);
- /* ActivateGadget(&TicNumber,FrontWindow,NULL); */
- }
- if (Pointer == (APTR)&TicUp)
- {
- RemoveGadget(FrontWindow,&TicNumber);
- TicNumberSInfo.LongInt=TicNumberSInfo.LongInt+1;
- stci_d(TicNumberSIBuff,TicNumberSInfo.LongInt);
- len =strlen(TicNumberSIBuff);
- TicNumberSInfo.BufferPos=len;
- TicNumberSInfo.DispPos=0;
- AddGadget(FrontWindow,&TicNumber,-1L);
- RefreshGadgets(&TicNumber,FrontWindow,NULL);
- /* ActivateGadget(&TicNumber,FrontWindow,NULL); */
-
- }
- if (Pointer == (APTR)&MinUp)
- {
- RemoveGadget(FrontWindow,&MinValue);
- temp = atof(MinValueSIBuff);
- temp+=increment;
- GetString(MinValueSIBuff,temp);
- len =strlen(MinValueSIBuff);
- MinValueSInfo.BufferPos=len;
- MinValueSInfo.DispPos=0;
- AddGadget(FrontWindow,&MinValue,-1L);
- RefreshGadgets(&MinValue,FrontWindow,NULL);
- /* ActivateGadget(&MinValue,FrontWindow,NULL); */
-
- }
- if (Pointer == (APTR)&MaxUp)
- {
- RemoveGadget(FrontWindow,&MaxValue);
- temp = atof(MaxValueSIBuff);
- temp+=increment;
- GetString(MaxValueSIBuff,temp);
- len =strlen(MaxValueSIBuff);
- MaxValueSInfo.BufferPos=len;
- MaxValueSInfo.DispPos=0;
- AddGadget(FrontWindow,&MaxValue,-1L);
- RefreshGadgets(&MaxValue,FrontWindow,NULL);
- /* ActivateGadget(&MaxValue,FrontWindow,NULL); */
- }
- if (Pointer == (APTR)&MinDown)
- {
- RemoveGadget(FrontWindow,&MinValue);
- temp = atof(MinValueSIBuff);
- temp-=increment;
- GetString(MinValueSIBuff,temp);
- len =strlen(MinValueSIBuff);
- MinValueSInfo.BufferPos=len;
- MinValueSInfo.DispPos=0;
- AddGadget(FrontWindow,&MinValue,-1L);
- RefreshGadgets(&MinValue,FrontWindow,NULL);
- /* ActivateGadget(&MinValue,FrontWindow,NULL); */
- }
- if (Pointer == (APTR)&MaxDown)
- {
- RemoveGadget(FrontWindow,&MaxValue);
- temp = atof(MaxValueSIBuff);
- temp-=increment;
- GetString(MaxValueSIBuff,temp);
- len =strlen(MaxValueSIBuff);
- MaxValueSInfo.BufferPos=len;
- MaxValueSInfo.DispPos=0;
- AddGadget(FrontWindow,&MaxValue,-1L);
- RefreshGadgets(&MaxValue,FrontWindow,NULL);
- /* ActivateGadget(&MaxValue,FrontWindow,NULL); */
- }
-
- if (Pointer == (APTR)&AxisContinue)
- {
- if (TicNumberSInfo.LongInt<1) {Message(" Tic Number Must Exceed 0 "); return(0);}
- QuitAxisFlag = STOP;
- return(1);
- }
- }
- if ( MesClass == RAWKEY)
- {
- if (MesCode ==196) /* RETURN key RELEASED */
- {
- if (TicNumberSInfo.LongInt<1) {Message(" Tic Number Must Exceed 0 "); return(0);}
- QuitAxisFlag = STOP;
- return(1);
- }
- }
- return(0);
- }
-
-
- AdjustTics(dmin, dmax, ntics, tics)
- FFP *dmin, *dmax, *tics;
- short ntics;
- {
- FFP tmp, f_ntics;
- short i;
-
- f_ntics = (FFP)(ntics);
- tmp = (*dmax - *dmin) / f_ntics;
- tics[0]=*dmin;
- for (i=1; i<ntics; i++) {
- tics[i] = tics[i-1] + tmp;
- }
- return(0);
- }
-
-
- FFP GetIncriment(min,max,ticno)
- FFP min, max;
- short ticno;
- {
- FFP f_ticno;
-
- f_ticno = (FFP)(ticno);
- return((max - min) / f_ticno);
- }
-
-
-
-
-