Adobe Flex Button 图标 — 更改为灰度并返回

发布于 2024-12-03 14:33:44 字数 259 浏览 3 评论 0原文

到目前为止,我对禁用按钮图标的解决方案是使用第二个灰度图标,并根据按钮的启用值交换图标。显然这是非常hackish的。

我想深入了解按钮的图标,并在禁用按钮时应用某种灰度过滤器,并在重新启用按钮时删除过滤器。我尝试了一些方法,但我对 Flash 图形了解不够,无法真正了解该怎么做。

有人能给我一些指点吗?理想情况下,我想要一个 Flex 3 解决方案(因为我的大多数应用程序仍然是 mx/spark 混合的),但 Flex 4 也可以。

Until now, my solution for a disabled button's icon was to have a second, greyscale icon and swap the icons based on the button's enabled value. Obviously this is very hackish.

I'd like to drill down into the button's icon and apply some kind of greyscale filter when the button is disabled and remove the filter when the button is re-enabled. I tried a couple of things, but I don't know enough about Flash graphics to really have a good idea about what to do.

Can anyone give me some pointers? Ideally, I'd like a Flex 3 solution (since most of my apps are still mx/spark mixed), but Flex 4 would be OK too.

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

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

发布评论

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

评论(2

我早已燃尽 2024-12-10 14:33:44

这是 Flex3 解决方案。

mx:Button 其内部有一个子图标。您可以覆盖 updateDisplayList 函数和 enabled setter 以使该图标变为黑白。

为了使图像变成黑白图像,您需要对颜色的 RGB 值进行平均。以下是广播和电视的公式:

grey = R * 0.3 + b2 * 0.59 + b3 * 0.11

在您的情况下,您可以使用 flash.filters.ColorMatrixFilter,此滤镜会转换目标的颜色。滤镜的黑白矩阵:

[ 0.3, 0.59, 0.11, 0,
  0.3, 0.59, 0.11, 0,
  0.3, 0.59, 0.11, 0,
  0,   0,    1,    0 ]

最后一列指定每种颜色的被加数,因此您可以使图像更红、更绿、棕褐色等。

滤镜应用于显示组件,如下所示:

var filter = Filter();
component.filters.push(filter); // doesn't work, and not because null pointer
component.filters = [filter];   // works

重新分配很重要包含新过滤器的数组,否则组件将不会更新它。

That's a Flex3 solution.

mx:Button has icon as child inside itself. You can override updateDisplayList function and enabled setter to make this icon black-and-white.

In order to make an image black-and-white you need to average out the RGB values of color. Here is the formula from broadcasting and TV:

grey = R * 0.3 + b2 * 0.59 + b3 * 0.11

In your case you can use flash.filters.ColorMatrixFilter on icon, this filter transforms colors of the target. The black-and-white matrix for filter:

[ 0.3, 0.59, 0.11, 0,
  0.3, 0.59, 0.11, 0,
  0.3, 0.59, 0.11, 0,
  0,   0,    1,    0 ]

The last column specifies the summand to each color, so you can make your image more red, more green, sepia, etc.

The filter is applied to display component as follows:

var filter = Filter();
component.filters.push(filter); // doesn't work, and not because null pointer
component.filters = [filter];   // works

It's important to reassign array with new filters, as otherwise the component won't update it.

韵柒 2024-12-10 14:33:44

使用皮肤!在 Flex 4 中,他们通过皮肤文件使这变得更加容易,并且能够放置每个状态属性。这是我们的一个有点相似,基本上使用状态和过滤器来改变效果:

<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:fb="http://ns.adobe.com/flashbuilder/2009" width="28" height="28" xmlns:Common="UI.Common.*" xmlns:Controls="Core.Flex.Controls.*">
    <fx:Metadata>[HostComponent("Core.Flex.Controls.ToggleIcon")]</fx:Metadata>
    <s:states>
        <s:State name="up" />
        <s:State name="over" stateGroups="overStates" />
        <s:State name="down" stateGroups="downStates" />
        <s:State name="disabled" stateGroups="disabledStates" />
        <s:State name="upAndSelected" stateGroups="selectedStates, selectedUpStates" />
        <s:State name="overAndSelected" stateGroups="overStates, selectedStates" />
        <s:State name="downAndSelected" stateGroups="downStates, selectedStates" />
        <s:State name="disabledAndSelected" stateGroups="selectedUpStates, disabledStates, selectedStates" />
    </s:states>

    <s:Group left="2" right="2" top="2" bottom="2" useHandCursor="true" buttonMode="true">
        <Controls:ColorRect width="24" height="24" FillColor="#154b6b" StrokeColor="#FFFFFF" StrokeWeight=".1" alpha=".8" radiusX="6" radiusY="6" includeIn="up, disabled">
            <Controls:filters>
                <s:BevelFilter blurX="5" blurY="5" strength=".56" quality="3" distance="3"/>
            </Controls:filters>
        </Controls:ColorRect>

        <Controls:ColorRect width="24" height="24" FillColor="#1C648E" StrokeColor="#FFFFFF" StrokeWeight="2" radiusX="6" radiusY="6" includeIn="over">
            <Controls:filters>
                <s:BevelFilter blurX="5" blurY="5" strength=".87" quality="3" distance="3"/>
            </Controls:filters>
        </Controls:ColorRect>

        <Controls:ColorRect width="24" height="24" FillColor="#154b6b" StrokeColor="#FFFFFF" StrokeWeight=".1" radiusX="6" radiusY="6" includeIn="down, selectedStates">
            <Controls:filters>
                <s:BevelFilter blurX="5" blurY="5" strength=".1" quality="3" highlightColor="#000000" distance="3"/>
            </Controls:filters>
        </Controls:ColorRect>

        <s:BitmapImage source="{hostComponent.Icon}" left="2" top="2" right="2" bottom="2" alpha=".9" alpha.over="1" alpha.selectedStates="1"/>
    </s:Group>

</s:SparkSkin>

Use a skin! In flex 4 they made this much easier with the skin files, and being able to put per state properties. Here's one of ours that's somewhat similar, basically use states and filters to change the effect:

<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:fb="http://ns.adobe.com/flashbuilder/2009" width="28" height="28" xmlns:Common="UI.Common.*" xmlns:Controls="Core.Flex.Controls.*">
    <fx:Metadata>[HostComponent("Core.Flex.Controls.ToggleIcon")]</fx:Metadata>
    <s:states>
        <s:State name="up" />
        <s:State name="over" stateGroups="overStates" />
        <s:State name="down" stateGroups="downStates" />
        <s:State name="disabled" stateGroups="disabledStates" />
        <s:State name="upAndSelected" stateGroups="selectedStates, selectedUpStates" />
        <s:State name="overAndSelected" stateGroups="overStates, selectedStates" />
        <s:State name="downAndSelected" stateGroups="downStates, selectedStates" />
        <s:State name="disabledAndSelected" stateGroups="selectedUpStates, disabledStates, selectedStates" />
    </s:states>

    <s:Group left="2" right="2" top="2" bottom="2" useHandCursor="true" buttonMode="true">
        <Controls:ColorRect width="24" height="24" FillColor="#154b6b" StrokeColor="#FFFFFF" StrokeWeight=".1" alpha=".8" radiusX="6" radiusY="6" includeIn="up, disabled">
            <Controls:filters>
                <s:BevelFilter blurX="5" blurY="5" strength=".56" quality="3" distance="3"/>
            </Controls:filters>
        </Controls:ColorRect>

        <Controls:ColorRect width="24" height="24" FillColor="#1C648E" StrokeColor="#FFFFFF" StrokeWeight="2" radiusX="6" radiusY="6" includeIn="over">
            <Controls:filters>
                <s:BevelFilter blurX="5" blurY="5" strength=".87" quality="3" distance="3"/>
            </Controls:filters>
        </Controls:ColorRect>

        <Controls:ColorRect width="24" height="24" FillColor="#154b6b" StrokeColor="#FFFFFF" StrokeWeight=".1" radiusX="6" radiusY="6" includeIn="down, selectedStates">
            <Controls:filters>
                <s:BevelFilter blurX="5" blurY="5" strength=".1" quality="3" highlightColor="#000000" distance="3"/>
            </Controls:filters>
        </Controls:ColorRect>

        <s:BitmapImage source="{hostComponent.Icon}" left="2" top="2" right="2" bottom="2" alpha=".9" alpha.over="1" alpha.selectedStates="1"/>
    </s:Group>

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