From ef658c4a58f2431f2aabf9cd146a1b5f2b72bcbb Mon Sep 17 00:00:00 2001 From: Tim Young Date: Tue, 6 Mar 2018 14:50:11 -0600 Subject: [PATCH] Keep things from being dropped off the map --- EduNetworkBuilder/NetworkDevice.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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)