/* * Copyright 2008 (c) Lance Pollard * www.systemsofseven.com/blog * www.4ddesignlab.com * LanceJPollard@gmail.com * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package com.fourD.layouts { import mx.core.ILayoutElement; import mx.core.UIComponent; public class CoverFlowLayout extends FourDLayout { public function CoverFlowLayout() { super(); } private var _angle:Number = 70; [Bindable] public function get angle():Number { return _angle; } public function set angle(value:Number):void { _angle = value; if (target) target.invalidateDisplayList(); } private var _gap:Number = 0; [Bindable] public function get gap():Number { return _gap; } public function set gap(value:Number):void { _gap = value; if (target) target.invalidateDisplayList(); } private var _distance:Number = 10; [Bindable] public function get distance():Number { return _distance; } public function set distance(value:Number):void { _distance = value; if (target) target.invalidateDisplayList(); } private var _direction:String = "horizontal"; [Bindable] [Inspectable(defaultValue="horizontal", enumeration="horizontal,vertical,null")] public function get direction():String { return _direction; } public function set direction(value:String):void { _direction = value; if (target) target.invalidateDisplayList(); } private var init:Boolean = false; protected var maxChildHeight:Number; protected var maxChildWidth:Number; protected var abs:Number; protected var offset:Number=0; [Bindable] public var radius:Number; [Bindable] public var anglePer:Number; override public function initializeLayoutEquation():void { selectedChild = target.getLayoutElementAt(selectedIndex) as UIComponent; maxChildHeight = Number((selectedChild as ILayoutElement).getPreferredBoundsWidth()); maxChildWidth = Number((selectedChild as ILayoutElement).getPreferredBoundsHeight()); if (!gap) { if (direction == "horizontal") { gap = maxChildHeight / 3; } } if (!radius) { radius = target.width/2; } if (!anglePer) { anglePer = (Math.PI * 2) / numOfItems; } preferredLayoutElementWidth = 120; preferredLayoutElementHeight = 120; } override public function getLayoutElementToken(layoutElement:ILayoutElement, index:int):Object { var token:Object = new Object(); // must do this to set the element width and height before anything else setLayoutElementWidth(layoutElement, preferredLayoutElementWidth, token, target.width); setLayoutElementHeight(layoutElement, preferredLayoutElementHeight, token, target.height); // then this is the equation for each item abs = Math.abs(selectedIndex - index); offset += token.width; token.x = (selectedChild as ILayoutElement).getPreferredBoundsWidth() + ((abs - 1) * gap)// + offset; if (_gap > 0) token.x += (abs - 1) * (_gap + token.width); token.y = -(maxChildHeight - layoutElement.getPreferredBoundsHeight()) / 2; token.z = (selectedChild as ILayoutElement).getPreferredBoundsWidth() + abs * 5; (layoutElement as UIComponent).includeInLayout = false; token.rotationY = angle; if(index < selectedIndex) { token.x = -token.x + token.width/2; token.rotationY *= -1; } else if(index == selectedIndex) { token.x = 0; token.z = -200 / 2; token.rotationY = 0; offset = 0; } token.x = token.x + target.width/2 - token.width/2; token.y = (token.y*-1) + target.height/2 - token.height/2; return token; } } }