Fix for image resize flicker when using MaxSize

This commit is contained in:
pjft 2018-06-04 18:55:14 +01:00
parent 0928498ef2
commit 68dff607c8

View file

@ -55,20 +55,19 @@ void ImageComponent::resize()
mSize = textureSize; mSize = textureSize;
Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y())); Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y()));
if(resizeScale.x() < resizeScale.y()) if(resizeScale.x() < resizeScale.y())
{ {
mSize[0] *= resizeScale.x(); mSize[0] *= resizeScale.x(); // this will be mTargetSize.x(). We can't exceed it, nor be lower than it.
mSize[1] *= resizeScale.x(); // we need to make sure we're not creating an image larger than max size
mSize[1] = Math::min(Math::round(mSize[1] *= resizeScale.x()), mTargetSize.y());
}else{ }else{
mSize[0] *= resizeScale.y(); mSize[1] = Math::round(mSize[1] *= resizeScale.y()); // this will be mTargetSize.y(). We can't exceed it.
mSize[1] *= resizeScale.y();
// for SVG rasterization, always calculate width from rounded height (see comment above)
// we need to make sure we're not creating an image larger than max size
mSize[0] = Math::min((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
} }
// for SVG rasterization, always calculate width from rounded height (see comment above)
mSize[1] = Math::round(mSize[1]);
mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x();
}else if(mTargetIsMin) }else if(mTargetIsMin)
{ {
mSize = textureSize; mSize = textureSize;
@ -91,8 +90,9 @@ void ImageComponent::resize()
} }
// for SVG rasterization, always calculate width from rounded height (see comment above) // for SVG rasterization, always calculate width from rounded height (see comment above)
mSize[1] = Math::round(mSize[1]); // we need to make sure we're not creating an image smaller than min size
mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x(); mSize[1] = Math::max(Math::round(mSize[1]), mTargetSize.y());
mSize[0] = Math::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
}else{ }else{
// if both components are set, we just stretch // if both components are set, we just stretch