示例#1
0
        /// <summary>
        /// Test to see if the given point is inside of the current bounds
        /// </summary>
        /// <returns><c>true</c>, if in bounds, <c>false</c> otherwise.</returns>
        /// <param name="point">Point.</param>
        public virtual bool PointInBound(SKPoint point)
        {
            // Clear hit handle and test point
            HitHandle = null;
            var inBounds = (ValueBetween(point.X, Left, Right) && ValueBetween(point.Y, Top, Bottom));

            // Test all handles to see if they have been hit
            if (TopLeftHandle != null && TopLeftHandle.PointInBound(point))
            {
                HitHandle = TopLeftHandle;
                inBounds  = true;
            }
            else if (TopHandle != null && TopHandle.PointInBound(point))
            {
                HitHandle = TopHandle;
                inBounds  = true;
            }
            else if (TopRightHandle != null && TopRightHandle.PointInBound(point))
            {
                HitHandle = TopRightHandle;
                inBounds  = true;
            }
            else if (RightHandle != null && RightHandle.PointInBound(point))
            {
                HitHandle = RightHandle;
                inBounds  = true;
            }
            else if (BottomRightHandle != null && BottomRightHandle.PointInBound(point))
            {
                HitHandle = BottomRightHandle;
                inBounds  = true;
            }
            else if (BottomHandle != null && BottomHandle.PointInBound(point))
            {
                HitHandle = BottomHandle;
                inBounds  = true;
            }
            else if (BottomLeftHandle != null && BottomLeftHandle.PointInBound(point))
            {
                HitHandle = BottomLeftHandle;
                inBounds  = true;
            }
            else if (LeftHandle != null && LeftHandle.PointInBound(point))
            {
                HitHandle = LeftHandle;
                inBounds  = true;
            }
            else if (inBounds)
            {
                // See if we are in bounds
                HitOffset = new SKPoint((Left > Right) ? point.X - Right : point.X - Left, (Top > Bottom) ? point.Y - Bottom : point.Y - Top);
            }

            return(inBounds);
        }
示例#2
0
        /// <summary>
        /// Draws the bounding box and its edit handles into the given canvas
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        public virtual void Draw(SKCanvas canvas)
        {
            // Anything to process?
            if (State != KimonoShapeState.Selected &&
                State != KimonoShapeState.Constructing &&
                State != KimonoShapeState.Grouping)
            {
                return;
            }

            // Define the paint style
            var paint = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 1
            };

            // Set stroke based on the state
            switch (State)
            {
            case KimonoShapeState.Grouping:
                paint.Color = KimonoColor.Ice;
                break;

            case KimonoShapeState.Selected:
                paint.Color = KimonoColor.Tungsten;
                break;

            case KimonoShapeState.Constructing:
                paint.Color = KimonoColor.Aqua;
                break;
            }

            // Draw bounding frame
            canvas.DrawRect(Rect, paint);

            // Draw the four corner handles
            TopLeftHandle?.Draw(canvas);
            TopRightHandle?.Draw(canvas);
            BottomRightHandle?.Draw(canvas);
            BottomLeftHandle?.Draw(canvas);

            // Draw optional handles
            TopHandle?.Draw(canvas);
            RightHandle?.Draw(canvas);
            BottomHandle?.Draw(canvas);
            LeftHandle?.Draw(canvas);
        }
示例#3
0
        /// <summary>
        /// Updates the location of the edit handles when the bounds has been relocated or
        /// resized.
        /// </summary>
        public virtual void BoundsChanged()
        {
            // Anything to process?
            if (TopLeftHandle == null)
            {
                return;
            }

            // Adjust the four courner drag handles
            TopLeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset);
            TopRightHandle.MoveTo(Right - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset);
            BottomRightHandle.MoveTo(Right - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset);
            BottomLeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset);

            // Set handle state
            var newHandleState = (State == KimonoShapeState.Selected) ? KimonoShapeState.Unselected : State;

            // Adjust top and bottom drag handles based on width
            if (Width < 50)
            {
                // Too small so remove handles
                TopHandle    = null;
                BottomHandle = null;
            }
            else
            {
                // Move or create handles as needed
                if (TopHandle == null)
                {
                    TopHandle        = new KimonoHandle(HorizontalCenter - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset, KimonoHandleConstraint.Vertical, newHandleState);
                    TopHandle.Moved += (point) =>
                    {
                        Top = point.Y;
                    };
                }
                else
                {
                    TopHandle.MoveTo(HorizontalCenter - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset);
                }

                if (BottomHandle == null)
                {
                    BottomHandle        = new KimonoHandle(HorizontalCenter - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset, KimonoHandleConstraint.Vertical, newHandleState);
                    BottomHandle.Moved += (point) =>
                    {
                        Bottom = point.Y;
                    };
                }
                else
                {
                    BottomHandle.MoveTo(HorizontalCenter - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset);
                }
            }

            // Adjust left and right drag handles based on the height
            if (Height < 50)
            {
                // Too small so remove handles
                LeftHandle  = null;
                RightHandle = null;
            }
            else
            {
                // Move or create handles as needed
                if (LeftHandle == null)
                {
                    LeftHandle        = new KimonoHandle(Left - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset, KimonoHandleConstraint.Horizontal, newHandleState);
                    LeftHandle.Moved += (point) =>
                    {
                        Left = point.X;
                    };
                }
                else
                {
                    LeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset);
                }

                if (RightHandle == null)
                {
                    RightHandle        = new KimonoHandle(Right - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset, KimonoHandleConstraint.Horizontal, newHandleState);
                    RightHandle.Moved += (point) =>
                    {
                        Right = point.X;
                    };
                }
                else
                {
                    RightHandle.MoveTo(Right - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset);
                }
            }
        }