#include "xmlslider.h"

// ----------------------------------------------------------------------------
CXmlSlider::CXmlSlider(CXmlUi* pXmlUi, CXmlLayout* pParent)
	: CXmlFrame(pXmlUi, pParent)
{
	m_type				= eXmlUiType_Slider;

	m_thumbTexture		= NULL;
	m_orientation		= eOrientation_Vertical;
	m_minValue			= 0.0f;
	m_maxValue			= 0.0f;
	m_defaultValue		= 0.0f;
	m_smallStep			= 0.0f;
	m_largeStep			= 0.0f;
}

// ----------------------------------------------------------------------------
CXmlSlider::~CXmlSlider()
{
	XML_SAFE_DLETE(m_thumbTexture);
}

// ----------------------------------------------------------------------------
void CXmlSlider::LoadNodeAttribute(const DOMNamedNodeMap* nodeMap)
{
	CXmlFrame::LoadNodeAttribute(nodeMap);

	const XMLCh* nodeValue;
	if ( (nodeValue = GetNodeAttribute(nodeMap, "minValue")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_minValue = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "maxValue")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_maxValue = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "defaultValue")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_defaultValue = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "smallStep")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_smallStep = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "largeStep")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_largeStep = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
}

// ----------------------------------------------------------------------------
void CXmlSlider::LoadNodeElement(const DOMNode* node, const char* nodeName)
{
	CXmlFrame::LoadNodeElement(node, nodeName);

	// Thumb Texture
	if ( XMLString::compareString(nodeName, "ThumbTexture") == 0 )
	{
		XML_SAFE_DLETE(m_thumbTexture);
		m_thumbTexture = new CXmlTexture(m_pXmlUi, this);
		m_thumbTexture->LoadFromDOMNode(node);
	}
}

// ----------------------------------------------------------------------------
void CXmlSlider::Inherit(CXmlLayout* pXmlLayout)
{
	CXmlFrame::Inherit(pXmlLayout);
	CXmlSlider* pXmlSlider = dynamic_cast<CXmlSlider*>(pXmlLayout);
	if (pXmlSlider)
	{
		if (pXmlSlider->m_thumbTexture)
		{
			XML_SAFE_DLETE(m_thumbTexture);
			m_thumbTexture = new CXmlTexture(m_pXmlUi, this);
			m_thumbTexture->Inherit(pXmlSlider->m_thumbTexture);
		}

		m_orientation		= pXmlSlider->m_orientation;		
		m_minValue			= pXmlSlider->m_minValue;
		m_maxValue			= pXmlSlider->m_maxValue;
		m_defaultValue		= pXmlSlider->m_defaultValue;
		m_smallStep			= pXmlSlider->m_smallStep;
		m_largeStep			= pXmlSlider->m_largeStep;
	}
}