本文整理汇总了C++中sf::Text::getString方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::getString方法的具体用法?C++ Text::getString怎么用?C++ Text::getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::getString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: breakTextLines
void breakTextLines(sf::Text& t, float maxX)
{
sf::String s = t.getString();
std::size_t lastBreakCharIdx = s.getSize();
static sf::String const breakBeforeChars("([{\"'`'");
static auto const isBreakBeforeChar = [] (sf::Uint32 c) {
return breakBeforeChars.find(c) != sf::String::InvalidPos;
};
for (std::size_t i = 0; i < s.getSize(); ++i) {
if (t.findCharacterPos(i).x > maxX) {
if (lastBreakCharIdx > i)
lastBreakCharIdx = i;
if (s.getSize() > lastBreakCharIdx &&
!std::iswgraph(static_cast<std::wint_t>(s[lastBreakCharIdx + 1]))
) {
s[lastBreakCharIdx + 1] = '\n';
} else {
s.insert(lastBreakCharIdx + 1, '\n');
}
t.setString(s);
i += 1;
}
if (!std::iswalnum(static_cast<std::wint_t>(s[i]))) {
lastBreakCharIdx = i;
if (i > 0 && isBreakBeforeChar(s[i]))
lastBreakCharIdx -= 1;
}
}
}
示例2:
float getStrWidth(sf::Text const &ref)
{
float ret = static_cast<std::string const&>(ref.getString())
.length();
if (ref.getCharacterSize() <= 12)
return ((ref.getCharacterSize() - 4)) * ret;
if (ref.getCharacterSize() >= 20)
return ((ref.getCharacterSize() - 8) * ret);
return ((ref.getCharacterSize() - 5) * ret);
}
示例3: trimTextToRectangleWidth
void assetHandle::trimTextToRectangleWidth(sf::Text &text, sf::RectangleShape &rect)
{
while(true)
{
sf::FloatRect floatRect = text.getGlobalBounds();
if ((floatRect.left + floatRect.width) > rect.getSize().x)
{
std::string newString = text.getString();
newString = newString.substr(0, newString.size()-1);
text.setString(newString);
}
else
break;
}
}
示例4: setStr
inline void setStr(const std::string& mStr)
{
if(impl.getString() == "")
{
impl.setString(mStr);
taAppear();
taJump();
createTA(10.f) += [this, mStr](auto&, FT)
{
};
return;
}
createTA() += [this, mStr](auto&, FT)
{
impl.setString(mStr);
};
taJump();
}
示例5: Widget
Label::Label(Updatable *parent, const sf::Text &text, const sf::Vector2f &position, int characterSize) : Widget(parent, sf::FloatRect(position.x, position.y, characterSize * text.getString().getSize(), characterSize)), m_text(text)
{
m_focus=false;
setCharacterSize(characterSize);
}
示例6: 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;
}