SFML community forums
Help => General => Topic started by: prchakal on December 12, 2008, 12:38:47 pm
-
Im creating a little gui lib, and i dont know how i can draw a part of my sf::String.
For example:
My textBox(sf::String) will have the text: 1234567890ABC, but i want show only a part of it, only the last 5 digits: 90ABC.
How i do it?
-
Do you want to clip your string in terms of characters, or in terms of pixels?
-
Clip strings:
sf::String teste(this->texto);
teste.SetStyle( this->caixaTexto.GetStyle() );
teste.SetSize( this->caixaTexto.GetSize() );
teste.SetPosition( this->caixaTexto.GetPosition().x, this->caixaTexto.GetPosition().y );
teste.SetText( this->caixaTexto.GetText() );
string tempStr = this->texto;
while ( teste.GetRect().GetWidth() > this->largura )
{
tempStr = this->texto.substr(1, tempStr.size()-1);
this->caixaTexto.SetText(tempStr);
teste.SetText( this->caixaTexto.GetText() );
}
gui::Core::app->Draw(teste);
Im doing it, but dont is perfect.
-
Solved:
void gui::CaixaTexto::desenhar()
{
//desenhar texto
if (this->senha == false)
{
this->caixaTexto.SetText(this->texto);
}
else
{
this->caixaTexto.SetText( gui::Util::strpad(this->texto, '*', this->texto.size()) );
}
sf::String caixaTextoTemp(this->texto);
caixaTextoTemp.SetStyle( this->caixaTexto.GetStyle() );
caixaTextoTemp.SetSize( this->caixaTexto.GetSize() );
caixaTextoTemp.SetPosition( this->caixaTexto.GetPosition().x, this->caixaTexto.GetPosition().y );
caixaTextoTemp.SetText( this->caixaTexto.GetText() );
string tempStr = this->texto;
if (this->senha == true)
{
tempStr = gui::Util::strpad(tempStr, '*', tempStr.size());
}
while ( caixaTextoTemp.GetRect().GetWidth() > this->largura )
{
tempStr.erase(0,1);
caixaTextoTemp.SetText(tempStr);
}
gui::Core::app->Draw(caixaTextoTemp);
//desenhar marcador
if ( this->piscarMarcador == true && gui::Core::foco == this )
{
sf::Shape sh=sf::Shape::Line(caixaTextoTemp.GetPosition().x + caixaTextoTemp.GetRect().GetWidth() + 2, caixaTextoTemp.GetPosition().y + 3, caixaTextoTemp.GetPosition().x + caixaTextoTemp.GetRect().GetWidth() + 2, caixaTextoTemp.GetPosition().y + this->altura, 2, sf::Color(255, 255, 255));
gui::Core::app->Draw(sh);
}
}