Esempio n. 1
0
        void IEventPortal.PortalMouseDown(UIMouseDownEventArgs e)
        {
            //find hit svg graphics....
            VgHitChain hitChain = GetFreeHitChain();

            hitChain.SetRootGlobalPosition(e.X, e.Y);
            //1. hit test
            HitTestCore(this.SvgRoot.SvgDoc.Root, hitChain, e.X, e.Y);
            SetEventOrigin(e, hitChain);
            //2. propagate event  portal
            ForEachOnlyEventPortalBubbleUp(e, hitChain, portal =>
            {
                portal.PortalMouseDown(e);
                return(true);
            });
            if (!e.CancelBubbling)
            {
                //2. propagate events
                ForEachSvgElementBubbleUp(e, hitChain, () =>
                {
                    //-------
                    //temp test only
                    //-------
                    var svgElement = e.ExactHitObject as SvgElement;
                    //if (svgElement is SvgRect)
                    //{
                    //    ((SvgRect)svgElement).FillColor = Color.White;
                    //}
                    return(true);
                });
            }

            e.CancelBubbling = true;
            ReleaseHitChain(hitChain);
        }
Esempio n. 2
0
        void IEventPortal.PortalMouseUp(UIMouseUpEventArgs e)
        {
            //find hit svg graphics....
            VgHitChain hitChain = GetFreeHitChain();

            hitChain.SetRootGlobalPosition(e.X, e.Y);
            //1. hit test
            HitTestCore(this.SvgRoot.SvgDoc.Root, hitChain, e.X, e.Y);
            SetEventOrigin(e, hitChain);
            //2. propagate event  portal
            ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) =>
            {
                portal.PortalMouseUp(e);
                return(true);
            });
            if (!e.CancelBubbling)
            {
                //2. propagate events
                ForEachEventListenerBubbleUp(e, hitChain, () =>
                {
                    e.CurrentContextElement.ListenMouseUp(e);
                    return(true);
                });
            }

            e.CancelBubbling = true;
            ReleaseHitChain(hitChain);
        }
Esempio n. 3
0
 static void SetEventOrigin(UIEventArgs e, VgHitChain hitChain)
 {
     int count = hitChain.Count;
     if (count > 0)
     {
         VgHitInfo hitInfo = hitChain.GetHitInfo(count - 1);
         e.SetExactHitObject(hitInfo);
     }
 }
        static void ForEachSvgElementBubbleUp(UIEventArgs e, VgHitChain hitChain, System.Func <bool> listenerAction)
        {
            for (int i = hitChain.Count - 1; i >= 0; --i)
            {
                //propagate up
                var hitInfo = hitChain.GetHitInfo(i);
                //---------------------
                //hit on element

                e.SetLocation((int)hitInfo.x, (int)hitInfo.y);
                if (listenerAction())
                {
                    return;
                }
            }
        }
Esempio n. 5
0
 static void ForEachOnlyEventPortalBubbleUp(UIEventArgs e, VgHitChain hitPointChain, System.Func<IEventPortal, bool> eventPortalAction)
 {
     //only listener that need tunnel down 
     for (int i = hitPointChain.Count - 1; i >= 0; --i)
     {
         //propagate up 
         VgHitInfo hitInfo = hitPointChain.GetHitInfo(i);
         if (hitInfo.hitElem.GetController() is SvgElement svg &&
            SvgElement.UnsafeGetController(svg) is IEventPortal controller)
         {
             e.SetLocation((int)hitInfo.x, (int)hitInfo.y);
             if (eventPortalAction(controller))
             {
                 return;
             }
         }
     }
 }
        static void ForEachEventListenerBubbleUp(UIEventArgs e, VgHitChain hitChain, System.Func <bool> listenerAction)
        {
            for (int i = hitChain.Count - 1; i >= 0; --i)
            {
                //propagate up
                VgHitInfo hitInfo = hitChain.GetHitInfo(i);

                IUIEventListener controller = SvgElement.UnsafeGetController(hitInfo.GetSvgElement()) as IUIEventListener;
                //switch (hitInfo.hitObjectKind)
                //{
                //    default:
                //        {
                //            continue;
                //        }
                //    case HitObjectKind.Run:
                //        {
                //            CssRun run = (CssRun)hitInfo.hitObject;
                //            controller = CssBox.UnsafeGetController(run.OwnerBox) as IEventListener;

                //        } break;
                //    case HitObjectKind.CssBox:
                //        {
                //            CssBox box = (CssBox)hitInfo.hitObject;
                //            controller = CssBox.UnsafeGetController(box) as IEventListener;
                //        } break;
                //}

                //---------------------
                if (controller != null)
                {
                    //found controller

                    e.SetCurrentContextElement(controller);
                    e.SetLocation((int)hitInfo.x, (int)hitInfo.y);
                    if (listenerAction())
                    {
                        return;
                    }
                }
            }
        }
 static void ForEachOnlyEventPortalBubbleUp(UIEventArgs e, VgHitChain hitPointChain, EventPortalAction eventPortalAction)
 {
     //only listener that need tunnel down
     for (int i = hitPointChain.Count - 1; i >= 0; --i)
     {
         //propagate up
         var        hitInfo = hitPointChain.GetHitInfo(i);
         SvgElement svg     = hitInfo.hitElem.GetController() as SvgElement;
         if (svg != null)
         {
             var controller = SvgElement.UnsafeGetController(svg) as IEventPortal;
             if (controller != null)
             {
                 e.SetLocation((int)hitInfo.x, (int)hitInfo.y);
                 if (eventPortalAction(controller))
                 {
                     return;
                 }
             }
         }
     }
 }
 public static void HitTestCore(SvgElement root, VgHitChain chain, float x, float y)
 {
     ////1.
     //chain.AddHit(root, x, y);
     ////2. find hit child
     //int j = root.ChildCount;
     //for (int i = 0; i < j; ++i)
     //{
     //}
     //var child = root.GetFirstNode();
     //TODO: review here again!
     // throw new System.NotImplementedException();
     //TODO: check hit test core on svg again!
     //while (child != null)
     //{
     //    //test hit text core again
     //    var node = child.Value;
     //    if (node.HitTestCore(chain, x, y))
     //    {
     //        break;
     //    }
     //    child = child.Next;
     //}
 }
Esempio n. 9
0
        void IEventPortal.PortalMouseMove(UIMouseMoveEventArgs e)
        {
            int x = e.X;
            int y = e.Y;

            if (e.IsDragging)
            {
                //dragging *** , if changed

                //handle mouse drag
                VgHitChain hitChain = GetFreeHitChain();
                hitChain.SetRootGlobalPosition(x, y);
                HitTestCore(this.SvgRoot.SvgDoc.Root, hitChain, e.X, e.Y);
                SetEventOrigin(e, hitChain);
                //---------------------------------------------------------
                //propagate mouse drag
                ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) =>
                {
                    portal.PortalMouseMove(e);
                    return(true);
                });
                //---------------------------------------------------------
                if (!e.CancelBubbling)
                {
                    //clear previous svg selection
                    ClearPreviousSelection();
                    //if (hitChain.Count > 0)
                    //{
                    //    //create selection range
                    //    _htmlContainer.SetSelection(new SelectionRange(
                    //        _latestMouseDownChain,
                    //        hitChain,
                    //        this.ifonts));
                    //}
                    //else
                    //{
                    //    _htmlContainer.SetSelection(null);
                    //}


                    ForEachEventListenerBubbleUp(e, hitChain, () =>
                    {
                        e.CurrentContextElement.ListenMouseMove(e);
                        return(true);
                    });
                }


                //---------------------------------------------------------
                ReleaseHitChain(hitChain);
            }
            else
            {
                //mouse move
                //---------------------------------------------------------
                VgHitChain hitChain = GetFreeHitChain();
                hitChain.SetRootGlobalPosition(x, y);
                HitTestCore(this.SvgRoot.SvgDoc.Root, hitChain, e.X, e.Y);
                SetEventOrigin(e, hitChain);
                //---------------------------------------------------------

                ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) =>
                {
                    portal.PortalMouseMove(e);
                    return(true);
                });
                //---------------------------------------------------------
                if (!e.CancelBubbling)
                {
                    ForEachEventListenerBubbleUp(e, hitChain, () =>
                    {
                        e.CurrentContextElement.ListenMouseMove(e);
                        return(true);
                    });
                }
                ReleaseHitChain(hitChain);
            }
        }
Esempio n. 10
0
 void ReleaseHitChain(VgHitChain hitChain)
 {
     hitChain.Clear();
     this.hitChainPools.Push(hitChain);
 }