From a99a9ed69638c03185c5d0e9a215db15ea3e19cb Mon Sep 17 00:00:00 2001 From: Tim Young Date: Tue, 6 Jun 2017 17:14:56 -0500 Subject: [PATCH] Cleaning up select multiple and move system --- EduNetworkBuilder/Network.cs | 1 + EduNetworkBuilder/NetworkBuilder.cs | 45 +++++++++++++++++++++-------- EduNetworkBuilder/NetworkDevice.cs | 5 ++++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 70287aa..f69fa93 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -348,6 +348,7 @@ namespace EduNetworkBuilder myPBox = What; myPBox.BackgroundImage = TheNetImageBackground; myPBox.BackgroundImageLayout = ImageLayout.Stretch; + myPBox.SizeMode = PictureBoxSizeMode.StretchImage; Print(); myPBox.Invalidate(); } diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 7781ef3..54b3b1e 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -940,11 +940,13 @@ namespace EduNetworkBuilder } else { - if (MouseIsDown && ItemClickedOn == null && ItemsSelected.Count > 0) + if (MouseIsDown && ItemsSelected.Count > 0) { //We were dragging stuff. All done now MouseIsDown = false; ItemsSelected.Clear(); //clear it so we stop moving these ones + UpdateLinks(); + UpdateVisuals(); return; } if (MouseIsDown && ItemClickedOn == null) @@ -983,8 +985,10 @@ namespace EduNetworkBuilder Rectangle selectbox = new Rectangle(topCorner.X, topCorner.Y, botCorner.X - topCorner.X, botCorner.Y - topCorner.Y); ItemsSelected.AddRange(myNetwork.DevicesInRectangle(selectbox)); - Console.WriteLine("Selected " + ItemsSelected.Count + " items"); + //Console.WriteLine("Selected " + ItemsSelected.Count + " items"); MouseIsDown = false; + DrawHighlightBoxes(); + pbNetworkView.Invalidate(); return; } MouseIsDown = false; @@ -1116,6 +1120,23 @@ namespace EduNetworkBuilder myNetwork.Invalidate(newrec); } + private void DrawHighlightBoxes() + { + Image tImage = new Bitmap(pbNetworkView.BackgroundImage.Width, pbNetworkView.BackgroundImage.Height); + Graphics tGraphics = Graphics.FromImage(tImage); + tGraphics.Clear(Color.Transparent); //erase the whole thing + + Color tColor = Color.LightGreen; + SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(128, tColor.R, tColor.G, tColor.B)); + foreach (NetworkDevice nd in ItemsSelected) + { + tGraphics.FillRectangle(semiTransBrush, nd.GetMyRectangle()); + } + pbNetworkView.Image = tImage; + pbNetworkView.Invalidate(); + + } + private void pbNetworkView_MouseMove(object sender, MouseEventArgs e) { //Only do this 10 times a second @@ -1156,25 +1177,25 @@ namespace EduNetworkBuilder int sy; int swidth; int sheight; - if(ClickedImageLocation.X > e.Location.X ) + if(ClickedLocation.X > MouseLocation.X ) { - sx = e.Location.X; - swidth = ClickedImageLocation.X - sx; + sx = MouseLocation.X; + swidth = ClickedLocation.X - sx; } else { - sx = ClickedImageLocation.X; - swidth = e.Location.X -sx; + sx = ClickedLocation.X; + swidth = MouseLocation.X - sx; } - if (ClickedImageLocation.Y > e.Location.Y) + if (ClickedLocation.Y > MouseLocation.Y) { - sy = e.Location.Y; - sheight = ClickedImageLocation.Y - sy; + sy = MouseLocation.Y; + sheight = ClickedLocation.Y - sy; } else { - sy = ClickedImageLocation.Y; - sheight = e.Location.Y - sy; + sy = ClickedLocation.Y; + sheight = MouseLocation.Y - sy; } Rectangle selectbox = new Rectangle(sx,sy,swidth,sheight); diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 5b96e87..14637a0 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -701,6 +701,11 @@ namespace EduNetworkBuilder return new Point(MyLocation.X + delta, MyLocation.Y + delta); } + public Rectangle GetMyRectangle() + { + return new Rectangle(MyLocation.X, MyLocation.Y, Size, Size); + + } public void ChangeLocation(Point Location) { MyLocation = NB.GetSnapped(Location);