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

Author Topic: Text Scale After Resizing  (Read 3135 times)

0 Members and 1 Guest are viewing this topic.

gokaysatir

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Text Scale After Resizing
« on: March 09, 2013, 04:05:04 pm »
Hi,

I am trying to display text using SFML 2.0.

Text is displayed very nice at first, but while resizing i recreate the text object and use this code for scaling:

sf::Text crd; // Create text object..
crd.setFont(My_Fonts::types[0]); // Select font..
crd.setString("Sample Text"); // Set string..
crd.setOrigin(0, 0);
crd.setPosition(10* 1000 / width, 400); // Set position using width variable so it remains at the same point after resizing.. I couldn't find a way to make y point remain unchanged, (400 * 1000/height) doesn't work..
// Variable 1000 is an experimental value i use to specify the gap between text and window border..

crd.setCharacterSize(12U);
crd.setColor(sf::Color(0,0,0));
crd.scale(height/width, 1.0f); // Set scale x according to y and leave y untouched..
texts.push_back(crd); // Put it into an array..

With this code i can save x scale but the y scale is deformed and after resizing the text is displayed stretched.

I hope i could explain my problem. Thanks in advance:)


gokaysatir

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Text Scale After Resizing
« Reply #1 on: March 09, 2013, 04:14:17 pm »
In order to make my code more clear i can give an example:

When the window size.x  = 500;

The position.x = 10 * (1000/500) = 20;

And when the window size.x = 1000;

x position gets the value "10".

So if "20" in 500.x size equals 20 pixels, "10" in 1000.x size equals 20 pixels too. The position is safe.

I couldn't use this approach for y coordinate. Also couldn't prevent the deformation in y scale.

Sorry for my bad English :-[


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10988
    • View Profile
    • development blog
    • Email
Re: Text Scale After Resizing
« Reply #2 on: March 09, 2013, 09:09:48 pm »
You should rather adjust the sf::View of the window, than trying to scale everything manually (e.g. see here).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

gokaysatir

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Text Scale After Resizing
« Reply #3 on: March 09, 2013, 10:51:02 pm »
Hi,

You're right ::) I tried to reset view variables after resizing and it's ok now. Text is displayed perfect again.

Thank you :)

 

anything