function EstaEnPantalla(var rDestino,rOrigen:Trect;const espejo:bytebool):bytebool;
// Determina si la imagen que debe ser dibujada aparece en pantalla y modifica
//los rectángulos origen y destino si estos exceden las dimensiones adecuadas.
begin
with rDestino do
if (left<Limites_Lienzo.right) and (right>=Limites_Lienzo.left) and
(top<Limites_Lienzo.bottom) and (bottom>=Limites_Lienzo.top) then
begin
result:=true;
//Reducir el tamaño del cuadro si sale de pantalla
if espejo then
begin//caso del espejo
if right>Limites_Lienzo.right then
begin
right:=Limites_Lienzo.right;
rOrigen.Left:=rOrigen.Right-right+left;
end;
if left<Limites_Lienzo.left then
begin
left:=Limites_Lienzo.left;
rOrigen.right:=rOrigen.left+right-left;
end;
end
else
begin// caso normal
if right>Limites_Lienzo.right then
begin
right:=Limites_Lienzo.right;
rOrigen.Right:=rOrigen.Left+right-left;
end;
if left<Limites_Lienzo.left then
begin
left:=Limites_Lienzo.left;
rOrigen.Left:=rOrigen.Right-right+left;
end;
end;
if bottom>Limites_Lienzo.bottom then
begin
bottom:=Limites_Lienzo.bottom;
rOrigen.Bottom:=rOrigen.top+bottom-top;
end;
if top<Limites_Lienzo.top then
begin
top:=Limites_Lienzo.top;
rOrigen.top:=rOrigen.Bottom-bottom+top;
end;
end
else
result:=false;
end;