Beispiel #1
0
void
vsBuiltInFont::CreateStringInDisplayList(vsDisplayList *list, const vsString &string, float size, float capSize, JustificationType j, float maxWidth)
{
	if ( maxWidth > 0.f )
	{
		WrapLine(string, size, capSize, j, maxWidth);

		float lineHeight = capSize;
		float lineMargin = capSize * c_lineMarginFactor;

//		float baseOffsetDown = lineHeight * (m_wrappedLineCount * 0.5f);
		float totalHeight = (lineHeight * s_wrappedLineCount) + (lineMargin * (s_wrappedLineCount-1));
		float baseOffsetDown = totalHeight * 0.5f;
		float topLinePosition = baseOffsetDown - totalHeight + lineHeight;

//		float halfTotalHeight = totalHeight * 0.5f;
		list->Clear();

		vsVector2D offset(0.f,topLinePosition);

		for ( int i = 0; i < s_wrappedLineCount; i++ )
		{
			offset.y = topLinePosition + (i*(lineHeight+lineMargin));
			s_tempFontList.Clear();
			BuildDisplayListFromString( &s_tempFontList, s_wrappedLine[i].c_str(), size, capSize, j, offset );
			list->Append(s_tempFontList);
		}
		vsVector2D tl,br;
		list->GetBoundingBox(tl,br);
		/*
		float height = br.y-tl.y;
		list->Clear();

		for ( int i = 0; i < m_wrappedLineCount; i++ )
		{
			offset.Set(0.f,lineHeight*i - 0.5f*height);
			s_tempFontList.Clear();
			BuildDisplayListFromString( &s_tempFontList, m_wrappedLine[i].c_str(), size, capSize, j, offset );
			list->Append(s_tempFontList);
		}*/
	}
	else
	{
		float lineHeight = capSize;
		float totalHeight = lineHeight;
		float baseOffsetDown = totalHeight * 0.5f;
		float topLinePosition = baseOffsetDown - totalHeight + lineHeight;
		list->Clear();

		vsVector2D offset(0.f,topLinePosition);

		list->Clear();
		BuildDisplayListFromString( list, string.c_str(), size, capSize, j, offset );
	}
}
Beispiel #2
0
void
vsBuiltInFont::BuildDisplayListFromString( vsDisplayList *list, const char *string, float size, float capSize, JustificationType j, const vsVector2D &offset_in )
{
	vsVector2D offset = offset_in;
	size_t len = strlen(string);

	if ( j != Justification_Left )
	{
		BuildDisplayListFromString(list, string, size, capSize, Justification_Left);
		float width = GetDisplayListWidth(list);

		if ( j == Justification_Right )
			offset.x = -width;
		if ( j == Justification_Center )
			offset.x = -(width*0.5f);

		list->Clear();
	}

	//float iniXOffset = offset.x;

	list->VertexBuffer(s_P);

	vsTransform2D t;

	for ( size_t i = 0; i < len; i++ )
	{
		char thisChar = string[i];
		float thisSize = GetSizeForCharacter(thisChar, size, capSize);
		int index = lookup_letterIndex(thisChar);

		if ( index < 57 && index >= 0 )
		{
			vsAssert(index < 57, "Unknown char??");

			offset.x += c_kerningFactor * thisSize;

			t.SetTranslation( offset-(thisSize*baseline) );
			t.SetScale( vsVector2D(thisSize,thisSize) );

			list->PushTransform(t);
			list->LineListBuffer( &s_I[index] );
			list->PopTransform();
		}

//		AppendCharacterToList( string[i], list, offset, thisSize );


		offset.x += c_kerningFactor * thisSize;
	}

	list->ClearArrays();
}
vsDisplayList * 
vsBuiltInFont::CreateString_Internal(const char* string, float size, float capSize, JustificationType j)
{
	vsDisplayList *result = NULL;
	vsDisplayList loader(1024 * 10);
	
	BuildDisplayListFromString( &loader, string, size, capSize, j );
	
	int displayListSize = loader.GetSize();
	if ( displayListSize )
	{
		result = new vsDisplayList( displayListSize );
		result->Append(loader);
	}
	
	return result;
}