Change how we do filled stuff. And add ability to add drag marks on the corners when in shape edit mode

This commit is contained in:
Tim Young 2018-02-26 17:50:48 -06:00
parent 552c949a11
commit 483951f022
2 changed files with 38 additions and 17 deletions

View File

@ -29,7 +29,7 @@ namespace EduNetworkBuilder
finished //There was an appropriate reason this packet finished. It stopped
}
public enum VLANTagType { Tagged, Untagged, Forbidden }
public enum NetShapeType { none, circle, rectangle, filled_circle, filled_rectangle }
public enum NetShapeType { none, circle, rectangle, }
public enum LinkType { normal, wireless, broken }
public enum PacketType { none, ping_request, ping_answer, arp_request, arp_answer, dhcp_request,
dhcp_answer, vpn_packet, tun_packet, tracert_request, tracert_reply }

View File

@ -15,13 +15,14 @@ namespace EduNetworkBuilder
{
public NetShapeType MyShape = NetShapeType.none;
public Rectangle InArea;
public Color WhatColor = Color.Empty;
public Color LineColor = Color.Empty;
public Color FillColor = Color.Empty;
public NetShape(NetShapeType What, Rectangle Where, Color color)
{
MyShape = What;
InArea = Where;
WhatColor = color;
FillColor = color;
}
public NetShape(XmlNode what)
{
@ -32,26 +33,42 @@ namespace EduNetworkBuilder
/// Draw the specified shape on the image
/// </summary>
/// <param name="baseImage"></param>
public void Draw(Image baseImage)
public void Draw(Image baseImage, bool InShapeEditMode = false)
{
Graphics G = Graphics.FromImage(baseImage);
Pen coloredPen = new Pen(WhatColor);
Brush coloredBrush = new SolidBrush(WhatColor);
Pen trimPen = new Pen(LineColor);
Brush coloredBrush = new SolidBrush(FillColor);
switch(MyShape)
{
case NetShapeType.circle:
G.DrawEllipse(coloredPen, InArea);
break;
case NetShapeType.filled_circle:
if(FillColor != Color.Empty)
G.FillEllipse(coloredBrush,InArea);
if (LineColor != Color.Empty)
G.DrawEllipse(trimPen, InArea);
break;
case NetShapeType.rectangle:
G.DrawRectangle(coloredPen, InArea);
break;
case NetShapeType.filled_rectangle:
if (FillColor != Color.Empty)
G.FillRectangle(coloredBrush, InArea);
if (LineColor != Color.Empty)
G.DrawRectangle(trimPen, InArea);
break;
}
if(InShapeEditMode)
{
int sz = 5;
Color edgeColor = Color.Black;
if (FillColor == Color.Black) edgeColor = Color.White;
coloredBrush = new SolidBrush(edgeColor);
//We want to put drag-marks on the corners of our rectangle
Rectangle TL = new Rectangle(InArea.X, InArea.Y, sz, sz);
Rectangle TR = new Rectangle(InArea.X + InArea.Width - sz, InArea.Y, sz, sz);
Rectangle BL = new Rectangle(InArea.X, InArea.Y + InArea.Height - sz, sz, sz);
Rectangle BR = new Rectangle(InArea.X + InArea.Width - sz, InArea.Y + InArea.Height - sz, sz, sz);
G.FillRectangle(coloredBrush, TL);
G.FillRectangle(coloredBrush, TR);
G.FillRectangle(coloredBrush, BL);
G.FillRectangle(coloredBrush, BR);
}
G.Dispose();
}
@ -71,8 +88,11 @@ namespace EduNetworkBuilder
RectangleConverter converter = new RectangleConverter();
InArea = (Rectangle)converter.ConvertFromString(Individual.InnerText);
break;
case "color":
WhatColor = Color.FromName(Individual.InnerText);
case "fillcolor":
FillColor = Color.FromName(Individual.InnerText);
break;
case "linecolor":
LineColor = Color.FromName(Individual.InnerText);
break;
}
}
@ -85,7 +105,8 @@ namespace EduNetworkBuilder
writer.WriteElementString("what", MyShape.ToString());
RectangleConverter converter = new RectangleConverter();
writer.WriteElementString("where", converter.ConvertToString(InArea));
writer.WriteElementString("color", WhatColor.Name);
writer.WriteElementString("fillcolor", FillColor.Name);
writer.WriteElementString("linecolor", LineColor.Name);
writer.WriteEndElement();
}
}