#ifndef GRAPHIX_HH
#define GRAPHIX_HH

//#include "mystruct.hh"
#include "typedef.hh"
#include "video.hh"
#include "bitmap.hh"
#include "palette.hh"

class Graphix
{
   public:
      // MODE SETTING METHOD
      WORD SetVideoMode(BYTE mode, UWORD viewport = 0); //Returns the number of pages available in video memory after resolution settings
      UWORD GetScreenWidth(void);
      UWORD GetScreenHeight(void);

      // PALLETTE METHODS
      void SetPalette(Palette &myPal);
      void GetPalette(Palette &myPal);
      void GetBIOSPalette(Palette &myPal);
      
      // DRAWING METHODS
      void PutPixel(WORD x, WORD y, UBYTE color);
      UBYTE GetPixel(WORD x, WORD y);
      void SetDrawPage(UDWORD thePage);
      void SetVisiblePage(UDWORD thePage);
      void V_Line(WORD x, WORD top_y, WORD len, UBYTE color);
      void H_Line(WORD left_x, WORD y, WORD len, UBYTE color);
      void Box(WORD x1, WORD y1, WORD x2, WORD y2, UBYTE color);
      void FilledBox(WORD x1, WORD y1, WORD x2, WORD y2, UBYTE color);
      void Circle(WORD x, WORD y, WORD r, UBYTE color);
      void FilledCircle(WORD x, WORD y, WORD r, UBYTE color);
      void Line(WORD x1, WORD y1, WORD x2, WORD y2, UBYTE color);
      
      // VIDEO MEMORY METHODS
      void ClearScreen(UBYTE color);
      void ClearVideoMemory(UBYTE color);
      void WaitVerticalRetrace(void);
      void ScrollY(WORD direction);
      void SetScrollingSpeed(UWORD ySpeed);
      void ClearScrollingY(void);
      
      // BITMAP METHODS
      BYTE LoadRAW(char *filename, Bitmap &myBitmap, Palette &myPal, UDWORD xSize, UDWORD ySize, WORD palStart, UBYTE transparent, UBYTE transpColor);
      BYTE LoadRAWTile(char *filename, Bitmap myBitmaps[], Palette &myPal, UDWORD picXSize, UDWORD picYSize, UDWORD tileXSize, UDWORD tileYSize, WORD palStart, WORD nrOfTiles, UBYTE transparent, UBYTE transpColor);
      BYTE SaveRAW(char *filename, Bitmap &myBitmap, Palette &myPal, WORD palStart);
      BYTE LoadPCX(char *filename, Bitmap &myBitmap, Palette &myPal, UBYTE transparent,UBYTE transpColor);
      BYTE LoadPCXTile(char *filename, Bitmap myBitmaps[], Palette &myPal, UDWORD tileXSize, UDWORD tileYSize, WORD nrOfTiles, UBYTE transparent, UBYTE transpColor);
      BYTE SavePCX(char *filename, Bitmap &myBitmap, Palette &myPal);
      
      void DrawBitmap(WORD x, WORD y, Bitmap &myBitmap);
      void GetRAMBitmap(WORD x, WORD y, WORD width, WORD height, Bitmap &mySrc, Bitmap &myDst);
      WORD ConvertSolidToTransparentBitmap(Bitmap &myBitmap, UBYTE transpColor);
      void ConvertTransparentToSolidBitmap(Bitmap &myBitmap);
      WORD FlipBitmapVertical(Bitmap &myBitmap);
      WORD FlipBitmapHorizontal(Bitmap &myBitmap);
      void GetScreenBitmap(WORD x,WORD y,WORD width,WORD height,Bitmap &myBitmap);
      WORD ScaleBitmap(Bitmap &srcBmp, Bitmap &dstBmp, WORD newXSize, WORD newYSize);
      WORD ScaleBitmapX(Bitmap &srcBmp, Bitmap &dstBmp, WORD newXSize);
      WORD ScaleBitmapY(Bitmap &srcBmp, Bitmap &dstBmp, WORD newYSize);
      
      // TEXT METHODS
      void Print(WORD x, WORD y, BYTE text[]);
      WORD SetFontColor(UBYTE color);
      UBYTE GetFontColor(void);
      Graphix(void);
      ~Graphix(void);
   private:
      void SetText(void);
      void ConvPlan2LinBitmap(Bitmap &myBitmap);
      void ConvLin2PlanBitmap(Bitmap &myBitmap);
      WORD LoadSystemFonts(UBYTE theMode);
      
      UBYTE myCurrentMode;
      WORD myCurrentScreenWidth;
      Video *myVideoMode; 
      Bitmap* myFonts;
      UBYTE colorTable[768];
      UBYTE myFontColor;
};

#endif
