#ifndef _VGUI_CONTROLGRAB_H
#define _VGUI_CONTROLGRAB_H

/* controlgrab.h */
#include "controls.h"
#include "gui/gui.h"

namespace VGUI
{
	class ControlSet
	{
	private:
		string name;
		string type;
		CONTROL ctrl;
		TEXTURE_HANDLE * tex, * tex_sel;

	public:
		ControlSet() { name = ""; type = ""; tex = tex_sel = NULL; }
		ControlSet ( const CONTROL& c, const string& n, const string& t, TEXTURE_HANDLE* tx, TEXTURE_HANDLE* txx )
		  : name(n), type(t), ctrl(c), tex(tx), tex_sel(txx) { }
		~ControlSet() { }
		string GetName() { return name; }
		void SetName( string new_name ) { name = new_name; }
		string GetType() { return type; }
		void SetType( string new_type ) { type = new_type; }
		CONTROL& GetControl() { return ctrl; }
		void SetControl( CONTROL &new_ctrl ) { ctrl = new_ctrl; }
		TEXTURE_HANDLE * GetTex() { return tex; }
		void SetTex( TEXTURE_HANDLE * new_tex ) { tex = new_tex; }
		TEXTURE_HANDLE * GetTexSel() { return tex_sel; }
		void SetTexSel( TEXTURE_HANDLE * new_tex_sel ) { tex_sel = new_tex_sel; }
	};


	class ControlGrab : public Widget
	{
	private:
		void BuildControlVectors();
		void DestroyControlVectors();
		void EditControlsPage( int i );

		TEXTURE_HANDLE add_tex, add_tex_sel;
		TEXTURE_HANDLE key_tex, joy_axis_tex, joy_btn_tex, mouse_btn_tex, mouse_move_tex;
		TEXTURE_HANDLE key_tex_sel, joy_axis_tex_sel, joy_btn_tex_sel, mouse_btn_tex_sel, mouse_move_tex_sel;
		bool l_down, r_down, mbtn_down, adding, pressed;
		bool analog;
		string setting;
		float spacing;
		vector<ControlSet*> local_controls;
		unsigned int selected_icon, pressed_icon, clicked_icon;
		Uint32 add_start;
		bool only_one;
		bool in_details;
		string parent_page_name;

	public:
		ControlGrab();
		ControlGrab( Widget *w );
		~ControlGrab() { DestroyControlVectors(); }

		void Draw();
		void Draw( float opacity );
		void Save();
		bool MouseOver( float x, float y );
		string MousePress( float x, float y );
		string MouseRelease( float x, float y );
		void ResetValue();
		void IncValuePress();
		void DecValuePress();
		void IncValueRelease();
		void DecValueRelease();
		void Press();
		void Release();
		void GrabKey( SDLKey key );
		void GrabMouseMovement( string direction );
		void GrabMouseButton( int button_idx );
		void GrabJoyButton( Uint8 joy_idx, Uint8 joy_btn );
		void GrabJoyMove( Uint8 joy_idx, Uint8 joy_axis, bool joy_positive, float joy_value );
		void SelectIcon( unsigned int new_selected_icon ) { selected_icon = new_selected_icon; }
		void DeleteControl( int i );

		string GetSetting() { return setting; }
		float GetSpacing() { return spacing; }
		bool GetAdding() { return adding; }
		bool GetAnalog() { return analog; }
		bool GetOnlyOne() { return only_one; }
		string GetParentPage() { return parent_page_name; }
		void SetSetting( string new_setting ) { setting = new_setting; BuildControlVectors(); }
		void SetSpacing( float new_spacing );
		void SetAnalog( bool new_analog ) { analog = new_analog; }
		void SetOnlyOne( bool new_only_one ) { only_one = new_only_one; }
		void SetParentPage( string new_parent ) { parent_page_name = new_parent; }
		ControlSet* GetControlSet( int i ) { return local_controls[i]; }
	};
}

#endif // _VGUI_CONTROLGRAB_H
