Exemplo n.º 1
0
        /// <summary>
        /// Check point position to see if it's on tracker
        /// </summary>
        /// <param name="point">Current Point Position</param>
        /// <returns></returns>
        public bool Hit_Test(Point point)
        {
            //Check if the point is somewhere on the tracker
            if (!ControlRect.Contains(point))
            {
                //should never happen
                Cursor.Current = Cursors.Arrow;

                return(false);
            }
            else if (SmallRect[0].Contains(point))
            {
                Cursor.Current = Cursors.SizeNWSE;
                CurrBorder     = RESIZE_BORDER.RB_TOPLEFT;
            }
            else if (SmallRect[3].Contains(point))
            {
                Cursor.Current = Cursors.SizeNWSE;
                CurrBorder     = RESIZE_BORDER.RB_BOTTOMRIGHT;
            }
            else if (SmallRect[1].Contains(point))
            {
                Cursor.Current = Cursors.SizeNESW;
                CurrBorder     = RESIZE_BORDER.RB_TOPRIGHT;
            }
            else if (SmallRect[2].Contains(point))
            {
                Cursor.Current = Cursors.SizeNESW;
                CurrBorder     = RESIZE_BORDER.RB_BOTTOMLEFT;
            }
            else if (SmallRect[4].Contains(point))
            {
                Cursor.Current = Cursors.SizeNS;
                CurrBorder     = RESIZE_BORDER.RB_TOP;
            }
            else if (SmallRect[5].Contains(point))
            {
                Cursor.Current = Cursors.SizeNS;
                CurrBorder     = RESIZE_BORDER.RB_BOTTOM;
            }
            else if (SmallRect[6].Contains(point))
            {
                Cursor.Current = Cursors.SizeWE;
                CurrBorder     = RESIZE_BORDER.RB_LEFT;
            }
            else if (SmallRect[7].Contains(point))
            {
                Cursor.Current = Cursors.SizeWE;
                CurrBorder     = RESIZE_BORDER.RB_RIGHT;
            }
            else if (ControlRect.Contains(point))
            {
                Cursor.Current = Cursors.SizeAll;
                CurrBorder     = RESIZE_BORDER.RB_NONE;
            }


            return(true);
        }
Exemplo n.º 2
0
        private void CalculateStretchOffsets(int mouseX, int mouseY, ref int xOffset, ref int yOffset, RESIZE_BORDER border)
        {
            ICustomPaint theObject = moveReferenceObject;

            switch (border)
            {
            case RESIZE_BORDER.TOP:
                yOffset = mouseY - theObject.Y;
                xOffset = 0;
                break;

            case RESIZE_BORDER.BOTTOM:
                yOffset = mouseY - (theObject.Y + theObject.Height);
                xOffset = 0;
                break;

            case RESIZE_BORDER.LEFT:
                yOffset = 0;
                xOffset = mouseX - theObject.X;
                break;

            case RESIZE_BORDER.RIGHT:
                yOffset = 0;
                xOffset = mouseX - (theObject.X + theObject.Width);
                break;

            default:
                yOffset = 0;
                xOffset = 0;
                break;
            }
        }
Exemplo n.º 3
0
        public void DesignPane_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (mouseDown)
            {
                if (mMouseMode == MOUSE_MODE.SELECTED)
                {
                    if (mBorder != RESIZE_BORDER.NONE)
                    {
                        int xOffset = 0;
                        int yOffset = 0;
                        CalculateStretchOffsets(e.X, e.Y, ref xOffset, ref yOffset, mBorder);

                        trackerImage.Dispose();
                        trackerImage = (Bitmap)drawingImage.Clone();

                        for (int i = 0; i < selectedObjects.Count; i++)
                        {
                            ICustomPaint theObject = (ICustomPaint)selectedObjects[i];

                            switch (mBorder)
                            {
                            case RESIZE_BORDER.TOP:
                                if (theObject.Height - yOffset >= 0)
                                {
                                    if (theObject.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.None)
                                    {
                                        theObject.Height -= yOffset;
                                        theObject.Y      += yOffset;
                                    }
                                    else if (theObject.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Bottom || selectedObject.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Middle)
                                    {
                                        theObject.Y += yOffset;
                                    }
                                }
                                break;

                            case RESIZE_BORDER.RIGHT:
                                if (theObject.Width + xOffset >= 0)
                                {
                                    theObject.Width += xOffset;
                                }
                                break;

                            case RESIZE_BORDER.BOTTOM:
                                if (theObject.Height + yOffset >= 0)
                                {
                                    theObject.Height += yOffset;
                                }
                                break;

                            case RESIZE_BORDER.LEFT:
                                if (theObject.Width - xOffset >= 0)
                                {
                                    if (theObject.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.None)
                                    {
                                        theObject.Width -= xOffset;
                                        theObject.X     += xOffset;
                                    }
                                    else if (theObject.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Right || theObject.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Center)
                                    {
                                        theObject.X += xOffset;
                                    }
                                }
                                break;
                            }

                            TrackerRectangle selRectangle = new TrackerRectangle(theObject.GetRegion(), theObject.HorizontalAlignment, theObject.VerticalAlignment);
                            selRectangle.DrawSelectionTrackers((Bitmap)trackerImage);
                        }


                        PaintImage(trackerImage);
                        shouldRepaint = true;
                    }
                    else
                    {
                        if (Math.Abs(e.X - ptStart.X) > 0 || Math.Abs(e.Y - ptStart.Y) > 0)
                        {
                            trackerImage.Dispose();
                            trackerImage = (Bitmap)drawingImage.Clone();

                            for (int i = 0; i < selectedObjects.Count; i++)
                            {
                                ICustomPaint theObject = (ICustomPaint)selectedObjects[i];
                                MoveSelection(theObject, theObject.X + e.X - ptStart.X, theObject.Y + e.Y - ptStart.Y);
                            }

                            PaintImage(trackerImage);
                            ptStart       = new Point(e.X, e.Y);
                            shouldRepaint = true;
                        }
                    }

                    if (OnMoving != null && selectedObjects.Count > 0)
                    {
                        OnMoving((ICustomPaint)selectedObjects[selectedObjects.Count - 1]);
                    }
                }
            }
            else
            {
                if (selectedObjects.Count > 0)
                {
                    for (int i = 0; i < selectedObjects.Count; i++)
                    {
                        ICustomPaint theObject = (ICustomPaint)selectedObjects[i];
                        Rectangle    theArea   = theObject.GetRegion();
                        theArea.Offset(-TrackerRectangle.m_nOffset, -TrackerRectangle.m_nOffset);
                        theArea.Inflate(2 * TrackerRectangle.m_nOffset, 2 * TrackerRectangle.m_nOffset);

                        if (theArea.Contains(e.X, e.Y))
                        {
                            TrackerRectangle tmp = new TrackerRectangle(theObject.GetRegion(), theObject.HorizontalAlignment, theObject.VerticalAlignment);
                            int nResult          = 0;
                            this.Cursor         = tmp.CursorCheck(new Point(e.X, e.Y), ref nResult);
                            this.mBorder        = (RESIZE_BORDER)nResult;
                            moveReferenceObject = (ICustomPaint)selectedObjects[i];
                            return;
                        }
                    }
                }
                this.Cursor = Cursors.Default;
            }
        }