
//---------------------------------------------------------------------------
#ifndef HSClassH
#define HSClassH
//---------------------------------------------------------------------------

#define DEFAULT_FRAMES 0         // default to no frame blits
#define MAJOR_VERSION_NUMBER  27 // Position in VERSION_STRING to check during imports.
                                 // All file format changes are major version updates
#define LATEST_VERSION '3'

// Note: data in hotspot file is byte aligned.  When reading FontStyle, this can cause problms.  Either set the compiler to
//       byte align data or will need to account for sizeof (HSFixedData) being larger due to data alignment.  For example,
//       by default the data is double word aligned so the structure will be 3 bytes larger than it seems.  This is
//       important when reading the hotspot file if the whole strcture is to be read as a block.

// This structure has been declared to map directly onto the fixed sized elements of the hotspot so they can be read in
// as a single block.  The other members of the hotspot are of variable size so need to be read individually in HSData
struct HSFixedData { int    ID;              // Hotspot ID as defined in editor
                     int    NumPoints;       // Number of points in the hotspot
                     int    TextLength;      // Length of the text string
                     int    BlitLeft;        // Blit left
                     int    BlitTop;         // Blit Top
                     int    CentreX;         // Centre of hotspot
                     int    CentreY;         // Centre of hotspot
                     int    Tag;             // Spare
                     int    Flags;           // General
                     TColor PrimaryColour;   // Colour of segment if is to be flooded
                     TColor SecondaryColour; // Colour of segment if is to be flooded
                     int    LabelLeft;       // Left pos of hotspot label
                     int    LabelTop;        // Top pos of hotspot label
                     int    FontSize;        // Label font size
                     int    FontNameLen;     // Label font name
                     TColor FontColour;      // Label font colour
                     TFontStyles FontStyle;  // Have to put this at end of ints as it causes misallignment as is only 1 byte
                   };

// This structure contains the fixed block data as a structure so the block can be read in one go.  The rest of its members
// that are read from the file are a variable size do need to read individually.
struct HSData { HSFixedData HSFixed;
                char  *pText;             // Hotspot text as entered in editor
                POINT *pPtArray;          // Pointer that will point to an array of point structs defining the hotspot shape
                char  *FontName;          // Hotspot label font name
                TForm *DestForm;          // Address of the form to interact with (not read from file)
                int    bltNumFrames;      // Number of images in the TList holding various blit states (not read from file)
                AnsiString BlitDirectory; // Dir of where the blit is help for this hotspot
               };



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                         //
// THotSpot class                                                                                                          //
//                                                                                                                         //
// All the functionality for a single hotspot                                                                              //
//                                                                                                                         //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class THotSpot
{
  protected:
  int  mID;                // ID as defined in editor
  int  mNumPoints;         // Number of points in the hotspot
  int  mBlitLeft;          // Blit left
  int  mBlitTop;           // Blit Top
  int  mCentreX;           // Centre of hotspot as defined in editor
  int  mCentreY;           // Centre of hotspot as defined in editor
  int  mTag;               // Spare - general int entered in editor
  int  mFlags;             // Spare - general int entered in editor
  TColor mPrimaryColour;   // A colour associated with the hotspot defined in the editor for flood or outline
  TColor mSecondaryColour; // Another colour associated with the hotspot defined in the editor
  AnsiString  mText;       // Hotspot text string as defined in the editor
  POINT      *mpPtArray;   // Pointer to array of points defining the hotspot shape

  TImageList        *mbltStrip;     // Pointer to image list holding blit strip for this hotspot
  Graphics::TBitmap *mbmpBlitFrame; // Use to extract a single frame from the blot strip for transparent blits or blit drag

  int         mbltNumFrames;        // Number of frames in the blitstrip
  bool        mHSEnabled;           // Hotspot active or not - just a flag
  bool        mHSHot;               // Is its region enabled
  TForm      *mpfmDest;             // Form with which hotspot interacts
  HRGN        mhPolyRegion;         // HRGN is a handle to a region in memory
  TLabel     *TextLabel;            // Hotspot label - holds text defined in editor

  Graphics::TBitmap *THotSpot::LoadJPEG(AnsiString FileName);

  public:
  THotSpot(HSData &InitVals);       // Constructor builds a hotspot from the structure passed in
  ~THotSpot();

  // General member (interface) functions
  bool InRegion(int X, int Y);          // true if mouse pos in PolyRegion
  void FloodIt(TColor Colour=clWhite);  // Flood the hot spot in any colour but default to white as you can usually see this
  void OutlineIt(TColor Colour=clBlack, int Thickness=1);// Outline hotspot.  Use black def as fill is white
  void BlitImage(int bltState, bool Transparent=false);  // blit frame bltState from blit strip onto form


  // Getters
  bool   Enabled()       { return mHSEnabled;   }   // return whether hotspot is enabled or not
  bool   IsHot()         { return mHSHot;       }   // Check is detection enabled or not
  int    GetID()         { return mID;          }   // Get the hotspot ID as defined in the editor
  int    GetBlitLeft()   { return mBlitLeft;    }   // Get blit x pos as defined in editor
  int    GetBlitTop()    { return mBlitTop;     }   // Get blit y pos as defined in editor
  int    GetFlags()      { return mFlags;      }   // Get flag val as defined in editor
  int    GetTag()        { return mTag;         }   // Get flag val defined in editor
  int    GetCentreX()    { return mCentreX;     }   // Get hotspot centre X as defined in editor
  int    GetCentreY()    { return mCentreY;     }   // Get hotspot centre Y as defined in editor
  int    GetNumPoints()  { return mNumPoints;   }   // Get num points in hotspot
  HRGN   GetPolyRegion() { return mhPolyRegion; }   // Get the hotspots windows region

  TPoint *GetPtArray()         { return (TPoint *) mpPtArray;        } // Get points array that defines hotspot shape
  TPoint GetBlitPos()          { return TPoint(mBlitLeft, mBlitTop); } // Get blit x,y pos as defined in editor
  TColor GetPrimaryColour()    { return mPrimaryColour;              } // Get Primary colour as defined in editor
  TColor GetSecondaryColour()  { return mSecondaryColour;            } // Get Secondary colour as defined in editor
  AnsiString GetText()         { return mText;                       } // Get the hotspot text string defined in the editor

  TRect GetBlitSize(); // Return the rectangle bounding a single frame of the blit strip
  Graphics::TBitmap *GetBlitFrame(int BlitState);  // Get the requested frame from the image list and return as a bitmap

  // Setters
  void SetFlags(int State)  { mFlags |= State;    }       // Change flag val defined in editor
  void SetTag(int State)    { mTag=State;         }       // Change tag val defined in editor
  void Enable()             { mHSEnabled = true;  }       // enable hotspot - just a flag to be checked - still hot
  void Disable()            { mHSEnabled = false; }       // disable hotspot
  void MakeHot()            { mHSHot=true;        }       // Enable detection of this hotspot
  void MakeCold()           { mHSHot=false;       }       // Disable detection of this hotspot
  void ShowLabel()          { TextLabel->Visible=true;}   // Show hotspot label
  void HideLabel()          { TextLabel->Visible=false; } // Hide hotspot label

};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                         //
// THotSpotList class                                                                                                      //
//                                                                                                                         //
// Builds a list of hotspots by reading details from hotspot file, creating a hotspot, passing data read from file to      //
// hotspot object.                                                                                                         //
//                                                                                                                         //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class THotSpotList
{
  protected:
  int    mNumPolysInFile; // Number of hotspots held in the hotspot file (therefore number of list elements)
  int    mVersionNumber;  // Major version number of loaded file
  char   mszVersion[32];  // Version string to identify editor version used to create hotspot file
  bool   mScanStartToEnd; // if true, scan from list[0] else scan backwards down to 0


  Graphics::TBitmap *mpbmpBackground;  // Holds the backdrop image
  void mCreateHotSpots(TForm *fm,AnsiString  bmpFilename, AnsiString  hspFilename, int NumFrames, AnsiString BlitDir);
  Graphics::TBitmap *THotSpotList::LoadJPEG(AnsiString FileName,Graphics::TBitmap *Image);

  public:
  THotSpot  **HotSpot; // Pointer to array of pointers to hotspot objs. User's entry point to the hotspot list

  // Constructor and destructor
  THotSpotList(TForm *fm,AnsiString  bmpFilename, int NumFrames=DEFAULT_FRAMES, AnsiString  hspFilename="", AnsiString BlitDir="");
  ~THotSpotList();

  // General member functions
  int GetHotSpot(int X, int Y);  // return index of hotspot or -1 if not in list.
  bool ScanStartToEnd(bool Dir); // Set new scan direction and return previous scan direction
  void EnableAllHotSpots();      // Enable all hotspots by setting each hotspot enabled member
  void DisableAllHotSpots();     // Disable all hotspots by clearing each hotspot enabled member

  // Getters
  bool HotSpotActive(int HsNum); //{ return ((HsNum >=0) && HotSpot[HsNum]->Enabled()); } // true if a hotspot & enabled
  bool IsScanningStartToEnd()   { return mScanStartToEnd;    } // Get list scan direction
  int  NumHotSpots()            { return mNumPolysInFile;    } // Get number of hotspots in list
  int  VersionNumber()          { return mVersionNumber;     } // Get major version number of editor used to create file

  Graphics::TBitmap *GetBackground() { return mpbmpBackground; } // Get the address of the background bitmap
  AnsiString GetVersionString()      { return mszVersion;      } // Get the version string provided by the editor

};

#endif
