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 finished //There was an appropriate reason this packet finished. It stopped
} }
public enum VLANTagType { Tagged, Untagged, Forbidden } 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 LinkType { normal, wireless, broken }
public enum PacketType { none, ping_request, ping_answer, arp_request, arp_answer, dhcp_request, public enum PacketType { none, ping_request, ping_answer, arp_request, arp_answer, dhcp_request,
dhcp_answer, vpn_packet, tun_packet, tracert_request, tracert_reply } dhcp_answer, vpn_packet, tun_packet, tracert_request, tracert_reply }

View File

@ -15,13 +15,14 @@ namespace EduNetworkBuilder
{ {
public NetShapeType MyShape = NetShapeType.none; public NetShapeType MyShape = NetShapeType.none;
public Rectangle InArea; 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) public NetShape(NetShapeType What, Rectangle Where, Color color)
{ {
MyShape = What; MyShape = What;
InArea = Where; InArea = Where;
WhatColor = color; FillColor = color;
} }
public NetShape(XmlNode what) public NetShape(XmlNode what)
{ {
@ -32,26 +33,42 @@ namespace EduNetworkBuilder
/// Draw the specified shape on the image /// Draw the specified shape on the image
/// </summary> /// </summary>
/// <param name="baseImage"></param> /// <param name="baseImage"></param>
public void Draw(Image baseImage) public void Draw(Image baseImage, bool InShapeEditMode = false)
{ {
Graphics G = Graphics.FromImage(baseImage); Graphics G = Graphics.FromImage(baseImage);
Pen coloredPen = new Pen(WhatColor); Pen trimPen = new Pen(LineColor);
Brush coloredBrush = new SolidBrush(WhatColor); Brush coloredBrush = new SolidBrush(FillColor);
switch(MyShape) switch(MyShape)
{ {
case NetShapeType.circle: case NetShapeType.circle:
G.DrawEllipse(coloredPen, InArea); if(FillColor != Color.Empty)
break;
case NetShapeType.filled_circle:
G.FillEllipse(coloredBrush,InArea); G.FillEllipse(coloredBrush,InArea);
if (LineColor != Color.Empty)
G.DrawEllipse(trimPen, InArea);
break; break;
case NetShapeType.rectangle: case NetShapeType.rectangle:
G.DrawRectangle(coloredPen, InArea); if (FillColor != Color.Empty)
break;
case NetShapeType.filled_rectangle:
G.FillRectangle(coloredBrush, InArea); G.FillRectangle(coloredBrush, InArea);
if (LineColor != Color.Empty)
G.DrawRectangle(trimPen, InArea);
break; 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(); G.Dispose();
} }
@ -71,8 +88,11 @@ namespace EduNetworkBuilder
RectangleConverter converter = new RectangleConverter(); RectangleConverter converter = new RectangleConverter();
InArea = (Rectangle)converter.ConvertFromString(Individual.InnerText); InArea = (Rectangle)converter.ConvertFromString(Individual.InnerText);
break; break;
case "color": case "fillcolor":
WhatColor = Color.FromName(Individual.InnerText); FillColor = Color.FromName(Individual.InnerText);
break;
case "linecolor":
LineColor = Color.FromName(Individual.InnerText);
break; break;
} }
} }
@ -85,7 +105,8 @@ namespace EduNetworkBuilder
writer.WriteElementString("what", MyShape.ToString()); writer.WriteElementString("what", MyShape.ToString());
RectangleConverter converter = new RectangleConverter(); RectangleConverter converter = new RectangleConverter();
writer.WriteElementString("where", converter.ConvertToString(InArea)); writer.WriteElementString("where", converter.ConvertToString(InArea));
writer.WriteElementString("color", WhatColor.Name); writer.WriteElementString("fillcolor", FillColor.Name);
writer.WriteElementString("linecolor", LineColor.Name);
writer.WriteEndElement(); writer.WriteEndElement();
} }
} }