Keep things from being dropped off the map

This commit is contained in:
Tim Young 2018-03-06 14:50:11 -06:00
parent efa99fc719
commit ef658c4a58

View File

@ -821,16 +821,32 @@ namespace EduNetworkBuilder
{
return new Rectangle(MyLocation.X, MyLocation.Y, Size, Size);
}
private void TryPutLocation(Point Location)
{
Network myNet = NB.GetNetwork();
if (myNet == null) {
MyLocation = Location; // We cannot do checking. Hope for the best.
return;
}
int x = Location.X;
int y = Location.Y;
if (x < 0) x = 0;
if (x > myNet.myWidth - Size) x = myNet.myWidth - Size;
if (y < 0) y = 0;
if (y > myNet.myHeight - Size) y = myNet.myHeight - Size;
MyLocation = new Point(x,y);
IsDirty = true;
}
public void ChangeLocation(Point Location)
{
MyLocation = NB.GetSnapped(Location);
IsDirty = true;
TryPutLocation(NB.GetSnapped(Location));
}
public void ChangeLocationUnsnapped(Point Location)
{
MyLocation = Location;
IsDirty = true;
TryPutLocation(Location);
}
public void SetSize(int tSize)