Skip to content

Commit

Permalink
Foreground texture in Knob was wrongly positioned when a border was s…
Browse files Browse the repository at this point in the history
…et (which is supposed to be ignored when textures are used)
  • Loading branch information
texus committed Aug 30, 2023
1 parent b98ee39 commit 10d2e5b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Widgets/Knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ namespace tgui

m_bordersCached.updateParentSize(getSize());

if (m_spriteBackground.isSet() && m_spriteForeground.isSet())
{
if (m_spriteBackground.isSet())
m_spriteBackground.setSize(getSize());

if (m_spriteForeground.isSet())
{
m_spriteForeground.setSize({(m_spriteForeground.getTexture().getImageSize().x / static_cast<float>(m_spriteBackground.getTexture().getImageSize().x)) * getSize().x,
(m_spriteForeground.getTexture().getImageSize().y / static_cast<float>(m_spriteBackground.getTexture().getImageSize().y)) * getSize().y});
}
Expand Down Expand Up @@ -279,8 +281,8 @@ namespace tgui
if (m_spriteBackground.isSet() && m_spriteForeground.isSet())
{
// Only return true when the pixel under the mouse isn't transparent
if (!m_transparentTextureCached || !m_spriteBackground.isTransparentPixel(pos - m_bordersCached.getOffset())
|| !m_spriteForeground.isTransparentPixel(pos - m_bordersCached.getOffset() - ((getInnerSize() - m_spriteForeground.getSize()) / 2.f)))
if (!m_transparentTextureCached || !m_spriteBackground.isTransparentPixel(pos)
|| !m_spriteForeground.isTransparentPixel(pos - ((getInnerSize() - m_spriteForeground.getSize()) / 2.f)))
return true;
}
else // There is no texture, the widget has a circle shape
Expand Down Expand Up @@ -553,8 +555,11 @@ namespace tgui

Vector2f Knob::getInnerSize() const
{
return {std::max(0.f, getSize().x - m_bordersCached.getLeft() - m_bordersCached.getRight()),
std::max(0.f, getSize().y - m_bordersCached.getTop() - m_bordersCached.getBottom())};
if (m_spriteBackground.isSet())
return getSize();
else
return {std::max(0.f, getSize().x - m_bordersCached.getLeft() - m_bordersCached.getRight()),
std::max(0.f, getSize().y - m_bordersCached.getTop() - m_bordersCached.getBottom())};
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 10d2e5b

Please sign in to comment.