Advertisement
Guest User

bordercontainerskin

a guest
Sep 19th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <controls:BorderContainer width="200" height="200"
  2.                               borderWeight="2"
  3.                               backgroundColor="#FFFF00"
  4.                               backgroundAlpha=".5"
  5.                               borderColor="#000000"
  6.                               verticalCenter="0"
  7.                               horizontalCenter="0"
  8.                               cornerRadius="6"
  9.                               borderVisible="true"
  10.                               dropShadowVisible="false"
  11.                               borderSides="left top"
  12.                               borderStyle="solid"
  13.                               >
  14.         <s:Label text="top left"/>
  15.     </controls:BorderContainer>
  16.  
  17.  
  18.  
  19. Skin:
  20.  
  21.    
  22.     /**
  23.      *  The default skin class for a Spark BorderContainer component.
  24.      *
  25.      *  @see spark.components.BorderContainer
  26.      *
  27.      *  @langversion 3.0
  28.      *  @playerversion Flash 10
  29.      *  @playerversion AIR 1.5
  30.      *  @productversion Flex 4
  31.      */
  32.     public class BorderContainerSkin extends Skin
  33.     {
  34.        
  35.         //--------------------------------------------------------------------------
  36.         //
  37.         //  Constructor
  38.         //
  39.         //--------------------------------------------------------------------------
  40.        
  41.         /**
  42.          *  Constructor.
  43.          *
  44.          *  @langversion 3.0
  45.          *  @playerversion Flash 10
  46.          *  @playerversion AIR 1.5
  47.          *  @productversion Flex 4
  48.          */
  49.         public function BorderContainerSkin()
  50.         {
  51.             super();
  52.            
  53.             minWidth = 30;
  54.             minHeight = 30;
  55.            
  56.             states = [
  57.                 new State({name:"normal"}),
  58.                 new State({name:"disabled",
  59.                     overrides:[new SetProperty(this, "alpha", 0.5)]})
  60.             ];
  61.         }
  62.        
  63.         /**
  64.          *  The required skin part for SkinnableContainer
  65.          */
  66.         [Bindable]
  67.         public var contentGroup:Group;
  68.        
  69.         private var bgRect:Rect;
  70.         private var insetPath:Path;
  71.         private var dropShadow:RectangularDropShadow;
  72.        
  73.         //--------------------------------------------------------------------------
  74.         //
  75.         //  Overridden methods
  76.         //
  77.         //--------------------------------------------------------------------------
  78.        
  79.         /**
  80.          *  @private
  81.          */
  82.         override protected function createChildren():void
  83.         {
  84.             super.createChildren();
  85.            
  86.             bgRect = new Rect();
  87.             addElementAt(bgRect, 0);
  88.             bgRect.left = bgRect.top = bgRect.right = bgRect.bottom = 0;
  89.            
  90.             contentGroup = new Group();
  91.             addElement(contentGroup);  
  92.            
  93.             insetPath = new Path();
  94.             addElement(insetPath);
  95.            
  96.             sprite = new SpriteVisualElement();
  97.             addElementAt(sprite, 3);
  98.         }
  99.        
  100.         public var sprite:SpriteVisualElement;
  101.        
  102.         /**
  103.          *  @private
  104.          */
  105.         override protected function measure():void
  106.         {      
  107.             measuredWidth = contentGroup.measuredWidth;
  108.             measuredHeight = contentGroup.measuredHeight;
  109.             measuredMinWidth = contentGroup.measuredMinWidth;
  110.             measuredMinHeight = contentGroup.measuredMinHeight;
  111.            
  112.             var borderWeight:Number = getStyle("borderWeight");
  113.            
  114.             if (hostComponent && hostComponent.borderStroke)
  115.                 borderWeight = hostComponent.borderStroke.weight;
  116.            
  117.             if (borderWeight > 0)
  118.             {
  119.                 var borderSize:int = borderWeight * 2;
  120.                 measuredWidth += borderSize;
  121.                 measuredHeight += borderSize;
  122.                 measuredMinWidth += borderSize;
  123.                 measuredMinHeight += borderSize;
  124.             }
  125.         }
  126.        
  127.         /**
  128.          *  @private
  129.          */
  130.         override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
  131.            
  132.             // we could use the inset path to draw our rownded border sides but didn't realize it
  133.             // until i had all this other work done. plus more work.
  134.             // todo: use path to draw border - go back to border container skin original
  135.             var g:Graphics = sprite.graphics;
  136.             g.clear();
  137.            
  138.             var radiusObj:Object;
  139.             var hole:Object;
  140.             var borderColor:Number = getStyle("borderColor");
  141.             var borderAlpha:Number = getStyle("borderAlpha");
  142.             var borderWeight:Number;
  143.             var borderStyle:String = getStyle("borderStyle");
  144.             var borderVisible:Boolean = getStyle("borderVisible");
  145.             var borderSides:String = getStyle("borderSides");
  146.             var roundedBottomCorners:String = getStyle("roundedBottomCorners");
  147.             var bHasAllSides:Boolean = true;
  148.             var cornerRadius:Number = getStyle("cornerRadius");
  149.            
  150.             var bRoundedCorners:Boolean = getStyle("roundedBottomCorners").toString().toLowerCase() == "true";
  151.            
  152.             // BORDER //
  153.             if (hostComponent && hostComponent.borderStroke) {
  154.                 borderWeight = hostComponent.borderStroke.weight;
  155.             }
  156.             else {
  157.                 borderWeight = getStyle("borderWeight");
  158.             }
  159.            
  160.             if (!borderVisible) {
  161.                 //borderWeight = 0;
  162.             }
  163.            
  164.             if (isNaN(borderWeight)) {
  165.                 borderWeight = 1;
  166.             }
  167.            
  168.             var holeRadius:Number = Math.max(cornerRadius - borderWeight, 0);
  169.            
  170.             hole = {x: borderWeight,
  171.                     y: borderWeight,
  172.                     w: unscaledWidth - borderWeight * 2,
  173.                     h: unscaledHeight - borderWeight * 2,
  174.                     r: holeRadius };
  175.            
  176.             if (!bRoundedCorners) {
  177.                 radiusObj = {tl:cornerRadius, tr:cornerRadius, bl:0, br:0};
  178.                 hole.r = {tl:holeRadius, tr:holeRadius, bl:0, br:0};
  179.             }
  180.            
  181.             contentGroup.setStyle("left", borderWeight);
  182.             contentGroup.setStyle("right", borderWeight);
  183.             contentGroup.setStyle("top", borderWeight);
  184.             contentGroup.setStyle("bottom", borderWeight);
  185.    
  186.             // new support for border sides from mx.skins.halo.haloborder ////////
  187.             // TODO: Add support for corner radius for each corner
  188.             if (borderSides != "left top right bottom") {
  189.                
  190.                 // Convert the radius values from a scalar to an object
  191.                 // because we need to adjust individual radius values
  192.                 // if we are missing any sides.
  193.                 hole.r = { tl: holeRadius,
  194.                            tr: holeRadius,
  195.                            bl: bRoundedCorners ? holeRadius : 0,
  196.                            br: bRoundedCorners ? holeRadius : 0 };
  197.                
  198.                 radiusObj = { tl: cornerRadius,
  199.                               tr: cornerRadius,
  200.                               bl: bRoundedCorners ? cornerRadius : 0,
  201.                               br: bRoundedCorners ? cornerRadius : 0};
  202.                
  203.                 borderSides = borderSides.toLowerCase();
  204.                
  205.                 if (borderSides.indexOf("left") == -1) {
  206.                     hole.x = 0;
  207.                     hole.w += borderWeight;
  208.                     hole.r.tl = 0;
  209.                     hole.r.bl = 0;
  210.                     radiusObj.tl = 0;
  211.                     radiusObj.bl = 0;
  212.                     bHasAllSides = false;
  213.                     contentGroup.setStyle("left", 0);
  214.                 }
  215.                
  216.                 if (borderSides.indexOf("top") == -1) {
  217.                     hole.y = 0;
  218.                     hole.h += borderWeight;
  219.                     hole.r.tl = 0;
  220.                     hole.r.tr = 0;
  221.                     radiusObj.tl = 0;
  222.                     radiusObj.tr = 0;
  223.                     bHasAllSides = false;
  224.                     contentGroup.setStyle("top", 0);
  225.                 }
  226.                
  227.                 if (borderSides.indexOf("right") == -1) {
  228.                     hole.w += borderWeight;
  229.                     hole.r.tr = 0;
  230.                     hole.r.br = 0;
  231.                     radiusObj.tr = 0;
  232.                     radiusObj.br = 0;
  233.                     bHasAllSides = false;
  234.                     contentGroup.setStyle("right", 0);
  235.                 }
  236.                
  237.                 if (borderSides.indexOf("bottom") == -1) {
  238.                     hole.h += borderWeight;
  239.                     hole.r.bl = 0;
  240.                     hole.r.br = 0;
  241.                     radiusObj.bl = 0;
  242.                     radiusObj.br = 0;
  243.                     bHasAllSides = false;
  244.                     contentGroup.setStyle("bottom", 0);
  245.                 }
  246.             }
  247.            
  248.            
  249.             super.updateDisplayList(unscaledWidth, unscaledHeight);
  250.            
  251.             // update the bgRect stroke/fill
  252.             if (hostComponent && hostComponent.borderStroke)
  253.             {
  254.                 bgRect.stroke = hostComponent.borderStroke;
  255.             }
  256.             else if (!borderVisible)
  257.             {
  258.                 bgRect.stroke = null;
  259.             }
  260.             else if (bHasAllSides)  {
  261.                 var borderJoints:String = getStyle("borderJoints");
  262.                 var borderCaps:String = getStyle("borderCaps");
  263.                 var borderMiterLimit:Number = getStyle("borderMiterLimit");
  264.                 var borderPixelHinting:String = getStyle("borderPixelHinting");
  265.                 var borderScaleMode:String = getStyle("borderScaleMode");
  266.                 var stroke:SolidColorStroke;
  267.                
  268.                 if (!isNaN(borderColor))
  269.                 {
  270.                     if (isNaN(borderAlpha)) {
  271.                         borderAlpha = 1;
  272.                     }
  273.                    
  274.                     stroke = new SolidColorStroke(borderColor, borderWeight, borderAlpha);
  275.                    
  276.                    
  277.                     // Setting defaults if style is undefined
  278.                     // set default to miter
  279.                     if (borderJoints==null) {
  280.                         borderJoints = JointStyle.MITER;
  281.                     }
  282.                    
  283.                     stroke.joints = borderJoints;
  284.                    
  285.                     if (borderCaps==null) {
  286.                         borderCaps = CapsStyle.ROUND;
  287.                     }
  288.                    
  289.                     stroke.caps = borderCaps;
  290.                    
  291.                     if (isNaN(borderMiterLimit)) {
  292.                         borderMiterLimit = 3;
  293.                     }
  294.                    
  295.                     stroke.miterLimit = borderMiterLimit;
  296.                    
  297.                     if (borderPixelHinting==null) {
  298.                         borderPixelHinting = "false";
  299.                     }
  300.                     else {
  301.                         borderPixelHinting = "true";
  302.                     }
  303.                    
  304.                     stroke.pixelHinting = borderPixelHinting=="true" ? true : false;
  305.                    
  306.                     if (borderScaleMode==null) {
  307.                         borderScaleMode = LineScaleMode.NORMAL;
  308.                     }
  309.                    
  310.                     stroke.scaleMode = borderScaleMode;
  311.                    
  312.                     bgRect.stroke = stroke;
  313.                 }
  314.             }
  315.            
  316.             // BACKGROUND FILL
  317.             if (hostComponent && hostComponent.backgroundFill)
  318.             {
  319.                 bgRect.fill = hostComponent.backgroundFill;
  320.             }
  321.             else
  322.             {
  323.                 var bgImage:Object = getStyle("backgroundImage");
  324.                
  325.                 if (bgImage)
  326.                 {
  327.                     var bitmapFill:BitmapFill = bgRect.fill is BitmapFill ? BitmapFill(bgRect.fill) : new BitmapFill();
  328.                    
  329.                     bitmapFill.source = bgImage;
  330.                     bitmapFill.fillMode = getStyle("backgroundImageFillMode");
  331.                     bitmapFill.alpha = getStyle("backgroundAlpha");
  332.                    
  333.                     bgRect.fill = bitmapFill;
  334.                 }
  335.                 else
  336.                 {
  337.                     var bkgdColor:Number = getStyle("backgroundColor");
  338.                     var bkgdAlpha:Number = getStyle("backgroundAlpha");
  339.                    
  340.                     if (isNaN(bkgdAlpha))
  341.                         bkgdAlpha = 1;
  342.                    
  343.                     if (!isNaN(bkgdColor))
  344.                         bgRect.fill = new SolidColor(bkgdColor, bkgdAlpha);
  345.                     else
  346.                         bgRect.fill = new SolidColor(0, 0);
  347.                 }
  348.             }
  349.            
  350.             // Draw the shadow for the inset style
  351.             if (borderStyle == "inset" && hostComponent && hostComponent.borderStroke == null && borderVisible)
  352.             {            
  353.                 var negCR:Number = -cornerRadius;
  354.                 var path:String = "";
  355.                
  356.                 if (cornerRadius > 0 && borderWeight < 10)
  357.                 {
  358.                     // Draw each corner with two quadratics, using the following ratios:
  359.                     var a:Number = cornerRadius * 0.292893218813453;
  360.                     var s:Number = cornerRadius * 0.585786437626905;
  361.                     var right:Number = unscaledWidth - borderWeight;
  362.                    
  363.                     path += "M 0 " + cornerRadius; // M 0 CR
  364.                     path += " Q 0 " + s + " " + a + " " + a; // Q 0 s a a
  365.                     path += " Q " + s + " 0 " + cornerRadius + " 0"; // Q s 0 CR 0
  366.                     path += " L " + (right - cornerRadius) + " 0"; // L (right-CR) 0
  367.                     path += " Q " + (right - s) + " 0 " + (right - a) + " " + a; // Q (right-s) 0 (right-a) a
  368.                     path += " Q " + right + " " + s + " " + right + " " + cornerRadius; // Q right s right CR  
  369.                     insetPath.height = cornerRadius;
  370.                 }
  371.                 else
  372.                 {
  373.                     path += "M 0 0";
  374.                     path += " L " + (unscaledWidth - borderWeight) + " 0";
  375.                     insetPath.height = 1;
  376.                 }
  377.                
  378.                 insetPath.x = borderWeight;
  379.                 insetPath.y = borderWeight;
  380.                 insetPath.width = unscaledWidth - (borderWeight * 2);
  381.                 insetPath.data = path;
  382.                 insetPath.stroke = new SolidColorStroke(0x000000, 1, .12);
  383.             }
  384.             else
  385.             {
  386.                 insetPath.data = "";
  387.                 insetPath.stroke = null;
  388.             }
  389.            
  390.             bgRect.radiusX = bgRect.radiusY = cornerRadius;
  391.            
  392.             //super.updateDisplayList(unscaledWidth, unscaledHeight);
  393.            
  394.             if (getStyle("dropShadowVisible") == true)
  395.             {
  396.                 if (!dropShadow)
  397.                     dropShadow = new RectangularDropShadow();
  398.                
  399.                 dropShadow.alpha = 0.4;
  400.                 dropShadow.angle = 90;
  401.                 dropShadow.color = 0x000000;
  402.                 dropShadow.distance = 5;
  403.                 dropShadow.tlRadius = dropShadow.trRadius = dropShadow.blRadius = dropShadow.brRadius = cornerRadius + 1;
  404.                
  405.                 g.lineStyle();
  406.                 dropShadow.drawShadow(g, 0, 0, unscaledWidth, unscaledHeight);
  407.             }
  408.            
  409.             if (cornerRadius == 0 && bHasAllSides) {
  410.                 drawDropShadow(0, 0, unscaledWidth, unscaledHeight, 0, 0, 0, 0);
  411.                
  412.                 g.beginFill(borderColor);
  413.                 g.drawRect(0, 0, unscaledWidth, unscaledHeight);
  414.                 g.drawRect(borderWeight, borderWeight,
  415.                     unscaledWidth - 2 * borderWeight,
  416.                     unscaledHeight - 2 * borderWeight);
  417.                 g.endFill();
  418.             }
  419.             else if (radiusObj) {
  420.                 drawDropShadow(0, 0, unscaledWidth, unscaledHeight,
  421.                     radiusObj.tl, radiusObj.tr,
  422.                     radiusObj.br, radiusObj.bl);
  423.                
  424.                 drawRoundRect(
  425.                     0, 0, unscaledWidth, unscaledHeight, radiusObj,
  426.                     borderColor, 1,
  427.                     null, null, null, hole);
  428.                
  429.                 // Reset radius here so background drawing
  430.                 // below is correct.
  431.                 radiusObj.tl = Math.max(cornerRadius - borderWeight, 0);
  432.                 radiusObj.tr = Math.max(cornerRadius - borderWeight, 0);
  433.                 radiusObj.bl = bRoundedCorners ? Math.max(cornerRadius - borderWeight, 0) : 0;
  434.                 radiusObj.br = bRoundedCorners ? Math.max(cornerRadius - borderWeight, 0) : 0;
  435.             }
  436.             else {
  437.                 drawDropShadow(0, 0, unscaledWidth, unscaledHeight,
  438.                     cornerRadius, cornerRadius, cornerRadius, cornerRadius);
  439.                
  440.                 drawRoundRect(
  441.                     0, 0, unscaledWidth, unscaledHeight, cornerRadius,
  442.                     borderColor, 1,
  443.                     null, null, null, hole);
  444.                
  445.                 // Reset radius here so background drawing
  446.                 // below is correct.
  447.                 cornerRadius = Math.max(getStyle("cornerRadius") -
  448.                     borderWeight, 0);
  449.             }
  450.         }
  451.        
  452.         /**
  453.          *  Programatically draws a rectangle into this skin's Graphics object.
  454.          *
  455.          *  <p>The rectangle can have rounded corners.
  456.          *  Its edges are stroked with the current line style
  457.          *  of the Graphics object.
  458.          *  It can have a solid color fill, a gradient fill, or no fill.
  459.          *  A solid fill can have an alpha transparency.
  460.          *  A gradient fill can be linear or radial. You can specify
  461.          *  up to 15 colors and alpha values at specified points along
  462.          *  the gradient, and you can specify a rotation angle
  463.          *  or transformation matrix for the gradient.
  464.          *  Finally, the rectangle can have a rounded rectangular hole
  465.          *  carved out of it.</p>
  466.          *
  467.          *  <p>This versatile rectangle-drawing routine is used by many skins.
  468.          *  It calls the <code>drawRect()</code> or
  469.          *  <code>drawRoundRect()</code>
  470.          *  methods (in the flash.display.Graphics class) to draw into this
  471.          *  skin's Graphics object.</p>
  472.          *
  473.          *  @param x Horizontal position of upper-left corner
  474.          *  of rectangle within this skin.
  475.          *
  476.          *  @param y Vertical position of upper-left corner
  477.          *  of rectangle within this skin.
  478.          *
  479.          *  @param width Width of rectangle, in pixels.
  480.          *
  481.          *  @param height Height of rectangle, in pixels.
  482.          *
  483.          *  @param cornerRadius Corner radius/radii of rectangle.
  484.          *  Can be <code>null</code>, a Number, or an Object.
  485.          *  If it is <code>null</code>, it specifies that the corners should be square
  486.          *  rather than rounded.
  487.          *  If it is a Number, it specifies the same radius, in pixels,
  488.          *  for all four corners.
  489.          *  If it is an Object, it should have properties named
  490.          *  <code>tl</code>, <code>tr</code>, <code>bl</code>, and
  491.          *  <code>br</code>, whose values are Numbers specifying
  492.          *  the radius, in pixels, for the top left, top right,
  493.          *  bottom left, and bottom right corners.
  494.          *  For example, you can pass a plain Object such as
  495.          *  <code>{ tl: 5, tr: 5, bl: 0, br: 0 }</code>.
  496.          *  The default value is null (square corners).
  497.          *
  498.          *  @param color The RGB color(s) for the fill.
  499.          *  Can be <code>null</code>, a uint, or an Array.
  500.          *  If it is <code>null</code>, the rectangle not filled.
  501.          *  If it is a uint, it specifies an RGB fill color.
  502.          *  For example, pass <code>0xFF0000</code> to fill with red.
  503.          *  If it is an Array, it should contain uints
  504.          *  specifying the gradient colors.
  505.          *  For example, pass <code>[ 0xFF0000, 0xFFFF00, 0x0000FF ]</code>
  506.          *  to fill with a red-to-yellow-to-blue gradient.
  507.          *  You can specify up to 15 colors in the gradient.
  508.          *  The default value is null (no fill).
  509.          *
  510.          *  @param alpha Alpha value(s) for the fill.
  511.          *  Can be null, a Number, or an Array.
  512.          *  This argument is ignored if <code>color</code> is null.
  513.          *  If <code>color</code> is a uint specifying an RGB fill color,
  514.          *  then <code>alpha</code> should be a Number specifying
  515.          *  the transparency of the fill, where 0.0 is completely transparent
  516.          *  and 1.0 is completely opaque.
  517.          *  You can also pass null instead of 1.0 in this case
  518.          *  to specify complete opaqueness.
  519.          *  If <code>color</code> is an Array specifying gradient colors,
  520.          *  then <code>alpha</code> should be an Array of Numbers, of the
  521.          *  same length, that specifies the corresponding alpha values
  522.          *  for the gradient.
  523.          *  In this case, the default value is <code>null</code> (completely opaque).
  524.          *
  525.          *  @param gradientMatrix Matrix object used for the gradient fill.
  526.          *  The utility methods <code>horizontalGradientMatrix()</code>,
  527.          *  <code>verticalGradientMatrix()</code>, and
  528.          *  <code>rotatedGradientMatrix()</code> can be used to create the value for
  529.          *  this parameter.
  530.          *
  531.          *  @param gradientType Type of gradient fill. The possible values are
  532.          *  <code>GradientType.LINEAR</code> or <code>GradientType.RADIAL</code>.
  533.          *  (The GradientType class is in the package flash.display.)
  534.          *
  535.          *  @param gradientRatios (optional default [0,255])
  536.          *  Specifies the distribution of colors. The number of entries must match
  537.          *  the number of colors defined in the <code>color</code> parameter.
  538.          *  Each value defines the percentage of the width where the color is
  539.          *  sampled at 100%. The value 0 represents the left-hand position in
  540.          *  the gradient box, and 255 represents the right-hand position in the
  541.          *  gradient box.
  542.          *
  543.          *  @param hole (optional) A rounded rectangular hole
  544.          *  that should be carved out of the middle
  545.          *  of the otherwise solid rounded rectangle
  546.          *  { x: #, y: #, w: #, h: #, r: # or { br: #, bl: #, tl: #, tr: # } }
  547.          *
  548.          *  @see flash.display.Graphics#beginGradientFill()
  549.          *  
  550.          *  @langversion 3.0
  551.          *  @playerversion Flash 9
  552.          *  @playerversion AIR 1.1
  553.          *  @productversion Flex 3
  554.          */
  555.         protected function drawRoundRectSides(
  556.                                 x:Number, y:Number, width:Number, height:Number,
  557.                                 cornerRadius:Object = null,
  558.                                 color:Object = null,
  559.                                 alpha:Object = null,
  560.                                 gradientMatrix:Matrix = null,
  561.                                 gradientType:String = "linear",
  562.                                 gradientRatios:Array /* of Number */ = null,
  563.                                 hole:Object = null):void
  564.         {
  565.             var g:Graphics = g;
  566.    
  567.             // Quick exit if weight or height is zero.
  568.             // This happens when scaling a component to a very small value,
  569.             // which then gets rounded to 0.
  570.             if (width == 0 || height == 0)
  571.                 return;
  572.    
  573.             // If color is an object then allow for complex fills.
  574.             if (color !== null)
  575.             {
  576.                 if (color is uint)
  577.                 {
  578.                     g.beginFill(uint(color), Number(alpha));
  579.                 }
  580.                 else if (color is Array)
  581.                 {
  582.                     var alphas:Array = alpha is Array ?
  583.                                        alpha as Array :
  584.                                        [ alpha, alpha ];
  585.    
  586.                     if (!gradientRatios)
  587.                         gradientRatios = [ 0, 0xFF ];
  588.    
  589.                     g.beginGradientFill(gradientType,
  590.                                         color as Array, alphas,
  591.                                         gradientRatios, gradientMatrix);
  592.                 }
  593.             }
  594.    
  595.             var ellipseSize:Number;
  596.    
  597.             // Stroke the rectangle.
  598.             if (!cornerRadius)
  599.             {
  600.                 g.drawRect(x, y, width, height);
  601.             }
  602.             else if (cornerRadius is Number)
  603.             {
  604.                 ellipseSize = Number(cornerRadius) * 2;
  605.                 g.drawRoundRect(x, y, width, height,
  606.                                 ellipseSize, ellipseSize);
  607.             }
  608.             else
  609.             {
  610.                 GraphicsUtil.drawRoundRectComplex(g,
  611.                                        x, y, width, height,
  612.                                        cornerRadius.tl, cornerRadius.tr,
  613.                                        cornerRadius.bl, cornerRadius.br);
  614.             }
  615.    
  616.             // Carve a rectangular hole out of the middle of the rounded rect.
  617.             if (hole)
  618.             {
  619.                 var holeR:Object = hole.r;
  620.                 if (holeR is Number)
  621.                 {
  622.                     ellipseSize = Number(holeR) * 2;
  623.                     g.drawRoundRect(hole.x, hole.y, hole.w, hole.h,
  624.                                     ellipseSize, ellipseSize);
  625.                 }
  626.                 else
  627.                 {
  628.                     GraphicsUtil.drawRoundRectComplex(g,
  629.                                            hole.x, hole.y, hole.w, hole.h,
  630.                                            holeR.tl, holeR.tr, holeR.bl, holeR.br);
  631.                 }  
  632.             }
  633.    
  634.             if (color !== null)
  635.                 g.endFill();
  636.         }
  637.        
  638.        
  639.         /**
  640.          *  @private
  641.          *  Apply a drop shadow using a bitmap filter.
  642.          *
  643.          *  Bitmap filters are slow, and their slowness is proportional
  644.          *  to the number of pixels being filtered.
  645.          *  For a large HaloBorder, it's wasteful to create a big shadow.
  646.          *  Instead, we'll create the shadow offscreen
  647.          *  and stretch it to fit the HaloBorder.
  648.          */
  649.         public function drawDropShadow(x:Number, y:Number,
  650.                                             width:Number, height:Number,
  651.                                             tlRadius:Number, trRadius:Number,
  652.                                             brRadius:Number, blRadius:Number):void
  653.         {
  654.             // Do I need a drop shadow in the first place?  If not, return
  655.             // immediately.
  656.             if (getStyle("dropShadowVisible") == false ||
  657.                 getStyle("dropShadowVisible") == "false" ||
  658.                 width == 0 ||
  659.                 height == 0)
  660.             {
  661.                 return;
  662.             }
  663.            
  664.             // Calculate the angle and distance for the shadow
  665.             var distance:Number = getStyle("shadowDistance");
  666.             var direction:String = getStyle("shadowDirection");
  667.             var angle:Number;      
  668.             if (getStyle("borderStyle") == "applicationControlBar")
  669.             {
  670.                 var docked:Boolean = getStyle("docked");
  671.                 angle = docked ? 90 : getDropShadowAngle(distance, direction);
  672.                 distance = Math.abs(distance);
  673.             }
  674.             else
  675.             {
  676.                 angle = getDropShadowAngle(distance, direction);
  677.                 distance = Math.abs(distance) + 2;
  678.             }
  679.            
  680.             // Create a RectangularDropShadow object, set its properties,
  681.             // and draw the shadow
  682.             if (!dropShadow)
  683.                 dropShadow = new RectangularDropShadow();
  684.            
  685.             dropShadow.distance = distance;
  686.             dropShadow.angle = angle;
  687.             dropShadow.color = getStyle("dropShadowColor");
  688.             dropShadow.alpha = 0.4;
  689.            
  690.             dropShadow.tlRadius = tlRadius;
  691.             dropShadow.trRadius = trRadius;
  692.             dropShadow.blRadius = blRadius;
  693.             dropShadow.brRadius = brRadius;
  694.            
  695.             dropShadow.drawShadow(sprite.graphics, x, y, width, height);
  696.         }
  697.        
  698.         /**
  699.          *  @private
  700.          *  Convert the value of the shadowDirection property
  701.          *  into a shadow angle.
  702.          */
  703.         public function getDropShadowAngle(distance:Number,
  704.                                                 direction:String):Number
  705.         {
  706.             if (direction == "left")
  707.                 return distance >= 0 ? 135 : 225;
  708.                
  709.             else if (direction == "right")
  710.                 return distance >= 0 ? 45 : 315;
  711.                
  712.             else // direction == "center"
  713.                 return distance >= 0 ? 90 : 270;
  714.         }
  715.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement