home *** CD-ROM | disk | FTP | other *** search
/ Practice Anatomy Lab / PAL.ISO / pc / PAL.swf / scripts / __Packages / com / argosy / ui / ScrollBar.as < prev    next >
Encoding:
Text File  |  2007-03-19  |  5.1 KB  |  170 lines

  1. class com.argosy.ui.ScrollBar extends com.argosy.ui.baseUI
  2. {
  3.    var thumb;
  4.    var bar;
  5.    var up_arrow;
  6.    var down_arrow;
  7.    var __height;
  8.    var __width;
  9.    var current_value;
  10.    var last_value;
  11.    var bounding_box;
  12.    var dispatchEvent;
  13.    var onEnterFrame;
  14.    var onMouseMove;
  15.    function ScrollBar()
  16.    {
  17.       super();
  18.       this.init();
  19.    }
  20.    function init()
  21.    {
  22.       super.init();
  23.       this.build();
  24.    }
  25.    function get position()
  26.    {
  27.       return this.findThumbPercent();
  28.    }
  29.    function set position(new_pos)
  30.    {
  31.       this.thumb._y = this.bar._y + (this.bar._height - this.thumb._height) * new_pos;
  32.       this.thumbMoved();
  33.    }
  34.    function setReferenceSize(content_height, view_height)
  35.    {
  36.       if(content_height > view_height)
  37.       {
  38.          this.thumb._visible = true;
  39.          this.bar.enabled = true;
  40.          this.up_arrow.enabled = true;
  41.          this.down_arrow.enabled = true;
  42.          var _loc2_ = view_height / content_height * this.bar._height;
  43.          this.thumb.top._y = this.thumb.top._height;
  44.          this.thumb.middle._y = this.thumb.top._y;
  45.          this.thumb.middle._height = _loc2_ - (this.thumb.top._height - this.thumb.bottom._height);
  46.          this.thumb.bottom._y = this.thumb.middle._y + this.thumb.middle._height;
  47.          if(this.thumb._y < this.bar._y)
  48.          {
  49.             this.thumb._y = this.bar._y;
  50.          }
  51.          else if(this.thumb._y > this.bar._y + this.bar._height - this.thumb._height)
  52.          {
  53.             this.thumb._y = this.bar._y + this.bar._height - this.thumb._height;
  54.          }
  55.       }
  56.       else
  57.       {
  58.          this.thumb._visible = false;
  59.          this.bar.enabled = false;
  60.          this.up_arrow.enabled = false;
  61.          this.down_arrow.enabled = false;
  62.       }
  63.    }
  64.    function get size()
  65.    {
  66.       return this.__height;
  67.    }
  68.    function set size(new_size)
  69.    {
  70.       this.setSize(this.__width,new_size);
  71.    }
  72.    function build()
  73.    {
  74.       this.up_arrow.onPress = ascb.util.Proxy.create(this,this.click_up);
  75.       this.up_arrow.onRelease = this.up_arrow.onReleaseOutside = ascb.util.Proxy.create(this,this.release_up);
  76.       this.down_arrow.onPress = ascb.util.Proxy.create(this,this.click_down);
  77.       this.down_arrow.onRelease = this.down_arrow.onReleaseOutside = ascb.util.Proxy.create(this,this.release_down);
  78.       this.bar.onPress = ascb.util.Proxy.create(this,this.click_bar);
  79.       this.thumb.onPress = ascb.util.Proxy.create(this,this.click_thumb);
  80.       this.thumb.onRelease = this.thumb.onReleaseOutside = ascb.util.Proxy.create(this,this.release_thumb);
  81.       this.current_value = 0;
  82.       this.last_value = 0;
  83.       this.layout();
  84.    }
  85.    function layout()
  86.    {
  87.       this.up_arrow._y = this.up_arrow._height / 2;
  88.       this.down_arrow._y = this.__height - this.up_arrow._height / 2;
  89.       this.bar._y = this.up_arrow._y + this.up_arrow._height / 2;
  90.       this.bar.top._y = 0;
  91.       this.bar.middle._y = this.bar.top._height;
  92.       this.bar.middle._height = this.__height - this.up_arrow._height - this.down_arrow._height - this.bar.top._height - this.bar.bottom._height;
  93.       this.bar.bottom._y = this.bar.middle._y + this.bar.middle._height;
  94.       this.thumb._y = this.bar._y;
  95.       this.thumb._x = this.bounding_box._width / 2 - this.thumb._width / 2;
  96.    }
  97.    function setSize(nW, nH)
  98.    {
  99.       super.setSize(null,nH);
  100.    }
  101.    function thumbMoved()
  102.    {
  103.       if(this.thumb._y < this.bar._y)
  104.       {
  105.          this.thumb._y = this.bar._y;
  106.       }
  107.       else if(this.thumb._y > this.bar._y + this.bar._height - this.thumb._height)
  108.       {
  109.          this.thumb._y = this.bar._y + this.bar._height - this.thumb._height;
  110.       }
  111.       this.last_value = this.current_value;
  112.       this.current_value = this.findThumbPercent();
  113.       if(this.current_value != this.last_value)
  114.       {
  115.          this.dispatchEvent({type:"onScroll",target:this,value:this.current_value});
  116.       }
  117.    }
  118.    function findThumbPercent()
  119.    {
  120.       return Math.round((this.thumb._y - this.bar._y) / (this.bar._height - this.thumb._height) * 100) / 100;
  121.    }
  122.    function nudge(amount)
  123.    {
  124.       this.thumb._y += amount;
  125.       this.thumbMoved();
  126.    }
  127.    function click_up()
  128.    {
  129.       this.onEnterFrame = function()
  130.       {
  131.          this.nudge(-5);
  132.          this.thumbMoved();
  133.       };
  134.    }
  135.    function click_down()
  136.    {
  137.       this.onEnterFrame = function()
  138.       {
  139.          this.nudge(5);
  140.          this.thumbMoved();
  141.       };
  142.    }
  143.    function release_up()
  144.    {
  145.       this.onEnterFrame = null;
  146.    }
  147.    function release_down()
  148.    {
  149.       this.onEnterFrame = null;
  150.    }
  151.    function click_bar()
  152.    {
  153.       this.thumb._y = this._ymouse - this.thumb._height / 2;
  154.       this.thumbMoved();
  155.    }
  156.    function click_thumb()
  157.    {
  158.       this.thumb.startDrag(false,this.thumb._x,this.up_arrow._y + this.up_arrow._height / 2,this.thumb._x,this.__height - this.down_arrow._height - this.thumb._height);
  159.       this.onMouseMove = function()
  160.       {
  161.          this.thumbMoved();
  162.       };
  163.    }
  164.    function release_thumb()
  165.    {
  166.       this.thumb.stopDrag();
  167.       this.onMouseMove = null;
  168.    }
  169. }
  170.