//-------------------------------------------------------------------------
// Static helper method to allow other GUI classes to easily parse a colour
//-------------------------------------------------------------------------
void GUIColour::ParseColour( CIwTextParserITX* apParser, GUIColour* apColour )
{
	char lBuf[64];
	apParser->PeekString( lBuf, 64 );

	if( lBuf[0] == '{' )
	{
		// We've got an RGBA quartet
		uint32 lColour[4] = { 255, 255, 255, 255 };

		apParser->ReadUInt32Array( lColour, 4 );

		IwAssertMsg( GUI, lColour[0] < 256, ( "GUIColour %s has invalid red value", apColour->DebugGetName() ) );
		IwAssertMsg( GUI, lColour[1] < 256, ( "GUIColour %s has invalid green value", apColour->DebugGetName() ) );
		IwAssertMsg( GUI, lColour[2] < 256, ( "GUIColour %s has invalid blue value", apColour->DebugGetName() ) );
		IwAssertMsg( GUI, lColour[3] < 256, ( "GUIColour %s has invalid alpha value", apColour->DebugGetName() ) );

		apColour->SetColour( ( lColour[0] << 0) | ( lColour[1] << 8) | ( lColour[2] << 16) | ( lColour[3] << 24 ) );
	}
	else
	{
		// We've been given a named reference to an existing GUIColour
		CIwStringS lColourName;
		apParser->ReadString( lColourName );
		GUIColour* lpColour = ResourceFindByName<GUIColour>( lColourName.c_str(), RESTYPE_GUICOLOUR );

		IwAssertMsg( GUI, lpColour, ( "Unable to locate specified GUIColour: %s", lColourName.c_str() ) );
		apColour->SetColour( lpColour->GetColour() );
	}
}
//-----------------------------------------------------------------------------
// Parse an attribute from an ITX file
//-----------------------------------------------------------------------------
bool GUIBorder::ParseAttribute( CIwTextParserITX* apParser, const char* apAttrName )
{
#ifdef IW_BUILD_RESOURCES
	IW_CALLSTACK( "GUIBorder::ParseAttribute" );

	if( !strcmp( apAttrName, "bounds" ) )
	{
		IwAssertMsg( GUI, false, ("GUIBorder does not use 'bounds' parameter.  Use 'bounds_tl', 'bounds_mid' and 'bounds_br' instead" ) );
	}
	else if( !strcmp( apAttrName, "bounds_br" ) )
	{
		m_BRBounds.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "bounds_tl" ) )
	{
		m_TLBounds.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "material" ) )
	{
		CIwStringS lMaterialName;

		apParser->ReadString( lMaterialName );
		CIwMaterial* lpMaterial = ResourceFindByName<CIwMaterial>( lMaterialName.c_str(), "CIwMaterial" );
		IwAssertMsg( GUI, lpMaterial, ( "Material named %s not found", lMaterialName.c_str() ) );

		// Make a copy of the material so we can tweak colours etc later
		m_Material.Copy( *lpMaterial );
	}
	else if( !strcmp( apAttrName, "colour" ) )
	{
		GUIColour::ParseColour( apParser, &m_Colour );
		m_Material.SetColAmbient( m_Colour.GetColour() );
		m_Material.SetColDiffuse( m_Colour.GetColour() );
	}
	else if( !strcmp( apAttrName, "uv" ) )
	{
		// Read in pixel UV data
		int16 lUVData[8];
		apParser->ReadInt16Array( lUVData, 8 );
		float u[4], v[4];
		// Convert pixel UV positions into fractions of width/height
		for( uint32 i = 0; i < 8; i++ )
		{
			if( i & 1 )
			{
				v[i >> 1] = MakeUVValue( lUVData[i], m_Material.GetTexture()->GetHeight() );
			}
			else
			{
Пример #3
0
void CRenderer::RenderText( CIwGxFont * font, const CIwRect & rect, const CIwColour & color, const CIwStringS & txt, IwGxFontAlignHor hAlign, IwGxFontAlignVer vAlign )
{
	iwsfixed scale = IW_SFIXED(mDeviceParams.scale);
	iwsfixed offX  = mDeviceParams.offsetX;
	iwsfixed offY  = mDeviceParams.offsetY;

	CIwRect r;
	r.x = IW_FIXED_MUL(rect.x, scale) + offX;
	r.y = IW_FIXED_MUL(rect.y, scale) + offY;
	r.w = IW_FIXED_MUL(rect.w, scale);
	r.h = IW_FIXED_MUL(rect.h, scale);

	Flush();
	
	DefaultMaterial();

	IwGxFontClearFlags(0xffffffff);
	IwGxLightingOn();	
	IwGxFontSetFont( font );
	IwGxFontSetCol( color );
	//IwGxFontSetScale( scale );

	//Set the formatting rect - this controls where the text appears and what it is formatted against
	IwGxFontSetRect(r);
	IwGxFontSetAlignmentVer(vAlign);
	IwGxFontSetAlignmentHor(hAlign);

	//Draw the text
	IwGxFontDrawText(txt.c_str());
	IwGxLightingOff();
	IwGxFontFreeBuffers();
	Flush();

}
//-----------------------------------------------------------------------------
// Parse an attribute from an ITX file
//-----------------------------------------------------------------------------
bool GUIElement::ParseAttribute( CIwTextParserITX* apParser, const char* apAttrName )
{
#ifdef IW_BUILD_RESOURCES
	IW_CALLSTACK( "GUIElement::ParseAttribute" );

	if( !strcmp( apAttrName, "bounds" ) )
	{
		m_Bounds.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "addTemplate" ) )
	{
		CIwStringS lTemplateName;
		apParser->ReadString( lTemplateName );
		GUITemplate* lpTemplate = reinterpret_cast<GUITemplate*>( IwGetResManager()->GetResNamed( lTemplateName.c_str(), RESTYPE_GUITEMPLATE ) );
		IwAssertMsg( GUI, lpTemplate, ( "Unable to locate GUITemplate called %s", lTemplateName.c_str() ) );
		lpTemplate->CloneTemplateChildren( this );
	}
	else if( !strcmp( apAttrName, "useTemplate" ) )
	{
		CIwStringS lTemplateName;
		apParser->ReadString( lTemplateName );
		GUITemplate* lpTemplate = reinterpret_cast<GUITemplate*>( IwGetResManager()->GetResNamed(lTemplateName.c_str(), RESTYPE_GUITEMPLATE ) );
		IwAssertMsg( GUI, lpTemplate, ( "Unable to locate GUITemplate called %s", lTemplateName.c_str() ) );
		lpTemplate->CloneTemplate( this );
	}
	else if( !strcmp( apAttrName, "debug" ) )
	{
		SetFlags( GF_DEBUG );
	}
	else if( !strcmp( apAttrName, "enable" ) )
	{
		apParser->ReadBool( &m_Enabled );
	}
	else if( !strcmp( apAttrName, "offset" ) )
	{
		m_Offset.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "touchable" ) )
	{
		SetFlags( GF_TOUCHABLE );
	}
	else
		return CIwResource::ParseAttribute( apParser, apAttrName );
#endif
	return true;
}