view LightClone/Source/GuiLabel.cpp @ 65:41980ff0607d

Added shader and textures for bot
author koryspansel <koryspansel@bendbroadband.com>
date Wed, 05 Oct 2011 12:55:46 -0700
parents 3507bd831c7f
children
line wrap: on
line source

/*
 * GuiLabel
 */

#include "GuiLabel.h"

/*
 * GuiLabel
 */
GuiLabel::GuiLabel() : pFont(NULL), nLabelFlags(0)
{
}

/*
 * Initialize
 */
ErrorCode GuiLabel::Initialize(ServiceProvider* pServiceProvider)
{
	return GuiElement::Initialize(pServiceProvider);
}

/*
 * Render
 */
void GuiLabel::Render(GuiRenderContext& kContext)
{
	if(nFlags & GuiElementFlag_Visible)
	{
		if(pFont)
		{
			const D3DXVECTOR2& kLocation = GetPosition();

			RECT kRectangle;
			kRectangle.left		= (int32)kLocation.x;
			kRectangle.top		= (int32)kLocation.y;
			kRectangle.right	= (int32)kLocation.x;
			kRectangle.bottom	= (int32)kLocation.y;

			uint32 nFormat = 0;

			if(nLabelFlags & GuiLabelFlag_CenterX)
			{
				nFormat |= DT_CENTER;
			}

			if(nLabelFlags & GuiLabelFlag_CenterY)
			{
				nFormat |= DT_VCENTER;
			}

			//TODO: Hack to draw any pending triangles before drawing text
			kContext.Flush();

			pFont->DrawTextA(NULL, kLabel, kLabel.Length(), &kRectangle, nFormat | DT_CALCRECT, kColor);
			pFont->DrawTextA(NULL, kLabel, kLabel.Length(), &kRectangle, nFormat, kColor);
		}

		GuiElement::Render(kContext);
	}
}

/*
 * SetFont
 */
ErrorCode GuiLabel::SetFont(const char* pName, uint32 nSize, uint32 nWeight)
{
	pFont = NULL;

	ResourceManager* pResourceManager = NULL;
	
	ErrorCode eCode = pServiceProvider->GetService("ResourceManager", &pResourceManager);
	if(eCode == Error_Success)
	{
		eCode = pResourceManager->CreateFontFromName(pName, nSize, nWeight, &pFont);
	}

	return eCode;
}

/*
 * SetText
 */
ErrorCode GuiLabel::SetText(const char* pText)
{
	return kLabel = pText, Error_Success;
}

/*
 * SetLabelFlag
 */
ErrorCode GuiLabel::SetLabelFlag(uint32 nValue)
{
	return nLabelFlags |= nValue, Error_Success;
}

/*
 * ClearLabelFlag
 */
ErrorCode GuiLabel::ClearLabelFlag(uint32 nValue)
{
	return nLabelFlags &= ~nValue, Error_Success;
}