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

Author Topic: [Solved] Problem with calculating global bounds  (Read 7939 times)

0 Members and 1 Guest are viewing this topic.

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
[Solved] Problem with calculating global bounds
« on: October 28, 2015, 11:29:26 am »
Hi all,

I'm currently developing a class which represents a text menu for applications (like a main menu for a game). While doing so, I oriented myself at the sf::Text - class, which is used internally for displaying individual meny entries. It works as intended but when calculation the global bounds of the complete menu, the top-left coordinate of the menu is 0.f, 0.f. Width and height should be the same like the local bounds, which is correct (209, 150 in my example below). The local bounds are correctly calculated and stored as a member inside the class.

I used the same method for calculating the global bounds like sf::Text or sf::Sprite do:
sf::FloatRect TextMenu::getGlobalBounds() const
{
  return getTransform().transformRect( getLocalBounds() );  
}
 

... which should return the global coordinates of the menu with all transformations applied.

I have no idea why the global bounds are not correct.   :-\
The complete code with minimal example can be found here: https://github.com/SeriousITGuy/SFML-TextMenu

It is not a deal-breaker as the rest works like intended and is ready to use in my other projects, just wondering why this happens  ;)
I plan on posting this class in the wiki once it's completed and therefor it would be good to get rid of this minor issue.
« Last Edit: October 28, 2015, 01:28:22 pm by SeriousITGuy »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Problem with calculating global bounds
« Reply #1 on: October 28, 2015, 11:46:27 am »
Does getTransform() return what you expect?

The complete code with minimal example can be found here: https://github.com/SeriousITGuy/SFML-TextMenu
That's not minimal. It would be nice to embed a complete code with only a main() function in a single file, and without all the stuff specific to your project (e.g. other menu functionality).

And you should do it inline in the post, not link to external sources. Many people (e.g. me) don't always have the time to skim through multiple files in external repositories :) Furthermore, this has the advantage that it's persistent, so the question is still useful when your repository changes.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with calculating global bounds
« Reply #2 on: October 28, 2015, 11:48:14 am »
Quote
I have no idea why the global bounds are not correct.
What is "not correct"? Do you get an empty rectangle? The same as the local bounds? Is its position wrong? Its size? ...

In your example, you retrieve the global bounds before applying your transformations, is it intended?
Laurent Gomila - SFML developer

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: Problem with calculating global bounds
« Reply #3 on: October 28, 2015, 01:28:09 pm »
In your example, you retrieve the global bounds before applying your transformations, is it intended?

Oh my god, that was the problem. Now I feel dumb!  :o
Now it works. Thanks!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Problem with calculating global bounds
« Reply #4 on: October 28, 2015, 08:23:55 pm »
Now it works.
It would be nice if you posted what you did that actually works  ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [Solved] Problem with calculating global bounds
« Reply #5 on: October 28, 2015, 11:25:05 pm »
Quote
It would be nice if you posted what you did that actually works
He now gets the global bounds after applying transformations, obviously.
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: [Solved] Problem with calculating global bounds
« Reply #6 on: October 29, 2015, 03:58:51 am »
He now gets the global bounds after applying transformations, obviously.
He gets global bounds?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: [Solved] Problem with calculating global bounds
« Reply #7 on: October 29, 2015, 09:07:10 am »
Yes Laurent is correct. In my example program I instantiated TextMenu and saved the global bounds of it into a variable before even doing a transformation to it (menu.setPosition). I then used the saved bounds instead of calling getGlobalBounds again, therefore the transformation did not apply. Obvious mistake is obvious  :D

 

anything