/*
 * OSD Test plugin for the Video Disk Recorder
 *
 * osdtest256.c: main source file
 *
 * See the README file for copyright information and how to reach the author.
 */

#include <vdr/plugin.h>

static const char *VERSION        = "0.1.0";
static const char *DESCRIPTION    = "256 color, full-screen OSD test pattern";
static const char *MAINMENUENTRY  = "256 color OSD test";


class cOsd256 : public cOsdObject {
private:
  cOsd *osd;
public:
  cOsd256(void) { osd = NULL; }
  ~cOsd256(void) { delete osd; }
  virtual void Show(void);
  virtual eOSState ProcessKey(eKeys Key);
};

void cOsd256::Show(void)
{
  osd = cOsdProvider::NewOsd(60, 40);
  if (osd)
  {
      tArea Area = { 0, 0, 599, 499, 8 };
      if (osd->CanHandleAreas(&Area, 1) != oeOk)
      {
          // Set 1MB area
          Area.x2 = 359;
          Area.y2 = 251;
      }
      osd->SetAreas(&Area, 1);
      osd->DrawRectangle(0, 0, Area.x2, Area.y2, clrGray50);

      int w = Area.Width() / 60;
      int h = Area.Height() / 5;
      for (int i = 0; i < 60; i++)
          osd->DrawRectangle(w*i,  0,w*(i+1), h-1, 0xff000000+0x040404*(60-i));
      for (int i = 0; i < 60; i++)
          osd->DrawRectangle(w*i,  h,w*(i+1),2*h-1, 0xff000000+((15+i*4)<<16));
      for (int i = 0; i < 60; i++)
          osd->DrawRectangle(w*i,2*h,w*(i+1),3*h-1, 0xff000000+((15+(60-i)*4)<<8));
      for (int i = 0; i < 60; i++)
          osd->DrawRectangle(w*i,3*h,w*(i+1),4*h-1, 0xff000000+(15+i*4));
      for (int i = 0; i < 60; i++)
          osd->DrawRectangle(w*i,4*h,w*(i+1),5*h-1, 0xff000000+0x040404*(60-i));

      osd->Flush();
  }
}

eOSState cOsd256::ProcessKey(eKeys Key)
{
  eOSState state = cOsdObject::ProcessKey(Key);
  if (state == osUnknown)
  {
      switch (Key & ~k_Repeat)
      {
          case kOk:
          case kBack:
 	      return osEnd;

          default:
              return state;
       }

       osd->Flush();
       state = osContinue;
   }

  return state;
}


class cPluginOsdTest256 : public cPlugin {
public:
  cPluginOsdTest256(void) {};
  virtual ~cPluginOsdTest256() {};
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return DESCRIPTION; }
  virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
  virtual cOsdObject *MainMenuAction(void) { return new cOsd256; }
};


VDRPLUGINCREATOR(cPluginOsdTest256); // Don't touch this!
