Subversion Repositories wimsdev

Rev

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