home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / graphic / fractint / sources / pmfrdlg1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-25  |  42.1 KB  |  1,078 lines

  1. /*--------------------------------------------------
  2.    PMFRDLG1.C -- FRACTINT for PM
  3.  
  4.    Fractal Attributes Dialogs Module
  5.  
  6.    02/16/91      Code by Donald P. Egen (with help)
  7.  
  8.    This module contains all functions backing dialog
  9.    boxes that handle Fractal selection, parameters,
  10.    and so on used by the Fractal calculation engine.
  11.  ---------------------------------------------------*/
  12.  
  13. #define INCL_WIN
  14. #define INCL_GPI
  15. #define INCL_DOS
  16. #include <os2.h>
  17. #include <process.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <smplhelp.h>
  22.  
  23. #include "pmfract.h"
  24. #include "fractint.h"
  25. #include "fractype.h"
  26.  
  27. static VOID LoadExtents (HWND hwnd, PNEWPARAM npTempParms);
  28. static VOID LoadParams  (HWND hwnd, PNEWPARAM npTempParms);
  29. static VOID LoadTrigs   (HWND hwnd, unsigned char whichtrig);
  30. static VOID LoadImageXandY (HWND hwnd, SHORT cx, SHORT cy);
  31. static VOID LoadOptions (HWND hwnd, PNEWPARAM npTempParms);
  32.  
  33.  
  34. /*--------------------------------------------------
  35.   This function backs the Options/Set Parameters... dialog box.
  36.  
  37.   The current parameters for the calculation engine
  38.   are read into the local structure npTempParms
  39.   via InitNewParms (during WM_INITDLG) and set into
  40.   the dialog entry fields.
  41.  
  42.   Entry to any field is sensed via WM_CONTROL
  43.   notify messages, read, interpreded as a floating
  44.   point number, and it and other affected fields
  45.   updated.  Currently a nonsense string is not
  46.   explicitly detected (I assume the user is reading
  47.   the numbers echoed to him).
  48.  
  49.   The HELP button triggers an appropriate message
  50.   displayed via the SMPLHELP system.
  51.  
  52.   On dismiss, OK returns TRUE, Cancel returns FALSE.
  53.   The calling code will then finish scheduling
  54.   the parameters on an OK exit.
  55.  --------------------------------------------------*/
  56. MRESULT EXPENTRY SetExtentsDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  57.      {
  58.      char   achResponse[33];
  59.      double dTemp, dDelta;
  60.      char   tszFloatFormat[10];
  61.  
  62.      _fstrcpy(tszFloatFormat, szFloatFormat);
  63.  
  64.      switch (msg)
  65.           {
  66.           case WM_CONTROL:
  67.  
  68.                switch ( (USHORT) SHORT1FROMMP(mp1) )
  69.                     {
  70.                     case IDD_SET_XLEFT:
  71.                          if ( ((USHORT) SHORT2FROMMP(mp1)) == EN_KILLFOCUS )
  72.                             {
  73.                             WinQueryDlgItemText(hwnd, IDD_SET_XLEFT,
  74.                                  sizeof achResponse, achResponse);
  75.                             dTemp = atof(achResponse);
  76.                             npTempParms.XL = max(dTemp, npTempParms.mxXL);
  77.                             sprintf(achResponse, tszFloatFormat, npTempParms.XL);
  78.                             WinSetDlgItemText(hwnd, IDD_SET_XLEFT, achResponse);
  79.                             npTempParms.XCenter = (npTempParms.XL + npTempParms.XR) / 2.0;
  80.                             sprintf(achResponse, tszFloatFormat, npTempParms.XCenter);
  81.                             WinSetDlgItemText(hwnd, IDD_SET_XCENTER, achResponse);
  82.  
  83.                             return 0;
  84.                             }
  85.  
  86.                          break;
  87.  
  88.                     case IDD_SET_XRIGHT:
  89.                          if ( ((USHORT) SHORT2FROMMP(mp1)) == EN_KILLFOCUS )
  90.                             {
  91.                             WinQueryDlgItemText(hwnd, IDD_SET_XRIGHT,
  92.                                  sizeof achResponse, achResponse);
  93.                             dTemp = atof(achResponse);
  94.                             npTempParms.XR = min(dTemp,  npTempParms.mxXR);
  95.                             sprintf(achResponse, tszFloatFormat, npTempParms.XR);
  96.                             WinSetDlgItemText(hwnd, IDD_SET_XRIGHT, achResponse);
  97.                             npTempParms.XCenter = (npTempParms.XL + npTempParms.XR) / 2.0;
  98.                             sprintf(achResponse, tszFloatFormat, npTempParms.XCenter);
  99.                             WinSetDlgItemText(hwnd, IDD_SET_XCENTER, achResponse);
  100.  
  101.                             return 0;
  102.                             }
  103.  
  104.                          break;
  105.  
  106.                     case IDD_SET_YTOP:
  107.                          if ( ((USHORT) SHORT2FROMMP(mp1)) == EN_KILLFOCUS )
  108.                             {
  109.                             WinQueryDlgItemText(hwnd, IDD_SET_YTOP,
  110.                                  sizeof achResponse, achResponse);
  111.                             dTemp = atof(achResponse);
  112.                             npTempParms.YT = min(dTemp,  npTempParms.mxYT);
  113.                             sprintf(achResponse, tszFloatFormat, npTempParms.YT);
  114.                             WinSetDlgItemText(hwnd, IDD_SET_YTOP, achResponse);
  115.                             npTempParms.YCenter = (npTempParms.YT + npTempParms.YB) / 2.0;
  116.                             sprintf(achResponse, tszFloatFormat, npTempParms.YCenter);
  117.                             WinSetDlgItemText(hwnd, IDD_SET_YCENTER, achResponse);
  118.  
  119.                             return 0;
  120.                             }
  121.  
  122.                          break;
  123.  
  124.                     case IDD_SET_YBOTTOM:
  125.                          if ( ((USHORT) SHORT2FROMMP(mp1)) == EN_KILLFOCUS )
  126.                             {
  127.                             WinQueryDlgItemText(hwnd, IDD_SET_YBOTTOM,
  128.                                  sizeof achResponse, achResponse);
  129.                             dTemp = atof(achResponse);
  130.                             npTempParms.YB = max(dTemp, npTempParms.mxYB);
  131.                             sprintf(achResponse, tszFloatFormat, npTempParms.YB);
  132.                             WinSetDlgItemText(hwnd, IDD_SET_YBOTTOM, achResponse);
  133.                             npTempParms.YCenter = (npTempParms.YT + npTempParms.YB) / 2.0;
  134.                             sprintf(achResponse, tszFloatFormat, npTempParms.YCenter);
  135.                             WinSetDlgItemText(hwnd, IDD_SET_YCENTER, achResponse);
  136.  
  137.                             return 0;
  138.                             }
  139.  
  140.                          break;
  141.  
  142.                     case IDD_SET_XCENTER:
  143.                          if ( ((USHORT) SHORT2FROMMP(mp1)) == EN_KILLFOCUS )
  144.                             {
  145.                             WinQueryDlgItemText(hwnd, IDD_SET_XCENTER,
  146.                                  sizeof achResponse, achResponse);
  147.                             dTemp = atof(achResponse);
  148.                             dTemp = min(dTemp, npTempParms.mxXR);   /* upper AND lower bounds */
  149.                             dTemp = max(dTemp, npTempParms.mxXL);
  150.                             dDelta = dTemp - npTempParms.XCenter;
  151.                             npTempParms.XCenter = dTemp;
  152.                             if (dDelta < 0.0)
  153.                                {   /* shift left - check left edge first for out of bounds */
  154.                                dTemp = npTempParms.XL + dDelta;   /* new assumed left edge */
  155.                                npTempParms.XL = max(dTemp, npTempParms.mxXL); /* corrected left edge */
  156.                                dDelta = npTempParms.XL - npTempParms.XCenter;
  157.                                npTempParms.XR = npTempParms.XCenter - dDelta;
  158.                                }
  159.                             else
  160.                                {   /* shift right - check right edge first for out of bounds */
  161.                                dTemp = npTempParms.XR + dDelta;   /* new assumed right edge */
  162.                                npTempParms.XR = min(dTemp,  npTempParms.mxXR); /* corrected right edge */
  163.                                dDelta = npTempParms.XR - npTempParms.XCenter;
  164.                                npTempParms.XL = npTempParms.XCenter - dDelta;
  165.                                }
  166.                             sprintf(achResponse, tszFloatFormat, npTempParms.XL);
  167.                             WinSetDlgItemText(hwnd, IDD_SET_XLEFT, achResponse);
  168.                             sprintf(achResponse, tszFloatFormat, npTempParms.XR);
  169.                             WinSetDlgItemText(hwnd, IDD_SET_XRIGHT, achResponse);
  170.                             sprintf(achResponse, tszFloatFormat, npTempParms.XCenter);
  171.                             WinSetDlgItemText(hwnd, IDD_SET_XCENTER, achResponse);
  172.  
  173.                             return 0;
  174.                             }
  175.  
  176.                          break;
  177.  
  178.                     case IDD_SET_YCENTER:
  179.                          if ( ((USHORT) SHORT2FROMMP(mp1)) == EN_KILLFOCUS )
  180.                             {
  181.                             WinQueryDlgItemText(hwnd, IDD_SET_YCENTER,
  182.                                  sizeof achResponse, achResponse);
  183.                             dTemp = atof(achResponse);
  184.                             dTemp = min(dTemp, npTempParms.mxYT);   /* upper AND lower bounds */
  185.                             dTemp = max(dTemp, npTempParms.mxYB);
  186.                             dDelta = dTemp - npTempParms.YCenter;
  187.                             npTempParms.YCenter = dTemp;
  188.                             if (dDelta < 0.0)
  189.                                {   /* shift down - check bottom edge first for out of bounds */
  190.                                dTemp = npTempParms.YB + dDelta;   /* new assumed bottom edge */
  191.                                npTempParms.YB = max(dTemp, npTempParms.mxYB); /* corrected bottom edge */
  192.                                dDelta = npTempParms.YB - npTempParms.YCenter;
  193.                                npTempParms.YT = npTempParms.YCenter - dDelta;
  194.                                }
  195.                             else
  196.                                {   /* shift up - check top edge first for out of bounds */
  197.                                dTemp = npTempParms.YT + dDelta;   /* new assumed top edge */
  198.                                npTempParms.YT = min(dTemp, npTempParms.mxYT); /* corrected top edge */
  199.                                dDelta = npTempParms.YT - npTempParms.YCenter;
  200.                                npTempParms.YB = npTempParms.YCenter - dDelta;
  201.                                }
  202.                             sprintf(achResponse, tszFloatFormat, npTempParms.YB);
  203.                             WinSetDlgItemText(hwnd, IDD_SET_YBOTTOM, achResponse);
  204.                             sprintf(achResponse, tszFloatFormat, npTempParms.YT);
  205.                             WinSetDlgItemText(hwnd, IDD_SET_YTOP, achResponse);
  206.                             sprintf(achResponse, tszFloatFormat, npTempParms.YCenter);
  207.                             WinSetDlgItemText(hwnd, IDD_SET_YCENTER, achResponse);
  208.  
  209.                             return 0;
  210.                             }
  211.  
  212.                          break;
  213.  
  214.                     }
  215.                break;
  216.  
  217.           case WM_INITDLG:
  218.                CenterDialogBox(hwnd);
  219.  
  220.                InitNewParms(&npTempParms);
  221.  
  222.                LoadExtents (hwnd, &npTempParms);
  223.  
  224.                return 0;
  225.  
  226.           case WM_COMMAND:
  227.                switch (COMMANDMSG(&msg)->cmd)
  228.                     {
  229.                     case DID_OK:
  230.                          npNewParms = npTempParms;
  231.                          npNewParms.fNewParms = TRUE;
  232.                          WinDismissDlg (hwnd, TRUE) ;
  233.                          return 0 ;
  234.  
  235.                     case DID_CANCEL:
  236.                          npTempParms.fNewParms = FALSE;
  237.                          WinDismissDlg (hwnd, FALSE) ;
  238.                          return 0 ;
  239.  
  240.                     case IDD_SET_XDEF:
  241.                          /* zoom out to maximum range */
  242.                          npTempParms.XL = npTempParms.mxXL;
  243.                          npTempParms.XR = npTempParms.mxXR;
  244.                          npTempParms.YT = npTempParms.mxYT;
  245.                          npTempParms.YB = npTempParms.mxYB;
  246.                          npTempParms.XCenter = (npTempParms.XL + npTempParms.XR)/2.0;
  247.                          npTempParms.YCenter = (npTempParms.YT + npTempParms.YB)/2.0;
  248.                          /* refresh each diaglog box field */
  249.                          LoadExtents (hwnd, &npTempParms);
  250.  
  251.                          return 0;
  252.                     }
  253.                break;
  254.  
  255.           case WM_HELP:
  256.                SimpleHelp(hab, hwnd, szTitleBar,
  257.                        (HMODULE) 0, IDT_TEXT, IDT_HELP_EXTENT);
  258.  
  259.                return 0;
  260.  
  261.                break;
  262.           }
  263.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  264.      }
  265.  
  266. /*--------------------------------------------------
  267.   Local subfunction to SetExtents.
  268.  
  269.   This function loads the entry fields for
  270.   SetExtentsDlgProc.
  271.  --------------------------------------------------*/
  272. static VOID LoadExtents (HWND hwnd, PNEWPARAM npTempParms)
  273.      {
  274.      char achResponse[33];
  275.  
  276.      char   tszFloatFormat[10];
  277.  
  278.      _fstrcpy(tszFloatFormat, szFloatFormat);
  279.  
  280.      /* load each entryfield in turn */
  281.      sprintf(achResponse, tszFloatFormat, npTempParms->XL);
  282.      WinSetDlgItemText(hwnd, IDD_SET_XLEFT, achResponse);
  283.      sprintf(achResponse, tszFloatFormat, npTempParms->XR);
  284.      WinSetDlgItemText(hwnd, IDD_SET_XRIGHT, achResponse);
  285.      sprintf(achResponse, tszFloatFormat, npTempParms->YT);
  286.      WinSetDlgItemText(hwnd, IDD_SET_YTOP, achResponse);
  287.      sprintf(achResponse, tszFloatFormat, npTempParms->YB);
  288.      WinSetDlgItemText(hwnd, IDD_SET_YBOTTOM, achResponse);
  289.      sprintf(achResponse, tszFloatFormat, npTempParms->XCenter);
  290.      WinSetDlgItemText(hwnd, IDD_SET_XCENTER, achResponse);
  291.      sprintf(achResponse, tszFloatFormat, npTempParms->YCenter);
  292.      WinSetDlgItemText(hwnd, IDD_SET_YCENTER, achResponse);
  293.  
  294.      }
  295.  
  296. /*--------------------------------------------------
  297.   This function backs the View/Zoom/Value... dialog box.
  298.  
  299.   A default of 2.00 is suggested at initialization.
  300.  
  301.   On OK exit, the entry field contents is intrepreted
  302.   as a floating point number and returned.
  303.  --------------------------------------------------*/
  304. MRESULT EXPENTRY ZoomValueDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  305.      {
  306.      static USHORT usInOut = 0;
  307.  
  308.      double dTemp;
  309.      char   achResponse[33];
  310.      char   tszFloatFormat[10];
  311.  
  312.      _fstrcpy(tszFloatFormat, szFloatFormat);
  313.  
  314.      switch (msg)
  315.           {
  316.           case WM_INITDLG:
  317.                CenterDialogBox(hwnd);
  318.  
  319.                InitNewParms(&npTempParms);
  320.                switch (*((PUSHORT) PVOIDFROMMP(mp2) ) )
  321.                     {
  322.                     case IDM_ZOUT_PICK:
  323.                          WinSetDlgItemText(hwnd, IDD_NUMBER_PROMPT,
  324.                                                  szZoomOut) ;
  325.                          usInOut = IDM_ZOUT_PICK;
  326.                          break;
  327.                     default:       /* Paranoia */
  328.                          WinSetDlgItemText(hwnd, IDD_NUMBER_PROMPT,
  329.                                                  szZoomIn);
  330.                          usInOut = IDM_ZIN_PICK;
  331.                          break;
  332.                     }
  333.                WinSetDlgItemText(hwnd, IDD_NUMBER_EF, "2.00");
  334.  
  335.                return 0;
  336.  
  337.           case WM_COMMAND:
  338.                switch (COMMANDMSG(&msg)->cmd)
  339.                     {
  340.                     case DID_OK:
  341.                          WinQueryDlgItemText(hwnd, IDD_NUMBER_EF,
  342.                               sizeof achResponse, achResponse);
  343.                          dTemp = atof(achResponse);
  344.                          if (dTemp != 0.0)
  345.                             {
  346.                             switch (usInOut)
  347.                                  {
  348.                                  case IDM_ZIN_PICK:
  349.                                       CalcZoomValues (&npTempParms, dTemp, TRUE);
  350.                                       break;
  351.  
  352.                                  case IDM_ZOUT_PICK:
  353.                                       CalcZoomValues (&npTempParms, dTemp, FALSE);
  354.                                       break;
  355.                                  }
  356.                             npNewParms = npTempParms;
  357.                             npNewParms.fNewParms = TRUE;
  358.                             WinDismissDlg (hwnd, TRUE) ;
  359.                             return 0 ;
  360.                             }
  361.                          else
  362.                             WinAlarm(HWND_DESKTOP, WA_ERROR);
  363.                          break;
  364.  
  365.                     case DID_CANCEL:
  366.                          npTempParms.fNewParms = FALSE;
  367.                          WinDismissDlg (hwnd, FALSE) ;
  368.                          return 0 ;
  369.                     }
  370.                break ;
  371.           }
  372.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  373.      }
  374.  
  375. /*--------------------------------------------------
  376.   Subfunction for ZoomValuesDlgProc.
  377.  
  378.   Apply the new zoom value to all extent values.
  379.  --------------------------------------------------*/
  380. VOID    CalcZoomValues (PNEWPARAM npTempParms, double dFactor, BOOL InOrOut)
  381.      {
  382.      /* parm InOrOut is TRUE for IN, FALSE for OUT */
  383.  
  384.      if (InOrOut)
  385.         {    /* IN */
  386.         npTempParms->XL = npTempParms->XCenter -
  387.                  (npTempParms->XCenter - npTempParms->XL) / dFactor;
  388.         npTempParms->XR = npTempParms->XCenter +
  389.                  (npTempParms->XR - npTempParms->XCenter) / dFactor;
  390.         npTempParms->YT = npTempParms->YCenter +
  391.                  (npTempParms->YT - npTempParms->YCenter) / dFactor;
  392.         npTempParms->YB = npTempParms->YCenter -
  393.                  (npTempParms->YCenter - npTempParms->YB) / dFactor;
  394.         }
  395.      else   /* OUT */
  396.         {
  397.         npTempParms->XL = npTempParms->XCenter -
  398.                  (npTempParms->XCenter - npTempParms->XL) * dFactor;
  399.         npTempParms->XR = npTempParms->XCenter +
  400.                  (npTempParms->XR - npTempParms->XCenter) * dFactor;
  401.         npTempParms->YT = npTempParms->YCenter +
  402.                  (npTempParms->YT - npTempParms->YCenter) * dFactor;
  403.         npTempParms->YB = npTempParms->YCenter -
  404.                  (npTempParms->YCenter - npTempParms->YB) * dFactor;
  405.  
  406.         /* Out zooms are limited to [current bounds] because */
  407.         /*  beyond those limits is outside the set anyhow */
  408.         npTempParms->XL = max(npTempParms->XL, npTempParms->mxXL);
  409.         npTempParms->XR = min(npTempParms->XR, npTempParms->mxXR);
  410.         npTempParms->YT = min(npTempParms->YT, npTempParms->mxYT);
  411.         npTempParms->YB = max(npTempParms->YB, npTempParms->mxYB);
  412.         }
  413.  
  414.      }
  415.  
  416. /*--------------------------------------------------
  417.   This function backs the Options/Set Parameters... dialog box.
  418.  
  419.   The current parameters for the calculation engine
  420.   are read into the local structure npTempParms
  421.   via InitNewParms (during WM_INITDLG) and set into
  422.   the dialog entry fields.
  423.  
  424.   Entry to any field is sensed via WM_CONTROL
  425.   notify messages, read, interpreded as a floating
  426.   point number, and it and other affected fields
  427.   updated.  Currently a nonsense string is not
  428.   explicitly detected (I assume the user is reading
  429.   the numbers echoed to him).
  430.  
  431.   The HELP button triggers an appropriate message
  432.   displayed via the SMPLHELP system.
  433.  
  434.   On dismiss, OK returns TRUE, Cancel returns FALSE.
  435.   The calling code will then finish scheduling
  436.   the parameters on an OK exit.
  437.  --------------------------------------------------*/
  438. MRESULT EXPENTRY SetParametersDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  439.      {
  440.      char   achResponse[33];
  441.      double dTemp;
  442.      USHORT usWhichField, usNoteCode;
  443.      char   tszFloatFormat[10];
  444.  
  445.      _fstrcpy(tszFloatFormat, szFloatFormat);
  446.  
  447.      switch (msg)
  448.           {
  449.           case WM_CONTROL:
  450.  
  451.                usWhichField = (USHORT) SHORT1FROMMP(mp1) ;
  452.                usNoteCode = (USHORT) SHORT2FROMMP(mp1) ;
  453.  
  454.                if ( ( (usWhichField >= IDD_SET_P0) &&
  455.                       (usWhichField <= IDD_SET_P3) )
  456.                      /* if its an entryfield touched */
  457.                      /*  losing the focus */
  458.                      && ( usNoteCode == EN_KILLFOCUS ) )
  459.                   {
  460.                   WinQueryDlgItemText(hwnd, usWhichField,
  461.                         sizeof achResponse, achResponse);
  462.                   dTemp = atof(achResponse);
  463.                   npTempParms.param[usWhichField - IDD_SET_P0] = dTemp;
  464.                   sprintf(achResponse, tszFloatFormat, dTemp);
  465.                   WinSetDlgItemText(hwnd, usWhichField, achResponse);
  466.  
  467.                   return 0;
  468.  
  469.                   }
  470.  
  471.  
  472.                if ( ( (usWhichField >= IDD_SET_T1CB) &&
  473.                       (usWhichField <= IDD_SET_T4CB) )
  474.                     /* if it is one of the combo boxes */
  475.                     /* and the selection has changed */
  476.                       && ( usNoteCode == CBN_LBSELECT ) )
  477.                   {
  478.                       /* grab the new selection */
  479.                   npTempParms.trigndx[usWhichField - IDD_SET_T1CB] =
  480.                      (unsigned char) WinSendDlgItemMsg(hwnd,
  481.                           usWhichField, LM_QUERYSELECTION,
  482.                           MPFROMSHORT(0), MPFROMP(NULL) );
  483.  
  484.                   return 0;
  485.                   }
  486.  
  487.                break;
  488.  
  489.           case WM_INITDLG:
  490.  
  491.                CenterDialogBox(hwnd);
  492.  
  493.                InitNewParms(&npTempParms);
  494.  
  495.                LoadParams (hwnd, &npTempParms);
  496.  
  497.                    /* if no numeric parms ... */
  498.                if ('\0' == *fractalspecific[npTempParms.iFractType].param[0])
  499.                   {  /* ... but there are trig parms */
  500.                   if (0 != ( (fractalspecific[npTempParms.iFractType].flags) >> 6) & 7)
  501.                      {  /* ... start with cursor on the trig parm */
  502.                      WinSetFocus(HWND_DESKTOP, WinWindowFromID (hwnd, IDD_SET_T1CB) );
  503.                      return ( (MRESULT) TRUE) ;
  504.                      }
  505.                   else
  506.                      {  /* ... else start with cursor on "OK" button */
  507.                      WinSetFocus(HWND_DESKTOP, WinWindowFromID (hwnd,DID_OK) );
  508.                      return ( (MRESULT) TRUE) ;
  509.                      }
  510.                   }
  511.  
  512.                return 0;
  513.  
  514.           case WM_COMMAND:
  515.                switch (COMMANDMSG(&msg)->cmd)
  516.                     {
  517.                     case DID_OK:
  518.                          npNewParms = npTempParms;
  519.                          npNewParms.fNewParms = TRUE;
  520.                          WinDismissDlg (hwnd, TRUE) ;
  521.                          return 0 ;
  522.  
  523.                     case DID_CANCEL:
  524.                          npTempParms.fNewParms = FALSE;
  525.                          WinDismissDlg (hwnd, FALSE) ;
  526.                          return 0 ;
  527.  
  528.                     case IDD_SET_PDEF:
  529.                          /* copy parms from the engine table again */
  530.                          npTempParms.param[0] = fractalspecific[npTempParms.iFractType].paramvalue[0];
  531.                          npTempParms.param[1] = fractalspecific[npTempParms.iFractType].paramvalue[1];
  532.                          npTempParms.param[2] = fractalspecific[npTempParms.iFractType].paramvalue[2];
  533.                          npTempParms.param[3] = fractalspecific[npTempParms.iFractType].paramvalue[3];
  534.                          npTempParms.trigndx[0] = SIN;
  535.                          npTempParms.trigndx[1] = SQR;
  536.                          npTempParms.trigndx[2] = SINH;
  537.                          npTempParms.trigndx[3] = COSH;
  538.                          LoadParams (hwnd, &npTempParms);
  539.  
  540.                          return 0;
  541.  
  542.                     }
  543.                break;
  544.  
  545.           case WM_HELP:
  546.                SimpleHelp(hab, hwnd, szTitleBar,
  547.                        (HMODULE) 0, IDT_TEXT, IDT_HELP_PARAMS);
  548.  
  549.                return 0;
  550.  
  551.                break;
  552.           }
  553.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  554.      }
  555.  
  556.  
  557. /*--------------------------------------------------
  558.   Local subfunction to Options/Set Parameters.
  559.  
  560.   This function loads the dialog fields for
  561.   SetParametersDlgProc.
  562.  --------------------------------------------------*/
  563. static VOID LoadParams (HWND hwnd, PNEWPARAM npTempParms)
  564.      {
  565.      int numTrig;
  566.      char achResponse[33];
  567.  
  568.      char   tszFloatFormat[10];
  569.  
  570.      _fstrcpy(tszFloatFormat, szFloatFormat);
  571.  
  572.      /* load each field in turn */
  573.      WinSetDlgItemText(hwnd, IDD_SET_PFRACTALTYPE,
  574.                        GetFractalName(npTempParms->iFractType) );
  575.  
  576.      if ('\0' != *fractalspecific[npTempParms->iFractType].param[0])
  577.         {
  578.         WinSetDlgItemText(hwnd, IDD_SET_P0TEXT,
  579.              fractalspecific[npTempParms->iFractType].param[0]);
  580.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P0), TRUE);
  581.         sprintf(achResponse, tszFloatFormat, npTempParms->param[0]);
  582.         WinSetDlgItemText(hwnd, IDD_SET_P0, achResponse);
  583.         }
  584.      else
  585.         {
  586.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P0), FALSE);
  587.         WinSetDlgItemText(hwnd, IDD_SET_P0TEXT, szValueNotApplicable);
  588.         WinSetDlgItemText(hwnd, IDD_SET_P0, "");
  589.         }
  590.  
  591.      if ('\0' != *fractalspecific[npTempParms->iFractType].param[1])
  592.         {
  593.         WinSetDlgItemText(hwnd, IDD_SET_P1TEXT,
  594.              fractalspecific[npTempParms->iFractType].param[1]);
  595.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P1) , TRUE);
  596.         sprintf(achResponse, tszFloatFormat, npTempParms->param[1]);
  597.         WinSetDlgItemText(hwnd, IDD_SET_P1, achResponse);
  598.         }
  599.      else
  600.         {
  601.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P1), FALSE);
  602.         WinSetDlgItemText(hwnd, IDD_SET_P1TEXT, szValueNotApplicable);
  603.         WinSetDlgItemText(hwnd, IDD_SET_P1, "");
  604.         }
  605.  
  606.      if ('\0' != *fractalspecific[npTempParms->iFractType].param[2])
  607.         {
  608.         WinSetDlgItemText(hwnd, IDD_SET_P2TEXT,
  609.              fractalspecific[npTempParms->iFractType].param[2]);
  610.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P2) , TRUE);
  611.         sprintf(achResponse, tszFloatFormat, npTempParms->param[2]);
  612.         WinSetDlgItemText(hwnd, IDD_SET_P2, achResponse);
  613.         }
  614.      else
  615.         {
  616.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P2), FALSE);
  617.         WinSetDlgItemText(hwnd, IDD_SET_P2TEXT, szValueNotApplicable);
  618.         WinSetDlgItemText(hwnd, IDD_SET_P2, "");
  619.         }
  620.  
  621.      if ('\0' != *fractalspecific[npTempParms->iFractType].param[3])
  622.         {
  623.         WinSetDlgItemText(hwnd, IDD_SET_P3TEXT,
  624.              fractalspecific[npTempParms->iFractType].param[3]);
  625.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P3) , TRUE);
  626.         sprintf(achResponse, tszFloatFormat, npTempParms->param[3]);
  627.         WinSetDlgItemText(hwnd, IDD_SET_P3, achResponse);
  628.         }
  629.      else
  630.         {
  631.         WinEnableWindow ( WinWindowFromID(hwnd, IDD_SET_P3), FALSE);
  632.         WinSetDlgItemText(hwnd, IDD_SET_P3TEXT, szValueNotApplicable);
  633.         WinSetDlgItemText(hwnd, IDD_SET_P3, "");
  634.         }
  635.  
  636.      numTrig = ( (fractalspecific[npTempParms->iFractType].flags) >> 6) & 7;
  637.  
  638.      if (numTrig >= 1)
  639.         {
  640.         LoadTrigs(WinWindowFromID(hwnd, IDD_SET_T1CB),
  641.                   npTempParms->trigndx[0]);
  642.         }
  643.      else
  644.         {
  645.         WinSetDlgItemText(hwnd, IDD_SET_T1TEXT, "");
  646.         WinEnableWindow(WinWindowFromID(hwnd, IDD_SET_T1CB), FALSE);
  647.         }
  648.  
  649.      if (numTrig >= 2)
  650.         {
  651.         LoadTrigs(WinWindowFromID(hwnd, IDD_SET_T2CB),
  652.                   npTempParms->trigndx[1]);
  653.         }
  654.      else
  655.         {
  656.         WinSetDlgItemText(hwnd, IDD_SET_T2TEXT, "");
  657.         WinEnableWindow(WinWindowFromID(hwnd, IDD_SET_T2CB), FALSE);
  658.         }
  659.  
  660.      if (numTrig >= 3)
  661.         {
  662.         LoadTrigs(WinWindowFromID(hwnd, IDD_SET_T3CB),
  663.                   npTempParms->trigndx[2]);
  664.         }
  665.      else
  666.         {
  667.         WinSetDlgItemText(hwnd, IDD_SET_T3TEXT, "");
  668.         WinEnableWindow(WinWindowFromID(hwnd, IDD_SET_T3CB), FALSE);
  669.         }
  670.  
  671.      if (numTrig >= 4)
  672.         {
  673.         LoadTrigs(WinWindowFromID(hwnd, IDD_SET_T4CB),
  674.                   npTempParms->trigndx[3]);
  675.         }
  676.      else
  677.         {
  678.         WinSetDlgItemText(hwnd, IDD_SET_T4TEXT, "");
  679.         WinEnableWindow(WinWindowFromID(hwnd, IDD_SET_T4CB), FALSE);
  680.         }
  681.  
  682.      }
  683.  
  684.  
  685. /*--------------------------------------------------
  686.   Local subfunction to Options/Set Parameters.
  687.  
  688.   This function loads the Trig function selection
  689.   combo-boxes for SetParametersDlgProc.
  690.  --------------------------------------------------*/
  691. static VOID LoadTrigs(HWND hwnd, unsigned char whichtrig)
  692.      {
  693.      int i;
  694.  
  695.      /* zilch what might be there */
  696.      WinSendMsg(hwnd,LM_DELETEALL, MPFROMP(NULL), MPFROMP(NULL) );
  697.  
  698.      /* load'em up */
  699.      for (i = 0; i <= MAX_TRIG; i++)
  700.         {
  701.         WinSendMsg(hwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0),
  702.               MPFROMP(trigfn[i].name) );
  703.         }
  704.  
  705.      /* and indicate the current */
  706.      WinSendMsg(hwnd, LM_SELECTITEM, MPFROMSHORT((SHORT) whichtrig),
  707.               MPFROMSHORT(TRUE) );
  708.  
  709.      /* and ensure it is turned on */
  710.      WinEnableWindow(hwnd, TRUE);
  711.  
  712.      /* and set the initial entryfield value */
  713.      WinSetWindowText(hwnd, trigfn[whichtrig].name);
  714.  
  715.      }
  716.  
  717. /*--------------------------------------------------
  718.   This function backs the Options/Set Image... dialog box.
  719.  
  720.   Current status is set at initialization.
  721.   Use of the Screen/Window/Printer/640x480 buttons primes the
  722.   X and Y extent fields to suggest appropriate parameters.
  723.  
  724.   Help sends an appropriate message using the
  725.   SMPLHELP system.
  726.  --------------------------------------------------*/
  727. MRESULT EXPENTRY SetImageDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  728.      {
  729.  
  730.      switch (msg)
  731.           {
  732.           case WM_INITDLG:
  733.  
  734.                CenterDialogBox(hwnd);
  735.  
  736.                InitNewParms(&npTempParms);
  737.  
  738.                /* start with current image size */
  739.                LoadImageXandY (hwnd, npTempParms.cx, npTempParms.cy);
  740.  
  741.                /* set the current number of colors */
  742.                switch (npTempParms.colors)
  743.                       {
  744.                       case 2:
  745.                            WinSendDlgItemMsg(hwnd, IDD_IMG_C2,
  746.                                     BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  747.                            break;
  748.  
  749.                       case 16:
  750.                            WinSendDlgItemMsg(hwnd, IDD_IMG_C16,
  751.                                     BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  752.                            break;
  753.  
  754.                       case 256:
  755.                            WinSendDlgItemMsg(hwnd, IDD_IMG_C256,
  756.                                     BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  757.                            break;
  758.  
  759.                       /* I don't know how another value could have been set */
  760.  
  761.                       }
  762.  
  763.                /* and go away */
  764.                return 0;
  765.  
  766.           case WM_CONTROL:
  767.                {
  768.                SHORT sWho = SHORT1FROMMP(mp1);
  769.                SHORT sWhat = SHORT2FROMMP(mp1);
  770.  
  771.                /* keep track as buttons are pushed */
  772.                switch (sWhat)
  773.                     {
  774.                     case BN_CLICKED:
  775.                          switch (sWho)
  776.                               {
  777.                               /* if it is a Colors button, just record the fact */
  778.                               case IDD_IMG_C2:
  779.                                    npTempParms.colors = 2;
  780.                                    return 0;
  781.  
  782.                               case IDD_IMG_C16:
  783.                                    npTempParms.colors = 16;
  784.                                    return 0;
  785.  
  786.                               case IDD_IMG_C256:
  787.                                    npTempParms.colors = 256;
  788.                                    return 0;
  789.  
  790.                               }
  791.                     }
  792.                break;
  793.                }
  794.  
  795.           case WM_COMMAND:
  796.                switch (COMMANDMSG(&msg)->cmd)
  797.                     {
  798.                     /* if it is a Target button, set new values */
  799.                     /* in the entry fields */
  800.                     case IDD_IMG_WIN:
  801.                          LoadImageXandY (hwnd, cxClient, cyClient);
  802.  
  803.                          return 0;
  804.  
  805.                     case IDD_IMG_SCR:
  806.                          LoadImageXandY (hwnd, (SHORT) cxScreen, (SHORT) cyScreen);
  807.  
  808.                          return 0;
  809.  
  810.                     case IDD_IMG_PRT:
  811.                          LoadImageXandY (hwnd, (SHORT) cxPrinter, (SHORT) cyPrinter);
  812.  
  813.                          return 0;
  814.  
  815.                     case IDD_IMG_VGA:
  816.                          LoadImageXandY (hwnd, 640, 480);
  817.  
  818.                          return 0;
  819.  
  820.                     case DID_OK:
  821.                          /* On good return, read the values from the */
  822.                          /* X and Y entry fields, and return them.  */
  823.  
  824.                          if ( ! (WinQueryDlgItemShort(hwnd, IDD_IMG_X,
  825.                                    &npTempParms.cx, FALSE) &&
  826.                                  WinQueryDlgItemShort(hwnd, IDD_IMG_Y,
  827.                                    &npTempParms.cy, FALSE) ) )
  828.                             {
  829.                             /* false return is non-numeric in entry field */
  830.                             /* (user if playing with us) */
  831.                             /* yell and scream */
  832.                             WinMessageBox(HWND_DESKTOP, hwnd, szBadNumeric,
  833.                                    szTitleBar, ID_BADNUMERIC,
  834.                                    MB_OK | MB_ERROR | MB_APPLMODAL ) ;
  835.                             return 0;
  836.                             }
  837.  
  838.                          /* look's good.  go away. */
  839.                          npNewParms = npTempParms;
  840.                          npNewParms.fNewParms = TRUE;
  841.                          WinDismissDlg (hwnd, TRUE) ;
  842.                          return 0 ;
  843.  
  844.                     case DID_CANCEL:
  845.                          npTempParms.fNewParms = FALSE;
  846.                          WinDismissDlg (hwnd, FALSE) ;
  847.                          return 0 ;
  848.                     }
  849.                break ;
  850.  
  851.           case WM_HELP:
  852.                SimpleHelp(hab, hwnd, szTitleBar,
  853.                        (HMODULE) 0, IDT_TEXT, IDT_HELP_OPERATE);
  854.  
  855.                return 0;
  856.  
  857.                break;
  858.           }
  859.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  860.      }
  861.  
  862. /*--------------------------------------------------
  863.   Local subfunction to SetImageDlgProc.
  864.  
  865.   This function loads the entry fields for
  866.   Image X and Y.
  867.  --------------------------------------------------*/
  868. static VOID LoadImageXandY (HWND hwnd, SHORT cx, SHORT cy)
  869.      {
  870.  
  871.      /* Load new image size */
  872.      WinSetDlgItemShort(hwnd, IDD_IMG_X, cx, FALSE);
  873.      WinSetDlgItemShort(hwnd, IDD_IMG_Y, cy, FALSE);
  874.  
  875.      }
  876.  
  877. /*--------------------------------------------------
  878.   This function backs the Options/Set Options... dialog box.
  879.  
  880.   The current options for the calculation engine
  881.   are read into the local structure npTempParms
  882.   via InitNewParms (during WM_INITDLG) and set into
  883.   the dialog entry fields.
  884.  
  885.   Entry to any field is sensed via WM_CONTROL
  886.   notify messages, read, interpreded as needed.
  887.  
  888.   The HELP button triggers an appropriate message
  889.   displayed via the SMPLHELP system.
  890.  
  891.   On dismiss, OK returns TRUE, Cancel returns FALSE.
  892.   The calling code will then finish scheduling
  893.   the parameters on an OK exit.
  894.  --------------------------------------------------*/
  895. MRESULT EXPENTRY SetOptionsDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  896.      {
  897.  
  898.      BOOL   rc;
  899.  
  900.      switch (msg)
  901.           {
  902.           case WM_CONTROL:
  903.                {
  904.                SHORT sWho = SHORT1FROMMP(mp1);
  905.                SHORT sWhat = SHORT2FROMMP(mp1);
  906.  
  907.                /* keep track as buttons are pushed */
  908.                switch (sWhat)
  909.                     {
  910.                     case BN_CLICKED:
  911.                          switch (sWho)
  912.                               {
  913.                               /* if it is a Passes or Math button, just record the fact */
  914.                               case IDD_OPT_PASSES1:
  915.                                    npTempParms.stdCalcMode = '1';
  916.                                    return 0;
  917.  
  918.                               case IDD_OPT_PASSES2:
  919.                                    npTempParms.stdCalcMode = '2';
  920.                                    return 0;
  921.  
  922.                               case IDD_OPT_PASSESG:
  923.                                    npTempParms.stdCalcMode = 'g';
  924.                                    return 0;
  925.  
  926.                               case IDD_OPT_PASSESB:
  927.                                    npTempParms.stdCalcMode = 'b';
  928.                                    return 0;
  929.  
  930.                               case IDD_OPT_MATHI:
  931.                                    npTempParms.cFloatflag = 0;
  932.                                    return 0;
  933.  
  934.                               case IDD_OPT_MATHF:
  935.                                    npTempParms.cFloatflag = 1;
  936.                                    return 0;
  937.                               }
  938.                     }
  939.                break;
  940.                }
  941.  
  942.  
  943.           case WM_INITDLG:
  944.                CenterDialogBox(hwnd);
  945.  
  946.                InitNewParms(&npTempParms);
  947.  
  948.                LoadOptions (hwnd, &npTempParms);
  949.  
  950.                return ((MRESULT) TRUE);
  951.  
  952.           case WM_COMMAND:
  953.                switch (COMMANDMSG(&msg)->cmd)
  954.                     {
  955.                     case DID_OK:
  956.                          /* On good return, read the values from the */
  957.                          /* entry fields, and return them.  */
  958.  
  959.                          rc = WinQueryDlgItemShort(hwnd, IDD_OPT_MAXITER,
  960.                                    &npTempParms.maxiter, FALSE);
  961.                          rc = rc && WinQueryDlgItemShort(hwnd, IDD_OPT_BIOMORF,
  962.                                    &npTempParms.biomorph, TRUE);
  963.                          rc = rc && WinQueryDlgItemShort(hwnd, IDD_OPT_DECOMP,
  964.                                    &npTempParms.decomp[0], FALSE);
  965.                          rc = rc && WinQueryDlgItemShort(hwnd, IDD_OPT_INCOLOR,
  966.                                    &npTempParms.inside, TRUE);
  967.                          rc = rc && WinQueryDlgItemShort(hwnd, IDD_OPT_OUTCOLR,
  968.                                    &npTempParms.outside, TRUE);
  969.                          rc = rc && WinQueryDlgItemShort(hwnd, IDD_OPT_DISTEST,
  970.                                    &npTempParms.distest, FALSE);
  971.                          if (!rc)
  972.                             {
  973.                             /* false return is non-numeric in entry field */
  974.                             /* (user is f***ing with us)                  */
  975.                             /*   yell and scream                          */
  976.                             WinMessageBox(HWND_DESKTOP, hwnd, szBadNumeric,
  977.                                    szTitleBar, ID_BADNUMERIC,
  978.                                    MB_OK | MB_ERROR | MB_APPLMODAL ) ;
  979.                             return 0;
  980.                             }
  981.  
  982.                          /* looks good, flag it and go away */
  983.                          npNewParms = npTempParms;
  984.                          npNewParms.fNewParms = TRUE;
  985.                          WinDismissDlg (hwnd, TRUE) ;
  986.                          return 0 ;
  987.  
  988.                     case DID_CANCEL:
  989.                          npTempParms.fNewParms = FALSE;
  990.                          WinDismissDlg (hwnd, FALSE) ;
  991.                          return 0 ;
  992.  
  993.                     case IDD_SET_ODEF:
  994.                          npTempParms.stdCalcMode = 'g';
  995.                          npTempParms.cFloatflag = 0;
  996.                          if (npTempParms.colors > 16)
  997.                             npTempParms.maxiter = 250;
  998.                          else
  999.                             npTempParms.maxiter = 150;
  1000.                          npTempParms.biomorph = -1;
  1001.                          npTempParms.decomp[0] = 0;
  1002.                          npTempParms.inside = 1;
  1003.                          npTempParms.outside = -1;
  1004.                          npTempParms.distest = 0;
  1005.                          /* refresh each diaglog box field */
  1006.                          LoadOptions (hwnd, &npTempParms);
  1007.  
  1008.                          return 0;
  1009.                     }
  1010.                break;
  1011.  
  1012.           case WM_HELP:
  1013.                SimpleHelp(hab, hwnd, szTitleBar,
  1014.                        (HMODULE) 0, IDT_TEXT, IDT_HELP_OPERATE);
  1015.  
  1016.                return 0;
  1017.  
  1018.                break;
  1019.           }
  1020.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  1021.      }
  1022.  
  1023. /*--------------------------------------------------
  1024.   Local subfunction to SetOptionsDlgProc
  1025.  
  1026.   This function loads the entry fields for
  1027.   SetOptionsDlgProc.
  1028.  --------------------------------------------------*/
  1029. static VOID LoadOptions (HWND hwnd, PNEWPARAM npTempParms)
  1030.      {
  1031.  
  1032.      /* set the current calculation mode */
  1033.      switch (npTempParms->stdCalcMode)
  1034.             {
  1035.             case '1':
  1036.                  WinSendDlgItemMsg(hwnd, IDD_OPT_PASSES1,
  1037.                           BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  1038.                  WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDD_OPT_PASSES1) );
  1039.                  break;
  1040.  
  1041.             case '2':
  1042.                  WinSendDlgItemMsg(hwnd, IDD_OPT_PASSES2,
  1043.                           BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  1044.                  WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDD_OPT_PASSES2) );
  1045.                  break;
  1046.  
  1047.             case 'g':
  1048.                  WinSendDlgItemMsg(hwnd, IDD_OPT_PASSESG,
  1049.                           BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  1050.                  WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDD_OPT_PASSESG) );
  1051.                  break;
  1052.  
  1053.             case 'b':
  1054.                  WinSendDlgItemMsg(hwnd, IDD_OPT_PASSESB,
  1055.                           BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  1056.                  WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDD_OPT_PASSESB) );
  1057.                  break;
  1058.  
  1059.             }
  1060.  
  1061.      /* now the math type */
  1062.      if (npTempParms->cFloatflag)
  1063.             WinSendDlgItemMsg(hwnd, IDD_OPT_MATHF,
  1064.                           BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  1065.      else
  1066.             WinSendDlgItemMsg(hwnd, IDD_OPT_MATHI,
  1067.                           BM_SETCHECK, MPFROMSHORT(1), MPFROMP(NULL) );
  1068.  
  1069.      /* now load each entry field */
  1070.      WinSetDlgItemShort(hwnd, IDD_OPT_MAXITER, npTempParms->maxiter, FALSE);
  1071.      WinSetDlgItemShort(hwnd, IDD_OPT_BIOMORF, npTempParms->biomorph, TRUE);
  1072.      WinSetDlgItemShort(hwnd, IDD_OPT_DECOMP, npTempParms->decomp[0], FALSE);
  1073.      WinSetDlgItemShort(hwnd, IDD_OPT_INCOLOR, npTempParms->inside, TRUE);
  1074.      WinSetDlgItemShort(hwnd, IDD_OPT_OUTCOLR, npTempParms->outside, TRUE);
  1075.      WinSetDlgItemShort(hwnd, IDD_OPT_DISTEST, npTempParms->distest, FALSE);
  1076.  
  1077.      }
  1078.