/**********************************************************************************/
/*                                                                                */
/*  DLG_PARAMS - dialog callbacks for vortex image parameters                     */
/*                                                                                */
/**********************************************************************************/

#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include "const.h"
#include "classes.h"
#include "funcdefs.h"
#include "vortex.rh"
#include "extern.h"

extern "C"

INT_PTR CALLBACK DialogVortexParams ( HWND hdwnd , UINT message ,
                                      WPARAM wParam , LPARAM /* lParam */ )
{
   int id ;
   char msg[256] ;

   switch ( message ) {
      
      case WM_INITDIALOG:
         SetDlgItemInt ( hdwnd , IDC_IMAGE_ROWS , vortex_params.nrows , TRUE ) ;
         SetDlgItemInt ( hdwnd , IDC_IMAGE_COLS , vortex_params.ncols , TRUE ) ;
         sprintf_s ( msg , "%.2lf", vortex_params.eye_Y ) ;
         SetDlgItemText ( hdwnd , IDC_EYE_Y , msg ) ;
         sprintf_s ( msg , "%.2lf", vortex_params.eye_Z ) ;
         SetDlgItemText ( hdwnd , IDC_EYE_Z , msg ) ;
         sprintf_s ( msg , "%.2lf", vortex_params.min_row ) ;
         SetDlgItemText ( hdwnd , IDC_MIN_ROW , msg ) ;
         sprintf_s ( msg , "%.2lf", vortex_params.max_row ) ;
         SetDlgItemText ( hdwnd , IDC_MAX_ROW , msg ) ;
         sprintf_s ( msg , "%.2lf", vortex_params.min_col ) ;
         SetDlgItemText ( hdwnd , IDC_MIN_COL , msg ) ;
         sprintf_s ( msg , "%.2lf", vortex_params.max_col ) ;
         SetDlgItemText ( hdwnd , IDC_MAX_COL , msg ) ;
         sprintf_s ( msg , "%.2lf", vortex_params.perim_width ) ;
         SetDlgItemText ( hdwnd , IDC_PERIM_WIDTH , msg ) ;
         SetDlgItemInt ( hdwnd , IDC_LENGTH_DIVISIONS , vortex_params.length_divisions , TRUE ) ;
         SetDlgItemInt ( hdwnd , IDC_ANGLE_DIVISIONS , vortex_params.angle_divisions , TRUE ) ;
         if (vortex_params.pattern == 1)
            CheckRadioButton ( hdwnd , IDC_CHECKER , IDC_SPIRAL , IDC_CHECKER ) ;
         else
            CheckRadioButton ( hdwnd , IDC_CHECKER , IDC_SPIRAL , IDC_SPIRAL ) ;
         return TRUE ;
         
      case WM_COMMAND:
         id = LOWORD ( wParam ) ;
         switch ( id ) {
            case IDOK:
               vortex_params.nrows = GetDlgItemInt ( hdwnd , IDC_IMAGE_ROWS , NULL , FALSE ) ;
               vortex_params.ncols = GetDlgItemInt ( hdwnd , IDC_IMAGE_COLS , NULL , FALSE ) ;
               GetDlgItemText ( hdwnd , IDC_EYE_Y , msg , 256 ) ;
               vortex_params.eye_Y = atof ( msg ) ;
               GetDlgItemText ( hdwnd , IDC_EYE_Z , msg , 256 ) ;
               vortex_params.eye_Z = atof ( msg ) ;
               GetDlgItemText ( hdwnd , IDC_MIN_ROW , msg , 256 ) ;
               vortex_params.min_row = atof ( msg ) ;
               GetDlgItemText ( hdwnd , IDC_MAX_ROW , msg , 256 ) ;
               vortex_params.max_row = atof ( msg ) ;
               GetDlgItemText ( hdwnd , IDC_MIN_COL , msg , 256 ) ;
               vortex_params.min_col = atof ( msg ) ;
               GetDlgItemText ( hdwnd , IDC_MAX_COL , msg , 256 ) ;
               vortex_params.max_col = atof ( msg ) ;
               GetDlgItemText ( hdwnd , IDC_PERIM_WIDTH , msg , 256 ) ;
               vortex_params.perim_width = atof ( msg ) ;
               vortex_params.length_divisions = GetDlgItemInt ( hdwnd , IDC_LENGTH_DIVISIONS , NULL , FALSE ) ;
               vortex_params.angle_divisions = GetDlgItemInt ( hdwnd , IDC_ANGLE_DIVISIONS , NULL , FALSE ) ;
               if (IsDlgButtonChecked ( hdwnd , IDC_CHECKER ))
                   vortex_params.pattern = 1 ;
               else if (IsDlgButtonChecked ( hdwnd , IDC_SPIRAL ))
                   vortex_params.pattern = 2 ;
               EndDialog ( hdwnd , TRUE ) ;
               return TRUE ;  // Tell Windows we processed this message
            case IDCANCEL:
               EndDialog ( hdwnd , FALSE ) ;
               return TRUE ;  // Tell Windows we processed this message
            }
      }
      
   return FALSE ;  // Tell Windows we did not process this message
}
