#include "AdeptHeaders.hpp"

#include "GUITextObject.hpp"
#include <MLR\MLR.hpp>

using namespace MidLevelRenderer;
//#############################################################################
//###########################    GUITextObject   ##############################
//#############################################################################

GUITextObject::ClassData*
	GUITextObject::DefaultData = NULL;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	GUITextObject::InitializeClass()
{
	Verify(!DefaultData);
	DefaultData =
		new ClassData(
			GUITextObjectClassID,
			"Adept::GUITextObject",
			Receiver::DefaultData,
			0,
			NULL
		);
	Register_Object(DefaultData);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	GUITextObject::TerminateClass()
{
	Unregister_Object(DefaultData);
	delete DefaultData;
	DefaultData = NULL;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
GUITextObject::GUITextObject(
	ClassData *class_data,
	MemoryStream *stream
):
	Receiver(class_data)
{
	Check_Pointer(this);
	Check_Object(stream);

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
GUITextObject::GUITextObject(
	ClassData *class_data,
	HGOSFONT3D font_handle,
	const char *display_string,
	int x_location,
	int y_location
) :
	Receiver(class_data)
{
	Check_Pointer(this);

	textFont = font_handle;
	displayString = display_string;
	xLocation = x_location;
	yLocation = y_location;
	isBold = false;
	isItalic = false;
	isVisible = true;
	isProportional = true;
	isWordWrap = false;
	textSize = 1.0f;
	textColor.alpha = 1.0f;
	textColor.red = 1.0f;
	textColor.green = 1.0f;
	textColor.blue = 1.0f;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
GUITextObject::GUITextObject(
	ClassData *class_data,
	Page *instance_page
):
	Receiver(class_data)
{
	Check_Pointer(this);
	Check_Object(instance_page);

	textObjectName = instance_page->GetName();
	//
	//-------------------------------------
	//Get the Font Name and Create the Font
	//-------------------------------------
	//
	instance_page->GetEntry("FontName", &fontName, true);
	textFont = gos_LoadFont(fontName, 0);

	//
	//--------------------------------
	//Get Text that is to be displayed
	//--------------------------------
	//
	const char *temp_string = "";
	instance_page->GetEntry("FontName", &temp_string);
	displayString = temp_string;

	//
	//--------------------------------
	//Get Text that is to be displayed
	//--------------------------------
	//
	isVisible = true;
	instance_page->GetEntry("StartsDisplayed", &isVisible);

	//
	//-----------------
	//Get Text Location
	//-----------------
	//
	instance_page->GetEntry("XLocation", &xLocation, true);
	if((xLocation < 0) || (xLocation > Environment.screenWidth))
	{
		STOP(("X Location for %s must be > 0 and < %d", (const char*)textObjectName, Environment.screenWidth));
	}

	instance_page->GetEntry("YLocation", &yLocation, true);
	if((yLocation < 0) || (yLocation > Environment.screenHeight))
	{
		STOP(("Y Location for %s must be > 0 and < %d", (const char*)textObjectName, Environment.screenHeight));
	}

	//
	//---------
	//Get Color
	//---------
	//
	textColor.alpha = 1.0f;
	textColor.red = 1.0f;
	textColor.green = 1.0f;
	textColor.blue = 1.0f;
	instance_page->GetEntry("Color", &textColor);
	//
	//------------------------
	//Get Various Text Options
	//------------------------
	//
	textSize = 1.0f;
	instance_page->GetEntry("StartsDisplayed", &textSize);
	if(textSize <= 0)
	{
		STOP(("Text Size Must be > 0"));
	}

	isWordWrap = false;
	instance_page->GetEntry("WordWrap", &isWordWrap);

	isProportional = false;
	instance_page->GetEntry("Proportional", &isProportional);

	isBold = false;
	instance_page->GetEntry("Bold", &isBold);

	isItalic = false;
	instance_page->GetEntry("Italic", &isItalic);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	GUITextObject::Save(MemoryStream *stream)
{
	Check_Object(this);
	Check_Object(stream);

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	GUITextObject::DrawText()
{
	Check_Object(this);

	if(isVisible)
	{
		gos_TextSetRegion(0, 0, Environment.screenWidth, Environment.screenHeight);
		gos_TextSetAttributes(
			textFont, 
			MidLevelRenderer::GOSCopyColor(&textColor),
			textSize, 
			isWordWrap, 
			isProportional, 
			isBold, 
			isItalic
		);
		gos_TextSetPosition(xLocation, yLocation);
		gos_TextDraw(displayString);
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	GUITextObject::HideText()
{
	Check_Object(this);
	isVisible = false;

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	GUITextObject::ShowText()
{
	Check_Object(this);
	isVisible = true;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
GUITextObject::~GUITextObject()
{
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	GUITextObject::TestInstance()
{
	Verify(IsDerivedFrom(DefaultData));
}






