#ifndef PFROGCONSOLE_INCLUDE_H___
#define PFROGCONSOLE_INCLUDE_H___

#define MAXBUFFERLINES 5000
#define NUMVISIBLELINES 17
#define CHARHEIGHT 7
#define LINEBUFFER 1024

#ifdef _DEBUG
	#define CONSOLE_DEBUG
#else
	#undef CONSOLE_DEBUG
#endif

#ifdef FORCE_CONSOLE_ENABLE
	#define CONSOLE_DEBUG
#endif

#define PFROGCONSOLE_VERSION "1.24 - 06/08/2007"

#include <stdio.h>
#include <PocketFrog/PocketFrog.h>

using namespace Frog;


class PFrogConsole
{

private:
	unsigned long SESSIONID;	// autogenerated

	long _VersionTimeout;

	//charset
	Surface *carsurf[256];
	// the file name
	TCHAR filename[255];
	// we want to log also on file
	bool logonfile;

	// opened console?
	bool consoleopened;

	int drawchar(Display *display, int x, int y, char car);

	// console width
	int consoleWidth;

	// console lines
	struct lines {
		char line[LINEBUFFER];
		unsigned char level;
		struct lines *next;
	};
	struct lines *lineshead, *lastline;
	unsigned int linescount;

	// fixed lines
	struct fixedlines {
		unsigned short ID;
		int x, y;
		char line[LINEBUFFER];
		bool drawalways;
		struct fixedlines *next;
	};
	struct fixedlines *fixedlineshead;
	unsigned int fixedlinescount;

	bool logHeader;

	unsigned char LOGLEVEL;

	// line number stuff
	bool _addLineNumber;
	unsigned long consoleAutoIncNumber;

	// from which line we want to draw
	unsigned long drawStartLine;

	// draw arrows
	void DrawArrow(Display *display, int x, int y, bool upArrow, bool clicked);
	bool stylusDownOnUpArrow, stylusDownOnDownArrow, stylusDownOnBackBar;
	unsigned int lastMouseY;
	unsigned int tickMouseCounter;
	unsigned int _displayWidth;

	// private routines for drawing scrollbars
	void DrawScrollBars(Display *display);

	// console addline enabled?
	bool consoleAddLineEnabled;


	static PFrogConsole* instance_ptr_;
	PFrogConsole() { };

public:

	static PFrogConsole* instance()
    {
            if (instance_ptr_ == NULL)
            {
                    instance_ptr_ = new PFrogConsole;
            }

            return instance_ptr_;
    }

	~PFrogConsole(void);

	void init(unsigned char curlogLevel, Display *display, Pixel charcolor, bool logOnFile, bool addLineNumber);
	void destroy();
	void drawtext(Display *display, int x, int y, char *pattern, ...);
	void addconsole(unsigned char level, char *pattern, ...);
	void logfile(unsigned char level, char *pattern, ...);
	void draw(Display *display);
	void StylusUp( Point stylus );
	void StylusDown( Point stylus );
	void StylusMove( Point stylus );
	unsigned short addfixedline(bool drawalways,int x, int y, char *pattern, ...);
	void setfixedline(unsigned short ID, char *pattern, ...);
	void SetLogHeader(bool s);
	void EnableConsoleAddline(bool e);
	void OpenConsole(bool open);
};

#endif