コード例 #1
0
ファイル: Shape.cs プロジェクト: kaldap/XnaFlash
 private PathBuilder GetByLineStyle(LineStyle style, SubShape subShape)
 {
     if (style == null) return null;
     if (subShape.Lines.ContainsKey(style)) return subShape.Lines[style];
     var b = new PathBuilder(false, style.NoClose);
     b.Tag = style;
     subShape.Lines.Add(style, b);
     return b;
 }
コード例 #2
0
ファイル: Shape.cs プロジェクト: kaldap/XnaFlash
 private PathBuilder GetByFillStyle(FillStyle style, SubShape subShape)
 {
     if (style == null) return null;
     if (subShape.Fills.ContainsKey(style)) return subShape.Fills[style];
     var b = new PathBuilder(true, false);
     b.Tag = style;
     subShape.Fills.Add(style, b);
     return b;
 }
コード例 #3
0
ファイル: Shape.cs プロジェクト: kaldap/XnaFlash
        public Shape(ISwfDefinitionTag tag, ISystemServices services, FlashDocument document)
        {
            var state = services.VectorDevice.State;
            var t = tag as DefineShapeTag;
            var shapes = t.Shape.SubShapes;

            ID = tag.CharacterID;
            Bounds = t.ShapeBounds;
            _subShapes = new SubShape[shapes.Length];
            for (int s = 0; s < _subShapes.Length; s++)
            {
                var subShape = _subShapes[s] = new SubShape();
                var shape = shapes[s];

                subShape._fills = new SubShapeFill[shape.Fills.Count];
                subShape._strokes = new SubShapeStroke[shape.Lines.Count];

                var paints = new List<VGPaint>(shape.Fills.Count + shape.Lines.Count);
                int i = 0;
                VGPaint paint;

                foreach (var f in shape.Fills)
                {
                    paints.Add(paint = MakeFill(f.Key, services.VectorDevice, document));
                    subShape._fills[i++] = new SubShapeFill
                    {
                        Paint = paint,
                        FillMatrix = f.Key.Matrix,
                        Path = services.VectorDevice.PreparePath(f.Value.GetPath(), VGPaintMode.Fill)
                    };
                }

                i = 0;
                foreach (var l in shape.Lines)
                {
                    paint = l.Key.HasFill ? MakeFill(l.Key.Fill, services.VectorDevice, document) : services.VectorDevice.CreateColorPaint(l.Key.Color);
                    paints.Add(paint);

                    state.StrokeStartCap = l.Key.StartCapStyle;
                    state.StrokeEndCap = l.Key.EndCapStyle;
                    state.StrokeJoin = l.Key.JoinStyle;
                    state.StrokeMiterLimit = (float)l.Key.MiterLimit;
                    subShape._strokes[i++] = new SubShapeStroke
                    {
                        Paint = paint,
                        Path = services.VectorDevice.PreparePath(l.Value.GetPath(), VGPaintMode.Stroke),
                        Thickness = l.Key.Width,
                        FillMatrix = l.Key.HasFill ? l.Key.Fill.Matrix : VGMatrix.Identity,
                        ScaleX = !l.Key.NoHScale,
                        ScaleY = !l.Key.NoVScale
                    };
                }

                subShape._paints = paints.ToArray();
            }
        }
コード例 #4
0
ファイル: Shape.cs プロジェクト: kaldap/XnaFlash
        private void LoadEdges(IEnumerable<ShapeRecord> records, bool rtReverse)
        {
            bool ltReverse = !rtReverse;
            int x = 0, y = 0, tx, ty, cx, cy;
            Point? refPt = null;
            PathBuilder ltFill = null, rtFill = null;
            PathBuilder stroke = null;
            List<SubShape> subShapes = new List<SubShape>();
            SubShape subShape = new SubShape(this);

            foreach (var r in records)
            {
                switch (r.Type)
                {
                    case ShapeRecord.ShapeRecordType.StraightEdge:
                        tx = x + r.DrawDeltaX;
                        ty = y + r.DrawDeltaY;

                        if (!refPt.HasValue) refPt = new Point(x, y);
                        if (ltFill != null) ltFill.Line(x, y, tx, ty, ltReverse);
                        if (rtFill != null) rtFill.Line(x, y, tx, ty, rtReverse);
                        if (stroke != null) stroke.Line(x, y, tx, ty, rtReverse);

                        x = tx;
                        y = ty;
                        break;
                    case ShapeRecord.ShapeRecordType.CurvedEdge:
                        cx = x + r.DrawControlX;
                        cy = y + r.DrawControlY;
                        tx = cx + r.DrawDeltaX;
                        ty = cy + r.DrawDeltaY;

                        if (!refPt.HasValue) refPt = new Point(x, y);
                        if (ltFill != null) ltFill.Curve(x, y, tx, ty, cx, cy, ltReverse);
                        if (rtFill != null) rtFill.Curve(x, y, tx, ty, cx, cy, rtReverse);
                        if (stroke != null) stroke.Curve(x, y, tx, ty, cx, cy, rtReverse);

                        x = tx;
                        y = ty;
                        break;
                    case ShapeRecord.ShapeRecordType.StyleChange:
                        if (r.NewMoveTo)
                        {
                            x = r.MoveDeltaX;
                            y = r.MoveDeltaY;
                        }
                        if (r.NewFillStyle0)
                            ltFill = GetByFillStyle(r.FillStyle0, subShape);
                        if (r.NewFillStyle1)
                            rtFill = GetByFillStyle(r.FillStyle1, subShape);
                        if (r.NewLineStyle)
                            stroke = GetByLineStyle(r.LineStyle, subShape);
                        if (r.NewStyles)
                        {
                            foreach (var s in subShape.Fills.Values) s.Flush();
                            foreach (var s in subShape.Lines.Values) s.Flush();
                            subShapes.Add(subShape);
                            subShape = new SubShape(this);
                        }
                        break;
                }
            }

            foreach (var s in subShape.Fills.Values) s.Flush();
            foreach (var s in subShape.Lines.Values) s.Flush();
            subShapes.Add(subShape);

            ReferencePoint = refPt ?? new Point(0, 0);
            SubShapes = subShapes.ToArray();
        }