<?xml version="1.0" encoding="utf-8"?>
<!--

////////////////////////////////////////////////////////////////////////////////
//
//    Copyright 2014 Ardisia Labs LLC. All Rights Reserved.
//
//    This file is 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:Module xmlns:fx="http://ns.adobe.com/mxml/2009" 
          xmlns:s="library://ns.adobe.com/flex/spark" 
          xmlns:mx="library://ns.adobe.com/flex/mx" 
          xmlns:containers="containers.*"
          xmlns:data="containers.data.*"
          xmlns:separators="ardisia.components.separators.*"
          xmlns:rotaryField="ardisia.components.rotaryField.*"
          frameRate="60"
          width="100%" height="100%"
          removedFromStage="removedFromStageHandler(event)">
    
    <!-- scripts -->
    <fx:Script>
        <![CDATA[
            import ardisia.utils.GraphicsUtils;
            
            //--------------------------------------
            //  methods
            //--------------------------------------
            
            public function creationComplete():void
            {
                rotaryHandler();
            }
            
            //--------------------------------------
            //  event handlers
            //--------------------------------------
            
            protected function rotaryHandler(event:Event = null):void
            {
                var g:Graphics = rotaryCanvas.skin.graphics;
                var angleRad:Number = Math.PI * (rotaryField.value / 180 + angleOffsetSelect.value / 180);
                
                // x = cx + r * cos a
                // y = cy + r * sin a
                var x:Number = 50 + 50 * Math.cos(angleRad);
                var y:Number = 50 + 50 * Math.sin(angleRad);
                
                g.clear();
                g.lineStyle(1, 0, 1, false, LineScaleMode.NORMAL, CapsStyle.ROUND, JointStyle.ROUND);
                
                GraphicsUtils.drawArrow(g, new Point(50, 50), new Point(x, y), 25, 8);
            }
            
            protected function removedFromStageHandler(event:Event):void
            {
                
            }
            
        ]]>
    </fx:Script>
    
    <!-- declarations -->
    <fx:Declarations>
        
    </fx:Declarations>
    
    <!-- states -->
    <s:states>
        <s:State name="stockholm" />
        <s:State name="london" />
        <s:State name="spark" />
    </s:states>
    
    <!-- application -->
    <containers:DemoApplicationWrapper id="demoAppWrapper" 
                                       width="100%" height="100%"
                                       westRegionTitle="RotaryField Description"
                                       description="UI component used to select an angle from 0 to 360 degrees.&#13;&#13;Handles focus, keyboard, and mouse interaction.&#13;&#13;The wheel popup can be closed via the mouse or by hitting the ESCAPE key, and the entered value can be committed by using the ENTER key.&#13;&#13;Fully skinnable."
                                       currentState.stockholm="stockholm" currentState.london="london" currentState.spark="spark">
        
        <containers:expandingContainerContent>
            
            <!--- expanding container #1 -->
            <data:ExpandingContainerData>
                <data:label>API</data:label>
                <data:content>
                    <s:FormHeading label="Properties:"/>
                    <s:FormItem label="Snap Interval:">
                        <s:HSlider id="snapIntervalSelect"
                                   width="100"
                                   minimum="1" maximum="180" value="1" snapInterval="1"/>
                        <s:helpContent>
                            <s:Image source="@Embed(source='icons/question.png')"
                                     toolTip="The snapInterval for the 'value' property."/>
                        </s:helpContent>
                    </s:FormItem>
                    <s:FormItem label="Angle Offset:">
                        <s:HSlider id="angleOffsetSelect"
                                   width="100"
                                   minimum="-360" maximum="360" value="-90" snapInterval="15" stepSize="15"
                                   change="rotaryHandler()"/>
                        <s:helpContent>
                            <s:Image source="@Embed(source='icons/question.png')"
                                     toolTip="Used to change what direction 0 degrees points towards on the ellipse.&#13;&#13;The Flash based coordinate system has 0 degrees at due East. This angle offsets the location of 0 degrees from due East.&#13;&#13;Positive increases in angle move the angle in a clockwise direction."/>
                        </s:helpContent>
                    </s:FormItem>
                </data:content>
            </data:ExpandingContainerData>
            
        </containers:expandingContainerContent>
        
        <containers:centerContent>
            
            <!--- example #1 -->
            <data:PrimaryContentData>
                <data:tabLabel>Example</data:tabLabel>
                <data:exampleDescription>Basic example to demonstrate the RotaryField component by displaying an arrow at the selected angle.  Note: the popup will detect screen overflow and adjust accordingly.</data:exampleDescription>
                <data:primaryContent>
                    <s:HGroup horizontalCenter="0" verticalCenter="0">
                        <rotaryField:RotaryField id="rotaryField" 
                                                 snapInterval="{snapIntervalSelect.value}"
                                                 angleOffset="{angleOffsetSelect.value}"
                                                 valueCommit="rotaryHandler(event);"/>
                        <s:BorderContainer>
                            <s:BorderContainer id="rotaryCanvas"
                                               top="2" right="2" bottom="2" left="2"
                                               width="100" height="100"/>
                        </s:BorderContainer>
                    </s:HGroup>
                </data:primaryContent>
            </data:PrimaryContentData>
            
        </containers:centerContent>
        
    </containers:DemoApplicationWrapper>
    
</s:Module>