#ifndef _CGUI_H_
#define _CGUI_H_

#include "../App/EngineH.h"
#include "../TextureManager/CTextureManager.h"
#include "CBaseGUI.h"
#include "CImageGUI.h"
#include "CButtonGUI.h"
#include "CLabelGUI.h"
#include "CEditGUI.h"
#include "CCheckBoxGUI.h"
#include "CRadioButtonGUI.h"
#include "CSliderGUI.h"

/*
 *	TYPE_OBJECT :
 *  0 - C_IMAGE_0
 *  1 - C_BUTTON_0
 *  2 - C_CHECKBOX_0
 *  3 - C_RADIOBUTTON_0
 *  4 - C_LABEL_0
 *  5 - C_EDIT_0
 *  6 - C_SLIDER_0
 */

struct TScriptObject
{
	int type_object;				// znaci objekt (BUTTON, LABEL, IMAGE, ...)
	TRect rect;						// velikost objektu
	TRGBi color;					// barva
	std::string text;				// text (plati u EDIT, LABEL)
	std::string group;				// skupina (plati u RADIOBOXU)
	std::string font;				// danej font pro (EDIT, LABEL)
	int size;						// velikost fontu
	
	uint		texture_id;			// id textury pro W_GUI_EDITOR
	std::string name_texture_1;		// cesta k textura 1
	std::string name_texture_2;		// cesta k textura 2
	std::string name_texture_3;		// cesta k textura 3
	std::string name;				// jmeno objektu pro pristup z enginu (misto cisel)

	// data pro slider
	int max_arr, hod_arr, akt_arr;
};

class C_GUI_0
{
private :
	std::vector<C_BASEGUI_0*>	_vBase;
	std::vector<TScriptObject>	_script_object;
	C_BASEGUI_0					*_focus;
	TPoint						_screen;
	C_LOG_FILE					_logFile;

	//**//  Funkce  //**//
	void						_readstr(FILE *f, std::string &str);
	void						_CreateScriptObject(C_TEXTURE_MANAGER_0 *tm, int tmFlag=TM_NONE);
		
public :
	C_GUI_0();
	~C_GUI_0();
	
public :
	void						Add(C_BASEGUI_0 *o);
	void						Render();
	void						RenderText();
	void						Keyboard(bool keys[255]);
	int							MouseClick(int button, int x, int y);
	int							MouseMove(int x, int y);
	inline int					MouseMove(HWND hWnd)
	{
		POINT pMouse;
		GetCursorPos(&pMouse);
		ScreenToClient(hWnd, &pMouse);
		return this->MouseMove(pMouse.x, pMouse.y);
	}
	void						Focus(C_BASEGUI_0 *f) {_focus = f;}

	bool						LoadGUIScript(std::string file_name, C_TEXTURE_MANAGER_0 *tm=NULL, int tmFlag=TM_LINEAR);
	void						SetScreen(float x, float y);
	TRect						PrevedRectNaScreen(TRect rect);
	int							PrevedIntXNaScreen(int x);
	int							PrevedIntYNaScreen(int y);
	void						CreateAktualScriptObject(C_TEXTURE_MANAGER_0 *tm, int tmFlag=TM_NONE) {_CreateScriptObject(tm, tmFlag);}
	void						SetScriptObject(std::vector<TScriptObject> s) {_script_object = s;}
	std::vector<TScriptObject>	GetScriptObject() const { return _script_object; }
	void						DeleteMenu();
	int							GetIterObject(std::string name);
	C_BASEGUI_0*   				GetPointerObject(std::string name)
	{
		if(_vBase.size() == 0) return NULL;
		std::vector<C_BASEGUI_0*>::iterator iter = _vBase.begin() + GetIterObject(name);
		return (C_BASEGUI_0*)(*iter);
	}
};

#endif //_CGUI_H_
