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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - almog01

Pages: [1]
1
Hi! :)

Since the button object doesn't actually exist on the window - its visual representation is only a part of the texture used to draw the render texture to the window - no, not directly. You can, of course, calculate where it should be in relation to the render texture.

One other thing you could do is set up different views to represent the render textures and then use each of those views for the co-ordinate conversion.
So, set up - in addition to the normal window view - a view that places the co-ordinates of the render texture aligned with where they would be in the window. You could use a view's viewport to help with framing. Then, convert the mouse position to each view depending on which one you are comparing.

I had really short schedule for completing the project so in the end I was forced to just draw the button directly on the main window and live with it ::)
I was hoping that there is easier solution since I don't have much experience with view and viewport so I didn't try your solution yet. Maybe in the future I could try it and report if that works :)

Thanks for the help anyway!

2
Hello  :)

Usually I like to split my game window (of type RenderWindow) to regions: each region is a RenderTexture which in the end drawn on the main RenderWindow.
By doing this I can split completely the region of the game from the region of the toolbar for instance.

Problem is, when I place a button on the RenderTexture, and I want to check if the button was clicked:

first I'm saving the global coordinates of the mouse click:
const Vector2f mousePos = m_window.mapPixelToCoords({ event.mouseButton.x, event.mouseButton.y });
 
then I check if the button (of type RectangleShape) contains the position of the click:
if (m_button.getGlobalBounds().contains(mousePos))
 

And it doesn't work because the m_button.getGlobalBounds() returns the bounds that are relative to the RenderTexture, while m_window.mapPixelToCoords returns coordinates that are relative to the main RenderWindow.
It works only if the button was drawn directly on the main RenderWindow.

Is there a way to convert the mousePos coordinates to be relative to the RenderTexture. Or other way around, to check the GlobalBounds of the button that are relative to the RenderWindow?

Pages: [1]