I am not going to include any code in this post as I think it is possible to explain my confusion without it, however, I will readily post some if that is what is wanted.
So, I am working on simple program which simulates planetary orbits. I am trying to add a functionality in which the user is able to click the name of an orbital object and have their view be centered on it. Moving the view is not an issue, and functions fine. The problem that I am encountering is how to correctly detect if a mouse click is positioned on the planets name text.
Psuedocode:
sf::Mouse MouseObject;
EventLoop()
{
if(LeftClickDetected)
{
HandleLeftClick(MouseObject.getPosition(Window));
}
}
void HandleLeftClick(sf::Vector2i ClickCoordinate)
{
sf::floatRect TextBounds = PlanetText.getGlobalBounds();
if(TextBounds.contains(ClickCoordinate.x, ClickCoordinate.y)
{
//Move Player View
}
}
This however is not enough, as it turns out that the position of the mouse and the position of the text use two separate units of measurements. The mouse position is based off of which pixel it falls on, either in relation to the upper left edge of the entire screen or based just the window depending on how you call the function. sf::text objects however, use a system of measurement related to their position in screenspace, also changing with various transformations and scaling.
How would I go about detecting if a mouse click falls within a piece of text's, (or any other drawables), bounding box? I've tried other variations and have scoured the documentation, but could not find much. sf::transform seems that it might be the path to take but I still cannot seem to solve this.