Able to resize existing shapes

This commit is contained in:
Tim Young 2018-02-28 10:14:23 -06:00
parent 46bf7acee0
commit 4531e0526a
3 changed files with 64 additions and 3 deletions

View File

@ -105,9 +105,9 @@ namespace EduNetworkBuilder
int fY = ClickPoint.Y;
int halfWidth = InArea.Width / 2;
int halfHeight = InArea.Height / 2;
if (ClickPoint.X < InArea.X + halfWidth) fX = InArea.X;
if (ClickPoint.X > InArea.X + halfWidth) fX = InArea.X;
else fX = InArea.X + InArea.Width;
if (ClickPoint.Y < InArea.Y + halfHeight) fY = InArea.Y;
if (ClickPoint.Y > InArea.Y + halfHeight) fY = InArea.Y;
else fY = InArea.Y + InArea.Height;
return new Point(fX, fY);

View File

@ -485,6 +485,25 @@ namespace EduNetworkBuilder
return Dest;
}
/// <summary>
/// this is a reverse of clickedPos. Translate an image x/y to a picturebox location
/// </summary>
/// <param name="ImageLocation">The location on the backgroundimage</param>
/// <returns></returns>
public Point PictureBoxPoint(Point ImageLocation)
{
if (myPBox == null) return new Point(-1, -1);
double deltaX = (double)TheNetImage.Width / myPBox.Width;
double deltaY = (double)TheNetImage.Height / myPBox.Height;
Point Dest = new Point((int)(ImageLocation.X / deltaX), (int)(ImageLocation.Y / deltaY));
if (Dest.X > TheNetImage.Width) Dest = new Point(TheNetImage.Width, Dest.Y);
if (Dest.Y > TheNetImage.Height) Dest = new Point(Dest.X, TheNetImage.Height);
if (Dest.X < 0) Dest = new Point(0, Dest.Y);
if (Dest.Y < 0) Dest = new Point(Dest.X, 0);
return Dest;
}
public Point clickedPosCentered(Point pixelClickedOn)
{
Point NetPoint = clickedPos(pixelClickedOn);
@ -1120,6 +1139,16 @@ namespace EduNetworkBuilder
Shapes.Add(what);
}
public NetShape ShapeAtPoint(Point location)
{
foreach(NetShape shape in Shapes)
{
if (shape.CornersAreClickedOn(location))
return shape;
}
return null;
}
void KillAllExtraWindows(bool EvenRTF=false)
{
for(int i = Application.OpenForms.Count -1; i >=0; i--)

View File

@ -54,6 +54,7 @@ namespace EduNetworkBuilder
private Point OrigClickPoint = new Point(-1, -1);
private NetShapeType CurrentShape = NetShapeType.none;
private NetShape ShapeForEditing = null;
private string InitialFileLoad = "";
@ -1505,10 +1506,22 @@ namespace EduNetworkBuilder
Color LineColor = Color.FromName(lColor);
if (LineColor.Name != "Empty" || FillColor.Name != "Empty")
{
if (ShapeForEditing == null)
{
NetShape NS = new NetShape(CurrentShape, selectbox, FillColor, LineColor);
myNetwork.AddShape(NS);
UpdateForm();
}
else
{
ShapeForEditing.MyShape = CurrentShape;
ShapeForEditing.InArea = selectbox;
ShapeForEditing.FillColor = FillColor;
ShapeForEditing.LineColor = LineColor;
UpdateForm();
}
}
}
catch
@ -1638,7 +1651,26 @@ namespace EduNetworkBuilder
OrigClickPoint = myNetwork.clickedPosCentered(e.Location);
ClickedImageLocation = e.Location;
//See if we have clicked on something
ItemClickedOn = myNetwork.ItemAtPosition(location);
if (!myNetwork.InShapeEditMode)
{
ItemClickedOn = myNetwork.ItemAtPosition(location);
ShapeForEditing = null;
}
else
{
ItemClickedOn = null;
ShapeForEditing = myNetwork.ShapeAtPoint(location);
if(ShapeForEditing != null)
{
//we set the drag-point for the opposite corner
ClickedLocation = ShapeForEditing.OppositePoint(location);
ClickedImageLocation = myNetwork.PictureBoxPoint(ClickedLocation);
CurrentShape = ShapeForEditing.MyShape;
cbFillColor.Text = ShapeForEditing.FillColor.Name;
cbLineColor.Text = ShapeForEditing.LineColor.Name;
btnUpdateShape(); //Change the shape to what we are editing
}
}
if(e.Button == MouseButtons.Left)
MouseIsDown = true;
LastMouseDown = DateTime.UtcNow;