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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - alseether

Pages: [1]
1
Graphics / Re: sf::Text alignment problem
« on: September 07, 2015, 12:46:34 pm »
I've tested your solution and the text doesn't appear. Will be better if i explain a little more the code.

The variables diffX and diffY are only the difference between sizes, for example, in a button with (200,100) size
and a text with a bounding box with (160, 60), the text should left 20 pixels on each side.

In the image, the bounding box and the text are positioned in the same coordinates, but i don't know why the text isn't inside the box.

2
Graphics / Re: sf::Text alignment problem
« on: September 07, 2015, 12:15:26 pm »
That will result a negative number.

I think the problem have to be something related with the character size, or maybe the glyph.
I neither understand why the Y alignment it's ok but the X one not.

Thanks

3
Graphics / sf::Text alignment problem
« on: September 07, 2015, 11:57:34 am »
Hi, like thousand people here, i'm trying to make a button with a text centered inside.
I've been searching in the forum some solutions, but it seems useless for me.
The thing is, i,ve decided to center my text using the getLocalBounds() function.
Basically, this is my code:

int diffX = rect.width - txt.getLocalBounds().width;
int diffY = rect.height - txt.getLocalBounds().height;
float posX = rect.left + diffX / 2.f;
float posY = rect.top + diffY / 2.f;
       
txt.setPosition(sf::Vector2f(posX, posY));
txt.setColor(sf::Color::White);
 

Were rect is the rectangle of the button and txt is (obviously) my text.
I calculate de difference between both sizes and i set the text position leaving the half of the difference on each side.
The problem is that the bounding box of the text it's perfectly aligned, but text isn't.

This is how it looks:



(Note: i'm not sure if i'm uploading the image properly)
(Note2: sorry about ortography, i'm not English)

Thanks.

Pages: [1]