Indeed. It seemed weird at first glance but it is indeed a rather good solution.
I'm getting some little artefacts but I'll see if I can get rid of them later.
Thank you very much.
For those who are interested, here is the modified code:
EDIT: this solution only works if the texture has the same size than the circle.
EDIT2: I've updated the following code. It should work with any texture smaller or larger than the circle and produces no visual glitches.
void ArcCircle::setPortion(float portion)
{
m_portion = portion > 1.0 ? 1.0 : portion;
m_portion = portion < 0 ? 0 : portion;
if (getTexture())
{
Vector2i offset(0,0);
Vector2u size = getTexture()->getSize();
Vector2u halfSize(size.x / 2, size.y / 2);
Vector2f factor((float) halfSize.x / m_radius, (float) halfSize.y / m_radius);
switch ((int) (m_portion * 100) / 25)
{
case 0:
offset.x = round(getPoint(getPointCount() - 1).x * factor.x);
setTextureRect(IntRect(halfSize.x, 0, offset.x - halfSize.x, halfSize.y));
break;
case 1:
offset.y = round(getPoint(getPointCount() - 1).y * factor.y);
setTextureRect(IntRect(halfSize.x, 0, halfSize.x, offset.y));
break;
case 2:
offset.x = round(getPoint(getPointCount() - 1).x * factor.x);
setTextureRect(IntRect(offset.x, 0, size.x - offset.x, size.y));
break;
case 3:
setTextureRect(IntRect(0, 0, size.x, size.y));
break;
default:
setTextureRect(IntRect(0, 0, size.x, size.y));
break;
}
}
update();
}