diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index cb9faa4..bfdb7f7 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -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)