/**
 *  GraphTFT plugin for the Video Disk Recorder 
 * 
 *  display.h - A plugin for the Video Disk Recorder
 *
 *  (c) 2004 Lars Tegeler, Sascha Volkenandt  
 *
 * This code is distributed under the terms and conditions of the
 * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
 *
 * $Id: display.h,v 1.11 2004/05/25 08:41:15 tegeler Exp $
 *
 **/

#ifndef __GTFT_DISPLAY_H
#define __GTFT_DISPLAY_H

#include <map>
#include <string>
#include <vector>
#include "renderer.h"
#include "theme.h"
#include <vdr/thread.h>
#include <vdr/status.h>
#include <vdr/tools.h>

using std::map;
using std::string;
using std::vector;

class cGraphTFTDisplay: public cStatus, cThread {
public:
	enum { MaxTabs = 6 };

	enum DisplayMode {
		NormalTV     = 0x01,
		NormalRadio  = 0x02,
		NormalMask   = 0x07,
		ReplayNormal = 0x08,
		ReplayMP3    = 0x10,
		ReplayDVD    = 0x18,
		ReplayMask   = 0x38,
		OsdMenu      = 0x40,
		OsdMask      = 0xc0,
	};

private:
	cTimeMs	timeMs;

	int tabs[MaxTabs+1];
	int charInTabs[MaxTabs+1];

	// some structures and types
	typedef vector <string> Strings;

	struct RecordingInfo {
		string name;
		const cDevice *device;
	};
	typedef vector <RecordingInfo> Recordings;
	
	struct ReplayInfo {
		DisplayMode lastMode;
		string name;
		string folder;
		cControl *control;
	};

        struct MenuItem {
		string text;
		string tabs[MaxTabs];
	};
	
	struct MenuInfo {
		DisplayMode lastMode;
		int currentPos;
		int currentPosLast;
		int topPos;
		string title;
		string current;
		string buttons[4];
		string text;
		int textScroll;
		vector<MenuItem> items;
	};

	// renderer
  Renderer *_render;

	// update thread
	bool _active;
	int _updateIn;
	int _Dumped;
	int _recordingIn;
	int _volumeIn;
	int _messageIn;
	int _delayIn;
	cMutex _mutex;
	cCondVar _doUpdate;

	// animation stuff
	bool _animation;
	int _displayFrame;
	int _frameIn;

	// display contents
	DisplayMode _mode;
	bool _mute;
	int _channel;
	int _volume;
	int _showRecording;
	time_t _presentTime;
	time_t _followingTime;
	string _channelText;
	string _channelInfo;
	string _presentTitle;
	string _presentSubtitle;
	string _followingTitle;
	string _followingSubtitle;
	string _message;
	Recordings _recordings;
	ReplayInfo _replay;
	MenuInfo _menu;
	cGraphTFTThemeItem *_pSelect;
	map <string,string> _menuImageMap;

	// init pbp stuff
	bool _pbpActive;
	cDevice *_dev;
	const cChannel *_chan;

protected:
	// update thread
	virtual void Action();

	// helper functions
	bool StoppedTimer(const char *Name);
	void UpdateProgramme();

	// status interface
	virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber);
	virtual void OsdChannel(const char *Text);
	virtual void OsdProgramme(time_t PresentTime, const char *PresentTitle, const char *PresentSubtitle, time_t FollowingTime, const char *FollowingTitle, const char *FollowingSubtitle);
	virtual void SetVolume(int Volume, bool Absolute);
#if VDRVERSNUM >= 10338
	virtual void Replaying(const cControl *Control, const char *Name, const char *FileName, bool On);
	virtual void Recording(const cDevice *Device, const char *Name, const char *FileName, bool On);
#else
	virtual void Recording(const cDevice *Device, const char *Name);
	virtual void Replaying(const cControl *Control, const char *Name);
#endif
	virtual void OsdStatusMessage(const char *Message);
	virtual void OsdTitle(const char *Title);
	virtual void OsdItem(const char *Text, int Index);
	virtual void OsdCurrentItem(const char *Text);
	virtual void OsdClear(void);
	virtual void OsdHelpKeys(const char *Red, const char *Green, const char *Yellow, const char *Blue);
	virtual void OsdTextItem(const char *Text, bool Scroll);

public:
	cGraphTFTDisplay();
	~cGraphTFTDisplay();

  int Init( const char * dev, const char * cfgDir);
	
	// thread stuff
	bool Start() { return cThread::Start(); } //imported from cThread
	void Stop();
	bool Active() const { return _active; }
 
	// display stuff
  void Display(int section);
  void DisplayImage(int x, int y, int width, int height, int transperents, string image);
  void DisplayImageFile(int x, int y, int width, int height, int transperent, string file, string image);
  void DisplayImageCover(int x, int y, int width, int height, int transperent, string file);
  void DisplayDate(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayDateOnly(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayTimeOnly(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayText(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines, string text);
  void DisplayChannelName(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayChannelNameOnly(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayChannelNumber(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayRectangle(int x, int y, int width, int height, int transperent, int red, int green, int blue);
  void DisplayLogo(int x, int y, int width, int height, int transperent, string image ,string type, int animated, int delay, int count);
  void DisplayPresentTitle(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayPresentSubtitle(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayPresentTime(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayFollowingTitle(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayFollowingSubtitle(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayFollowingTime(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayTimebar( int x, int y ,int width, int height,int red, int green, int blue, int transperents , int sw);
  void DisplayMessage(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayRecording(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayReplay(int Progress, int Current, int Total); 
  void DisplayMenuTitle(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines );
  void DisplayMenuText(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines );
  void DisplayMenuTextBackground(int x, int y, int width, int height, int transperent, string image);
  void DisplayMenu(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines, int redSelect, int greenSelect, int blueSelect, int transperentsSelect, string fontSelect, int sizeSelect, int alignSelect, int linesSelect, string imageItem, string imageItemSelectedFront, string imageItemSelectedBack );
  void DisplayMenuButton(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines, int buttonNumber);
  void DisplayMenuButtonBackground(int x, int y, int width, int height, int transperent, string image, string imageOff, int buttonNumber);
  void DisplayVolumebar( int x, int y ,int width, int height, int red, int green, int blue, int transperent  );
  void DisplaySymbols(int x, int y, int width, int height, int transperent, string path, string path2, int symbol);
  void DisplayRecordingSymbol(int x, int y, int width, int height, int transperent, string path, string path2);
  void DisplayReplayName(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayReplayFolder(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayReplayProcessBar(int x, int y ,int width, int height, int red, int green, int blue, int transperents);
  void DisplayReplayCurrent(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayReplayTotal(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayReplayRemaining(int x, int y, int width, int height,int red, int green, int blue, int transperents, string font, int size, int align, int lines);
  void DisplayMessageBackground(int x, int y, int width, int height, int transperent, string image);
  void DisplayVolumeBackground(int x, int y, int width, int height, int transperent, string image);
  void DisplayVolumeMuteSymbole(int x, int y, int width, int height, int transperent, string image, string image2);
  void DisplayShow();
  void DisplayClear();

	//Tabs
	int Tab(int n) {return (n >= 0 && n <= MaxTabs) ? tabs[n] : 0;}
	const char *GetTabbedText(const char *s, int Tab);
	virtual void SetTabs(int Tab1, int Tab2 = 0, int Tab3 = 0, int Tab4 = 0, int Tab5 = 0);

};
#endif // __GTFT_DISPLAY_H
