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

Author Topic: Unsure of how to find the "Pixel Position" of sf::Text. [Solved]  (Read 1197 times)

0 Members and 1 Guest are viewing this topic.

HavingPhun

  • Newbie
  • *
  • Posts: 7
    • View Profile
Unsure of how to find the "Pixel Position" of sf::Text. [Solved]
« on: November 30, 2015, 10:07:31 pm »
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:
(click to show/hide)

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.
« Last Edit: December 01, 2015, 02:20:30 am by HavingPhun »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Unsure of how to find the "Pixel Position" of sf::Text.
« Reply #1 on: November 30, 2015, 11:56:01 pm »
It sounds like you're already using an sf::View so you should have already read its tutorial  :P

The part you need here is the final section of that tutorial, but please read the entire thing; you'll need to know it all at some point!

HINT: mouse positions are "pixel" positions whereas SFML graphics positions are world "co-ordinates".
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

HavingPhun

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Unsure of how to find the "Pixel Position" of sf::Text. [Solved]
« Reply #2 on: December 01, 2015, 02:20:07 am »
Thank you, that was exactly what I needed. I hadn't looked at the tutorial for several months, and was simply relying on previous experience with views and the sfml documentation. Thanks for your help.

 

anything