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

Author Topic: auto-scale/positioning of Text  (Read 1816 times)

0 Members and 2 Guests are viewing this topic.

durito

  • Newbie
  • *
  • Posts: 2
    • View Profile
auto-scale/positioning of Text
« on: September 09, 2009, 10:27:04 am »
Hi all,

First of all, I'm new to SFML and so far very happy with it (I used SDL before).

I'm now using SFML for a project with OpenGL rendering and some text output (with sf::String).

Code: [Select]
sf::String Text("text", _font, 16);
Text.SetPosition(20.0, 20.0);


The "text" is then rendered as expected with the given position and size in a sf::RenderWindow. But as soon as the window is resized, the text changes its size and position and seems to be scaled. How can I avoid this text-autoscaling? I need this text on a given position on the screen and not jumping around as soon as the window is resized  :shock:

thanks,
Daniel

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
auto-scale/positioning of Text
« Reply #1 on: September 09, 2009, 10:32:55 am »
This is because of the default view's behaviour. To get the expected result, you have to adjust it when the window is resized.

Code: [Select]
while (event loop ...)
{
    if (event.Type == sf::Event::Resized)
    {
        float width = static_cast<float>(event.Size.Width);
        float height = static_cast<float>(event.Size.Height);
        window.GetDefaultView().SetRect(sf::FloatRect(0, 0, width, height));
    }
}
Laurent Gomila - SFML developer

durito

  • Newbie
  • *
  • Posts: 2
    • View Profile
auto-scale/positioning of Text
« Reply #2 on: September 09, 2009, 11:13:24 am »
great, thanks!