/*
 * CC OSD for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: ccosd.h,v 1.2 2005/11/02 16:08:26 aegyssus Exp $
 */

#ifndef __CCOSD_H
#define __CCOSD_H

//NTSC screen size
#define OSDWIDTH                 480 //600 // in pixels
#define OSDHEIGHT                390 //420 // in pixels

#define CHAR_WIDTH m_Font->Width('W')
#define CHAR_HEIGHT m_Font->Height()

#include <linux/dvb/frontend.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <vdr/osd.h>
#include <vdr/thread.h>
#include <vdr/status.h>
#include <vdr/channels.h>
#include <vdr/transfer.h>
#include <vdr/osdcontroller.h>

#include "commons.h"
#include "ccreceiver.h"
#include "scroller.h"
class cOsd;
class cSubtitlesPage;
class cMutex;
class cSubtitlesPage;


using namespace NonInteractiveOsdPatch;

typedef struct {
	byte color;
	bool bItalic;	
	bool bUnderline;	
	
	int nX, nY; //character level position		
	CC_Data commands[CC_BUFFER_SIZE];
	int nBufferPos;
} sCcContext;

class cCcOsd: public cThread, public cStatus, public cOsdListener {
private:
  bool m_Active;
  bool m_Enabled;
  cOsd *m_Osd;
  cCcReceiver *m_Receiver;
  const cFont *m_Font;
  byte nChannel;  
  cMutex m_Mutex;

protected:
  virtual void Action(void);
  virtual void ChannelSwitch(const cDevice * device, int channelNumber);
  virtual void Activate(bool On);
  virtual void Show();
  virtual void Hide();
public:
  cCcOsd(void);
  ~cCcOsd();
  void setCCType(int ccType);
  void setActive(bool enabled);

	//virtual void Show(void);
  //virtual eOSState ProcessKey(eKeys Key);

protected:
	bool Process(CC_Data* data, bool bWorkInBuffer);
	bool DoCommand(sCcContext *context, byte hi, byte lo);
	void SetChannel(byte chn);
	void ClearScreen(void);
	bool WriteInBuffer(CC_Data *data, int pos, int len);
	void ClearBuffer(void);
	void ClearLine(byte line, byte pos, int len);
	void SetRollUp(sCcContext *context, int nRollupMode);
	bool PrintLine(sCcContext *cx, char *row, int len);
	bool PrintRollUp(sCcContext *cx, char **text, int lines);
	void InitOSD(void);
	void Restart(); //reattach the receiver
private:		
	bool bWriteInBuffer;
	bool bSkipBuffer;	
	cCcScroller scroller;
	sCcContext *crtContext, *bufferContext;

	bool bTextMode;  
	int nRollup;
};

#endif //__CCOSD_H
