home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / qs / controls / FisheyeTile.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  12.1 KB  |  329 lines

  1. package qs.controls
  2. {
  3.    import flash.geom.Rectangle;
  4.    import mx.core.UIComponent;
  5.    import qs.controls.fisheyeClasses.FisheyeAxis;
  6.    import qs.controls.fisheyeClasses.FisheyeBase;
  7.    import qs.controls.fisheyeClasses.FisheyeItem;
  8.    
  9.    public class FisheyeTile extends FisheyeBase
  10.    {
  11.       private var _vMouseItems:Array = [];
  12.       
  13.       private var _colLength:int;
  14.       
  15.       private var _vItems:Array = [];
  16.       
  17.       private var _direction:String = "vertical";
  18.       
  19.       private var _tileHeight:int;
  20.       
  21.       private var _hItems:Array = [];
  22.       
  23.       private var _pdata:Array = [];
  24.       
  25.       private var _rowLength:int = 4;
  26.       
  27.       protected var hAxis:FisheyeAxis = new FisheyeAxis();
  28.       
  29.       private var _hMouseItems:Array = [];
  30.       
  31.       private var _mouseData:Array = [];
  32.       
  33.       protected var vAxis:FisheyeAxis = new FisheyeAxis();
  34.       
  35.       private var _tileWidth:int;
  36.       
  37.       private var _mouseBounds:Rectangle = new Rectangle();
  38.       
  39.       public function FisheyeTile()
  40.       {
  41.          super();
  42.          this.hAxis.direction = "horizontal";
  43.          this.vAxis.direction = "vertical";
  44.       }
  45.       
  46.       override protected function findItemForPosition(param1:Number, param2:Number) : Number
  47.       {
  48.          var _loc3_:Number = NaN;
  49.          var _loc4_:Number = NaN;
  50.          var _loc8_:FisheyeItem = null;
  51.          var _loc9_:Number = NaN;
  52.          var _loc10_:Number = NaN;
  53.          var _loc5_:Number = Infinity;
  54.          if(dataProvider.length == 0)
  55.          {
  56.             return NaN;
  57.          }
  58.          if(this._mouseBounds.contains(param1,param2) == false)
  59.          {
  60.             return NaN;
  61.          }
  62.          var _loc6_:int = 0;
  63.          while(_loc6_ < this._hMouseItems.length)
  64.          {
  65.             _loc8_ = this._hMouseItems[_loc6_];
  66.             _loc9_ = _loc8_.x + _loc8_.eomWidth * _loc8_.scale / 2;
  67.             _loc10_ = param1 - _loc9_;
  68.             if(Math.abs(_loc10_) >= Math.abs(_loc5_))
  69.             {
  70.                break;
  71.             }
  72.             _loc5_ = _loc10_;
  73.             _loc3_ = _loc6_;
  74.             _loc6_++;
  75.          }
  76.          if(isNaN(_loc3_))
  77.          {
  78.             return NaN;
  79.          }
  80.          _loc5_ = Infinity;
  81.          var _loc7_:int = 0;
  82.          while(_loc7_ < this._vMouseItems.length)
  83.          {
  84.             _loc8_ = this._vMouseItems[_loc7_];
  85.             _loc9_ = _loc8_.y + _loc8_.eomHeight * _loc8_.scale / 2;
  86.             _loc10_ = param2 - _loc9_;
  87.             if(Math.abs(_loc10_) >= Math.abs(_loc5_))
  88.             {
  89.                break;
  90.             }
  91.             _loc5_ = _loc10_;
  92.             _loc4_ = _loc7_;
  93.             _loc7_++;
  94.          }
  95.          if(isNaN(_loc4_))
  96.          {
  97.             return NaN;
  98.          }
  99.          return _loc4_ * this._rowLength + _loc3_;
  100.       }
  101.       
  102.       override protected function commitProperties() : void
  103.       {
  104.          var _loc2_:int = 0;
  105.          var _loc3_:int = 0;
  106.          var _loc1_:Boolean = this.itemsChanged;
  107.          super.commitProperties();
  108.          if(_loc1_)
  109.          {
  110.             this._hItems = [];
  111.             this._vItems = [];
  112.             this._hMouseItems = [];
  113.             this._vMouseItems = [];
  114.             this._colLength = Math.ceil(dataProvider.length / this._rowLength);
  115.             _loc2_ = 0;
  116.             while(_loc2_ < this._rowLength)
  117.             {
  118.                this._hItems[_loc2_] = new FisheyeItem();
  119.                this._hMouseItems[_loc2_] = new FisheyeItem();
  120.                _loc2_++;
  121.             }
  122.             _loc3_ = 0;
  123.             while(_loc3_ < this._colLength)
  124.             {
  125.                this._vItems[_loc3_] = new FisheyeItem();
  126.                this._vMouseItems[_loc3_] = new FisheyeItem();
  127.                _loc3_++;
  128.             }
  129.          }
  130.       }
  131.       
  132.       public function set rowLength(param1:int) : void
  133.       {
  134.          this._rowLength = param1;
  135.       }
  136.       
  137.       override protected function measure() : void
  138.       {
  139.          var _loc1_:int = 0;
  140.          var _loc3_:UIComponent = null;
  141.          this._tileWidth = 0;
  142.          this._tileHeight = 0;
  143.          _loc1_ = 0;
  144.          while(_loc1_ < renderers.length)
  145.          {
  146.             _loc3_ = renderers[_loc1_];
  147.             this._tileWidth = Math.max(this._tileWidth,_loc3_.getExplicitOrMeasuredWidth());
  148.             this._tileHeight = Math.max(this._tileHeight,_loc3_.getExplicitOrMeasuredHeight());
  149.             _loc1_++;
  150.          }
  151.          this._tileWidth = Math.max(this._tileWidth,this._tileHeight);
  152.          this._tileHeight = this._tileWidth;
  153.          _loc1_ = 0;
  154.          while(_loc1_ < this._rowLength)
  155.          {
  156.             this._hItems[_loc1_].eomWidth = this._hMouseItems[_loc1_].eomWidth = this._tileWidth;
  157.             this._hItems[_loc1_].eomHeight = this._hMouseItems[_loc1_].eomHeight = this._tileHeight;
  158.             _loc1_++;
  159.          }
  160.          var _loc2_:int = 0;
  161.          while(_loc2_ < this._colLength)
  162.          {
  163.             this._vItems[_loc2_].eomWidth = this._vMouseItems[_loc2_].eomWidth = this._tileWidth;
  164.             this._vItems[_loc2_].eomHeight = this._vMouseItems[_loc2_].eomHeight = this._tileHeight;
  165.             _loc2_++;
  166.          }
  167.          animator.invalidateLayout();
  168.       }
  169.       
  170.       public function get rowLength() : int
  171.       {
  172.          return this._rowLength;
  173.       }
  174.       
  175.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  176.       {
  177.          populateMajorAxisForDefault(this._hMouseItems,this.hAxis,param1);
  178.          align(this._hMouseItems,this.hAxis);
  179.          populateMajorAxisForDefault(this._vMouseItems,this.vAxis,param2);
  180.          align(this._vMouseItems,this.vAxis);
  181.          var _loc3_:FisheyeItem = this._hMouseItems[0];
  182.          var _loc4_:FisheyeItem = this._hMouseItems[this._hMouseItems.length - 1];
  183.          var _loc5_:FisheyeItem = this._vMouseItems[0];
  184.          var _loc6_:FisheyeItem = this._vMouseItems[this._vMouseItems.length - 1];
  185.          this._mouseBounds.left = _loc3_.x + _loc3_.eomWidth * _loc3_.scale / 2 - _loc3_.eomWidth / 2;
  186.          this._mouseBounds.top = _loc5_.y + _loc5_.eomHeight * _loc5_.scale / 2 - _loc5_.eomHeight / 2;
  187.          this._mouseBounds.right = _loc4_.x + _loc4_.eomWidth * _loc4_.scale / 2 + _loc4_.eomWidth / 2;
  188.          this._mouseBounds.bottom = _loc6_.y + _loc6_.eomHeight * _loc6_.scale / 2 + _loc6_.eomHeight / 2;
  189.          super.updateDisplayList(param1,param2);
  190.       }
  191.       
  192.       override protected function generateLayout() : void
  193.       {
  194.          var _loc5_:int = 0;
  195.          var _loc6_:Number = NaN;
  196.          var _loc7_:FisheyeItem = null;
  197.          var _loc8_:Number = NaN;
  198.          var _loc9_:Number = NaN;
  199.          var _loc10_:FisheyeItem = null;
  200.          var _loc11_:Number = NaN;
  201.          var _loc12_:int = 0;
  202.          var _loc13_:Number = NaN;
  203.          var _loc14_:int = 0;
  204.          var _loc15_:UIComponent = null;
  205.          var _loc16_:LayoutTarget = null;
  206.          var _loc17_:Number = NaN;
  207.          var _loc18_:Number = NaN;
  208.          var _loc19_:Number = NaN;
  209.          var _loc1_:int = int(dataProvider.length);
  210.          var _loc2_:Number = isNaN(hilightedItemIndex) ? selectedItemIndex : hilightedItemIndex;
  211.          if(isNaN(_loc2_))
  212.          {
  213.             populateMajorAxisForDefault(this._hItems,this.hAxis,unscaledWidth);
  214.             align(this._hItems,this.hAxis);
  215.             populateMajorAxisForDefault(this._vItems,this.vAxis,unscaledHeight);
  216.             align(this._vItems,this.vAxis);
  217.          }
  218.          else
  219.          {
  220.             _loc6_ = _loc2_ % this._rowLength;
  221.             _loc7_ = this._hMouseItems[_loc6_];
  222.             _loc8_ = _loc7_.x + _loc7_.eomWidth * _loc7_.scale - this._tileWidth * maxScaleWithDefault / 2;
  223.             if(_loc8_ < 0)
  224.             {
  225.                _loc8_ = 0;
  226.             }
  227.             if(_loc8_ + this._tileWidth * maxScaleWithDefault > unscaledWidth)
  228.             {
  229.                _loc8_ = unscaledWidth - this._tileWidth * maxScaleWithDefault;
  230.             }
  231.             populateMajorAxisFor(this._hItems.slice(_loc6_),0,unscaledWidth - _loc8_,this.hAxis);
  232.             _loc5_ = _loc6_;
  233.             while(_loc5_ < this._rowLength)
  234.             {
  235.                this._hItems[_loc5_].x += _loc8_;
  236.                _loc5_++;
  237.             }
  238.             if(_loc6_ > 0)
  239.             {
  240.                populateMajorAxisFor(this._hItems.slice(0,_loc6_),_loc6_,_loc8_ - defaultSpacingWithDefault,this.hAxis);
  241.                _loc7_ = this._hItems[_loc6_ - 1];
  242.                _loc13_ = _loc8_ - (_loc7_.x + _loc7_.eomWidth * _loc7_.scale + defaultSpacingWithDefault);
  243.                _loc12_ = 0;
  244.                while(_loc12_ < _loc6_)
  245.                {
  246.                   this._hItems[_loc12_].x += _loc13_;
  247.                   _loc12_++;
  248.                }
  249.             }
  250.             _loc9_ = Math.floor(_loc2_ / this._rowLength);
  251.             _loc10_ = this._vMouseItems[_loc9_];
  252.             _loc11_ = _loc10_.y + _loc10_.eomHeight * _loc10_.scale - this._tileHeight * maxScaleWithDefault / 2;
  253.             if(_loc11_ < 0)
  254.             {
  255.                _loc11_ = 0;
  256.             }
  257.             if(_loc11_ + this._tileHeight * maxScaleWithDefault > unscaledHeight)
  258.             {
  259.                _loc11_ = unscaledHeight - this._tileHeight * maxScaleWithDefault;
  260.             }
  261.             populateMajorAxisFor(this._vItems.slice(_loc9_),0,unscaledHeight - _loc11_,this.vAxis);
  262.             _loc12_ = _loc9_;
  263.             while(_loc12_ < this._colLength)
  264.             {
  265.                this._vItems[_loc12_].y += _loc11_;
  266.                _loc12_++;
  267.             }
  268.             if(_loc9_ > 0)
  269.             {
  270.                populateMajorAxisFor(this._vItems.slice(0,_loc9_),_loc9_,_loc11_ - defaultSpacingWithDefault,this.vAxis);
  271.                _loc10_ = this._vItems[_loc9_ - 1];
  272.                _loc13_ = _loc11_ - (_loc10_.y + _loc10_.eomHeight * _loc10_.scale + defaultSpacingWithDefault);
  273.                _loc14_ = 0;
  274.                while(_loc14_ < _loc9_)
  275.                {
  276.                   this._vItems[_loc14_].y += _loc13_;
  277.                   _loc14_++;
  278.                }
  279.             }
  280.          }
  281.          var _loc3_:String = getStyle("zoomMode");
  282.          var _loc4_:* = _loc3_ != "resize";
  283.          _loc5_ = 0;
  284.          while(_loc5_ < _loc1_)
  285.          {
  286.             _loc15_ = renderers[_loc5_];
  287.             _loc7_ = this._hItems[_loc5_ % this._rowLength];
  288.             _loc10_ = this._vItems[Math.floor(_loc5_ / this._rowLength)];
  289.             _loc16_ = animator.targetFor(_loc15_);
  290.             if(_loc4_)
  291.             {
  292.                _loc17_ = _loc7_.eomWidth * _loc7_.scale / (_loc10_.eomHeight * _loc10_.scale);
  293.                _loc18_ = _loc15_.getExplicitOrMeasuredWidth() / _loc15_.getExplicitOrMeasuredHeight();
  294.                if(_loc18_ / _loc17_ > 1)
  295.                {
  296.                   _loc19_ = _loc7_.eomWidth * _loc7_.scale / _loc15_.getExplicitOrMeasuredWidth();
  297.                   _loc16_.scaleX = _loc16_.scaleY = _loc19_;
  298.                   _loc16_.x = _loc7_.x;
  299.                   _loc16_.y = _loc10_.y + _loc10_.eomWidth * _loc10_.scale / 2 - _loc15_.getExplicitOrMeasuredHeight() * _loc19_ / 2;
  300.                }
  301.                else
  302.                {
  303.                   _loc19_ = _loc10_.eomHeight * _loc10_.scale / _loc15_.getExplicitOrMeasuredHeight();
  304.                   if(isNaN(_loc19_))
  305.                   {
  306.                      _loc19_ = 0;
  307.                   }
  308.                   _loc16_.scaleX = _loc16_.scaleY = _loc19_;
  309.                   _loc16_.x = _loc7_.x + _loc7_.eomHeight * _loc7_.scale / 2 - _loc15_.getExplicitOrMeasuredWidth() * _loc19_ / 2;
  310.                   _loc16_.y = _loc10_.y;
  311.                }
  312.                _loc16_.unscaledWidth = _loc15_.getExplicitOrMeasuredWidth();
  313.                _loc16_.unscaledHeight = _loc15_.getExplicitOrMeasuredHeight();
  314.             }
  315.             else
  316.             {
  317.                _loc16_.x = _loc7_.x;
  318.                _loc16_.unscaledWidth = _loc7_.eomWidth * _loc7_.scale;
  319.                _loc16_.y = _loc10_.y;
  320.                _loc16_.unscaledHeight = _loc10_.eomHeight * _loc10_.scale;
  321.                _loc16_.scaleX = _loc16_.scaleY = 1;
  322.             }
  323.             _loc5_++;
  324.          }
  325.       }
  326.    }
  327. }
  328.  
  329.