Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to draw a part of sf::String  (Read 2316 times)

0 Members and 1 Guest are viewing this topic.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
How to draw a part of sf::String
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to draw a part of sf::String
« Reply #1 on: December 12, 2008, 12:58:04 pm »
Do you want to clip your string in terms of characters, or in terms of pixels?
Laurent Gomila - SFML developer

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
How to draw a part of sf::String
« Reply #2 on: December 12, 2008, 01:24:45 pm »
Clip strings:
Code: [Select]

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.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
How to draw a part of sf::String
« Reply #3 on: December 12, 2008, 02:40:23 pm »
Solved:

Code: [Select]

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);
    }

}

 

anything