#ifndef BIWAK_GRAPHIC_DISPLAY_HPP
#define BIWAK_GRAPHIC_DISPLAY_HPP
//----------------------------------------------------------------------------
///
/// \brief  Abstract graphical display
///
///         See implementation files for further information.
///
/// \date   20151226
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <biwak/font.h>       // TFont
#include <biwak/graphic_types.h>       // TRgb


//extern const TRgb black;
extern const TRgb blue, green, red, yellow, white, magenta, cyan, grey;
extern const TRgb lightGreen, lightBlue, lightRed;
extern const TRgb lightGrey;
extern const TRgb darkGreen, darkBlue, darkRed, darkGrey, darkDarkGrey;
extern const TRgb bordeaux;
extern const TRgb darkDarkViolet;

#define RGBMAX    0xFF
constexpr const TRgb black {.red=0,    .green=0,   .blue=0};
constexpr const TRgb __black  {.red=0,    .green=0,   .blue=0};
constexpr const TRgb __lightGrey {.red=RGBMAX/2, .green=RGBMAX/2,         .blue=RGBMAX/2};
// constexpr const TRgb lightGrey {.red=RGBMAX/2, .green=RGBMAX/2,         .blue=RGBMAX/2};

enum ETextFlags
{
   eTextFlagsNone=0x0,
   eTextFlagsHCenter=0x1,
   eTextFlagsHRAlign=0x2,
   eTextFlagsVCenter=0x4,
   eTextFlagsHVCenter=eTextFlagsVCenter | eTextFlagsHCenter,
   eTextFlagsBold=0x8,
   eTextFlagsItalic=0x10,
};

bool operator==(const TRgb &a, const TRgb &b);

//---Declaration--------------------------------------------------------------


class CGraphicDisplay: public CFont
{

   protected:
      int yPos, xPos;
      int m_ySize, m_xSize;

      TRgb fg, bg;
      bool drawBackground;

      bool mirrored;

      typedef TRgb TRgbLine[320];
      // TRgb m_line[320][2];
      TRgbLine m_line;
      TRgb lineColor;
      int lineSize;

      enum class EPixelStream
      {
         stopped,
         started
      };
      EPixelStream pixelStream;

   public:

      CGraphicDisplay(int width = 128, int height = 128);
      ~CGraphicDisplay();
      void reset();
      void putString(const char *string);
      void putChar(const char ch);
      void clear();
      void drawMatrix(int x, int y, int xSize, int ysize, int fontBytesPerLine, const void *matrix);
      int width()
      {
         return(m_xSize);
      }
      int height()
      {
         return(m_ySize);
      }
      virtual void clear(const TRgb color);
      void gotoxy(int x, int y, bool translate = true );
      virtual void gotoxyHw()=0;
      virtual void setFrame(int x1, int y1, int x2, int y2)=0;

      void setFg( const TRgb &color ){ fg = color; };
      void setBg( const TRgb &color ){ bg = color; };
      const TRgb &getFg( ){ return( fg ); };
      const TRgb &getBg( ){ return( bg ); };
      void setDrawBackground(bool _drawBackground)
      {
         drawBackground=_drawBackground;
      }
      void prepareLine(const TRgb startColor, int size);
      void drawText(int x, int y, const char *text, int eTextFlags=eTextFlagsNone);
      void drawLines(int x, int y, const char* const text[]);
      void drawBar(int x1, int y1, int x2, int y2, const TRgb color);
      void drawBar(int x1, int y1, int x2, int y2, const TRgb startColor, const TRgb endColor);
      void drawPixel(int x, int y, const TRgb &color );
      void drawLine(int x0, int y0, int x1, int y1, const TRgb &color);
      void drawHLine(int x0, int y0, int x1, const TRgb &color);
      void drawVLine(int x0, int y0, int y1, const TRgb &color);
      void drawRect(int x0, int y0, int x1, int y1, const TRgb &color);
      void drawCircle(int x0, int y0, int radius, bool filled, const TRgb &color);
      void drawCircleHLine(int x0, int y0, int radius, bool filled, const TRgb &color);
      void drawCircleBlock(int x0, int y0, int radius, bool filled, const TRgb &color);
      virtual bool setRotation(bool rot)=0;

      virtual void drawPixels( const TRgb *pixels, int count) = 0;
      virtual void drawPixel( const TRgb color) = 0;
      virtual void pixelStreamStart(){};
      virtual void pixelStreamStop(){};
};


//---fin----------------------------------------------------------------------
#endif // ? ! BIWAK_GRAPHIC_DISPLAY_HPP
