本文整理汇总了C++中sf::Text::getFont方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::getFont方法的具体用法?C++ Text::getFont怎么用?C++ Text::getFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::getFont方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateText
Primitive::Ptr Renderer::CreateText( const sf::Text& text, sf::Color background_color_hint ) {
Primitive::Ptr primitive( new Primitive );
const sf::Font& font = text.getFont();
unsigned int character_size = text.getCharacterSize();
sf::Color color = text.getColor();
if( m_preblend ) {
color = sf::Color::White;
}
sf::Vector2f atlas_offset = LoadFont( font, character_size, background_color_hint, text.getColor() );
const sf::String& str = text.getString();
std::size_t length = str.getSize();
float horizontal_spacing = static_cast<float>( font.getGlyph( L' ', character_size, false ).advance );
float vertical_spacing = static_cast<float>( font.getLineSpacing( character_size ) );
sf::Vector2f position( std::floor( text.getPosition().x + .5f ), std::floor( text.getPosition().y + static_cast<float>( character_size ) + .5f ) );
const static float tab_spaces = 2.f;
sf::Uint32 previous_character = 0;
for( std::size_t index = 0; index < length; ++index ) {
sf::Uint32 current_character = str[index];
position.x += static_cast<float>( font.getKerning( previous_character, current_character, character_size ) );
switch( current_character ) {
case L' ':
position.x += horizontal_spacing;
continue;
case L'\t':
position.x += horizontal_spacing * tab_spaces;
continue;
case L'\n':
position.y += vertical_spacing;
position.x = 0.f;
continue;
case L'\v':
position.y += vertical_spacing * tab_spaces;
continue;
default:
break;
}
const sf::Glyph& glyph = font.getGlyph( current_character, character_size, false );
Primitive::Vertex vertex0;
Primitive::Vertex vertex1;
Primitive::Vertex vertex2;
Primitive::Vertex vertex3;
vertex0.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left ), static_cast<float>( glyph.bounds.top ) );
vertex1.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left ), static_cast<float>( glyph.bounds.top + glyph.bounds.height ) );
vertex2.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left + glyph.bounds.width ), static_cast<float>( glyph.bounds.top ) );
vertex3.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left + glyph.bounds.width ), static_cast<float>( glyph.bounds.top + glyph.bounds.height ) );
vertex0.color = color;
vertex1.color = color;
vertex2.color = color;
vertex3.color = color;
// Let SFML cast the Rect for us.
sf::FloatRect texture_rect( glyph.textureRect );
vertex0.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top );
vertex1.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top + texture_rect.height );
vertex2.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top );
vertex3.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top + texture_rect.height );
primitive->AddVertex( vertex0 );
primitive->AddVertex( vertex1 );
primitive->AddVertex( vertex2 );
primitive->AddVertex( vertex2 );
primitive->AddVertex( vertex1 );
primitive->AddVertex( vertex3 );
position.x += static_cast<float>( glyph.advance );
previous_character = current_character;
}
AddPrimitive( primitive );
return primitive;
}