Пример #1
0
        void NodeHostControl_Paint(object sender, PaintEventArgs e)
        {
            foreach (Control c in this.Controls)
            {
                IControlPointOwner cpowner = c as IControlPointOwner;
                if (cpowner != null)
                {
                    List <KeyValuePair <IControlPoint, IControlPoint> > hitlist = new List <KeyValuePair <IControlPoint, IControlPoint> >();
                    foreach (IControlPoint cp in cpowner.GetControlPoints())
                    {
                        //if (cp.isConnected())
                        {
                            foreach (IControlPoint target in cp.GetTargets())
                            {
                                if (target.MarkForDelete == true || cp.MarkForDelete == true)
                                {
                                    //cp.DisconnectControlPoint(target);
                                    hitlist.Add(new KeyValuePair <IControlPoint, IControlPoint>(cp, target));
                                    continue;
                                }


                                if (target == null)
                                {
                                    continue;
                                }
                                IControlPoint realTarget = target;
                                //proxy method
                                //if (mOwner != null)
                                //{
                                //   realTarget = mOwner.GetProxyControlPoint(this, target);
                                //}

                                //show @ level method:
                                if (GetCPLevel(target) != this.mGroupID)
                                {
                                    continue;
                                }

                                //TODO: add the concept endpoints having a color

                                Pen p = mTriggerPen;
                                if (realTarget.ToString() == "Activate")
                                {
                                    p = mTriggerActivatePen;
                                }
                                if (realTarget.ToString() == "Deactivate")
                                {
                                    p = mTriggerDeactivatePen;
                                }

                                if (cp.HighLight == true || realTarget.HighLight == true)
                                {
                                    p = mHighlightPen;
                                }

                                Point P1 = PointToClient(cp.GetPosition());
                                Point V1 = PointToClient(cp.GetVector());
                                Point V2 = PointToClient(realTarget.GetVector());
                                Point P2 = PointToClient(realTarget.GetPosition());


                                //smart(ish) routing for horizontal links...

                                //wire to self
                                if (P2.Y == P1.Y && Math.Abs(P1.X - P2.X) == 300)
                                {
                                    V1.Y -= 30;
                                    V2.Y -= 30;
                                    e.Graphics.DrawBezier(p,
                                                          P1,
                                                          (V1),
                                                          (V2),
                                                          P2);
                                }
                                else if (P2.X - P1.X < -50)// && P2.X - P1.X < 250)
                                {
                                    //if (P2.X - P1.X > 0 && P2.X - P1.X < 250)
                                    //{
                                    //   int num = (250 * (250 - (P2.X - P1.X)) / 250);
                                    //   V1.X -= num;
                                    //   V2.X += num;
                                    //}
                                    //int num = (250 * (250 - (P2.Y - P1.Y)) / 250);
                                    int num = (P2.Y - P1.Y) / 2;
                                    if (V2.Y > V1.Y)
                                    {
                                        V1.Y += 2 * num;
                                        V2.Y -= 30;
                                    }
                                    else
                                    {
                                        V1.Y -= 30;
                                        V2.Y -= 2 * num;
                                    }
                                    e.Graphics.DrawBezier(p,
                                                          P1,
                                                          (V1),
                                                          (V2),
                                                          P2);
                                }
                                else
                                {
                                    if (P2.X - P1.X > 0 && P2.X - P1.X < 250)
                                    {
                                        int num = (250 * (250 - (P2.X - P1.X)) / 250);
                                        V1.X -= num;
                                        V2.X += num;
                                    }
                                    else if (P2.X - P1.X > -50 && P2.X - P1.X < 0)
                                    {
                                        int num = (250 * (-50 - (P2.X - P1.X)) / 50);
                                        V1.X += num;
                                        V2.X -= num;
                                    }

                                    e.Graphics.DrawBezier(p,
                                                          P1,
                                                          (V1),
                                                          (V2),
                                                          P2);
                                }
                            }

                            //clean up
                        }
                    }
                    foreach (KeyValuePair <IControlPoint, IControlPoint> target in hitlist)
                    {
                        target.Key.DisconnectControlPoint(target.Value);
                    }
                }
            }

            //base.AutoScroll = true;
            //base.AutoScrollPosition = mAutoScrollPosition;
            //base.AutoScroll = false;
        }
Пример #2
0
        //void EndMove()
        //{
        //   mLastOffset = Point.e
        //}

        public void MoveControl(int x, int y, int keyPosX, int keyPosY)
        {
            mbMoving = true;
            Point thisPosition = this.PointToScreen(new Point(x, y));

            thisPosition = this.Parent.PointToClient(thisPosition);
            thisPosition.Offset(-keyPosX, -keyPosY);


            bool hitTopBoundry = false;

            if (thisPosition.Y < 0)
            {
                hitTopBoundry = true;
            }

            if (thisPosition.X - mHost.AutoScrollPosition.X > 0 && thisPosition.Y - mHost.AutoScrollPosition.Y > 0)
            {
                this.Location = thisPosition;
                //OnMoved();
            }
            else if (thisPosition.Y - mHost.AutoScrollPosition.Y > 0) //slide
            {
                thisPosition.X = 0;
                this.Location  = thisPosition;

                //OnMoved();
            }
            else if (thisPosition.X - mHost.AutoScrollPosition.X > 0) //slide
            {
                thisPosition.Y = 0;
                this.Location  = thisPosition;
                //OnMoved();
            }

            if (thisPosition.X - mHost.AutoScrollPosition.X > mHost.AutoScrollMinSize.Width - 300)
            {
                thisPosition.X = mHost.AutoScrollMinSize.Width + mHost.AutoScrollPosition.X - 300;
                this.Location  = thisPosition;
            }
            if (thisPosition.Y - mHost.AutoScrollPosition.Y > mHost.AutoScrollMinSize.Height - 300)
            {
                thisPosition.Y = mHost.AutoScrollMinSize.Height + mHost.AutoScrollPosition.Y - 300;
                this.Location  = thisPosition;
            }
            OnMoved();

            //if (thisPosition != this.Location)
            //{
            //   OnMoved();
            //}

            if (hitTopBoundry && thisPosition.X < 200)
            {
                DragOutOfHost();
            }

            mHost.Invalidate(false);
            return;

            IControlPointOwner cpowner = this as IControlPointOwner;

            if (cpowner != null)
            {
                foreach (IControlPoint cp in cpowner.GetControlPoints())
                {
                    if (cp.isConnected())
                    {
                        foreach (IControlPoint target in cp.GetTargets())
                        {
                            if (target == null)
                            {
                                continue;
                            }

                            Point p1     = mHost.PointToClient(cp.GetPosition());
                            Point p2     = mHost.PointToClient(target.GetPosition());
                            int   top    = Math.Min(p1.Y, p2.Y);
                            int   bottom = Math.Max(p1.Y, p2.Y);
                            int   left   = Math.Min(p1.X, p2.X);
                            int   right  = Math.Max(p1.X, p2.X);

                            Rectangle r = Rectangle.FromLTRB(left - 10, top - 10, right + 10, bottom + 10);
                            mHost.Invalidate(r, false);
                        }
                    }
                }
            }
        }