public TransferActorAction(TDocument doc, TActor actor, TLayer parent)
        {
            this.document  = doc;
            this.actor     = actor;
            this.oldData   = new ActorMatrixData();
            this.newData   = new ActorMatrixData();
            this.oldParent = actor.parent;
            this.newParent = parent;

            this.oldData.position = actor.position;
            this.oldData.scale    = actor.scale;
            this.oldData.skew     = actor.skew;
            this.oldData.rotation = actor.rotation;

            // actor's position based on new parent
            PointF pt = actor.parent.logicalToScreen(actor.position);

            pt = parent.screenToLogical(pt);

            // actor's rotation based on new parent
            float angle = actor.rotationOnScreen();

            if (parent is TActor)
            {
                angle -= ((TActor)parent).rotationOnScreen();
            }
            TUtil.normalizeDegreeAngle(angle);

            // for scale
            RectangleF bound = actor.bound();
            PointF     s     = actor.logicalVectorToScreen(new PointF(bound.Width, bound.Height));
            SizeF      scale = new SizeF(1, 1);

            Matrix m2 = new Matrix();

            m2.Translate(pt.X, pt.Y);
            m2.Rotate((float)(angle * 180 / Math.PI));
            m2.Translate(-actor.anchor.X * actor.bound().Width, -actor.anchor.Y * actor.bound().Height);

            Matrix m = parent.matrixFromScreen();

            m.Multiply(m2);
            if (m.IsInvertible)
            {
                PointF[] aPos = { s };
                m.Invert();
                m.TransformVectors(aPos);
                s     = aPos[0];
                scale = new SizeF(s.X / bound.Width, s.Y / bound.Height);
            }

            this.newData.position = pt;
            this.newData.scale    = scale;
            this.newData.skew     = actor.skew;
            this.newData.rotation = angle;

            oldIndex = actor.parent.childs.IndexOf(actor);
        }
Esempio n. 2
0
        public void transferLayer(TActor item, TLayer target)
        {
            // item's position based on new parent
            PointF pt = item.parent.logicalToScreen(item.position);

            pt = target.screenToLogical(pt);

            // item's rotation based on new parent
            float angle = item.rotationOnScreen();

            if (target is TActor)
            {
                angle -= ((TActor)target).rotationOnScreen();
            }
            TUtil.normalizeDegreeAngle(angle);

            // for scale
            RectangleF bound = item.bound();
            PointF     s     = item.logicalVectorToScreen(new PointF(bound.Width, bound.Height));

            // new properties
            item.position = pt;
            item.rotation = angle;
            item.scale    = new Size(1, 1);

            Matrix m = target.matrixFromScreen();

            m.Multiply(item.matrix);
            if (m.IsInvertible)
            {
                PointF[] aPos = { s };
                m.Invert();
                m.TransformVectors(aPos);
                s          = aPos[0];
                item.scale = new SizeF(s.X / bound.Width, s.Y / bound.Height);
            }

            item.parent.childs.Remove(item);
            target.childs.Add(item);
            item.parent = target;
        }