Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
 public ButtonPart(ButtonRecord rec, FlashDocument doc)
 {
     Character = doc[rec.CharacterID];
     Depth = rec.CharacterDepth;
     Matrix = rec.CharacterMatrix;
     CxForm = rec.CxForm;
     Up = rec.Up;
     Over = rec.Over;
     Down = rec.Down;
 }
Exemplo n.º 3
0
 internal RootMovieClip(FlashDocument document, ISystemServices services)
     : base(null, document, null)
 {
     ButtonStack = new VGMatrixStack(32);
     Services = services;
     Transparent = true;
     Root = this;
     StartTime = DateTime.Now;
     Document = document;
     Antialiasing = VGAntialiasing.Faster;
     GlobalScope = new GlobalScope(this);
     Context.RootClip = this;
     Context.Scope.AddFirst(GlobalScope);
 }
Exemplo n.º 4
0
        public ButtonInfo(ISwfDefinitionTag tag, ISystemServices services, FlashDocument document)
        {
            if (tag is DefineButtonTag)
                tag = new DefineButton2Tag(tag as DefineButtonTag);

            var b = tag as DefineButton2Tag;
            CxForm = null;
            TrackAsMenu = b.TrackAsMenu;
            Actions = b.Actions;
            ID = tag.CharacterID;

            Parts = b.Parts
                .Where(r => r.Up || r.Down || r.Over)
                .OrderBy(r => r.CharacterDepth)
                .Select(r => new ButtonPart(r, document))
                .Where(p => p.Character != null)
                .ToArray();

            GenerateHits(b, services, document);
        }
Exemplo n.º 5
0
        private void GenerateHits(DefineButton2Tag tag, ISystemServices services, FlashDocument document)
        {
            var hit = tag.Parts.Where(r => r.HitTest).Select(r => new ButtonPart(r, document));
            foreach (var h in hit)
            {
                if (h.Character == null) continue;
                if (!h.Character.Bounds.HasValue) continue;
                _hitBounds = Rectangle.Union(_hitBounds, TransformBounds(h.Character.Bounds.Value, h.Matrix));
            }
            if (_hitBounds == Rectangle.Empty)
                return;

            // Make Hit (using Color surface since Alpha8 is not supported everywhere)
            using (var surface = services.VectorDevice.CreateSurface(HitTestSize, HitTestSize, SurfaceFormat.Color))
            {
                var state = services.VectorDevice.CreateState();
                state.SetAntialiasing(VGAntialiasing.None);
                state.NonScalingStroke = true;
                state.FillRule = VGFillRule.EvenOdd;
                state.ColorTransformationEnabled = true;
                state.SetProjection(_hitBounds.Width, _hitBounds.Height);
                state.PathToSurface.Push(VGMatrix.Translate(-_hitBounds.Left, -_hitBounds.Top));

                using (var context = services.VectorDevice.BeginRendering(surface, state, new DisplayState(), true))
                {
                    foreach (var h in hit.OrderBy(c => c.Depth))
                    {
                        if (!(h.Character is Movie.IDrawable)) continue;
                        if (!h.Character.Bounds.HasValue) continue;

                        state.PathToSurface.PushCombineLeft(h.Matrix);
                        (h.Character as Movie.IDrawable).Draw(context);
                        state.PathToSurface.Pop();
                    }
                }

                Func<Color, byte> isCovered = (c) => (byte)((c.A != 0) ? 1 : 0);
                Color[] data = new Color[surface.Width * surface.Height];
                surface.Target.GetData(data);
                for (int y = 0; y < surface.Height; y++)
                {
                    for (int x = 0; x < surface.Width; )
                    {
                        var b = isCovered(data[x++]);
                        b <<= 1;
                        b |= isCovered(data[x++]);
                        b <<= 1;
                        b |= isCovered(data[x++]);
                        b <<= 1;
                        b |= isCovered(data[x++]);
                        b <<= 1;
                        b |= isCovered(data[x++]);
                        b <<= 1;
                        b |= isCovered(data[x++]);
                        b <<= 1;
                        b |= isCovered(data[x++]);
                        b <<= 1;
                        b |= isCovered(data[x++]);
                        _hitTestBitmap[(x / 8) - 1, y] = b;
                    }
                }
            }
        }
Exemplo n.º 6
0
        private VGPaint MakeFill(FillStyle f, IVGDevice device, FlashDocument document)
        {
            VGPaint paint = null;

            switch (f.FillType)
            {
                case FillStyle.FillStyleType.Solid:
                    paint = device.CreateColorPaint(f.Color);
                    break;
                case FillStyle.FillStyleType.Linear:
                    paint = device.CreateLinearPaint(f.Gradient.AsEnumerable(), f.Gradient.InterpolationMode == GradientInfo.Interpolation.Linear);
                    break;
                case FillStyle.FillStyleType.Radial:
                case FillStyle.FillStyleType.Focal:
                    paint = device.CreateRadialPaint(f.Gradient.AsEnumerable(), f.Gradient.InterpolationMode == GradientInfo.Interpolation.Linear);
                    break;
                case FillStyle.FillStyleType.RepeatingBitmap:
                case FillStyle.FillStyleType.RepeatingNonsmoothedBitmap:
                case FillStyle.FillStyleType.ClippedBitmap:
                case FillStyle.FillStyleType.ClippedNonsmoothedBitmap:
                    paint = device.CreatePatternPaint((document[f.BitmapID] as Bitmap).Image);
                    break;
            }

            if (paint is VGColorPaint)
                return paint;

            if (paint is VGGradientPaint)
            {
                if (f.Gradient is FocalGradientInfo)
                    (paint as VGRadialPaint).FocalPoint = (float)(f.Gradient as FocalGradientInfo).FocalPoint;

                var p = paint as VGGradientPaint;
                p.GradientFilter = TextureFilter.Linear;
                switch (f.Gradient.PadMode)
                {
                    case GradientInfo.Padding.Pad:
                        p.AddressMode = TextureAddressMode.Clamp;
                        break;
                    case GradientInfo.Padding.Reflect:
                        p.AddressMode = TextureAddressMode.Mirror;
                        break;
                    case GradientInfo.Padding.Repeat:
                        p.AddressMode = TextureAddressMode.Wrap;
                        break;
                }
            }

            if (paint is VGPatternPaint)
            {
                var i = (paint as VGPatternPaint).Pattern;
                switch (f.FillType)
                {
                    case FillStyle.FillStyleType.RepeatingBitmap:
                        i.ImageFilter = TextureFilter.Linear;
                        i.AddressMode = TextureAddressMode.Wrap;
                        break;
                    case FillStyle.FillStyleType.RepeatingNonsmoothedBitmap:
                        i.ImageFilter = TextureFilter.Point;
                        i.AddressMode = TextureAddressMode.Wrap;
                        break;
                    case FillStyle.FillStyleType.ClippedBitmap:
                        i.ImageFilter = TextureFilter.Linear;
                        i.AddressMode = TextureAddressMode.Clamp;
                        break;
                    case FillStyle.FillStyleType.ClippedNonsmoothedBitmap:
                        i.ImageFilter = TextureFilter.Point;
                        i.AddressMode = TextureAddressMode.Clamp;
                        break;
                }
            }

            return paint;
        }
Exemplo n.º 7
0
        public Text(DefineTextTag tag, ISystemServices services, FlashDocument document)
        {
            ID = tag.CharacterID;
            Matrix = tag.Matrix;
            Bounds = tag.Bounds;

            var path = new VGPath();
            var parts = new List<VGPreparedPath>();
            var scale = Vector2.One;
            var leftTop = new Vector2(tag.Bounds.Left, tag.Bounds.Top);

            Font font = null;
            ushort? lastFont = null;
            VGColor? lastColor = null;

            foreach (var rec in tag.TextRecords)
            {
                if ((rec.HasFont && lastFont != rec.FontId) || (rec.HasColor && lastColor != rec.Color))
                {
                    if (!path.IsEmpty && lastFont.HasValue && lastColor.HasValue)
                    {
                        var pp = services.VectorDevice.PreparePath(path, VGPaintMode.Fill);
                        pp.Tag = services.VectorDevice.CreateColorPaint(lastColor.Value);
                        parts.Add(pp);
                    }

                    path = new VGPath();
                }

                if (rec.HasColor) lastColor = rec.Color;
                if (rec.HasFont)
                {
                    font = document[rec.FontId] as Font;
                    scale = scale = new Vector2(rec.FontSize, rec.FontSize);
                    if (font != null) lastFont = rec.FontId;
                }

                if (font == null || !lastColor.HasValue || rec.Glyphs.Length == 0)
                    continue;

                var offset = new Vector2(rec.HasXOffset ? rec.XOffset : 0, rec.HasYOffset ? rec.YOffset : 0);
                var refPt = Vector2.Zero;
                if (rec.Glyphs[0].GlyphIndex < font.GlyphFont.Length)
                    refPt = font.GlyphFont[rec.Glyphs[0].GlyphIndex].ReferencePoint * scale;
                var xoff = Vector2.Zero;

                foreach (var g in rec.Glyphs)
                {
                    if (g.GlyphIndex >= font.GlyphFont.Length) continue;

                    var fg = font.GlyphFont[g.GlyphIndex];
                    if (fg.GlyphPath == null) continue;

                    var rpt = fg.ReferencePoint.X * scale.X;

                    var p = fg.GlyphPath.Clone();
                    p.Scale(scale);
                    p.Offset(offset + xoff);
                    path.Append(p);

                    xoff.X += g.GlyphAdvance;
                }
            }

            if (!path.IsEmpty && lastFont.HasValue && lastColor.HasValue)
            {
                var pp = services.VectorDevice.PreparePath(path, VGPaintMode.Fill);
                pp.Tag = services.VectorDevice.CreateColorPaint(lastColor.Value);
                parts.Add(pp);
            }

            TextParts = parts.ToArray();
        }