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 - Chopa17

Pages: [1]
1
Window / Re: Checking the position of the cursor in relation to buttons
« on: September 15, 2018, 08:50:44 pm »
Thanks, adding mapPixelToCoords() after subtracting the title bar height does work for fullscreen but not if the window is resized. However, I just found that you can pass the window to the get mouse position function. ie.
sf::Vector2i xPos = sf::Mouse::getPosition( TR_GameManager::GetGameWindow() );
This replaces the manual subtraction of the title bar height and works for resized windows as well.

2
Window / Checking the position of the cursor in relation to buttons
« on: September 15, 2018, 05:18:57 pm »
I'm trying to setup a changing texture based upon hovering over a button but having an issue that the hovering isn't matching up with the buttons rectangle, the image below demonstrates the problem for two different sized buttons (which have been cropped out from a maximised window with a titlebar).


This is my relevant piece of code:
void TR_GUI_Button::Draw()
{
        if (!m_bIsVisible) return;

        sf::Sprite xSprite;
        sf::Vector2i xPos = sf::Mouse::getPosition();

        if (!m_xRect.contains(xPos))
        {
                xSprite.setTexture(m_xDefaultTexture);
        }
        else
        {
                xSprite.setTexture(m_xHoverTexture);
        }

        float fScaleX = m_xRect.width / xSprite.getGlobalBounds().width;
        float fScaleY = m_xRect.height / xSprite.getGlobalBounds().height;
        xSprite.setScale(sf::Vector2f(fScaleX, fScaleY));
        xSprite.setPosition(static_cast<float>(m_xRect.left), static_cast<float>(m_xRect.top));

        TR_GameManager::GetGameWindow().draw(xSprite);
}
 

I thought it might be because the window's title bar wasn't being included so I added this code to the draw function:
xPos.y -= ::GetSystemMetrics(SM_CYCAPTION);

This still doesn't match up as it now overcompensates for the larger button.


Any help would be appreciated.

Pages: [1]
anything