1 /**
  2  * UI button
  3  * @param {BB_Sprite} sprite
  4  * @param {Number} x
  5  * @param {Number} y
  6  * @param {Number} w
  7  * @param {Number} h
  8  * @param {Number} sx
  9  * @param {Number} sy
 10  * @constructor
 11  */
 12 function BB_Button(sprite, x, y, w, h, sx, sy) {
 13 	this.sprite = sprite;
 14 	this.set(w, h, x, y);
 15 	this.sx = sx;
 16 	this.sy = sy;
 17 	this.active = false;
 18 	this.disabled = false;
 19 }
 20 
 21 /**
 22  * Extends CP_Item
 23  */
 24 BB_Button.prototype = new CP_Item();
 25 
 26 /**
 27  * Draw the button
 28  */
 29 BB_Button.prototype.paint = function(ctx) {
 30 	var sy = this.sy;
 31 	if (!this.disabled) {
 32 		sy += this.h;
 33 		if (this.active) {
 34 			sy += this.h;
 35 		}
 36 	}
 37 	this.sprite.paint(ctx, this.x, this.y, this.w, this.h, this.sx, sy);
 38 };
 39 
 40 /**
 41  * Check button active state
 42  * @param {Number} x
 43  * @param {Number} y
 44  * @returns {Boolean}
 45  */
 46 BB_Button.prototype.check = function(x, y) {
 47 	this.active = this.x <= x
 48 		&& this.x + this.w >= x
 49 		&& this.y <= y
 50 		&& this.y + this.h >= y;
 51 	return this.active;
 52 };