Cleaning up select multiple and move system

This commit is contained in:
Tim Young 2017-06-06 17:14:56 -05:00
parent 693c77cfe0
commit a99a9ed696
3 changed files with 39 additions and 12 deletions

View File

@ -348,6 +348,7 @@ namespace EduNetworkBuilder
myPBox = What; myPBox = What;
myPBox.BackgroundImage = TheNetImageBackground; myPBox.BackgroundImage = TheNetImageBackground;
myPBox.BackgroundImageLayout = ImageLayout.Stretch; myPBox.BackgroundImageLayout = ImageLayout.Stretch;
myPBox.SizeMode = PictureBoxSizeMode.StretchImage;
Print(); Print();
myPBox.Invalidate(); myPBox.Invalidate();
} }

View File

@ -940,11 +940,13 @@ namespace EduNetworkBuilder
} }
else else
{ {
if (MouseIsDown && ItemClickedOn == null && ItemsSelected.Count > 0) if (MouseIsDown && ItemsSelected.Count > 0)
{ {
//We were dragging stuff. All done now //We were dragging stuff. All done now
MouseIsDown = false; MouseIsDown = false;
ItemsSelected.Clear(); //clear it so we stop moving these ones ItemsSelected.Clear(); //clear it so we stop moving these ones
UpdateLinks();
UpdateVisuals();
return; return;
} }
if (MouseIsDown && ItemClickedOn == null) 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); Rectangle selectbox = new Rectangle(topCorner.X, topCorner.Y, botCorner.X - topCorner.X, botCorner.Y - topCorner.Y);
ItemsSelected.AddRange(myNetwork.DevicesInRectangle(selectbox)); ItemsSelected.AddRange(myNetwork.DevicesInRectangle(selectbox));
Console.WriteLine("Selected " + ItemsSelected.Count + " items"); //Console.WriteLine("Selected " + ItemsSelected.Count + " items");
MouseIsDown = false; MouseIsDown = false;
DrawHighlightBoxes();
pbNetworkView.Invalidate();
return; return;
} }
MouseIsDown = false; MouseIsDown = false;
@ -1116,6 +1120,23 @@ namespace EduNetworkBuilder
myNetwork.Invalidate(newrec); 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) private void pbNetworkView_MouseMove(object sender, MouseEventArgs e)
{ {
//Only do this 10 times a second //Only do this 10 times a second
@ -1156,25 +1177,25 @@ namespace EduNetworkBuilder
int sy; int sy;
int swidth; int swidth;
int sheight; int sheight;
if(ClickedImageLocation.X > e.Location.X ) if(ClickedLocation.X > MouseLocation.X )
{ {
sx = e.Location.X; sx = MouseLocation.X;
swidth = ClickedImageLocation.X - sx; swidth = ClickedLocation.X - sx;
} }
else else
{ {
sx = ClickedImageLocation.X; sx = ClickedLocation.X;
swidth = e.Location.X -sx; swidth = MouseLocation.X - sx;
} }
if (ClickedImageLocation.Y > e.Location.Y) if (ClickedLocation.Y > MouseLocation.Y)
{ {
sy = e.Location.Y; sy = MouseLocation.Y;
sheight = ClickedImageLocation.Y - sy; sheight = ClickedLocation.Y - sy;
} }
else else
{ {
sy = ClickedImageLocation.Y; sy = ClickedLocation.Y;
sheight = e.Location.Y - sy; sheight = MouseLocation.Y - sy;
} }
Rectangle selectbox = new Rectangle(sx,sy,swidth,sheight); Rectangle selectbox = new Rectangle(sx,sy,swidth,sheight);

View File

@ -701,6 +701,11 @@ namespace EduNetworkBuilder
return new Point(MyLocation.X + delta, MyLocation.Y + delta); 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) public void ChangeLocation(Point Location)
{ {
MyLocation = NB.GetSnapped(Location); MyLocation = NB.GetSnapped(Location);