Subversion Repositories wimsdev

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. function GroupManager(){
  3.         this.EventObject=EventObject
  4.         this.EventObject();
  5.        
  6.         this.x = this.y = null;
  7.         this.w = this.h = null;
  8.         this._objects={};
  9.        
  10. };
  11. GroupManager._NewSetLocation = function(x,y){
  12.         var byX=x-this.x;
  13.         var byY=y-this.y;
  14.         if(this._grpUX) byX=0; else x=null;
  15.         if(this._grpUY) byY=0; else y=null;
  16.         if(x!=null || y!=null) this._OldDynGMSetLocation(x,y);
  17.         if(!this._grpUX || !this._grpUY) {
  18.                 this._grpManager.changeLocationBy(byX,byY);
  19.         }
  20. }
  21. var p= dynapi.setPrototype("GroupManager","EventObject")
  22. p._setSize = function(dlyr){
  23.         var lw,lh,px,py;
  24.         if(!dlyr) return;
  25.         // store previous x,y
  26.         px=this.x; py=this.y;
  27.         // calc x,y
  28.         this.x = (this.x==null||(dlyr.x!=null && this.x>dlyr.x))? dlyr.x:this.x;
  29.         this.y = (this.y==null||(dlyr.y!=null && this.y>dlyr.y))? dlyr.y:this.y;
  30.         // calc w,h
  31.         lw=(dlyr.x+dlyr.w)-this.x; lh=(dlyr.y+dlyr.h)-this.y;
  32.         this.w = (this.w==null||(dlyr.w!=null && this.w<lw))? lw:this.w;
  33.         this.h = (this.h==null||(dlyr.h!=null && this.h<lh))? lh:this.h;
  34.         // add trailing or leading w/h
  35.         if(px>dlyr.x) this.w+=(px-dlyr.x);
  36.         if(py>dlyr.y) this.h+=(py-dlyr.y);
  37. }
  38. p._resetSize = function(){
  39.         var o,objs=this._objects;
  40.         this.x=this.y=this.w=this.h=null;
  41.         for (var i in objs){
  42.                 o=objs[i];
  43.                 this._setSize(o);
  44.         }
  45. };
  46.  
  47. p.add = function(dlyr,unlockX,unlockY){
  48.         var lw,lh;
  49.         if(!dlyr) return;
  50.         if(this._objects[dlyr.id]) return;
  51.         dlyr._grpManager=this;
  52.         dlyr._grpUX = unlockX;
  53.         dlyr._grpUY = unlockY;
  54.         dlyr._OldDynGMSetLocation = dlyr.setLocation;
  55.         dlyr.setLocation = GroupManager._NewSetLocation;
  56.         if (this.x==dlyr.x) this.w+=dlyr.w;    
  57.         this._objects[dlyr.id]=dlyr;
  58.         this._setSize(dlyr);
  59.         return dlyr;
  60. };
  61. p.changeLocationBy = function(byX,byY) {
  62.         var o,objs=this._objects;
  63.         for (var i in objs){
  64.                 o=objs[i];
  65.                 o._OldDynGMSetLocation(o.x+byX,o.y+byY,true);
  66.         }
  67.         this.x+=byX; this.y+=byY;
  68.         // Check for boundary, if any
  69.         if (this._boundary) {
  70.                 var x=this.x,y=this.y;
  71.                 var dB = this._boundary;
  72.                 var b=dB[2];
  73.                 var r=dB[1];
  74.                 var l=dB[3];
  75.                 var t=dB[0];
  76.                 var w=this.w;
  77.                 var h=this.h;
  78.                 if (this.x<l||this.w>=r) x=l;
  79.                 else if (this.x+w>r) x=r-w;
  80.                 if (this.y<t||this.h>=b) y=t;
  81.                 else if (this.y+h>b) y=b-h;
  82.                 if(this.x!=x||this.y!=y) this.setLocation(x,y);
  83.         }
  84. };
  85. p.remove = function(dlyr){
  86.         if(!dlyr) return;
  87.         dlyr=this._objects[dlyr.id];
  88.         if(dlyr) {
  89.                 this._objects = dynapi.functions.removeFromObject(this._objects,dlyr.id);
  90.                 dlyr.setLocation = dlyr._OldDynGMSetLocation;
  91.                 dlyr._OldDynGMSetLocation = null;
  92.                 dlyr._grpManager = null;
  93.                 this._resetSize();
  94.         }
  95. };
  96. p.sendMessage = function(msg,a1,a2,a3,a4,a5,a6,a7){
  97.         var o,objs=this._objects;
  98.         for (var i in objs){
  99.                 o=objs[i]
  100.                 if(o[msg]) o[msg](a1,a2,a3,a4,a5,a6,a7);
  101.                 else eval(o+'.'+msg);
  102.         }
  103. };
  104. p.setBoundary = function(t,r,b,l){
  105.         if(t==null && arguments.length==1) this._boundary = null;
  106.         else this._boundary = [t,r,b,l];
  107. };
  108. p.setLocation = function(x,y) {
  109.         var byX=x-this.x;
  110.         var byY=y-this.y;
  111.         this.changeLocationBy(byX,byY);
  112. };
  113. p.unlockX = function(b,dlyr){
  114.         if(!dlyr) {
  115.                 var objs=this._objects;
  116.                 for (var i in objs) objs[i]._grpUX=b;
  117.         }else{
  118.                 dlyr=this._objects[dlyr.id];
  119.                 if(dlyr) dlyr._grpUX=b;
  120.         }
  121.         if(!b) this._resetSize();
  122. };
  123. p.unlockY = function(b,dlyr){
  124.         var objs=this._objects;
  125.         if(!dlyr) {
  126.                 var objs=this._objects;
  127.                 for (var i in objs) objs[i]._grpUY=b;
  128.         }else{
  129.                 dlyr=this._objects[dlyr.id];
  130.                 if(dlyr) dlyr._grpUY=b;
  131.         }
  132.         if(!b) this._resetSize();
  133. };