弹性。使用矩阵缩放画布

发布于 2024-10-28 09:20:00 字数 59 浏览 2 评论 0原文

嗨,我想知道如何使用矩阵来增加画布的分量! 如果可能,请显示研究代码)

Hi, I was wondering how you can use the matrix to increase the component of the canvas!
If possible, show the code for the study)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情洁癖 2024-11-04 09:20:00

首先,您需要探索 相应文档

然后您可以尝试以下代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute" minHeight="600" minWidth="955" xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
        /**
         * Stores the button size multiplier on roll over.
         */
        public static const SIZE_MULTIPLIER:Number = 2.5;

        /**
         * Stores initial button's transfrom matrix.
         */
        private var buttonMatrix:Matrix;

        protected function zoomedButton_rollOverHandler(event:MouseEvent):void
        {
            var zoomedButton:Button = event.currentTarget as Button;
            // Get initial button transform matrix
            var matrix:Matrix = zoomedButton.transform.matrix;
            buttonMatrix = matrix.clone();
            // Modify matrix to move button's center to the Canvas (0, 0) point. 
            matrix.translate(-zoomedButton.width / 2 - zoomedButton.x,
                -zoomedButton.height / 2 - zoomedButton.y);
            // Modify matrix to scale using multiplier value
            matrix.scale(SIZE_MULTIPLIER, SIZE_MULTIPLIER);
            // Modify matrix to return button back
            matrix.translate(zoomedButton.width / 2 + zoomedButton.x,
                zoomedButton.height / 2 + zoomedButton.y);
            // Apply resulting matrix
            zoomedButton.transform.matrix = matrix;
        }

        protected function zoomedButton_rollOutHandler(event:MouseEvent):void
        {
            var zoomedButton:Button = event.currentTarget as Button;
            // Restore buttons position
            zoomedButton.transform.matrix = buttonMatrix;
        }
    ]]>
    </mx:Script>

    <mx:Panel height="50%" horizontalCenter="0" verticalCenter="0" width="50%" layout="absolute">
        <mx:Button label="Test" rollOut="zoomedButton_rollOutHandler(event)"
            rollOver="zoomedButton_rollOverHandler(event)" x="100" y="50" />
    </mx:Panel>
</mx:Application>

我使用带有layout =“absolute”的Panel来进行说明,但它与Canvas相同(因此您可以毫无问题地使用Canvas)。

当然,您可以使用 concat() 方法来形成矩阵,并考虑使用scale()和translate()方法作为快捷方式:

        protected function zoomedButton_rollOverHandler(event:MouseEvent):void
        {
            var zoomedButton:Button = event.currentTarget as Button;
            var matrix:Matrix = zoomedButton.transform.matrix;
            buttonMatrix = matrix.clone();
            matrix.
                concat(new Matrix(1, 0, 0, 1, -zoomedButton.width / 2 - zoomedButton.x,
                                  -zoomedButton.height / 2 - zoomedButton.y));
            matrix.concat(new Matrix(SIZE_MULTIPLIER, 0, 0, SIZE_MULTIPLIER));
            matrix.
                concat(new Matrix(1, 0, 0, 1, zoomedButton.width / 2 + zoomedButton.x,
                                  zoomedButton.height / 2 + zoomedButton.y));
            zoomedButton.transform.matrix = matrix;
        }

希望这会有所帮助:)

First of all you need to explore corresponding documentation.

Then you can try the following code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute" minHeight="600" minWidth="955" xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
        /**
         * Stores the button size multiplier on roll over.
         */
        public static const SIZE_MULTIPLIER:Number = 2.5;

        /**
         * Stores initial button's transfrom matrix.
         */
        private var buttonMatrix:Matrix;

        protected function zoomedButton_rollOverHandler(event:MouseEvent):void
        {
            var zoomedButton:Button = event.currentTarget as Button;
            // Get initial button transform matrix
            var matrix:Matrix = zoomedButton.transform.matrix;
            buttonMatrix = matrix.clone();
            // Modify matrix to move button's center to the Canvas (0, 0) point. 
            matrix.translate(-zoomedButton.width / 2 - zoomedButton.x,
                -zoomedButton.height / 2 - zoomedButton.y);
            // Modify matrix to scale using multiplier value
            matrix.scale(SIZE_MULTIPLIER, SIZE_MULTIPLIER);
            // Modify matrix to return button back
            matrix.translate(zoomedButton.width / 2 + zoomedButton.x,
                zoomedButton.height / 2 + zoomedButton.y);
            // Apply resulting matrix
            zoomedButton.transform.matrix = matrix;
        }

        protected function zoomedButton_rollOutHandler(event:MouseEvent):void
        {
            var zoomedButton:Button = event.currentTarget as Button;
            // Restore buttons position
            zoomedButton.transform.matrix = buttonMatrix;
        }
    ]]>
    </mx:Script>

    <mx:Panel height="50%" horizontalCenter="0" verticalCenter="0" width="50%" layout="absolute">
        <mx:Button label="Test" rollOut="zoomedButton_rollOutHandler(event)"
            rollOver="zoomedButton_rollOverHandler(event)" x="100" y="50" />
    </mx:Panel>
</mx:Application>

I used the Panel with layout="absolute" for illustrating purposes but it is the same as Canvas (so you can use Canvas without any problem).

And of course you can use concat() method to form the matrix and consider scale() and translate() methods as shortcuts:

        protected function zoomedButton_rollOverHandler(event:MouseEvent):void
        {
            var zoomedButton:Button = event.currentTarget as Button;
            var matrix:Matrix = zoomedButton.transform.matrix;
            buttonMatrix = matrix.clone();
            matrix.
                concat(new Matrix(1, 0, 0, 1, -zoomedButton.width / 2 - zoomedButton.x,
                                  -zoomedButton.height / 2 - zoomedButton.y));
            matrix.concat(new Matrix(SIZE_MULTIPLIER, 0, 0, SIZE_MULTIPLIER));
            matrix.
                concat(new Matrix(1, 0, 0, 1, zoomedButton.width / 2 + zoomedButton.x,
                                  zoomedButton.height / 2 + zoomedButton.y));
            zoomedButton.transform.matrix = matrix;
        }

Hope this helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文