コード例 #1
0
        private IEnumerable <LoadedShape> ReadShapes(string filePath)
        {
            using (XmlReader xmlReader = XmlReader.Create(filePath, new XmlReaderSettings {
                IgnoreWhitespace = true
            }))
            {
                xmlReader.ReadToFollowing("Shapes");
                XmlReader innerReader = xmlReader.ReadSubtree();
                // Read past the Shapes element so that we get to it's child elements.
                innerReader.Read();

                List <LoadedShape> loadedShapes = new List <LoadedShape>();
                while (innerReader.Read())
                {
                    if (innerReader.NodeType != XmlNodeType.EndElement)
                    {
                        // Reached a shape child of the Shapes element.

                        string shapeType = innerReader.LocalName;
                        Dictionary <string, string> attributes = GetAllAttributes(innerReader);
                        LoadedShape loadedShape = new LoadedShape(shapeType, attributes);
                        loadedShapes.Add(loadedShape);
                    }
                }

                return(loadedShapes);
            }
        }
コード例 #2
0
        private Pen CreatePen(LoadedShape shape)
        {
            // Mixing up colour vs color spellings here. A bit annoying.
            string colourName = shape.Attributes["Colour"];
            Color  colour     = Color.FromName(colourName);

            return(new Pen(colour));
        }
コード例 #3
0
        private Rectangle ExtractRectangleDataFromLoadedShape(LoadedShape shape)
        {
            int x      = Convert.ToInt32(shape.Attributes["X"]);
            int y      = Convert.ToInt32(shape.Attributes["Y"]);
            int width  = Convert.ToInt32(shape.Attributes["W"]);
            int height = Convert.ToInt32(shape.Attributes["H"]);

            return(new Rectangle(x, y, width, height));
        }
コード例 #4
0
        private DrawableLine CreateDrawableLine(LoadedShape loadedLine, Pen pen)
        {
            // Get the start and end coords from the value loaded from the file.
            int startX = Convert.ToInt32(loadedLine.Attributes["StartX"]);
            int startY = Convert.ToInt32(loadedLine.Attributes["StartY"]);
            int endX   = Convert.ToInt32(loadedLine.Attributes["EndX"]);
            int endY   = Convert.ToInt32(loadedLine.Attributes["EndY"]);

            // Create Points from these values.
            Point startPoint = new Point(startX, startY);
            Point endPoint   = new Point(endX, endY);

            return(new DrawableLine(pen, startPoint, endPoint));
        }
コード例 #5
0
        private DrawableEllipse CreateDrawableEllipse(LoadedShape loadedEllipse, Pen pen)
        {
            Rectangle boundingRectangle = ExtractRectangleDataFromLoadedShape(loadedEllipse);

            return(new DrawableEllipse(pen, boundingRectangle));;
        }
コード例 #6
0
        private DrawableRectangle CreateDrawableRectangle(LoadedShape loadedRectangle, Pen pen)
        {
            Rectangle rectangle = ExtractRectangleDataFromLoadedShape(loadedRectangle);

            return(new DrawableRectangle(pen, rectangle));
        }