Beispiel #1
0
 protected override Cursor CursorForHandle(ResizeHandle handle)
 {
     var def = base.CursorForHandle(handle);
     return _currentTool == null || handle == ResizeHandle.Center
                ? def
                : _currentTool.CursorForHandle(handle) ?? def;
 }
Beispiel #2
0
 protected virtual Cursor CursorForHandle(ResizeHandle handle)
 {
     switch (handle)
     {
         case ResizeHandle.TopLeft:
         case ResizeHandle.BottomRight:
             return Cursors.SizeNWSE;
         case ResizeHandle.TopRight:
         case ResizeHandle.BottomLeft:
             return Cursors.SizeNESW;
         case ResizeHandle.Top:
         case ResizeHandle.Bottom:
             return Cursors.SizeNS;
         case ResizeHandle.Left:
         case ResizeHandle.Right:
             return Cursors.SizeWE;
         case ResizeHandle.Center:
             return Cursors.SizeAll;
         default:
             return Cursors.Default;
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="obj"></param>
        public PathwayResizeHandler(PPathwayObject obj)
        {
            this.m_obj = obj;
            this.m_obj.VisibleChanged += new PPropertyEventHandler(Object_VisibleChanged);
            this.m_obj.HighLightChanged += new PPropertyEventHandler(Object_VisibleChanged);
            this.m_canvas = obj.Canvas;

            for (int i = 0; i < 8; i++)
            {
                ResizeHandle handle = new ResizeHandle();
                handle.MouseEnter += new PInputEventHandler(ResizeHandle_MouseEnter);
                handle.MouseLeave += new PInputEventHandler(ResizeHandle_MouseLeave);
                handle.MouseDown += new PInputEventHandler(ResizeHandle_MouseDown);
                handle.MouseDrag += new PInputEventHandler(ResizeHandle_MouseDrag);
                handle.MouseUp += new PInputEventHandler(ResizeHandle_MouseUp);
                handle.Cursor = GetCursor(i);
                handle.HandlePosition = i;
                m_resizeHandles.Add(handle);
            }
        }
Beispiel #4
0
        private static bool HitTest(DocRectangle docRect, Point pt, out ResizeHandle handle)
        {
            handle = ResizeHandle.None;

            if (docRect == null)
                return false;

            Rectangle rc = new Rectangle(
                (int)(docRect.X * Factor),
                (int)(docRect.Y * Factor),
                (int)(docRect.Width * Factor),
                (int)(docRect.Height * Factor));

            bool contains = rc.Contains(pt);
            if(contains)
            {
                int W = pt.X - rc.Left;
                int N = pt.Y - rc.Top;
                int S = rc.Bottom - pt.Y;
                int E = rc.Right - pt.X;

                int rad = 5;
                if(E < rad)
                {
                    handle |= ResizeHandle.East;
                }
                else if (W < rad)
                {
                    handle |= ResizeHandle.West;
                }
                if(S < rad)
                {
                    handle |= ResizeHandle.South;
                }
                else if (N < rad)
                {
                    handle |= ResizeHandle.North;
                }

                if (handle == ResizeHandle.None)
                    handle = ResizeHandle.Move;
            }
            return contains;
        }
Beispiel #5
0
        private void UpdateCursor(ResizeHandle handle)
        {
            switch(this.m_toolmode)
            {
                case ToolMode.Select:
                    this.Cursor = Cursors.Default;
                    break;

                case ToolMode.Move:
                    switch (handle)
                    {
                        case ResizeHandle.North | ResizeHandle.East:
                        case ResizeHandle.South | ResizeHandle.West:
                            this.Cursor = Cursors.SizeNESW;
                            break;

                        case ResizeHandle.North | ResizeHandle.West:
                        case ResizeHandle.South | ResizeHandle.East:
                            this.Cursor = Cursors.SizeNWSE;
                            break;

                        case ResizeHandle.West:
                        case ResizeHandle.East:
                            this.Cursor = Cursors.SizeWE;
                            break;

                        case ResizeHandle.North:
                        case ResizeHandle.South:
                            this.Cursor = Cursors.SizeNS;
                            break;

                        case ResizeHandle.Move:
                            this.Cursor = Cursors.SizeAll;
                            break;

                        default:
                            this.Cursor = Cursors.Default;
                            break;
                    }
                    break;

                case ToolMode.Link:
                    switch (handle)
                    {
                        case ResizeHandle.Move: // body -- attribute
                            this.Cursor = Cursors.Cross;
                            break;

                        case ResizeHandle.None:
                            this.Cursor = Cursors.No;
                            break;

                        default: // along edge -- inheritance
                            this.Cursor = Cursors.UpArrow;
                            break;
                    }
                    break;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Finds object at absolute point (regardless of scroll position or page)
        /// </summary>
        /// <param name="pt"></param>
        /// <returns></returns>
        private DocObject Pick(Point pt, out DocLine line, out ResizeHandle handle)
        {
            line = null;
            handle = ResizeHandle.None;

            if (this.m_schema == null)
                return null;

            pt.X -= this.AutoScrollPosition.X;
            pt.Y -= this.AutoScrollPosition.Y;

            PointF ptFloat = new PointF(pt.X, pt.Y);

            foreach(DocType docType in this.m_schema.Types)
            {
                if (HitTest(docType.DiagramRectangle, pt, out handle))
                    return docType;

                if(docType is DocSelect)
                {
                    DocSelect docSel = (DocSelect)docType;
                    foreach (DocLine docLine in docSel.Tree)
                    {
                        DocPoint docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1];
                        PointF ptA = new PointF((float)(docPoint.X * Factor), (float)docPoint.Y * Factor);
                        if (Math.Abs(ptFloat.X - ptA.X) < 4 && Math.Abs(ptFloat.Y - ptA.Y) <= 5)
                        {
                            handle = ResizeHandle.Move;
                            line = docLine;
                            return docType;
                        }
                    }
                }
            }

            foreach (DocEntity docType in this.m_schema.Entities)
            {
                if (HitTest(docType.DiagramRectangle, pt, out handle))
                    return docType;

                foreach(DocAttribute docAttr in docType.Attributes)
                {
                    if (docAttr.DiagramLine != null)
                    {
                        for(int i = 0; i < docAttr.DiagramLine.Count-1; i++)
                        {
                            PointF ptA = new PointF((float)(docAttr.DiagramLine[i].X * Factor), (float)docAttr.DiagramLine[i].Y * Factor);
                            PointF ptB = new PointF((float)(docAttr.DiagramLine[i+1].X * Factor), (float)docAttr.DiagramLine[i+1].Y * Factor);

                            PointF ptClosest = new PointF();
                            double distance = FindDistanceToSegment(ptFloat, ptA, ptB, out ptClosest);
                            if(distance < 3.0)
                            {
                                return docAttr;
                            }
                        }
                    }
                }

                foreach(DocLine docLine in docType.Tree)
                {
                    if (docLine.DiagramLine.Count > 0)
                    {
                        DocPoint docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1];
                        PointF ptA = new PointF((float)(docPoint.X * Factor), (float)docPoint.Y * Factor);
                        if (Math.Abs(ptFloat.X - ptA.X) < 4 && Math.Abs(ptFloat.Y - ptA.Y) <= 5)
                        {
                            line = docLine;
                            handle = ResizeHandle.Move;
                            return docType;
                        }
                    }
                }
            }

            foreach (DocComment docType in this.m_schema.Comments)
            {
                if (HitTest(docType.DiagramRectangle, pt, out handle))
                    return docType;
            }

            foreach (DocPageTarget docType in this.m_schema.PageTargets)
            {
                if (HitTest(docType.DiagramRectangle, pt, out handle))
                    return docType;

                foreach(DocPageSource docSource in docType.Sources)
                {
                    if (HitTest(docSource.DiagramRectangle, pt, out handle))
                        return docSource;
                }
            }

            foreach (DocPrimitive docType in this.m_schema.Primitives)
            {
                if (HitTest(docType.DiagramRectangle, pt, out handle))
                    return docType;
            }

            foreach (DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs)
            {
                foreach (DocDefinitionRef docType in docSchemaRef.Definitions)
                {
                    if (HitTest(docType.DiagramRectangle, pt, out handle))
                        return docType;

                    foreach (DocLine docLine in docType.Tree)
                    {
                        DocPoint docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1];
                        PointF ptA = new PointF((float)(docPoint.X * Factor), (float)docPoint.Y * Factor);
                        if (Math.Abs(ptFloat.X - ptA.X) < 4 && Math.Abs(ptFloat.Y - ptA.Y) <= 5)
                        {
                            handle = ResizeHandle.Move;
                            line = docLine;
                            return docType;
                        }
                    }
                }
            }

            return null;
        }