#ifndef _VGUI_PAGE_H
#define _VGUI_PAGE_H

/* page.h */
#include <map>
#include <string>
#include <GL/gl.h>
#include <SDL/SDL.h>
#include "multiplay.h"
#include "textures.h"
#include "font.h"
#include "gamestate.h"
#include "settings.h"
#include "configfile.h"
#include "globals.h"
#include "widget.h"

namespace VGUI
{
	class Page
	{
	public:
		Page( string filename )
		  : path(filename), name(""), cur_obj(0), cancel_obj(0), default_obj(0), num_widgets(0),
		    clicked_obj(10000), is_dialog(false), l_pressed(false), r_pressed(false), has_changes(false)
		  { Init(); }
		//Page( string n, vector<Widget*>& widgets, int d_obj, int x_obj );
		~Page();
		Page( const Page& rhs )
		  : path(rhs.path), name(rhs.name), cur_obj(rhs.cur_obj), cancel_obj(rhs.cancel_obj),
		    default_obj(rhs.default_obj), num_widgets(rhs.num_widgets), clicked_obj(rhs.clicked_obj),
		    is_dialog(rhs.is_dialog), l_pressed(rhs.l_pressed), r_pressed(rhs.r_pressed),
		    has_changes(rhs.has_changes)
		  { Init(); }
		const Page& operator=( const Page& rhs );
		void Draw() { Draw( 1.0 ); }
		void Draw( float opacity );
		void UpWidget();
		void DownWidget();
		void RightWidgetPress();
		void LeftWidgetPress();
		void RightWidgetRelease();
		void LeftWidgetRelease();
		void BackspacePress();
		void DeletePress();
		void BackspaceRelease();
		void DeleteRelease();
		void KeyPress();
		string KeyRelease();
		void Type( SDLKey key );
		void CancelPress();
		string CancelRelease();
		string ExecWidget();
		void SaveSettings();
		void ClearSettings();
		void SelectDefault();
		void MouseSelect( float x, float y );
		bool MouseOver( float x, float y );
		string MousePressWidget( float x, float y );
		string MouseReleaseWidget( float x, float y );
		void StartGame();
		void ControlGrabKey( SDLKey key );
		void ControlGrabMouseMove( string direction );
		void ControlGrabMouseButton( int button_idx );
		void ControlGrabJoyButton( Uint8 joy_idx, Uint8 joy_btn );
		void ControlGrabJoyMove( Uint8 joy_idx, Uint8 joy_axis, bool joy_positive, float joy_value );
		bool HasChanges() { return has_changes; }

		Widget* GetWidget( int idx ) { return page_objects[idx]; }
		Widget* GetWidget( string name );
		bool GetDialog() { return is_dialog; }
		int GetNumWidgets() { return num_widgets; }
		string GetName() { return name; }
		void SetDialog( bool new_dialog ) { is_dialog = new_dialog; }
		void SetName( string new_name ) { name = new_name; }

	private:
		void Init();
		void ReleaseWidgets();

		string path;
		string name;
		unsigned int cur_obj, cancel_obj, default_obj;
		unsigned int num_widgets;
		unsigned int clicked_obj;
		bool is_dialog;
		bool l_pressed, r_pressed;
		bool has_changes;
		vector<Widget*> page_objects;
		CONFIGFILE menu_file;
		TEXTURE_HANDLE background;
	};
}

#endif // _VGUI_PAGE_H
