Beispiel #1
0
        /// <summary>
        /// Set all the PrimitivePens into xml document
        /// </summary>
        private void SetPrimitivePens(XmlDocument doc, XmlElement newTemplate, BackgroundTemplate template)
        {
            XmlElement primitivePens = doc.CreateElement("PrimitivePens");

            for (int i = 0; i < template.PrimitivePens.Count; i++)
            {
                SerializablePen pen = (SerializablePen)template.PrimitivePens[i];

                XmlElement penElement = doc.CreateElement("Pen");

                XmlAttribute index = doc.CreateAttribute("index");
                index.InnerText = "" + pen.Index;
                penElement.SetAttributeNode(index);

                XmlAttribute width = doc.CreateAttribute("width");
                width.InnerText = "" + pen.Width;
                penElement.SetAttributeNode(width);

                XmlAttribute color = doc.CreateAttribute("color");
                color.Value = pen.Color.Name;
                penElement.SetAttributeNode(color);

                XmlAttribute dashstyle = doc.CreateAttribute("dashstyle");
                dashstyle.Value = pen.DashStyle.ToString();
                penElement.SetAttributeNode(dashstyle);

                primitivePens.AppendChild(penElement);
            }

            newTemplate.AppendChild(primitivePens);
        }
        /// <summary>
        /// Draw the line
        /// </summary>
        public override void Draw(BackgroundTemplate parent, Graphics g, Rectangle r)
        {
            PointF newS, newD, oldP1, oldP2;

            oldP1 = this.m_Line.P1;
            oldP2 = this.m_Line.P2;

            //Update P1 P2 if the line is repeated
            this.CheckForIterater();

            newS = this.m_Line.P1;
            newD = this.m_Line.P2;

            switch (this.m_Line.LineType)
            {
            case LineType.LINE: GetLineRectIntersections(parent, ref newS, ref newD); break;

            case LineType.RAY: GetRayRectIntersections(parent, ref newD); break;

            case LineType.SEGMENT: break;
            }

            SerializablePen pen = parent.GetPrimitivePenByIndex(this.m_Line.PenIndex);

            if (pen != null)
            {
                g.DrawLine(pen.GetPen(), newS, newD);
            }

            this.m_Line.P1 = oldP1;
            this.m_Line.P2 = oldP2;
        }
Beispiel #3
0
        /// <summary>
        /// Parse all the pens, and add them into the PrimitivePens List in BackgroundTemplate
        /// </summary>
        private void ParsePrimitivePens(XmlNode primitivePensNode, BackgroundTemplate template)
        {
            for (int i = 0; i < primitivePensNode.ChildNodes.Count; i++)
            {
                XmlNode         penNode = primitivePensNode.ChildNodes[i];
                SerializablePen pen;

                //Get the pen color
                Color color = Color.Black;

                XmlAttribute attribute = penNode.Attributes["color"];

                if (attribute != null)
                {
                    String colorStr = attribute.Value;
                    color = ParseColor(colorStr);
                }

                pen = new SerializablePen(color);

                //Get the pen dashstyle
                attribute = penNode.Attributes["dashstyle"];
                if (attribute != null)
                {
                    switch (attribute.Value)
                    {
                    case "Solid": pen.DashStyle = DashStyle.Solid; break;

                    case "Dot": pen.DashStyle = DashStyle.Dot; break;

                    case "Dash": pen.DashStyle = DashStyle.Dash; break;

                    case "DashDot": pen.DashStyle = DashStyle.DashDot; break;

                    case "DashDotDot": pen.DashStyle = DashStyle.DashDotDot; break;

                    default: pen.DashStyle = DashStyle.Solid; break;
                    }
                }

                //get the pen width
                float width = 1f;
                attribute = penNode.Attributes["width"];
                if (attribute != null)
                {
                    try
                    {
                        width = float.Parse(attribute.Value);
                    }
                    catch { width = 1f; }
                }
                pen.Width = width;

                //get the pen index
                int index = i;

                attribute = penNode.Attributes["index"];
                if (attribute != null)
                {
                    try{
                        index = Int32.Parse(attribute.Value);
                    }
                    catch {
                        index = i;
                    }
                }
                pen.Index = index;

                template.PrimitivePens.Add(pen);
            }
        }