/******************************************************************************/
/*                                                                            */
/*  CLASSES - Headers for all classes                                         */
/*                                                                            */
/******************************************************************************/

class DIBimage ;

/*
--------------------------------------------------------------------------------

   Parameters specified by the user in dialog boxes
   These are global, declared in LIN.CPP and appearing in EXTERN.H.
   This facilitates initializing them in the main program, setting them in
   the DLG_? routines, and using them where needed.

--------------------------------------------------------------------------------
*/

typedef struct ER_Params {
   int nrows ;
   int ncols ;
   int width ;            // Line width, at least 1, often 3
   int depth ;            // Number of recursions, 0 is axiom
   int bad_rule ;         // Flags if a bad rule
   double angle ;         // Turning angle in degrees, 0-90
   char axiom[MAX_RULE+1] ;
   char primary[MAX_RULE+1] ;
   char secondary[MAX_RULE+1] ;
   } ER_PARAMS ;

typedef struct AG_Params {
   int nrows ;
   int ncols ;
   int width ;            // Initial line width, at least 1, often 3
   int depth ;            // Number of recursions, 0 is axiom
   int bad_rule ;         // Flags if a bad rule
   double angle ;         // Turning angle in degrees, 0-90
   double shrink ;        // Shrink factor 0-1, typically 0.5-0.8 or so
   char axiom[MAX_RULE+1] ;
   char primary[MAX_RULE+1] ;
   char secondary[MAX_RULE+1] ;
   } AG_PARAMS ;

typedef struct AG3D_Params {
   int nrows ;
   int ncols ;
   int width ;            // Initial line width, at least 1, often 3
   int depth ;            // Number of recursions, 0 is axiom
   int bad_rule ;         // Flags if a bad rule
   double angle ;         // Turning angle in degrees, 0-90
   double shrink ;        // Shrink factor 0-1, typically 0.5-0.8 or so
   double stepsize ;      // Only for outline of filled plane; fraction of F size
   double azimuth ;       // CCW rotation from seeing object from the -Y axis
   double elevation ;     // Elevation 0-90 degrees above the XY plane
   int n_axiom ;          // Number of operations in axiom
   int *axiom ;
   int n_erp ;            // N of operations in edge replacement production
   int *erp ;             // It is here
   int n_macros ;
   char macro_name[MAX_PRODUCTIONS][MAX_NAME_LENGTH+1] ;
   int macro_nops[MAX_PRODUCTIONS] ;
   char *macro_string[MAX_PRODUCTIONS] ;
   int n_productions ;                                  // Number of named productions
   char prod_name[MAX_PRODUCTIONS][MAX_NAME_LENGTH+1] ; // Name of each
   int prod_nrand[MAX_PRODUCTIONS] ;                    // Number of randomly selected versions of this one
   double prod_prob[MAX_PRODUCTIONS][MAX_RANDOMS] ;     // Probability of each version of production
   int prod_nops[MAX_PRODUCTIONS][MAX_RANDOMS] ;        // Number of operations in opstring
   int *prod_ops[MAX_PRODUCTIONS][MAX_RANDOMS] ;        // The operation string
   int n_colors ;         // Number of colors, up to 10 (0-9)
   int colors[10][3] ;    // RGB of each
   } AG3D_PARAMS ;

typedef struct PrintParams {
   int fraction ;
   int vert_scaling ;
   } PRINT_PARAMS ;


/*
--------------------------------------------------------------------------------

   Image header

--------------------------------------------------------------------------------
*/

typedef struct {
   int type ;        // 1=TON; 2=BMP
   int nr ;          // Number of rows
   int nc ;          // Number of columns
   int nbytes ;      // Number of bytes per pixel
   char *dib ;       // DIB for BMP file (allocated/deallocated)
   char *dibdata ;   // Its data starts here
   int inverted ;    // If BMP, is it bottom-to-top?
   }  IMAGE_HEADER ;

/*
--------------------------------------------------------------------------------

   Image - Abstract base class for all image types

--------------------------------------------------------------------------------
*/

class Image {

public:

   Image () ;                // Pleases compiler; NEVER invoked
   Image ( char *name ) ;    // Called by derived constructors
   virtual ~Image() ;        // Needed so derived destructor called
   int valid () ;
   char *get_name () ;
   int getrows () ;
   int getcols () ;
   virtual int write_bmp ( char *filename ) = NULL ;
   virtual int draw ( HWND hwnd , int printing ) = NULL ;

   int nr, nc ;              // Its dimensions
   unsigned char *img ;      // The image is here
   DIBimage *dib_image ;     // Its DIB for display
   int nbytes ;              // Number of bytes per pixel
   int error_code ;          // An error may have been generated

protected:
   char *name ;              // For identifying it in window title
} ;

/*
--------------------------------------------------------------------------------

   Image8 - 8 bit grayscale Image

--------------------------------------------------------------------------------
*/

class Image8: public Image {

public:

   Image8 () ;        // Default constructor, never called
   ~Image8 () ;
   Image8 ( ER_Params *params ) ;
   Image8 ( AG_Params *params ) ;
   int write_bmp ( char *filename ) ;
   int draw ( HWND hwnd , int printing ) ;
} ;

/*
--------------------------------------------------------------------------------

   Image24 - 24 bit true color Image

--------------------------------------------------------------------------------
*/

class Image24: public Image {

public:

   Image24 () ;        // Default constructor, never called
   ~Image24 () ;
   Image24 ( AG3D_Params *params ) ;
   int write_bmp ( char *filename ) ;
   int draw ( HWND hwnd , int printing ) ;
} ;

/*
--------------------------------------------------------------------------------

   DIBimage - This is a DIB manipulation class

--------------------------------------------------------------------------------
*/

class DIBimage {

public:

   DIBimage () ;                       // Default constructor (never called)
   DIBimage ( int nrows , int ncols , int nbytes , unsigned char *image ) ;
   ~DIBimage () ;
   int draw ( HWND hwnd , int printing ) ;
   int valid () ;

private:
   int nr ;        // Number of rows
   int nc ;        // Number of columns
   int nb ;        // Bytes per pixel (1 or 3 now)
   int rgb_size ;  // Number of RGBQUAD entries in bit_map_info
   int row_bytes ; // nc * nb padded (if needed) to LONG boundary for img
   BITMAPINFO *bit_map_info ;
   BITMAPINFOHEADER *bit_map_info_header ;
   RGBQUAD *rgb_quad ;
   unsigned char *img ; // The image is here
} ;
