Exemple #1
0
        /// <summary>
        /// Initializes our own drag and determines whether we are a slave or the master and if there are actual slave handles in that case
        /// </summary>
        public void InitializeDrag(IInputModeContext context)
        {
            coreHandle.InitializeDrag(context);
            if (context.ParentInputMode is MoveInputMode)
            {
                //If we are moved via MoveInputMode (happens when the whole edge is dragged)
                //We only delegate to the core handle
                return;
            }
            var index = bend.GetIndex();

            IBend firstBend = index > 0 ? bend.Owner.Bends[index - 1] : null;
            IBend lastBend  = index < bend.Owner.Bends.Count - 1 ? bend.Owner.Bends[index + 1] : null;

            if (firstBend != null && lastBend != null &&
                OuterControlPointHandle.AreCollinear(firstBend.Location, bend.Location, lastBend.Location))
            {
                //Put a marker in the context so that the slave handles can distinguish whether they are moved dependent from us, or are dragged directly
                var childContext = Contexts.CreateInputModeContext(context.ParentInputMode, context, Lookups.Single(this));
                firstSlaveHandle = firstBend.Lookup <IHandle>();
                lastSlaveHandle  = lastBend.Lookup <IHandle>();

                if (firstSlaveHandle != null)
                {
                    firstSlaveHandle.InitializeDrag(childContext);
                    firstOrigin = firstSlaveHandle.Location.ToPointD();
                }
                if (lastSlaveHandle != null)
                {
                    lastSlaveHandle.InitializeDrag(childContext);
                    lastOrigin = lastSlaveHandle.Location.ToPointD();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes our own drag and determines whether we are a slave or the master and if there are actual slave handles in that case
        /// </summary>
        public void InitializeDrag(IInputModeContext context)
        {
            coreHandle.InitializeDrag(context);
            if (context.ParentInputMode is MoveInputMode)
            {
                //If we are moved via MoveInputMode (happens when the whole edge is dragged)
                //We only delegate to the core handle
                return;
            }

            //If we are indirectly controlled from the other control point or the bend curve point
            //those implementations put a marker in the lookup
            //If such a marker is present, we DON'T delegate to the other handle and just move ourselves.
            var bcph = context.Lookup <InnerControlPointHandle>();
            var cph  = context.Lookup <OuterControlPointHandle>();

            if (bcph == null && cph == null)
            {
                //We are the master handle and so we control the other one
                var index = bend.GetIndex();

                //Whether this is the first or the last bend in such a control point triple
                var isFirstInTriplet = index % 3 == 1;

                IBend otherBend  = null;
                IBend middleBend = null;
                if (isFirstInTriplet && index < bend.Owner.Bends.Count - 1)
                {
                    //We are the first of the triple and there is a potential slave handle
                    //So get the slave and the middle bend
                    otherBend  = bend.Owner.Bends[index + 2];
                    middleBend = bend.Owner.Bends[index + 1];
                }
                else if (index >= 3)
                {
                    //We are the last of the triple and there is a potential slave handle
                    //So get the slave and the middle bend
                    otherBend  = bend.Owner.Bends[index - 2];
                    middleBend = bend.Owner.Bends[index - 1];
                }
                if (otherBend != null && AreCollinear(bend.Location, middleBend.Location, otherBend.Location))
                {
                    slaveHandle    = otherBend.Lookup <IHandle>();
                    middleLocation = middleBend.Location.ToPointD();
                }

                if (slaveHandle != null)
                {
                    //There not only a bend, but actually a handle to control
                    //notify it that it is the slave
                    //We just put ourselves in the context, so our presence serves as flag to the other handle
                    //And from now on control its actions.
                    var childContext = Contexts.CreateInputModeContext(context.ParentInputMode, context, Lookups.Single(this));
                    slaveHandle.InitializeDrag(childContext);
                    slaveOrigin = slaveHandle.Location.ToPointD();
                }
            }
        }
Exemple #3
0
 private void InputModeOnDragCanceled(object sender, InputModeEventArgs inputModeEventArgs)
 {
     Unregister();
     if (graph.Contains(bend))
     {
         var   edge         = bend.Owner;
         var   bendIndex    = bend.GetIndex();
         IBend previousBend = null;
         IBend nextBend     = null;
         if (bendIndex > 0)
         {
             previousBend = edge.Bends[bendIndex - 1];
         }
         IBend prevPrevBend = null;
         if (bendIndex > 1)
         {
             prevPrevBend = edge.Bends[bendIndex - 2];
         }
         if (bendIndex < edge.Bends.Count - 1)
         {
             nextBend = edge.Bends[bendIndex + 1];
         }
         IBend nextNextBend = null;
         if (bendIndex < edge.Bends.Count - 2)
         {
             nextNextBend = edge.Bends[bendIndex + 2];
         }
         graph.Remove(bend);
         //Also remove the additional bends
         if (previousBend != null)
         {
             graph.Remove(previousBend);
         }
         if (nextBend != null)
         {
             graph.Remove(nextBend);
         }
         //And roll back the position change of the adjacent bends
         if (prevPrevBend != null)
         {
             PointD oldLocation;
             if (bendInputMode.LocationMementos.TryGetValue(prevPrevBend, out oldLocation))
             {
                 graph.SetBendLocation(prevPrevBend, oldLocation);
             }
         }
         if (nextNextBend != null)
         {
             PointD oldLocation;
             if (bendInputMode.LocationMementos.TryGetValue(nextNextBend, out oldLocation))
             {
                 graph.SetBendLocation(nextNextBend, oldLocation);
             }
         }
     }
 }