home *** CD-ROM | disk | FTP | other *** search
- class com.argosy.ui.ScrollBar extends com.argosy.ui.baseUI
- {
- var thumb;
- var bar;
- var up_arrow;
- var down_arrow;
- var __height;
- var __width;
- var current_value;
- var last_value;
- var bounding_box;
- var dispatchEvent;
- var onEnterFrame;
- var onMouseMove;
- function ScrollBar()
- {
- super();
- this.init();
- }
- function init()
- {
- super.init();
- this.build();
- }
- function get position()
- {
- return this.findThumbPercent();
- }
- function set position(new_pos)
- {
- this.thumb._y = this.bar._y + (this.bar._height - this.thumb._height) * new_pos;
- this.thumbMoved();
- }
- function setReferenceSize(content_height, view_height)
- {
- if(content_height > view_height)
- {
- this.thumb._visible = true;
- this.bar.enabled = true;
- this.up_arrow.enabled = true;
- this.down_arrow.enabled = true;
- var _loc2_ = view_height / content_height * this.bar._height;
- this.thumb.top._y = this.thumb.top._height;
- this.thumb.middle._y = this.thumb.top._y;
- this.thumb.middle._height = _loc2_ - (this.thumb.top._height - this.thumb.bottom._height);
- this.thumb.bottom._y = this.thumb.middle._y + this.thumb.middle._height;
- if(this.thumb._y < this.bar._y)
- {
- this.thumb._y = this.bar._y;
- }
- else if(this.thumb._y > this.bar._y + this.bar._height - this.thumb._height)
- {
- this.thumb._y = this.bar._y + this.bar._height - this.thumb._height;
- }
- }
- else
- {
- this.thumb._visible = false;
- this.bar.enabled = false;
- this.up_arrow.enabled = false;
- this.down_arrow.enabled = false;
- }
- }
- function get size()
- {
- return this.__height;
- }
- function set size(new_size)
- {
- this.setSize(this.__width,new_size);
- }
- function build()
- {
- this.up_arrow.onPress = ascb.util.Proxy.create(this,this.click_up);
- this.up_arrow.onRelease = this.up_arrow.onReleaseOutside = ascb.util.Proxy.create(this,this.release_up);
- this.down_arrow.onPress = ascb.util.Proxy.create(this,this.click_down);
- this.down_arrow.onRelease = this.down_arrow.onReleaseOutside = ascb.util.Proxy.create(this,this.release_down);
- this.bar.onPress = ascb.util.Proxy.create(this,this.click_bar);
- this.thumb.onPress = ascb.util.Proxy.create(this,this.click_thumb);
- this.thumb.onRelease = this.thumb.onReleaseOutside = ascb.util.Proxy.create(this,this.release_thumb);
- this.current_value = 0;
- this.last_value = 0;
- this.layout();
- }
- function layout()
- {
- this.up_arrow._y = this.up_arrow._height / 2;
- this.down_arrow._y = this.__height - this.up_arrow._height / 2;
- this.bar._y = this.up_arrow._y + this.up_arrow._height / 2;
- this.bar.top._y = 0;
- this.bar.middle._y = this.bar.top._height;
- this.bar.middle._height = this.__height - this.up_arrow._height - this.down_arrow._height - this.bar.top._height - this.bar.bottom._height;
- this.bar.bottom._y = this.bar.middle._y + this.bar.middle._height;
- this.thumb._y = this.bar._y;
- this.thumb._x = this.bounding_box._width / 2 - this.thumb._width / 2;
- }
- function setSize(nW, nH)
- {
- super.setSize(null,nH);
- }
- function thumbMoved()
- {
- if(this.thumb._y < this.bar._y)
- {
- this.thumb._y = this.bar._y;
- }
- else if(this.thumb._y > this.bar._y + this.bar._height - this.thumb._height)
- {
- this.thumb._y = this.bar._y + this.bar._height - this.thumb._height;
- }
- this.last_value = this.current_value;
- this.current_value = this.findThumbPercent();
- if(this.current_value != this.last_value)
- {
- this.dispatchEvent({type:"onScroll",target:this,value:this.current_value});
- }
- }
- function findThumbPercent()
- {
- return Math.round((this.thumb._y - this.bar._y) / (this.bar._height - this.thumb._height) * 100) / 100;
- }
- function nudge(amount)
- {
- this.thumb._y += amount;
- this.thumbMoved();
- }
- function click_up()
- {
- this.onEnterFrame = function()
- {
- this.nudge(-5);
- this.thumbMoved();
- };
- }
- function click_down()
- {
- this.onEnterFrame = function()
- {
- this.nudge(5);
- this.thumbMoved();
- };
- }
- function release_up()
- {
- this.onEnterFrame = null;
- }
- function release_down()
- {
- this.onEnterFrame = null;
- }
- function click_bar()
- {
- this.thumb._y = this._ymouse - this.thumb._height / 2;
- this.thumbMoved();
- }
- function click_thumb()
- {
- 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);
- this.onMouseMove = function()
- {
- this.thumbMoved();
- };
- }
- function release_thumb()
- {
- this.thumb.stopDrag();
- this.onMouseMove = null;
- }
- }
-