SFML community forums

Help => Graphics => Topic started by: Stanislav on March 04, 2013, 12:50:03 pm

Title: Multiple problems with text drawing
Post by: Stanislav on March 04, 2013, 12:50:03 pm
Look at these two rectangles.

(http://img12.imageshack.us/img12/7797/screenshotjxs.png)

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  (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.
Title: Re: Multiple problems with text drawing
Post by: Laurent 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?
Title: Re: Multiple problems with text drawing
Post by: Stanislav 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 (http://stackoverflow.com/questions/14505571/centering-text-on-the-screen-with-sfml)

(http://i.imgur.com/4jzMouj.png)

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?
Title: Re: Multiple problems with text drawing
Post by: Laurent 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...
Title: Re: Multiple problems with text drawing
Post by: Stanislav 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:
(http://img805.imageshack.us/img805/6679/sfml1.png)

...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);
   
(http://img259.imageshack.us/img259/4541/sfml2.png)

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.