- Code: Select all
procedure TGraphConstraints.ConfineRect(var Rect: TRect); //(It doesnt keep the size of the rect)
begin
ConfinePt(Rect.TopLeft); //confining point (TopLeft)
ConfinePt(Rect.BottomRight); //confining point (BottomRight)
end;
The alternative I found to this code is the following:
- Code: Select all
procedure TGraphConstraints.ConfineRect(var Rect: TRect); //(Keeping the size of the Rect)
var DistanceBetweenYs,DistanceBetweenXs:integer;
begin
DistanceBetweenYs:=(Rect.Right-Rect.Left); // Right:Top
DistanceBetweenXs:=(Rect.Top-Rect.Bottom); // Left:Bottom
if Rect.Left < BoundsRect.Left then
Rect.Left := BoundsRect.Left;
if Rect.Right - DistanceBetweenYs < BoundsRect.Left then
Rect.Right := BoundsRect.Left+ DistanceBetweenYs;
if Rect.Right > BoundsRect.Right then
Rect.Right := BoundsRect.Right;
if Rect.Left + DistanceBetweenYs > BoundsRect.Right then
Rect.Left := BoundsRect.Right - DistanceBetweenYs;
if Rect.Bottom > BoundsRect.Bottom then
Rect.Bottom := BoundsRect.Bottom;
if Rect.Top - DistanceBetweenXs > BoundsRect.Bottom then
Rect.Top := BoundsRect.Bottom + DistanceBetweenXs;
if Rect.Top < BoundsRect.Top then
Rect.Top := BoundsRect.Top;
if Rect.Bottom + DistanceBetweenXs < BoundsRect.Top then
Rect.Bottom := BoundsRect.Top - DistanceBetweenXs;
end;
...yes...