<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright 2010 Chet Haase
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
    http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    viewSourceURL="srcview/index.html"
    width="350" height="300">

    <s:states>
        <s:State name="None"/>
        <s:State name="Blur"/>
        <s:State name="Glow"/>
        <s:State name="DropShadow"/>
    </s:states>
    <fx:Declarations>
        <s:BlurFilter id="blur" 
            blurX="{Number(blurX.text)}"
            blurY="{Number(blurY.text)}"
            quality="{Number(quality.text)}"/>
        <s:GlowFilter id="glow"
            blurX="{Number(blurX.text)}"
            blurY="{Number(blurY.text)}"
            quality="{Number(quality.text)}"
            color="{color.selectedColor}"
            alpha="{Number(alphaValue.text)}"
            inner="{inner.selectedValue=='true' ? true : false}"
            knockout="{knockout.selectedValue=='true' ? true : false}"/>
        <s:DropShadowFilter id="dropShadow"
            blurX="{Number(blurX.text)}"
            blurY="{Number(blurY.text)}"
            quality="{Number(quality.text)}"
            color="{color.selectedColor}"
            alpha="{Number(alphaValue.text)}"
            inner="{inner.selectedValue=='true' ? true : false}"
            knockout="{knockout.selectedValue=='true' ? true : false}"
            distance="{Number(distance.text)}"
            angle="{Number(angle.text)}"
            strength="{Number(strength.text)}"/>
        <s:RadioButtonGroup id="inner"/>
        <s:RadioButtonGroup id="knockout"/>
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.filters.IBitmapFilter;
            public function setFilter(stateName:String):void
            {
                currentState = (stateName=='None') ? '' : stateName;
                var filter:IBitmapFilter;
                switch (stateName)
                {
                    case "None":
                        break;
                    case "Blur":
                        filter = blur;
                        break;
                    case "Glow":
                        filter = glow;
                        break;
                    case "DropShadow":
                        filter = dropShadow;
                        break;
                }
                button.filters = filter ? [filter] : [];
                image.filters = filter ? [filter] : [];
                rect.filters = filter ? [filter] : [];
            }
        ]]>
    </fx:Script>
    
    <s:Group x="5" y="10">
        <s:Label text="Filter" y="10" baseline="15"/>
        <s:DropDownList x="70"  id="stateList" selectedItem="None"
                        change="setFilter(stateList.selectedItem)" baseline="15">
            <s:ArrayCollection>
                <fx:String>None</fx:String>
                <fx:String>Blur</fx:String>
                <fx:String>Glow</fx:String>
                <fx:String>DropShadow</fx:String>
            </s:ArrayCollection>
        </s:DropDownList>
    </s:Group>
    <s:Group x="5" y="35" excludeFrom="None">
        <s:Label text="blurX" baseline="15"/>
        <s:TextInput width="42" x="70" id="blurX" text="10" baseline="15"/>
        <s:Label text="blurY" baseline="40"/>
        <s:TextInput width="42" x="70" id="blurY" text="10" baseline="40"/>
        <s:Label text="quality" baseline="65"/>
        <s:TextInput width="42" x="70" id="quality" text="1" baseline="65"/>
    </s:Group>
    <s:Group x="5" y="110" includeIn="Glow, DropShadow">
        <s:Label text="alpha" baseline="15"/>
        <s:TextInput id="alphaValue" width="42" x="70" alpha="1" text="1" baseline="15"/>
        <s:Label text="color" baseline="40"/>
        <mx:ColorPicker width="42" x="70" id="color" selectedColor="0x0" baseline="40"/>
        <s:Label text="inner" baseline="65"/>
        <s:RadioButton label="true" x="70" groupName="inner" baseline="65"/>
        <s:RadioButton label="false" x="120" groupName="inner" selected="true" baseline="65"/>
        <s:Label text="knockout" baseline="90"/>
        <s:RadioButton label="true" x="70" groupName="knockout" baseline="90"/>
        <s:RadioButton label="false" x="120" groupName="knockout" selected="true" baseline="90"/>
    </s:Group>
    <s:Group x="5" y="210" includeIn="DropShadow">
        <s:Label text="dist" baseline="15"/>
        <s:TextInput width="42" x="70" id="distance" text="10" baseline="15"/>
        <s:Label text="angle" baseline="40"/>
        <s:TextInput width="42" x="70" id="angle" text="45" baseline="40"/>
        <s:Label text="strength" baseline="65"/>
        <s:TextInput width="42" x="70" id="strength" text="1" baseline="65"/>
    </s:Group>

    <s:Group x="215" y="10">
        <s:Button id="button" baseline="15" label="Filtered Button"/>
        <s:BitmapImage id="image" source="@Embed(source='images/SanFranciscoCropped1.jpg')" 
            width="100" height="80" y="38" smooth="false"/>
        <s:Rect id="rect" y="130" width="100" height="50">
            <s:fill>
                <s:SolidColor color="gray"/>
            </s:fill>
        </s:Rect>
    </s:Group>
</s:Application>