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

Author Topic: Multiple problems with text drawing  (Read 2183 times)

0 Members and 1 Guest are viewing this topic.

Stanislav

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Multiple problems with text drawing
« on: March 04, 2013, 12:50:03 pm »
Look at these two rectangles.



1. Cannot align the text vertically. In the first rectangle the text is correctly aligned, but in the second is not. If i change the text in the second rectangle to "Rectangle" then the text will be correctly aligned. Why is there difference between "Rectangle" and "Button"?  Here's how i set the position of the text in the rectangle:

text.setPosition(
     static_cast<int>(rect_x + ((rect_width - text_container.width) / 2)),         
     static_cast<int>(rect_y  + ((rect_height - text_container.height) / 2)));

http://www.sfml-dev.org/old-forum/viewtopic.php?t=5790&sid=c277620601084e8aa0f406a415a6b795
This doesn't help me at all. It gives me the same result.

2. What's that dot/line above the "R" in "Rectangle" and how to remove it? If the font size is relatively big then this thing appears over the first character.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Multiple problems with text drawing
« Reply #1 on: March 04, 2013, 01:21:15 pm »
1. Where is the origin of the text? At its center?

2. This should be fixed, do you use a recent revision of SFML 2?
Laurent Gomila - SFML developer

Stanislav

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Multiple problems with text drawing
« Reply #2 on: March 04, 2013, 02:16:54 pm »
1. Where is the origin of the text? At its center?
I don't use the setOrigin() function.

Some other guy had the same problem. The text is drawn little lower than it should be.
http://stackoverflow.com/questions/14505571/centering-text-on-the-screen-with-sfml



Quote from: Laurent
2. This should be fixed, do you use a recent revision of SFML 2?
Yeah, i'm using SFML 2. I downloaded it a month ago, is it recent enough?
« Last Edit: March 04, 2013, 02:38:14 pm by Stanislav »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Multiple problems with text drawing
« Reply #3 on: March 04, 2013, 02:45:39 pm »
Quote
I don't use the setOrigin() function.
Since you set the text position to the center of the box, it should work only if the text origin is set to its center. And the default origin is the top-left corner.

Quote
Some other guy had the same problem. The text is drawn little lower than it should be.
Yes, there are known issues about text centering, but without knowing exactly what you do (a complete/minimal example would help a lot for that) it's complicated to tell you what to do.

Quote
Yeah, i'm using SFML 2. I downloaded it a month ago, is it recent enough?
Yes. It's really strange, I was sure that it was fixed...
Laurent Gomila - SFML developer

Stanislav

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Multiple problems with text drawing
« Reply #4 on: April 12, 2013, 01:50:06 pm »
Since you set the text position to the center of the box, it should work only if the text origin is set to its center. And the default origin is the top-left corner. Yes, there are known issues about text centering, but without knowing exactly what you do (a complete/minimal example would help a lot for that) it's complicated to tell you what to do.

Well, that's how i'm setting the position:

text.setPosition(
    static_cast<int>(button_x + ((button_width - text_bounds.width) / 2)),                 
    static_cast<int>(button_y  + ((button_height - text_bounds.height) / 2)));
            
Without setOrigin() function:


...and now with setOrigin()(setting the origin to the center of the box):
text.setOrigin(button_x + button_width / 2, button_y + button_height / 2);
   


Quote
Yes. It's really strange, I was sure that it was fixed...
I didn't use the setView() function of the RenderWindow object before, now i'm using it and those lines/dots do not appear anymore.

« Last Edit: April 13, 2013, 11:06:33 am by Stanislav »