//Copyright (C) 2007 SiegeLord
//See ReadMe.txt and License.txt for copying information

#include "engine.h"

#ifndef GUI_NUM_TYPES
#define GUI_NUM_TYPES 10
#endif

enum EGUIType
{
	dummygui_type,
	keydummy_type,
	button_type,
	textbox_type,
	usergui_type
};

struct SGUIItem
{
	SGUIItem()
	{
		type = dummygui_type;
	};

	virtual ~SGUIItem() {};
	virtual int Handle() {return 0;};
	virtual void Draw() {};

	EGUIType type;

	int x;
	int y;
	int w;
	int h;

	int net_x;
	int net_y;

	bool active;
	bool visible;

	vector<SGUIItem*> children;
	SGUIItem* parent;
};

struct SKeyDummy : SGUIItem
{
	SKeyDummy()
	{
		type = keydummy_type;
	}
	virtual ~SKeyDummy() {};
	virtual int Handle();
	virtual void Draw() {};
};

struct SButton : SGUIItem
{
	SButton()
	{
		type = button_type;
	}

	virtual ~SButton();
	virtual int Handle();
	virtual void Draw();

	const char* text;
	int return_value;
	FONT* fnt;
	zColor color;
	float factor;

	zColor color_hover;
	zColor color_press;
	zColor color_up;
	float time;

	void SetText(const char* Text)
	{
		delete[] text;
		text = strdup(Text);
	}
};

struct STextBox : SGUIItem
{
	STextBox()
	{
		type = textbox_type;
	}

	virtual ~STextBox();
	virtual int Handle() {return 0;};
	virtual void Draw();

	const char* text;
	FONT* fnt;
	zColor color;
	int h_align;
	int v_align;

	void SetText(const char* Text)
	{
		delete[] text;
		text = strdup(Text);
	}
};

//use for the return values of gui items... this is a mask obviously, so only about 30 different
//values can be used
int GetMask(int n);

//centers the mouse on the first child gui item of the parameter
void CenterMouseOnTheFirst(SGUIItem* item);

//if parent is present, this is added as one of its children


SKeyDummy* CreateKeyDummy(SGUIItem* parent, int x, int y, int w, int h);

SButton* CreateButton(SGUIItem* parent, int x, int y, int w, int h, int ret, const char* text
				 	 , FONT* fnt);

STextBox* CreateTextBox(SGUIItem* parent, int x, int y, int w, int h, const char* text,
				  int v_align, int h_align, zColor color, FONT* fnt);

SGUIItem* InitGUIItem(SGUIItem* item, SGUIItem* parent, int x, int y, int w, int h);

int HandleGUI(SGUIItem* item);
//handles the logic of the gui and all of its children (also updates position
int DoGUILogic(SGUIItem* item, int x, int y);
//draws the gui and its children
void DrawGUI(SGUIItem* item);
//destroys the gui and its children
void DestroyGUI(SGUIItem* item);
