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

Author Topic: How to check RectangleShape 's bounds with resizing window?  (Read 2294 times)

0 Members and 1 Guest are viewing this topic.

jbos190

  • Newbie
  • *
  • Posts: 9
    • View Profile
How to check RectangleShape 's bounds with resizing window?
« on: December 31, 2013, 07:37:47 am »
Hello, I am trying to build some simple GUI widgets in SFML 2.1.  I am using a RectangleShape as a text entry box.  When the user clicks the mouse, I check if it is within the RectangleShape 's GlobalBounds.  This check works as long as I don't resize the window.  If I resize the window, the displayed shape gets distorted, but the GlobalBounds remains unchanged.  Then when I click on the displayed rectangle, the mouseButton event's coordinates are not contained in the RectangleShape's GlobalBounds. 

I tried using the RectangleShape 's LocalBounds and the TextureRect, but those don't work either.  To be clear, I want to be able to resize my window and have the RectangleShape resize with it.  But when that happens, how can I check to see if a mouse click is within the bounds of the RectangleShape?
« Last Edit: December 31, 2013, 07:48:45 am by jbos190 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to check RectangleShape 's bounds with resizing window?
« Reply #1 on: December 31, 2013, 07:50:13 am »
What changes when you resize the window is the mapping between pixels and world coordinates, the shape itself doesn't change. You must use the function window.mapPixelToCoords to convert your mouse position.
Laurent Gomila - SFML developer

jbos190

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: How to check RectangleShape 's bounds with resizing window?
« Reply #2 on: December 31, 2013, 08:11:51 am »
What changes when you resize the window is the mapping between pixels and world coordinates, the shape itself doesn't change. You must use the function window.mapPixelToCoords to convert your mouse position.

Thank you.  That worked.  I had been trying mapCoordsToPixel instead of mapPixelToCoords.  Oops  :-[ .