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); }
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; } } } }