Beispiel #1
0
        // move the anchor point of selected item the specified delta, parameters are based on real drawing canvas coordinates
        public void moveAnchorOfSelectedItem(float dx, float dy, bool fixedMove)
        {
            if (fixedMove)
            {
                double al = Math.Atan2(dy, dx) * 180 / Math.PI;
                float  d  = Math.Min(Math.Abs(dx), Math.Abs(dy));
                if (al >= -22.5 && al < 22.5)
                {
                    dy = 0;
                }
                else if (al >= 22.5 && al < 67.5)
                {
                    dx = d; dy = d;
                }
                else if (al >= 67.5 && al < 112.5)
                {
                    dx = 0;
                }
                else if (al >= 112.5 && al < 157.5)
                {
                    dx = -d; dy = d;
                }
                else if (al >= 157.5 || al < -157.5)
                {
                    dy = 0;
                }
                else if (al >= -157.5 && al < -112.5)
                {
                    dx = -d; dy = -d;
                }
                else if (al >= -112.5 && al < -67.5)
                {
                    dx = 0;
                }
                else if (al >= 67.5 && al < 22.5)
                {
                    dx = d; dy = -d;
                }
            }

            for (int i = 0; i < selectedItems.Count; i++)
            {
                TActor item   = this.selectedItems[i];
                TActor origin = item.backupActor;

                PointF screenPos = origin.parent.logicalToScreen(origin.position);
                screenPos.X += dx; screenPos.Y += dy;
                PointF     logicalPos = origin.screenToLogical(screenPos);
                RectangleF bound      = origin.bound();

                item.position = origin.parent.screenToLogical(screenPos);
                item.anchor   = new PointF(logicalPos.X / bound.Width, logicalPos.Y / bound.Height);
            }
        }
Beispiel #2
0
        // move the selected items the specified delta, parameters are based on real drawing canvas coordinates
        public void moveInteractionBound(float dx, float dy, bool fixedMove)
        {
            if (fixedMove)
            {
                double al = Math.Atan2(dy, dx) * 180 / Math.PI;
                float  d  = Math.Min(Math.Abs(dx), Math.Abs(dy));
                if (al >= -22.5 && al < 22.5)
                {
                    dy = 0;
                }
                else if (al >= 22.5 && al < 67.5)
                {
                    dx = d; dy = d;
                }
                else if (al >= 67.5 && al < 112.5)
                {
                    dx = 0;
                }
                else if (al >= 112.5 && al < 157.5)
                {
                    dx = -d; dy = d;
                }
                else if (al >= 157.5 || al < -157.5)
                {
                    dy = 0;
                }
                else if (al >= -157.5 && al < -112.5)
                {
                    dx = -d; dy = -d;
                }
                else if (al >= -112.5 && al < -67.5)
                {
                    dx = 0;
                }
                else if (al >= 67.5 && al < 22.5)
                {
                    dx = d; dy = -d;
                }
            }

            for (int i = 0; i < selectedItems.Count; i++)
            {
                TActor item   = this.selectedItems[i];
                TActor origin = item.backupActor;
                PointF p      = origin.logicalToScreen(origin.interactionBound.Location);
                p.X += dx; p.Y += dy;
                item.interactionBound = new RectangleF(origin.screenToLogical(p), origin.interactionBound.Size);
            }
        }
Beispiel #3
0
        //============== return value ===============//
        //
        //                    -1
        //      9                           9
        //        ┌───────────────────────┐
        //        │ 1         8         4 │
        //        │                       │
        //  -1    │ 5         0         7 │    -1
        //        │                       │
        //        │ 2         6         3 │
        //        └───────────────────────┘
        //      9                           9
        //                    -1
        //
        //
        // Anchor Point : 10
        //============================================//
        public int partOfSelection(float x, float y, out int cursor)
        {
            cursor = -1;

            if (selectedItems.Count == 0)
            {
                return(-1);
            }
            if (selectedItems.Count > 1)
            {
                return(containsInSelection(x, y) ? 0 : 9);
            }

            TActor actor = selectedItems[0];

            if (currentTool == TDocument.TOOL_PUZZLE && !actor.puzzle)
            {
                return(-1);
            }

            PointF screenPos  = new PointF(x, y);
            PointF logicalPos = currentTool != TDocument.TOOL_PUZZLE ? actor.screenToLogical(new PointF(x, y)) : actor.ownerScene().screenToLogical(new PointF(x, y));

            RectangleF actorBound        = actor.bound();
            PointF     anchorPosOnScreen = actor.logicalToScreen(new PointF(actorBound.Width * actor.anchor.X, actorBound.Height * actor.anchor.Y));

            RectangleF bound;

            if (currentTool == TDocument.TOOL_BOUNDING)
            {
                bound = actor.interactionBound;
            }
            else if (currentTool == TDocument.TOOL_PUZZLE)
            {
                bound = actor.puzzleArea;
            }
            else
            {
                bound = actorBound;
            }

            PointF[] boundOnScreen;
            if (currentTool == TDocument.TOOL_BOUNDING)
            {
                boundOnScreen = actor.interactionBoundOnScreen();
            }
            else if (currentTool == TDocument.TOOL_PUZZLE)
            {
                boundOnScreen = actor.puzzleAreaOnScreen();
            }
            else
            {
                boundOnScreen = actor.boundOnScreen();
            }
            int ctrl_size = 6;

            bool leftEdge    = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[0], boundOnScreen[1]) <= ctrl_size;
            bool bottomEdge  = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[1], boundOnScreen[2]) <= ctrl_size;
            bool rightEdge   = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[2], boundOnScreen[3]) <= ctrl_size;
            bool topEdge     = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[3], boundOnScreen[0]) <= ctrl_size;
            bool insideBound = bound.Contains(logicalPos);

            int    first_cursor = 0; // cursor form part 5
            double angle        = -Math.Atan2(boundOnScreen[1].Y - boundOnScreen[0].Y, boundOnScreen[1].X - boundOnScreen[0].X) * 180 / Math.PI;

            if (angle < 0)
            {
                angle += 360;
            }
            first_cursor = (int)((angle + 22.5) / 45) % 4;

            int part = -1;

            if (leftEdge && topEdge)
            {
                part = 1; cursor = (first_cursor - 1) % 4;
            }
            else if (leftEdge && bottomEdge)
            {
                part = 2; cursor = (first_cursor + 1) % 4;
            }
            else if (rightEdge && bottomEdge)
            {
                part = 3; cursor = (first_cursor + 3) % 4;
            }
            else if (rightEdge && topEdge)
            {
                part = 4; cursor = (first_cursor + 5) % 4;
            }
            else if (leftEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[0], boundOnScreen[1]))
            {
                part = 5; cursor = (first_cursor + 0) % 4;
            }
            else if (bottomEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[1], boundOnScreen[2]))
            {
                part = 6; cursor = (first_cursor + 2) % 4;
            }
            else if (rightEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[2], boundOnScreen[3]))
            {
                part = 7; cursor = (first_cursor + 4) % 4;
            }
            else if (topEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[3], boundOnScreen[0]))
            {
                part = 8; cursor = (first_cursor + 6) % 4;
            }
            else if (TUtil.distanceBetweenPoints(screenPos, anchorPosOnScreen) <= ctrl_size)
            {
                part = 10;
            }
            else if (insideBound)
            {
                part = 0;
            }
            else if (currentTool != TDocument.TOOL_BOUNDING && currentTool != TDocument.TOOL_PUZZLE)
            {
                if (TUtil.distanceBetweenPoints(screenPos, boundOnScreen[0]) <= ctrl_size * 3 ||
                    TUtil.distanceBetweenPoints(screenPos, boundOnScreen[1]) <= ctrl_size * 3 ||
                    TUtil.distanceBetweenPoints(screenPos, boundOnScreen[2]) <= ctrl_size * 3 ||
                    TUtil.distanceBetweenPoints(screenPos, boundOnScreen[3]) <= ctrl_size * 3)
                {
                    part = 9;
                }
            }

            return(part);
        }