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

Author Topic: [SOLVED] "True" global bounds (or position) of text  (Read 5475 times)

0 Members and 2 Guests are viewing this topic.

MrSnappingTurtle

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
[SOLVED] "True" global bounds (or position) of text
« on: December 24, 2014, 08:01:58 am »
Hey guys!

Hope you don't find my recent flood of questions.  :P

Anyways, I was wondering if there is a way to get the "true" global bounds of an sf::Text. What I mean is that when I use the following code, the rectangle doesn't cover the text completely:

playText_.setOrigin(sf::Vector2f(playText_.getLocalBounds().width / 2.0f, playText_.getLocalBounds().height / 2.0f));

selectionRect_.setSize(sf::Vector2f(playText_.getGlobalBounds().width, playText_.getGlobalBounds().height));
selectionRect_.setOrigin(sf::Vector2f(selectionRect_.getSize().x / 2.0f, selectionRect_.getSize().y / 2.0f));
selectionRect_.setPosition(playText_.getPosition());




Do you guys see what I mean? Is there any way around this issue?

EDIT: Now that I look at it, it looks like it is just offset to the top left... However, the origins are at the center so is there any way that can happen?
« Last Edit: December 25, 2014, 06:07:03 am by MrSnappingTurtle »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: "True" global bounds (or position) of text
« Reply #1 on: December 24, 2014, 10:48:04 am »
This question has been asked hundreds of times. The text bounds don't only contain a width and a height, but also a left and a top coordinate. In case of sf::Text, these are not zero.
Laurent Gomila - SFML developer

MrSnappingTurtle

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: "True" global bounds (or position) of text
« Reply #2 on: December 24, 2014, 07:43:21 pm »
This question has been asked hundreds of times. The text bounds don't only contain a width and a height, but also a left and a top coordinate. In case of sf::Text, these are not zero.

Sorry, I should rephrase my question, I kinda worded it awkwardly. I am aware that there is a .left and a .top. My problem is that with the code that I listed, the selection rectangle should cover the whole text but it doesn't. I am wondering if there is something I am doing wrong. 

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: "True" global bounds (or position) of text
« Reply #3 on: December 25, 2014, 12:24:45 am »
it looks like it is just offset to the top left
Then offset it back using .top and .left  ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: "True" global bounds (or position) of text
« Reply #4 on: December 25, 2014, 01:28:25 am »
Quote
Sorry, I should rephrase my question, I kinda worded it awkwardly
Your question was very clear. I should rather rephrase my answer (although I think it was clear enough too ;)): your code doesn't use the left / top coordinates. It should.
Laurent Gomila - SFML developer

MrSnappingTurtle

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: "True" global bounds (or position) of text
« Reply #5 on: December 25, 2014, 06:06:40 am »
Quote
Sorry, I should rephrase my question, I kinda worded it awkwardly
Your question was very clear. I should rather rephrase my answer (although I think it was clear enough too ;)): your code doesn't use the left / top coordinates. It should.

Ohhhhhhhh...derp. Thanks! That solves the issue!  ;D