home *** CD-ROM | disk | FTP | other *** search
/ Micromanía: 150 Juegos 2010 / 150Juegos_16.iso / Shareware / Shape Smash / shape-smash.swf / scripts / mx / managers / LayoutManager.as < prev    next >
Encoding:
Text File  |  2010-05-14  |  14.9 KB  |  436 lines

  1. package mx.managers
  2. {
  3.    import flash.display.Stage;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import mx.core.Application;
  7.    import mx.core.UIComponent;
  8.    import mx.core.mx_internal;
  9.    import mx.events.FlexEvent;
  10.    import mx.managers.layoutClasses.PriorityQueue;
  11.    
  12.    use namespace mx_internal;
  13.    
  14.    public class LayoutManager extends EventDispatcher implements ILayoutManager
  15.    {
  16.       private static var instance:LayoutManager;
  17.       
  18.       mx_internal static const VERSION:String = "2.0.1.0";
  19.       
  20.       private var invalidateClientSizeFlag:Boolean = false;
  21.       
  22.       private var invalidateSizeQueue:PriorityQueue;
  23.       
  24.       private var updateCompleteQueue:PriorityQueue;
  25.       
  26.       private var originalFrameRate:Number;
  27.       
  28.       private var _usePhasedInstantiation:Boolean = false;
  29.       
  30.       private var callLaterObject:UIComponent;
  31.       
  32.       private var invalidateClientPropertiesFlag:Boolean = false;
  33.       
  34.       private var invalidateDisplayListQueue:PriorityQueue;
  35.       
  36.       private var invalidateDisplayListFlag:Boolean = false;
  37.       
  38.       private var invalidatePropertiesFlag:Boolean = false;
  39.       
  40.       private var invalidatePropertiesQueue:PriorityQueue;
  41.       
  42.       private var invalidateSizeFlag:Boolean = false;
  43.       
  44.       private var callLaterPending:Boolean = false;
  45.       
  46.       private var targetLevel:int = 2147483647;
  47.       
  48.       public function LayoutManager()
  49.       {
  50.          updateCompleteQueue = new PriorityQueue();
  51.          invalidatePropertiesQueue = new PriorityQueue();
  52.          invalidatePropertiesFlag = false;
  53.          invalidateClientPropertiesFlag = false;
  54.          invalidateSizeQueue = new PriorityQueue();
  55.          invalidateSizeFlag = false;
  56.          invalidateClientSizeFlag = false;
  57.          invalidateDisplayListQueue = new PriorityQueue();
  58.          invalidateDisplayListFlag = false;
  59.          callLaterPending = false;
  60.          targetLevel = int.MAX_VALUE;
  61.          _usePhasedInstantiation = false;
  62.          super();
  63.       }
  64.       
  65.       public static function getInstance() : LayoutManager
  66.       {
  67.          if(!instance)
  68.          {
  69.             instance = new LayoutManager();
  70.          }
  71.          return instance;
  72.       }
  73.       
  74.       private function waitAFrame() : void
  75.       {
  76.          callLaterObject.callLater(doPhasedInstantiation);
  77.       }
  78.       
  79.       public function get usePhasedInstantiation() : Boolean
  80.       {
  81.          return _usePhasedInstantiation;
  82.       }
  83.       
  84.       public function validateClient(param1:ILayoutManagerClient, param2:Boolean = false) : void
  85.       {
  86.          var _loc3_:ILayoutManagerClient = null;
  87.          var _loc4_:int = 0;
  88.          var _loc5_:Boolean = false;
  89.          var _loc6_:int = 0;
  90.          _loc4_ = 0;
  91.          _loc5_ = false;
  92.          _loc6_ = targetLevel;
  93.          if(targetLevel == int.MAX_VALUE)
  94.          {
  95.             targetLevel = param1.nestLevel;
  96.          }
  97.          while(!_loc5_)
  98.          {
  99.             _loc5_ = true;
  100.             _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  101.             while(_loc3_)
  102.             {
  103.                _loc3_.validateProperties();
  104.                if(!_loc3_.updateCompletePendingFlag)
  105.                {
  106.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  107.                   _loc3_.updateCompletePendingFlag = true;
  108.                }
  109.                _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  110.             }
  111.             if(invalidatePropertiesQueue.isEmpty())
  112.             {
  113.                invalidatePropertiesFlag = false;
  114.                invalidateClientPropertiesFlag = false;
  115.             }
  116.             _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  117.             while(_loc3_)
  118.             {
  119.                _loc3_.validateSize();
  120.                if(!_loc3_.updateCompletePendingFlag)
  121.                {
  122.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  123.                   _loc3_.updateCompletePendingFlag = true;
  124.                }
  125.                if(invalidateClientPropertiesFlag)
  126.                {
  127.                   _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  128.                   if(_loc3_)
  129.                   {
  130.                      invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  131.                      _loc5_ = false;
  132.                      break;
  133.                   }
  134.                }
  135.                _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  136.             }
  137.             if(invalidateSizeQueue.isEmpty())
  138.             {
  139.                invalidateSizeFlag = false;
  140.                invalidateClientSizeFlag = false;
  141.             }
  142.             if(!param2)
  143.             {
  144.                _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  145.                while(_loc3_)
  146.                {
  147.                   _loc3_.validateDisplayList();
  148.                   if(!_loc3_.updateCompletePendingFlag)
  149.                   {
  150.                      updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  151.                      _loc3_.updateCompletePendingFlag = true;
  152.                   }
  153.                   if(invalidateClientPropertiesFlag)
  154.                   {
  155.                      _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  156.                      if(_loc3_)
  157.                      {
  158.                         invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  159.                         _loc5_ = false;
  160.                         break;
  161.                      }
  162.                   }
  163.                   if(invalidateClientSizeFlag)
  164.                   {
  165.                      _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  166.                      if(_loc3_)
  167.                      {
  168.                         invalidateSizeQueue.addObject(_loc3_,_loc3_.nestLevel);
  169.                         _loc5_ = false;
  170.                         break;
  171.                      }
  172.                   }
  173.                   _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  174.                }
  175.                if(invalidateDisplayListQueue.isEmpty())
  176.                {
  177.                   invalidateDisplayListFlag = false;
  178.                }
  179.             }
  180.          }
  181.          if(_loc6_ == int.MAX_VALUE)
  182.          {
  183.             targetLevel = int.MAX_VALUE;
  184.             if(!param2)
  185.             {
  186.                _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  187.                while(_loc3_)
  188.                {
  189.                   if(!_loc3_.initialized)
  190.                   {
  191.                      _loc3_.initialized = true;
  192.                   }
  193.                   _loc3_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  194.                   _loc3_.updateCompletePendingFlag = false;
  195.                   _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  196.                }
  197.             }
  198.          }
  199.       }
  200.       
  201.       private function validateDisplayList() : void
  202.       {
  203.          var _loc1_:ILayoutManagerClient = null;
  204.          _loc1_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  205.          while(_loc1_)
  206.          {
  207.             _loc1_.validateDisplayList();
  208.             if(!_loc1_.updateCompletePendingFlag)
  209.             {
  210.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  211.                _loc1_.updateCompletePendingFlag = true;
  212.             }
  213.             _loc1_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  214.          }
  215.          if(invalidateDisplayListQueue.isEmpty())
  216.          {
  217.             invalidateDisplayListFlag = false;
  218.          }
  219.       }
  220.       
  221.       private function validateSize() : void
  222.       {
  223.          var _loc1_:ILayoutManagerClient = null;
  224.          _loc1_ = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  225.          while(_loc1_)
  226.          {
  227.             _loc1_.validateSize();
  228.             if(!_loc1_.updateCompletePendingFlag)
  229.             {
  230.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  231.                _loc1_.updateCompletePendingFlag = true;
  232.             }
  233.             _loc1_ = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  234.          }
  235.          if(invalidateSizeQueue.isEmpty())
  236.          {
  237.             invalidateSizeFlag = false;
  238.          }
  239.       }
  240.       
  241.       public function invalidateProperties(param1:ILayoutManagerClient) : void
  242.       {
  243.          if(!invalidatePropertiesFlag && Boolean(Application.application.systemManager))
  244.          {
  245.             invalidatePropertiesFlag = true;
  246.             if(!callLaterPending)
  247.             {
  248.                if(!callLaterObject)
  249.                {
  250.                   callLaterObject = new UIComponent();
  251.                   callLaterObject.systemManager = Application.application.systemManager;
  252.                   callLaterObject.callLater(waitAFrame);
  253.                }
  254.                else
  255.                {
  256.                   callLaterObject.callLater(doPhasedInstantiation);
  257.                }
  258.                callLaterPending = true;
  259.             }
  260.          }
  261.          if(targetLevel <= param1.nestLevel)
  262.          {
  263.             invalidateClientPropertiesFlag = true;
  264.          }
  265.          invalidatePropertiesQueue.addObject(param1,param1.nestLevel);
  266.       }
  267.       
  268.       public function invalidateDisplayList(param1:ILayoutManagerClient) : void
  269.       {
  270.          if(!invalidateDisplayListFlag && Boolean(Application.application.systemManager))
  271.          {
  272.             invalidateDisplayListFlag = true;
  273.             if(!callLaterPending)
  274.             {
  275.                if(!callLaterObject)
  276.                {
  277.                   callLaterObject = new UIComponent();
  278.                   callLaterObject.systemManager = Application.application.systemManager;
  279.                   callLaterObject.callLater(waitAFrame);
  280.                }
  281.                else
  282.                {
  283.                   callLaterObject.callLater(doPhasedInstantiation);
  284.                }
  285.                callLaterPending = true;
  286.             }
  287.          }
  288.          invalidateDisplayListQueue.addObject(param1,param1.nestLevel);
  289.       }
  290.       
  291.       public function validateNow() : void
  292.       {
  293.          var _loc1_:int = 0;
  294.          if(!usePhasedInstantiation)
  295.          {
  296.             _loc1_ = 0;
  297.             while(callLaterPending && _loc1_++ < 100)
  298.             {
  299.                doPhasedInstantiation();
  300.             }
  301.          }
  302.       }
  303.       
  304.       public function invalidateSize(param1:ILayoutManagerClient) : void
  305.       {
  306.          if(!invalidateSizeFlag && Boolean(Application.application.systemManager))
  307.          {
  308.             invalidateSizeFlag = true;
  309.             if(!callLaterPending)
  310.             {
  311.                if(!callLaterObject)
  312.                {
  313.                   callLaterObject = new UIComponent();
  314.                   callLaterObject.systemManager = Application.application.systemManager;
  315.                   callLaterObject.callLater(waitAFrame);
  316.                }
  317.                else
  318.                {
  319.                   callLaterObject.callLater(doPhasedInstantiation);
  320.                }
  321.                callLaterPending = true;
  322.             }
  323.          }
  324.          if(targetLevel <= param1.nestLevel)
  325.          {
  326.             invalidateClientSizeFlag = true;
  327.          }
  328.          invalidateSizeQueue.addObject(param1,param1.nestLevel);
  329.       }
  330.       
  331.       public function isInvalid() : Boolean
  332.       {
  333.          return invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag;
  334.       }
  335.       
  336.       private function validateProperties() : void
  337.       {
  338.          var _loc1_:ILayoutManagerClient = null;
  339.          _loc1_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  340.          while(_loc1_)
  341.          {
  342.             _loc1_.validateProperties();
  343.             if(!_loc1_.updateCompletePendingFlag)
  344.             {
  345.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  346.                _loc1_.updateCompletePendingFlag = true;
  347.             }
  348.             _loc1_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  349.          }
  350.          if(invalidatePropertiesQueue.isEmpty())
  351.          {
  352.             invalidatePropertiesFlag = false;
  353.          }
  354.       }
  355.       
  356.       private function doPhasedInstantiation() : void
  357.       {
  358.          var _loc1_:ILayoutManagerClient = null;
  359.          if(usePhasedInstantiation)
  360.          {
  361.             if(invalidatePropertiesFlag)
  362.             {
  363.                validateProperties();
  364.                Application.application.dispatchEvent(new Event("validatePropertiesComplete"));
  365.             }
  366.             else if(invalidateSizeFlag)
  367.             {
  368.                validateSize();
  369.                Application.application.dispatchEvent(new Event("validateSizeComplete"));
  370.             }
  371.             else if(invalidateDisplayListFlag)
  372.             {
  373.                validateDisplayList();
  374.                Application.application.dispatchEvent(new Event("validateDisplayListComplete"));
  375.             }
  376.          }
  377.          else
  378.          {
  379.             if(invalidatePropertiesFlag)
  380.             {
  381.                validateProperties();
  382.             }
  383.             if(invalidateSizeFlag)
  384.             {
  385.                validateSize();
  386.             }
  387.             if(invalidateDisplayListFlag)
  388.             {
  389.                validateDisplayList();
  390.             }
  391.          }
  392.          if(invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag)
  393.          {
  394.             callLaterObject.callLater(doPhasedInstantiation);
  395.          }
  396.          else
  397.          {
  398.             usePhasedInstantiation = false;
  399.             callLaterPending = false;
  400.             _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  401.             while(_loc1_)
  402.             {
  403.                if(!_loc1_.initialized && _loc1_.processedDescriptors)
  404.                {
  405.                   _loc1_.initialized = true;
  406.                }
  407.                _loc1_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  408.                _loc1_.updateCompletePendingFlag = false;
  409.                _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  410.             }
  411.             dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  412.          }
  413.       }
  414.       
  415.       public function set usePhasedInstantiation(param1:Boolean) : void
  416.       {
  417.          var _loc2_:Stage = null;
  418.          if(_usePhasedInstantiation != param1)
  419.          {
  420.             _usePhasedInstantiation = param1;
  421.             _loc2_ = SystemManagerGlobals.topLevelSystemManagers[0].stage;
  422.             if(param1)
  423.             {
  424.                originalFrameRate = _loc2_.frameRate;
  425.                _loc2_.frameRate = 1000;
  426.             }
  427.             else
  428.             {
  429.                _loc2_.frameRate = originalFrameRate;
  430.             }
  431.          }
  432.       }
  433.    }
  434. }
  435.  
  436.