Exemple #1
0
        // scale the selected items the specified delta, parameters are based on real drawing canvas coordinates
        public void scaleInteractionBound(int part, float dx, float dy, bool fixedRatio)
        {
            for (int i = 0; i < selectedItems.Count; i++)
            {
                TActor item   = this.selectedItems[i];
                TActor origin = item.backupActor;

                PointF     d     = origin.screenVectorToLogical(new PointF(dx, dy));
                RectangleF bound = origin.interactionBound;

                if (fixedRatio)
                {
                    float z;
                    if (part == 1)
                    {
                        z = Math.Max(-d.X / bound.Width, -d.Y / bound.Height);
                        d = new PointF(-z * bound.Width, -z * bound.Height);
                    }
                    else if (part == 2)
                    {
                        z = Math.Max(-d.X / bound.Width, d.Y / bound.Height);
                        d = new PointF(-z * bound.Width, z * bound.Height);
                    }
                    else if (part == 3)
                    {
                        z = Math.Max(d.X / bound.Width, d.Y / bound.Height);
                        d = new PointF(z * bound.Width, z * bound.Height);
                    }
                    else if (part == 4)
                    {
                        z = Math.Max(d.X / bound.Width, -d.Y / bound.Height);
                        d = new PointF(z * bound.Width, -z * bound.Height);
                    }
                }

                float x1 = bound.Left, y1 = bound.Top, x2 = bound.Right, y2 = bound.Bottom;
                if (part == 1 || part == 2 || part == 5)
                {
                    x1 += d.X;
                }
                if (part == 3 || part == 4 || part == 7)
                {
                    x2 += d.X;
                }
                if (part == 1 || part == 4 || part == 8)
                {
                    y1 += d.Y;
                }
                if (part == 2 || part == 3 || part == 6)
                {
                    y2 += d.Y;
                }

                item.interactionBound = new RectangleF(x1, y1, x2 - x1, y2 - y1);
            }
        }
Exemple #2
0
        // scale the selected items the specified delta, parameters are based on real drawing canvas coordinates
        public void scaleSelectedItems(int part, float dx, float dy, bool fixedRatio)
        {
            for (int i = 0; i < selectedItems.Count; i++)
            {
                TActor item   = this.selectedItems[i];
                TActor origin = item.backupActor;
                PointF d      = origin.screenVectorToLogical(new PointF(dx, dy));

                float      sx = origin.scale.Width, sy = origin.scale.Height;
                RectangleF bound = origin.bound();
                float      px = origin.anchor.X * bound.Width, py = origin.anchor.Y * bound.Height;

                if (fixedRatio)
                {
                    float w = bound.Width * sx, h = bound.Height * sy;
                    float z;
                    if (part == 1)
                    {
                        z = Math.Max(-d.X / w, -d.Y / h);
                        d = new PointF(-z * w, -z * h);
                    }
                    else if (part == 2)
                    {
                        z = Math.Max(-d.X / w, d.Y / h);
                        d = new PointF(-z * w, z * h);
                    }
                    else if (part == 3)
                    {
                        z = Math.Max(d.X / w, d.Y / h);
                        d = new PointF(z * w, z * h);
                    }
                    else if (part == 4)
                    {
                        z = Math.Max(d.X / w, -d.Y / h);
                        d = new PointF(z * w, -z * h);
                    }
                }

                if (part == 1 || part == 2 || part == 5)
                {
                    sx -= sx * d.X / bound.Width;
                    px  = d.X + (bound.Width - d.X) * origin.anchor.X;
                }
                if (part == 3 || part == 4 || part == 7)
                {
                    sx += sx * d.X / bound.Width;
                    px  = origin.anchor.X * (bound.Width + d.X);
                }
                if (part == 1 || part == 4 || part == 8)
                {
                    sy -= sy * d.Y / bound.Height;
                    py  = d.Y + (bound.Height - d.Y) * origin.anchor.Y;
                }
                if (part == 2 || part == 3 || part == 6)
                {
                    sy += sy * d.Y / bound.Height;
                    py  = origin.anchor.Y * (bound.Height + d.Y);
                }

                PointF[] p0 = { new PointF(px, py) };
                origin.matrix.TransformPoints(p0);
                item.position = p0[0];
                item.scale    = new SizeF(sx, sy);

//                PointF p0 = item.logicalToScreen(new PointF(px, py));
//                item.position = item.parent.screenToLogical(p0);
//                item.scale = new SizeF(sx, sy);
            }
        }