home *** CD-ROM | disk | FTP | other *** search
/ 221.214.14.186 / 221.214.14.186.tar / 221.214.14.186 / zb / js / pz_glide.js < prev    next >
Text File  |  2003-10-07  |  8KB  |  203 lines

  1. // Glide LIB
  2.  
  3. // - added Ceil to correct a error that make one pixel jump at the end
  4. // - added Window object to handdle glide (pos&size) of windows
  5.  
  6. function winInit( x, y, w, h ) {
  7.     this.obj="window"
  8.     if (w!=null && h!=null) this.WHsize(w,h);
  9.     if (x!=null && y!=null) this.XYmove(x,y);
  10. }
  11.  
  12. //------------ ALL
  13.  
  14. function winGlideTo() {
  15.  
  16. if ( arguments.length == 6 ) this.XYglideTo(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]);              //(startSpeedXY,endSpeedXY,endx,endy,angleinc,speed)
  17. if ( arguments.length == 7 ) this.XYglideTo(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]); //(startSpeedXY,endSpeedXY,endx,endy,angleinc,speed, fnXY)
  18.  
  19. if ( arguments.length == 10 ) this.XYWHglideTo(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9],arguments[10]);                         //(startSpeedXY,endSpeedXY,endx,endy, startSpeedWH,endSpeedWH,endw,endh,angleinc,speed)
  20. if ( arguments.length == 11 ) this.XYWHglideTo(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9],arguments[10],arguments[11]);            //(startSpeedXY,endSpeedXY,endx,endy, startSpeedWH,endSpeedWH,endw,endh,angleinc,speed,fn)
  21.  
  22. }
  23.  
  24. function winXYWHglideTo( startSpeedXY,endSpeedXY,endx,endy, startSpeedWH,endSpeedWH,endw,endh,angleinc,speed,fn) {
  25.     this.XYglideTo(startSpeedXY,endSpeedXY,endx,endy,angleinc,speed)
  26.     this.WHglideTo(startSpeedWH,endSpeedWH,endw,endh,angleinc,speed,fn)
  27. }
  28.  
  29. function winXYmove(x,y) {
  30.     this.moveTo( Math.ceil( x ), Math.ceil( y ) )
  31.     this.x = x;
  32.     this.y = y;
  33. }
  34.  
  35. function winWHsize(w,h) {
  36.     this.resizeTo( Math.ceil( w ), Math.ceil( h ) )
  37.     this.w = w;
  38.     this.h = h;
  39. }
  40.  
  41. //------------ POS
  42.  
  43. function winXYGlideTo(startSpeed,endSpeed,endx,endy,angleinc,speed,fn) {
  44.     if (endx==null) endx = this.x
  45.     if (endy==null) endy = this.y
  46.     var distx = endx-this.x
  47.     var disty = endy-this.y
  48.     this.XYglideStart(startSpeed,endSpeed,endx,endy,distx,disty,angleinc,speed,fn)
  49. }
  50.  
  51. function winXYGlideStart(startSpeed,endSpeed,endx,endy,distx,disty,angleinc,speed,fn) {
  52.     if (this.XYglideActive) return
  53.     if (endx==this.x) var slantangle = 90
  54.     else if (endy==this.y) var slantangle = 0
  55.     else var slantangle = Math.abs(Math.atan(disty/distx)*180/Math.PI)
  56.     if (endx>=this.x) {
  57.         if (endy>this.y) slantangle = 360-slantangle
  58.     }
  59.     else {
  60.         if (endy>this.y) slantangle = 180+slantangle
  61.         else slantangle = 180-slantangle
  62.     }
  63.     slantangle *= Math.PI/180
  64.     var amplitude = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))
  65.     if (!fn) fn = null
  66.     this.XYglideActive = true
  67.     if (startSpeed == "fast") {
  68.         if (endSpeed=="fast") this.XYglide(1,amplitude/2,0,90,this.x,this.y,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  69.         else this.XYglide(0,amplitude,0,90,this.x,this.y,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  70.     }
  71.     else {
  72.         if (endSpeed=="fast") this.XYglide(0,amplitude,-90,0,this.x+distx,this.y+disty,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  73.         else this.XYglide(0,amplitude/2,-90,90,this.x+distx/2,this.y+disty/2,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  74.     }
  75. }
  76.  
  77. function winXYGlide(type,amplitude,angle,endangle,centerX,centerY,slantangle,endx,endy,distx,disty,angleinc,speed,fn) {
  78.     if (angle < endangle && this.XYglideActive) {
  79.         angle += angleinc
  80.         var u = amplitude*Math.sin(angle*Math.PI/180)
  81.         var x = centerX + u*Math.cos(slantangle)
  82.         var y = centerY - u*Math.sin(slantangle)
  83.         this.XYmove( x, y )
  84.         this.XYonGlide()
  85.         if (this.XYglideActive) setTimeout(this.obj+'.XYglide('+type+','+amplitude+','+angle+','+endangle+','+centerX+','+centerY+','+slantangle+','+endx+','+endy+','+distx+','+disty+','+angleinc+','+speed+',\''+fn+'\')',speed)
  86.         else this.XYonGlideEnd()
  87.     }
  88.     else {
  89.         if (type==1) this.XYglide(0,amplitude,-90,0,this.x+distx/2,this.y+disty/2,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  90.         else {
  91.             this.XYglideActive = false
  92.             this.XYmove(endx,endy)
  93.             this.XYonGlide()
  94.             this.XYonGlideEnd()
  95.             eval(fn)
  96.         }
  97.     }
  98. }
  99.  
  100. //------------ SIZE
  101.  
  102. function winWHGlideTo(startSpeed,endSpeed,endx,endy,angleinc,speed,fn) {
  103.     if (endx==null) endx = this.w
  104.     if (endy==null) endy = this.h
  105.     var distx = endx-this.w
  106.     var disty = endy-this.h
  107.     this.WHglideStart(startSpeed,endSpeed,endx,endy,distx,disty,angleinc,speed,fn)
  108. }
  109.  
  110. function winWHGlideStart(startSpeed,endSpeed,endx,endy,distx,disty,angleinc,speed,fn) {
  111.     if (this.WHglideActive) return
  112.     if (endx==this.w) var slantangle = 90
  113.     else if (endy==this.h) var slantangle = 0
  114.     else var slantangle = Math.abs(Math.atan(disty/distx)*180/Math.PI)
  115.     if (endx>=this.w) {
  116.         if (endy>this.h) slantangle = 360-slantangle
  117.     }
  118.     else {
  119.         if (endy>this.h) slantangle = 180+slantangle
  120.         else slantangle = 180-slantangle
  121.     }
  122.     slantangle *= Math.PI/180
  123.     var amplitude = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))
  124.     if (!fn) fn = null
  125.     this.WHglideActive = true
  126.     if (startSpeed == "fast") {
  127.         if (endSpeed=="fast") this.WHglide(1,amplitude/2,0,90,this.w,this.h,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  128.         else               this.WHglide(0,amplitude,0,90,this.w,this.h,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  129.     }
  130.     else {
  131.         if (endSpeed=="fast") this.WHglide(0,amplitude,-90,0,this.w+distx,this.h+disty,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  132.         else                   this.WHglide(0,amplitude/2,-90,90,this.w+distx/2,this.h+disty/2,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  133.     }
  134. }
  135.  
  136. function winWHGlide(type,amplitude,angle,endangle,centerX,centerY,slantangle,endx,endy,distx,disty,angleinc,speed,fn, wfn) {
  137.     if ( wfn==null && angle < endangle && this.WHglideActive) {
  138.         angle += angleinc
  139.         var u = amplitude*Math.sin(angle*Math.PI/180)
  140.         var w = centerX + u*Math.cos(slantangle)
  141.         var h = centerY - u*Math.sin(slantangle)
  142.         this.WHsize( w, h )
  143.         this.WHonGlide()
  144.         if (this.WHglideActive) setTimeout(this.obj+'.WHglide('+type+','+amplitude+','+angle+','+endangle+','+centerX+','+centerY+','+slantangle+','+endx+','+endy+','+distx+','+disty+','+angleinc+','+speed+',\''+fn+'\')',speed)
  145.         else this.WHonGlideEnd()
  146.     }
  147.     else {
  148.         if (type==1) this.WHglide(0,amplitude,-90,0,this.w+distx/2,this.h+disty/2,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  149.         else {
  150.             this.WHglideActive = false
  151.             this.WHsize(endx,endy)
  152.             this.WHonGlide()
  153.             this.WHonGlideEnd()
  154.             if (this.XYglideActive == false) eval(fn)
  155.             else                      setTimeout(this.obj+'.WHglide('+type+','+amplitude+','+angle+','+endangle+','+centerX+','+centerY+','+slantangle+','+endx+','+endy+','+distx+','+disty+','+angleinc+','+speed+',\''+fn+'\',\''+1+'\')',speed)
  156.         }
  157.     }
  158. }
  159.  
  160. // For windows
  161.  
  162. window.WinInit      = winInit
  163.  
  164. window.glideTo      = winGlideTo
  165. window.XYWHglideTo  = winXYWHglideTo
  166.  
  167. window.move         = winXYmove
  168. window.XYmove       = winXYmove
  169. window.XYglideTo    = winXYGlideTo
  170. window.XYglideStart = winXYGlideStart
  171. window.XYglide      = winXYGlide
  172. window.XYonGlide    = new Function()
  173. window.XYonGlideEnd = new Function()
  174.  
  175. window.size         = winWHsize
  176. window.WHsize       = winWHsize
  177. window.WHglideTo    = winWHGlideTo
  178. window.WHglideStart = winWHGlideStart
  179. window.WHglide      = winWHGlide
  180. window.WHonGlide    = new Function()
  181. window.WHonGlideEnd = new Function()
  182.  
  183. // For DynLayers
  184.  
  185. DynLayer.prototype.glideTo      = winGlideTo;
  186. DynLayer.prototype.XYWHglideTo  = winXYWHglideTo
  187.  
  188.  
  189. DynLayer.prototype.XYmove       = winXYmove
  190. DynLayer.prototype.XYglideTo    = winXYGlideTo
  191. DynLayer.prototype.XYglideStart = winXYGlideStart
  192. DynLayer.prototype.XYglide      = winXYGlide
  193. DynLayer.prototype.XYonGlide    = new Function()
  194. DynLayer.prototype.XYonGlideEnd = new Function()
  195.  
  196. DynLayer.prototype.WHsize       = winWHsize
  197. DynLayer.prototype.WHglideTo    = winWHGlideTo
  198. DynLayer.prototype.WHglideStart = winWHGlideStart
  199. DynLayer.prototype.WHglide      = winWHGlide
  200. DynLayer.prototype.WHonGlide    = new Function()
  201. DynLayer.prototype.WHonGlideEnd = new Function()
  202.  
  203.