private bool ClipCoordinates(ref float x, ref float y, ref float width, ref float height, ref float s, ref float t, ref float s2, ref float t2)
{
if((_enableClipping == false) || (_clipRectangles.Count == 0))
{
return false;
}
foreach(idRectangle clipRect in _clipRectangles)
{
float ox = x;
float oy = y;
float ow = width;
float oh = height;
if((ow <= 0.0f) || (oh <= 0.0f))
{
break;
}
if(x < clipRect.X)
{
width -= clipRect.X - x;
x = clipRect.X;
}
else if(x > (clipRect.X + clipRect.Width))
{
x = width = y = height = 0;
}
if(y < clipRect.Y)
{
height -= clipRect.Y - y;
y = clipRect.Y;
}
else if(y > (clipRect.Y + clipRect.Height))
{
x = width = y = height = 0;
}
if(width > clipRect.Width)
{
width = clipRect.Width - x + clipRect.X;
}
else if((x + width) > (clipRect.X + clipRect.Width))
{
width = clipRect.Right - x;
}
if(height > clipRect.Height)
{
height = clipRect.Height - y + clipRect.Y;
}
else if((y + height) > (clipRect.Y + clipRect.Height))
{
height = clipRect.Bottom - y;
}
if(ow > 0.0f)
{
float ns1, ns2, nt1, nt2;
// upper left
float u = (x - ox) / ow;
ns1 = s * (1.0f - u) + s2 * u;
// upper right
u = (x + width - ox) / ow;
ns2 = s * (1.0f - u) + s2 * u;
// lower left
u = (y - oy) / oh;
nt1 = t * (1.0f - u) + t2 * u;
// lower right
u = (y + height - oy) / oh;
nt2 = t * (1.0f - u) + t2 * u;
// set values
s = ns1;
s2 = ns2;
t = nt1;
t2 = nt2;
}
}
return ((width == 0) || (height == 0));
}