home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff218.lzh / Mandel / src / GotMenu.c < prev    next >
C/C++ Source or Header  |  1989-06-04  |  23KB  |  820 lines

  1. /*
  2.  * M A N D E L B R O T     C O N S T R U C T I O N   S E T
  3.  *
  4.  * (C) Copyright 1989 by Olaf Seibert.
  5.  * Mandel may be freely distributed. See file 'doc/Notice' for details.
  6.  *
  7.  * GotMenu and some (many) related things.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include "mandel.h"
  13. #ifdef DEBUG
  14. #   include <stdio.h>
  15. #   undef STATIC
  16. #   define STATIC   /* EMPTY */
  17. #endif
  18.  
  19. extern double ReMouse, ImMouse;
  20. extern UBYTE IPlotNr, EPlotNr;
  21. extern void UpdateDrwCm();
  22.  
  23. TEXT FileName[FNAME_SIZE+1] = "Mandel.pic";
  24. TEXT DirName[DNAME_SIZE+2]  = "";
  25. UBYTE Buffer[5][20];
  26.  
  27. int (*DepthFuncArray[])() = {
  28.     ZQuadMinC, ZC1MinZ, Z3PlusZCMin1MinC, UserProgFunc, I_ZQuadMinC
  29. };
  30.  
  31. void (*IPlotFuncArray[])() = {
  32.     None, PlotZ
  33. };
  34.  
  35. void (*EPlotFuncArray[])() = {
  36.     PlotIterationCount, PlotZ,
  37. };
  38.  
  39. /* Forward declarations of static procedures */
  40. STATIC void PrjNew();
  41.  
  42. void GotMenu(Code)
  43. USHORT Code;
  44. {
  45.     static void (*MenuFunc[])()= {
  46.     CprMenu, PrjMenu, OptMenu, DrwMenu, BatchMenu
  47.     };
  48.     while (Code != MENUNULL) {
  49.     (*MenuFunc[MENUNUM(Code)]) (Code);
  50.     Code = ItemAddress(MandelMenu, (long) Code)->NextSelect;
  51.     }
  52. }
  53.  
  54. void CprMenu(Code)
  55. USHORT Code;
  56. {
  57.     extern long Revision;    /* From IncRev */
  58.     ULONG OldIDCMP = MainWindow->IDCMPFlags;
  59.  
  60. #define DATE            "16 April 1989 V1.3 ("
  61. #define strlen_DATE        20
  62.  
  63.     static UBYTE DateVersion[strlen_DATE+9] = DATE;
  64.  
  65.     static struct IntuiText Body[] =
  66.     {
  67.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  68.         10, 15, NULL, (UBYTE *)"Mandelbrot Construction Set", &Body[1] },
  69.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  70.         10, 30, NULL, (UBYTE *)"By KosmoSoft Productions", &Body[2] },
  71.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  72.         10, 40, NULL, DateVersion, &Body[3] },
  73.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  74.         10, 55, NULL, (UBYTE *)"Ohh, please Copy-Me!", NULL }
  75.     },
  76.     ExitText =
  77.     {    MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  78.     AUTOLEFTEDGE, AUTOTOPEDGE, NULL, (UBYTE *)" OK ", NULL };
  79.  
  80.     sprintf(&DateVersion[strlen_DATE], "%ld)", Revision);
  81.  
  82.     ModifyIDCMP(MainWindow, OldIDCMP &~ (MENUVERIFY | SIZEVERIFY | REQVERIFY));
  83.     AutoRequest(MainWindow, &Body[0], NULL, &ExitText, NULL, NULL, 258L, 100L);
  84.     ModifyIDCMP(MainWindow, OldIDCMP);
  85. }
  86.  
  87. char *CatFileComponents(dest, dirname, filename)
  88. char *dest;
  89. char *dirname;
  90. char *filename;
  91. {
  92.     strcpy(dest, dirname);
  93.     if (dirname[0] && dirname[strlen(dirname) - 1] != ':')
  94.     strcat(dest, "/");
  95.     strcat(dest, FileName);
  96.  
  97.     return dest;
  98. }
  99.  
  100.  
  101. bool OpenAs(name)
  102. char *name;
  103. {
  104.     struct Mand MandChunk;
  105.     struct ILBM_info *ilbminfo, *win_read_iff();
  106.  
  107.     StopDrawing();
  108.     MandChunk.MandID = 0;
  109.     if (ilbminfo = win_read_iff(name, (short)FALSE,
  110.     MainWindow, sizeof(MandChunk), &MandChunk)) {
  111.     put_ea_cmap(&ilbminfo->cmap, NumColors, MandelScreen);
  112.     InterpretMAND(&MandChunk, ilbminfo);
  113.     }
  114.     Saved = TRUE;
  115.     NameValid = FALSE;
  116.  
  117.     return ilbminfo != NULL;
  118. }
  119.  
  120. bool SaveAs(name)
  121. char *name;
  122. {
  123.     struct Mand MandChunk;
  124.     unsigned char ea_colormap[3*MAXCOL];
  125.  
  126.     get_ea_cmap(ea_colormap, NumColors, MandelScreen);
  127.     MakeMAND(&MandChunk);
  128.     SuspendDrawing();
  129.     NameValid = Saved = write_iff(name, ea_colormap, MainWindow,
  130.         (short) 0, (short) 0, (short) TRUE, sizeof(MandChunk),
  131.         &MandChunk);
  132.     ResumeDrawing();
  133.  
  134.     return Saved;
  135. }
  136.  
  137. STATIC void PrjMenu(Code)
  138. USHORT Code;
  139. {
  140.     int SubNum = SUBNUM(Code);
  141.     int ItemNum = ITEMNUM(Code);
  142.  
  143.     struct Mand MandChunk;
  144.     char Name[DNAME_SIZE + FNAME_SIZE + 3];
  145.  
  146.     switch (ItemNum) {
  147.     case PRJNEW:
  148.     PrjNew(SubNum);
  149.     break;
  150.     case PRJOPN:
  151.     if ( get_fname(MainWindow, "Select a filename to OPEN",
  152.         FileName, DirName) == NULL )
  153.         break;
  154.     CatFileComponents(Name, DirName, FileName);
  155.     OpenAs(Name);
  156.     break;
  157.     case PRJSVE:    /* Save */
  158.     if (NameValid) skipto prjsve;
  159.     /* Fall Through */
  160.     case PRJSVA:    /* Save As */
  161.     if ( get_fname(MainWindow, "Select a filename to SAVE",
  162.         FileName, DirName) == NULL )
  163.         break;
  164. prjsve:
  165.     CatFileComponents(Name, DirName, FileName);
  166.     SaveAs(Name);
  167.     break;
  168.     case PRJSTP:
  169.     StopDrawing();
  170.     break;
  171.     case PRJQUI:
  172.     finished = TRUE;
  173.     }
  174. }
  175.  
  176. STATIC void OptMenu(Code)
  177. USHORT Code;
  178. {
  179.     int SubNum = SUBNUM(Code);
  180.     int ItemNum = ITEMNUM(Code);
  181.  
  182.     switch (ItemNum) {
  183.     case OPTCOL:
  184.     switch (SubNum) {
  185.     case OCSEL:
  186.         PenTableMode = SELECT;
  187.         Select();
  188.         break;
  189.     case OCMOD:
  190.         PenTableMode = MODULO;
  191.         break;
  192.     case OCRAN:
  193.         PenTableMode = RANGES;
  194.         break;
  195.     case OCPAL:
  196.         OpenColorWindow(MainWindow);
  197.     } /* End Switch SUBNUM */
  198.     InitPenTable();
  199.     break;
  200.     case OPTRES:
  201.     switch (SubNum) {
  202.     case ORNRM:
  203.         PixelStep = 1;
  204.         break;
  205.     case OR12:
  206.         PixelStep = 2;
  207.         break;
  208.     case OR13:
  209.         PixelStep = 3;
  210.         break;
  211.     case OR14:
  212.         PixelStep = 4;
  213.         break;
  214.     case ORFIL: /* Fill in */
  215.         DrawPicture((bool)TRUE);
  216.         break;
  217.     case ORHI:
  218.     case ORILC:
  219.     case OREHB:
  220.         {
  221.         USHORT newmode = MandelNScreen.ViewModes & ~(HIRES | LACE | EXTRA_HALFBRITE);
  222.  
  223.         if (ItemAddress(MandelMenu, MENU(OPTMENU, OPTRES, ORHI))
  224.             -> Flags & CHECKED)
  225.             newmode |= HIRES;
  226.         if (ItemAddress(MandelMenu, MENU(OPTMENU, OPTRES, ORILC))
  227.             -> Flags & CHECKED)
  228.             newmode |= LACE;
  229.         if (ItemAddress(MandelMenu, MENU(OPTMENU, OPTRES, OREHB))
  230.             -> Flags & CHECKED)
  231.             newmode |= EXTRA_HALFBRITE;
  232.         if (newmode != MandelNScreen.ViewModes) {
  233.             MandelNScreen.ViewModes = newmode;
  234.             if (Sure())
  235.             ReInitDisplay();
  236.             else
  237.             UpdateOptViewResCm();
  238.         }
  239.         }
  240.         break;
  241.     case ORBCK:
  242.         if (ItemAddress(MandelMenu, MENU(OPTMENU,OPTRES,ORBCK))->Flags & CHECKED)
  243.         DoBorderless(MainWindow, &borderinfo);
  244.         else
  245.         UndoBorderless(MainWindow, &borderinfo);
  246.     } /* End Switch SUBNUM */
  247.     break;
  248.     case OPTPAR:
  249.     Parameters();
  250.     break;
  251.     case OPTPRI:
  252.     switch (SubNum) {
  253.     case OPNOR:
  254.         SetDrawPri(0);
  255.         break;
  256.     case OPLOW:
  257.         SetDrawPri(-5);
  258.         break;
  259.     }
  260.     break;
  261.     } /* End Switch ITEMNUM */
  262. }
  263.  
  264. /*
  265.  *  This function sets the drawing function, numbered from 0.
  266.  */
  267.  
  268. void SetDrawingFunction(number)
  269. int number;
  270. {
  271.     if (number >= 0 && number <= DF5) {
  272.     FunctionNr = number;
  273.     DepthFunc = DepthFuncArray[FunctionNr];
  274.     }
  275. }
  276.  
  277. /*
  278.  *  This function sets the i plotting function, numbered from 0.
  279.  */
  280.  
  281. void SetIPlotFunction(number)
  282. int number;
  283. {
  284.     if (number >= 0 && number <= DIZ) {
  285.     IPlotNr = number;
  286.     IPlotFunc = IPlotFuncArray[IPlotNr];
  287.     }
  288. }
  289.  
  290. /*
  291.  *  This function sets the e plotting function, numbered from 0.
  292.  */
  293.  
  294. void SetEPlotFunction(number)
  295. int number;
  296. {
  297.     if (number >= 0 && number <= DEZ) {
  298.     EPlotNr = number;
  299.     EPlotFunc = EPlotFuncArray[EPlotNr];
  300.     }
  301. }
  302.  
  303. void DrwMenu(Code)
  304. USHORT Code;
  305. {
  306.     int ItemNum = ITEMNUM(Code);
  307.     int SubNum = SUBNUM(Code);
  308.  
  309.     switch (ItemNum) {
  310.     case DRWFUN:
  311.     SetDrawingFunction(SubNum + DF1);
  312.     break;
  313.     case DRWIPL:
  314.     SetIPlotFunction(SubNum + DINONE);
  315.     break;
  316.     case DRWEPL:
  317.     SetEPlotFunction(SubNum + DEDEPTH);
  318.     break;
  319.     }
  320. }
  321.  
  322. void UnImpl()
  323. {
  324.     static char alert[] = "\
  325. \0\144\25Mandelbrot Construction Set -- By KosmoSoft Productions\0a\
  326. \0\170\40Sorry, this function has not been implemented yet!\0";
  327.     DisplayAlert(RECOVERY_ALERT, alert, 50L);
  328. }
  329.  
  330. STATIC USHORT OldMinWidth, OldMinHeight, OldMaxWidth, OldMaxHeight;
  331.  
  332. /* Do not nest calls to DisableSizing: the original values will be lost. */
  333.  
  334. void DisableSizing()
  335. {
  336.     OldMinWidth = MainWindow->MinWidth;
  337.     OldMaxWidth = MainWindow->MaxWidth;
  338.     OldMinHeight = MainWindow->MinHeight;
  339.     OldMaxHeight = MainWindow->MaxHeight;
  340.     WindowLimits(MainWindow, (long) MainWindow->Width, (long) MainWindow->Height,
  341.             (long) MainWindow->Width, (long) MainWindow->Height);
  342. }
  343.  
  344. void EnableSizing()
  345. {
  346.     WindowLimits(MainWindow, (long) OldMinWidth, (long) OldMinHeight,
  347.             (long) OldMaxWidth, (long) OldMaxHeight);
  348. }
  349.  
  350. STATIC void PrjNew(SubNum)
  351. USHORT SubNum;
  352. {
  353.     struct Window *window;
  354.     int ID;
  355.     static double HShift = 0.0,
  356.           VShift = 0.0;
  357.     static double Factor = 3.0;
  358.     double Width = RightEdge - LeftEdge,
  359.        Height = TopEdge - BottomEdge,
  360.        NewLeftEdge = LeftEdge,
  361.        NewTopEdge = TopEdge,
  362.        NewRightEdge = RightEdge,
  363.        NewBottomEdge = BottomEdge;
  364.  
  365.     /* Stuff for the ABSOLUTE requester */
  366.  
  367.     static struct IntuiText RatioText = {
  368.     MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, 10, 90, NULL,
  369.     (UBYTE *) "Ratio:                    ", NULL    };
  370.     static struct IntuiText AbsText = {
  371.     MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, 10, 10, NULL,
  372.     (UBYTE *) "Select an absolute position", &RatioText };
  373.     static struct IntuiText LRTBText[] = {
  374.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  375.         (UBYTE *) "Left", NULL  },
  376.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  377.         (UBYTE *) "Right", NULL },
  378.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  379.         (UBYTE *) "Top", NULL   },
  380.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  381.         (UBYTE *) "Bottom", NULL    }
  382.     };
  383.     static struct StringInfo LRTBinfo[] = {
  384.     {   &Buffer[0][0], &Buffer[4][0], 0, 20, 0  },
  385.     {   &Buffer[1][0], &Buffer[4][0], 0, 20, 0  },
  386.     {   &Buffer[2][0], &Buffer[4][0], 0, 20, 0  },
  387.     {   &Buffer[3][0], &Buffer[4][0], 0, 20, 0  }
  388.     };
  389.     static struct Gadget LRTBGadget[] = {
  390.     {   &LRTBGadget[1], 66, 30, 160, 10,        /* next, LTWH */
  391.         GADGHCOMP,                    /* Flags */
  392.         RELVERIFY,                    /* Activation */
  393.         STRGADGET | REQGADGET,            /* GadgetType */
  394.         (APTR) NULL, NULL,                          /* rendering */
  395.         &LRTBText[0], 0, (APTR) &LRTBinfo[0],       /* "Left" */
  396.         NEGGADGETID+1, NULL },
  397.     {   &LRTBGadget[2], 66, 45, 160, 10,        /* next, LTWH */
  398.         GADGHCOMP,
  399.         RELVERIFY,
  400.         STRGADGET | REQGADGET,
  401.         (APTR) NULL, NULL,
  402.         &LRTBText[1], 0, (APTR) &LRTBinfo[1],       /* Right */
  403.         NEGGADGETID+1, NULL },
  404.     {   &LRTBGadget[3], 66, 60, 160, 10,        /* next, LTWH */
  405.         GADGHCOMP,
  406.         RELVERIFY,
  407.         STRGADGET | REQGADGET,
  408.         (APTR) NULL, NULL,
  409.         &LRTBText[2], 0, (APTR) &LRTBinfo[2],       /* Top */
  410.         NEGGADGETID+1, NULL },
  411.     {   NULL, 66, 75, 160, 10,            /* next, LTWH */
  412.         GADGHCOMP,
  413.         RELVERIFY,
  414.         STRGADGET | REQGADGET,
  415.         (APTR) NULL, NULL,
  416.         &LRTBText[3], 0, (APTR) &LRTBinfo[3],       /* Bottom */
  417.         NEGGADGETID+1, NULL }
  418.     };
  419.     static struct Requester AbsRequest = {
  420.     NULL, 25, 40, 260, 130, 0,0, &PositiveGadget, NULL,
  421.     &AbsText, 0, 1    };
  422.  
  423.     /* Stuff for the SHIFT requester */
  424.  
  425.     static struct IntuiText ShiftText = {
  426.     MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, 10, 10, NULL,
  427.     (UBYTE *) "Select a window shift amount", NULL  };
  428.     static struct IntuiText RDText[] = {
  429.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  430.         (UBYTE *) "Right", NULL },
  431.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  432.         (UBYTE *) "Down", NULL  }
  433.     };
  434.     static struct Gadget RDGadget[] = {
  435.     {   &RDGadget[1], 66, 45, 160, 10,        /* next, LTWH */
  436.         GADGHCOMP,
  437.         0,
  438.         STRGADGET | REQGADGET,
  439.         (APTR) NULL, NULL,
  440.         &RDText[0], 0, (APTR) &LRTBinfo[0],     /* Right */
  441.         0, NULL },
  442.     {   NULL, 66, 60, 160, 10,            /* next, LTWH */
  443.         GADGHCOMP,
  444.         0,
  445.         STRGADGET | REQGADGET,
  446.         (APTR) NULL, NULL,
  447.         &RDText[1], 0, (APTR) &LRTBinfo[1],     /* Down */
  448.         0, NULL }
  449.     };
  450.     static struct Requester ShiftRequest = {
  451.     NULL, 25, 40, 260, 130, 0,0, &PositiveGadget, NULL,
  452.     &ShiftText, 0, 1    };
  453.  
  454.     /* Stuff for the ZOOM requester */
  455.  
  456.     static struct IntuiText ZoomText = {
  457.     MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, 10, 10, NULL,
  458.     (UBYTE *) "Select a zoom center", NULL  };
  459.     static struct IntuiText RIFText[] = {
  460.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  461.         (UBYTE *) "X:Real", NULL },
  462.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  463.         (UBYTE *) "Y:Imag", NULL  },
  464.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -56, 0, NULL,
  465.         (UBYTE *) "Factor", NULL  }
  466.     };
  467.     static struct Gadget RIFGadget[] = {
  468.     {   &RIFGadget[1], 66, 30, 160, 10,         /* next, LTWH */
  469.         GADGHCOMP,
  470.         0,
  471.         STRGADGET | REQGADGET,
  472.         (APTR) NULL, NULL,
  473.         &RIFText[0], 0, (APTR) &LRTBinfo[0],    /* Re */
  474.         0, NULL },
  475.     {   &RIFGadget[2], 66, 45, 160, 10,        /* next, LTWH */
  476.         GADGHCOMP,
  477.         0,
  478.         STRGADGET | REQGADGET,
  479.         (APTR) NULL, NULL,
  480.         &RIFText[1], 0, (APTR) &LRTBinfo[1],    /* Im */
  481.         0, NULL },
  482.     {   NULL, 66, 60, 160, 10,            /* next, LTWH */
  483.         GADGHCOMP,
  484.         0,
  485.         STRGADGET | REQGADGET,
  486.         (APTR) NULL, NULL,
  487.         &RIFText[2], 0, (APTR) &LRTBinfo[2],    /* Factor */
  488.         0, NULL }
  489.     };
  490.     static struct Requester ZoomRequest = {
  491.     NULL, 25, 40, 260, 130, 0,0, &PositiveGadget, NULL,
  492.     &ZoomText, 0, 1    };
  493.  
  494.     switch (SubNum) {
  495.     case PNRED:
  496.     if (MouseStatus != FLASHING) return;
  497.     else {
  498.         register SHORT w = MainWindow -> GZZWidth,
  499.                h = MainWindow -> GZZHeight;
  500.         register SHORT X1, Y1, X2, Y2;
  501.  
  502.         /* If you cast less, Aztec seems to do it wrong... */
  503.         X1 = (-(long)FrameX1 * w) / ((long)FrameX2 - (long)FrameX1);
  504.         Y1 = (-(long)FrameY1 * h) / ((long)FrameY2 - (long)FrameY1);
  505.         X2 = ((long)(w-1-FrameX1) * w) / ((long)FrameX2 - (long)FrameX1)
  506.         - 1;
  507.         Y2 = ((long)(h-1-FrameY1) * h) / ((long)FrameY2 - (long)FrameY1)
  508.         - 1;
  509.  
  510.         NewLeftEdge   = LeftEdge + X1 * CXStep;
  511.         NewRightEdge  = LeftEdge + X2 * CXStep;
  512.         NewTopEdge      =  TopEdge - Y1 * CYStep;
  513.         NewBottomEdge =  TopEdge - Y2 * CYStep;
  514.  
  515.         skipto pnabs;
  516.     }
  517.     case PNENL:
  518.     if (MouseStatus != FLASHING) return;
  519.  
  520.     NewLeftEdge   = LeftEdge + FrameX1 * CXStep;
  521.     NewRightEdge  = LeftEdge + FrameX2 * CXStep;
  522.     NewTopEdge    =  TopEdge - FrameY1 * CYStep;
  523.     NewBottomEdge =  TopEdge - FrameY2 * CYStep;
  524.     skipto pnabs;
  525.     case PNSHF:
  526.     NegativeGadget.NextGadget = &RDGadget[0];
  527.     do {
  528.         sprintf(Buffer[0], "%1.6g",HShift);
  529.         sprintf(Buffer[1], "%1.6g",VShift);
  530.  
  531.         window = MyRequest(&ShiftRequest, MainWindow);
  532.         ID = WaitMyRequest(window);
  533.         EndMyRequest(&ShiftRequest, window, MainWindow);
  534.         if (ID == NEGGADGETID) return;
  535.  
  536.     } while (sscanf(Buffer[0], "%lf", &HShift)+
  537.         sscanf(Buffer[1], "%lf", &VShift) != 2);
  538.  
  539.     NewLeftEdge   = LeftEdge + HShift * Width;
  540.     NewRightEdge  = RightEdge + HShift * Width;
  541.     NewTopEdge    = TopEdge - VShift * Height;
  542.     NewBottomEdge = BottomEdge - VShift * Height;
  543.  
  544.     skipto pnabs;
  545.     case PNZI:
  546.     case PNZO: {
  547.     double ReMid, ImMid;
  548.  
  549.     if (MouseStatus == NOTFRAMING) {
  550.         ReMid = (RightEdge + LeftEdge) / 2.0;
  551.         ImMid = (TopEdge + BottomEdge) / 2.0;
  552.     } else {
  553.         ReMid = ReMouse;
  554.         ImMid = ImMouse;
  555.     }
  556.  
  557.     NegativeGadget.NextGadget = &RIFGadget[0];
  558.     do {
  559.         sprintf(Buffer[0], "%1.6g",ReMid);
  560.         sprintf(Buffer[1], "%1.6g",ImMid);
  561.         sprintf(Buffer[2], "%1.6g",Factor);
  562.  
  563.         window = MyRequest(&ZoomRequest, MainWindow);
  564.         ID = WaitMyRequest(window);
  565.         EndMyRequest(&ZoomRequest, window, MainWindow);
  566.         if (ID == NEGGADGETID) return;
  567.  
  568.     } while (sscanf(Buffer[0], "%lf", &ReMid)+
  569.          sscanf(Buffer[1], "%lf", &ImMid)+
  570.          sscanf(Buffer[2], "%lf", &Factor) != 3);
  571.     if (SubNum == PNZI) {
  572.         if (Factor == 0.0) {
  573.         Factor = 1.0;
  574.         }
  575.         Width /= Factor;
  576.         Height /= Factor;
  577.     } else {
  578.         Width *= Factor;
  579.         Height *= Factor;
  580.     }
  581.     NewLeftEdge   = ReMid - Width / 2.0;
  582.     NewTopEdge    = ImMid + Height / 2.0;
  583.     NewRightEdge  = NewLeftEdge + Width;
  584.     NewBottomEdge = NewTopEdge - Height;
  585.     skipto pnabs;
  586.     }
  587.     case PNABS:
  588.     NewLeftEdge = LeftEdge;
  589.     NewRightEdge = RightEdge;
  590.     NewTopEdge = TopEdge;
  591.     NewBottomEdge = BottomEdge;
  592.  
  593. pnabs:
  594.     NegativeGadget.NextGadget = &LRTBGadget[0];
  595.     sprintf(Buffer[0], "%1.10g", NewLeftEdge);
  596.     sprintf(Buffer[1], "%1.10g", NewRightEdge);
  597.     sprintf(Buffer[2], "%1.10g", NewTopEdge);
  598.     sprintf(Buffer[3], "%1.10g", NewBottomEdge);
  599.     sprintf(RatioText.IText+7, "%1.4f     ", Ratio(NewLeftEdge,
  600.         NewRightEdge, NewTopEdge, NewBottomEdge, MainWindow));
  601.  
  602.     do {
  603.         window = MyRequest(&AbsRequest, MainWindow);
  604.  
  605.         while ( (ID = WaitMyRequest(window) ) > NEGGADGETID) {
  606.         sscanf(Buffer[0], "%lf", &NewLeftEdge);
  607.         sscanf(Buffer[1], "%lf", &NewRightEdge);
  608.         sscanf(Buffer[2], "%lf", &NewTopEdge);
  609.         sscanf(Buffer[3], "%lf", &NewBottomEdge);
  610.         sprintf(RatioText.IText+7, "%1.4f     ",
  611.             Ratio(NewLeftEdge, NewRightEdge, NewTopEdge,
  612.             NewBottomEdge, MainWindow));
  613.  
  614.         PrintIText(AbsRequest.ReqLayer->rp, &RatioText, 0L, 0L);
  615.         }
  616.  
  617.         EndMyRequest(&AbsRequest, window, MainWindow);
  618.  
  619.     } while (sscanf(Buffer[0], "%lf", &NewLeftEdge)+
  620.          sscanf(Buffer[1], "%lf", &NewRightEdge)+
  621.          sscanf(Buffer[2], "%lf", &NewTopEdge)+
  622.          sscanf(Buffer[3], "%lf", &NewBottomEdge) < 4);
  623.  
  624.     if (ID != POSGADGETID) return;
  625.  
  626.     LeftEdge = NewLeftEdge;
  627.     RightEdge = NewRightEdge;
  628.     TopEdge = NewTopEdge;
  629.     BottomEdge = NewBottomEdge;
  630.  
  631.     StopFraming();
  632.     StopDrawing();
  633.  
  634.     break;
  635.     }
  636.     DrawPicture((bool)FALSE);   /* Don't fill in */
  637. }
  638.  
  639. float Ratio(l, r, t, b, window)
  640. double l, r, t, b;
  641. struct Window *window;
  642. {
  643.     float PixelRatio;
  644.     float ReImRatio;
  645.  
  646.     if (t == b) t = b+1;    /* You never know... */
  647.  
  648.     PixelRatio = (float) window->GZZWidth / window->GZZHeight;
  649.  
  650.     if (window->WScreen->ViewPort.Modes & HIRES) PixelRatio /= 2;
  651.     if (window->WScreen->ViewPort.Modes & LACE) PixelRatio *= 2;
  652.     ReImRatio = (r - l)/(t - b);
  653.  
  654.     return ReImRatio / PixelRatio;
  655. }
  656.  
  657. void Parameters()
  658. {
  659.     struct Window *window;
  660.     int ID;
  661.     int NewMaxDepth, NewRangeWidth, NewWBwidth, NewWBheight;
  662.  
  663.     static struct IntuiText ParamText = {
  664.     MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, 10, 10, NULL,
  665.     (UBYTE *) "Select these parameters", NULL   };
  666.     static struct IntuiText ParmText[] = {
  667.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -120, 0, NULL,
  668.         (UBYTE *) "Max depth", NULL },
  669.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -120, 0, NULL,
  670.         (UBYTE *) "Range width", NULL   },
  671.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -120, 0, NULL,
  672.         (UBYTE *) "Screen width", NULL  },
  673.     {   MYFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, -120, 0, NULL,
  674.         (UBYTE *) "Screen height", NULL  }
  675.     };
  676.     static struct StringInfo Parminfo[] = {
  677.     {   &Buffer[0][0], &Buffer[4][0], 0, 20, 0  },
  678.     {   &Buffer[1][0], &Buffer[4][0], 0, 20, 0  },
  679.     {   &Buffer[2][0], &Buffer[4][0], 0, 20, 0  },
  680.     {   &Buffer[3][0], &Buffer[4][0], 0, 20, 0  }
  681.     };
  682.     static struct Gadget ParmGadget[] = {
  683.     {   &ParmGadget[1], 130, 30, 96, 10,        /* next, LTWH */
  684.         GADGHCOMP,                    /* Flags */
  685.         RELVERIFY | LONGINT,            /* Activation */
  686.         STRGADGET | REQGADGET,            /* GadgetType */
  687.         (APTR) NULL, NULL,                          /* rendering */
  688.         &ParmText[0], 0, (APTR) &Parminfo[0],       /* "MaxDepth" */
  689.         0, NULL },
  690.     {   &ParmGadget[2], 130, 45, 96, 10,        /* next, LTWH */
  691.         GADGHCOMP,
  692.         RELVERIFY | LONGINT,
  693.         STRGADGET | REQGADGET,
  694.         (APTR) NULL, NULL,
  695.         &ParmText[1], 0, (APTR) &Parminfo[1],       /* "RangeWidth" */
  696.         0, NULL },
  697.     {   &ParmGadget[3], 130, 60, 96, 10,        /* next, LTWH */
  698.         GADGHCOMP,
  699.         RELVERIFY | LONGINT,
  700.         STRGADGET | REQGADGET,
  701.         (APTR) NULL, NULL,
  702.         &ParmText[2], 0, (APTR) &Parminfo[2],       /* "Screen width" */
  703.         0, NULL },
  704.     {   NULL, 130, 75, 96, 10,            /* next, LTWH */
  705.         GADGHCOMP,
  706.         RELVERIFY | LONGINT,
  707.         STRGADGET | REQGADGET,
  708.         (APTR) NULL, NULL,
  709.         &ParmText[3], 0, (APTR) &Parminfo[3],       /* "Screen height" */
  710.         0, NULL }
  711.     };
  712.     static struct Requester ParmRequest = {
  713.     NULL, 25, 40, 260, 130, 0,0, &PositiveGadget, NULL,
  714.     &ParamText, 0, 1    };
  715.  
  716.     /* Stuff for the PARAMETERS requester */
  717.     NegativeGadget.NextGadget = &ParmGadget[0];
  718.     Parminfo[0].LongInt = MaxDepth;
  719.     Parminfo[1].LongInt = RangeWidth;
  720.     Parminfo[2].LongInt = WBWidth;
  721.     Parminfo[3].LongInt = WBHeight;
  722.     do {
  723.     sprintf(Buffer[0], "%ld", Parminfo[0].LongInt);
  724.     sprintf(Buffer[1], "%ld", Parminfo[1].LongInt);
  725.     sprintf(Buffer[2], "%ld", Parminfo[2].LongInt);
  726.     sprintf(Buffer[3], "%ld", Parminfo[3].LongInt);
  727.  
  728.     window = MyRequest(&ParmRequest, MainWindow);
  729.     ID = WaitMyRequest(window);
  730.     EndMyRequest(&ParmRequest, window, MainWindow);
  731.     if (ID == NEGGADGETID) return;
  732.  
  733.     NewMaxDepth   = Parminfo[0].LongInt;
  734.     NewRangeWidth = Parminfo[1].LongInt;
  735.     NewWBwidth    = Parminfo[2].LongInt;
  736.     NewWBheight   = Parminfo[3].LongInt;
  737.     } while ( NewMaxDepth < 0 || NewMaxDepth > MAXDEPTH ||
  738.           NewRangeWidth < 0 || NewRangeWidth > MAXDEPTH );
  739.  
  740.     if (NewRangeWidth != RangeWidth)    InitPenTable();
  741.     MaxDepth = NewMaxDepth;
  742.     RangeWidth = NewRangeWidth;
  743.  
  744.     if ((NewWBwidth != WBWidth || NewWBheight != WBHeight) && Sure()) {
  745.      WBWidth = NewWBwidth;
  746.      WBHeight = NewWBheight;
  747.      ReInitDisplay();
  748.     }
  749. }
  750.  
  751. void UpdateCheckmarks()
  752. {
  753.     UpdateOptColorCm();
  754.     UpdateOptDrawResCm();
  755.     UpdateOptViewResCm();
  756.     UpdateOptPriCm();
  757.     UpdateDrwCm();
  758. }
  759.  
  760. void UpdateOptColorCm()
  761. {
  762.     SelectMenu(MENU(OPTMENU, OPTCOL, OCSEL), (bool)(PenTableMode == SELECT));
  763.     SelectMenu(MENU(OPTMENU, OPTCOL, OCMOD), (bool)(PenTableMode == MODULO));
  764.     SelectMenu(MENU(OPTMENU, OPTCOL, OCRAN), (bool)(PenTableMode == RANGES));
  765. }
  766.  
  767. void UpdateOptDrawResCm()
  768. {
  769.     SelectMenu(MENU(OPTMENU, OPTRES, ORNRM), (bool)(PixelStep == 1));
  770.     SelectMenu(MENU(OPTMENU, OPTRES, OR12 ), (bool)(PixelStep == 2));
  771.     SelectMenu(MENU(OPTMENU, OPTRES, OR13 ), (bool)(PixelStep == 3));
  772.     SelectMenu(MENU(OPTMENU, OPTRES, OR14 ), (bool)(PixelStep == 4));
  773. }
  774.  
  775. void UpdateOptViewResCm()
  776. {
  777.     SelectMenu(MENU(OPTMENU, OPTRES, ORHI ),
  778.            (bool)((MandelNScreen.ViewModes & HIRES) != 0));
  779.     SelectMenu(MENU(OPTMENU, OPTRES, ORILC),
  780.            (bool)((MandelNScreen.ViewModes & LACE) != 0));
  781.     SelectMenu(MENU(OPTMENU, OPTRES, OREHB),
  782.            (bool)((MandelNScreen.ViewModes & EXTRA_HALFBRITE) != 0));
  783.     SelectMenu(MENU(OPTMENU, OPTRES, ORBCK),
  784.            (bool)((MainWindow->Flags & BORDERLESS) != 0));
  785. }
  786.  
  787. void UpdateOptPriCm()
  788. {
  789.     SelectMenu(MENU(OPTMENU, OPTPRI, OPNOR), (bool)(DrawPri == 0));
  790.     SelectMenu(MENU(OPTMENU, OPTPRI, OPLOW), (bool)(DrawPri <  0));
  791. }
  792.  
  793. void UpdateFunCm()
  794. {
  795.     SelectMenu(MENU(DRWMENU, DRWFUN, DF1), (bool)(FunctionNr == DF1-DF1));
  796.     SelectMenu(MENU(DRWMENU, DRWFUN, DF2), (bool)(FunctionNr == DF2-DF1));
  797.     SelectMenu(MENU(DRWMENU, DRWFUN, DF3), (bool)(FunctionNr == DF3-DF1));
  798.     SelectMenu(MENU(DRWMENU, DRWFUN, DFUPF), (bool)(FunctionNr == DFUPF-DF1));
  799.     SelectMenu(MENU(DRWMENU, DRWFUN, DF5), (bool)(FunctionNr == DF5-DF1));
  800. }
  801.  
  802. void UpdateIPlotCm()
  803. {
  804.     SelectMenu(MENU(DRWMENU, DRWIPL, DINONE), (bool)(IPlotNr == DINONE-DINONE));
  805.     SelectMenu(MENU(DRWMENU, DRWIPL, DIZ)   , (bool)(IPlotNr == DIZ-DINONE));
  806. }
  807.  
  808. void UpdateEPlotCm()
  809. {
  810.     SelectMenu(MENU(DRWMENU, DRWEPL, DEDEPTH), (bool)(EPlotNr == DEDEPTH-DEDEPTH));
  811.     SelectMenu(MENU(DRWMENU, DRWEPL, DEZ)    , (bool)(EPlotNr == DEZ-DEDEPTH));
  812. }
  813.  
  814. void UpdateDrwCm()
  815. {
  816.     UpdateFunCm();
  817.     UpdateIPlotCm();
  818.     UpdateEPlotCm();
  819. }
  820.