Ejemplo n.º 1
0
        public static IDrawingObject ReadDrawingObject(BinaryReader reader)
        {
            // read object type
            IDrawingObject obj  = null;
            int            type = reader.ReadInt32();

            switch ((DrawingObjectType)type)
            {
            case DrawingObjectType.Shape:
            {
                // read shape type
                int       shapeType = reader.ReadInt32();
                ShapeBase shape;

                if ((ShapeType)shapeType == ShapeType.Ellipse)
                {
                    shape = new Ellipse();
                }
                else
                {
                    shape = new FreePencil();
                }
                //var shape = ShapeFactory.CreateShape((ShapeType) shapeType);
                // write shape location
                shape.Location = ReadPoint(reader);
                // write shape size
                shape.Size = ReadSize(reader);
                // write shape outline color
                shape.OutlineColor = ReadColor(reader);
                // write shape outline width
                shape.OutlineWidth = reader.ReadSingle();
                // write shape outline dash
                shape.OutlineDash = (DashStyle)reader.ReadInt32();
                // write shape fill color
                shape.FillColor = ReadColor(reader);

                if (shape.GetShapeType() != ShapeType.Ellipse)
                {
                    // write count vertex
                    var vcount = reader.ReadInt32();
                    for (int i = 0; i < vcount; i++)
                    {
                        Vertex v = ReadVertex(reader);
                        shape.Vertices.Add(v);
                    }
                }

                if (shape.GetShapeType() == ShapeType.Polygon || shape.GetShapeType() == ShapeType.Oblong ||
                    shape.GetShapeType() == ShapeType.IsoscelesTriangle)
                {
                    var s = shape as PolygonBase;
                    s.IsClosedFigure = true;
                }
            }
            break;
            }

            return(obj);
        }
Ejemplo n.º 2
0
        public static IDrawingObject ReadDrawingObject(BinaryReader reader)
        {
            // read object type
            IDrawingObject obj = null;
            int type = reader.ReadInt32();

            switch ((DrawingObjectType)type)
            {
                case DrawingObjectType.Shape:
                {
                    // read shape type
                    int shapeType = reader.ReadInt32();
                    ShapeBase shape;

                    if ((ShapeType) shapeType == ShapeType.Ellipse)
                        shape = new Ellipse();
                    else
                        shape = new FreePencil();
                    //var shape = ShapeFactory.CreateShape((ShapeType) shapeType);
                    // write shape location
                    shape.Location = ReadPoint(reader);
                    // write shape size
                    shape.Size = ReadSize(reader);
                    // write shape outline color
                    shape.OutlineColor = ReadColor(reader);
                    // write shape outline width
                    shape.OutlineWidth = reader.ReadSingle();
                    // write shape outline dash
                    shape.OutlineDash = (DashStyle) reader.ReadInt32();
                    // write shape fill color
                    shape.FillColor = ReadColor(reader);

                    if (shape.GetShapeType() != ShapeType.Ellipse)
                    {
                        // write count vertex
                        var vcount = reader.ReadInt32();
                        for (int i = 0; i < vcount; i++)
                        {
                            Vertex v = ReadVertex(reader);
                            shape.Vertices.Add(v);
                        }
                    }

                    if (shape.GetShapeType() == ShapeType.Polygon || shape.GetShapeType() == ShapeType.Oblong ||
                        shape.GetShapeType() == ShapeType.IsoscelesTriangle)
                    {
                        var s = shape as PolygonBase;
                        s.IsClosedFigure = true;
                    }
                }
                    break;
            }

            return obj;
        }