1 goog.provide('lime.GlossyButton'); 2 3 goog.require('lime.Button'); 4 goog.require('lime.Label'); 5 goog.require('lime.RoundedRect'); 6 goog.require('lime.fill.LinearGradient'); 7 8 /** 9 * Glossy button. Rounded button with some predefined style. 10 * Use lime.Button for lower level control. 11 * @param {string} txt Text shown on the button. 12 * @constructor 13 * @extends lime.Button 14 */ 15 lime.GlossyButton = function(txt) { 16 lime.Button.call(this, this.makeState_(txt), this.makeState_(txt)); 17 18 this.borderWidth = 2; 19 20 this.setColor('#62be00'); 21 22 }; 23 goog.inherits(lime.GlossyButton, lime.Button); 24 25 /** 26 * Make state for a button. 27 * @private 28 * @param {string} txt Text shown on the button. 29 * @return {lime.RoundedRect} state. 30 */ 31 lime.GlossyButton.prototype.makeState_ = function(txt) { 32 var state = new lime.RoundedRect(); 33 state.inner = new lime.RoundedRect(); 34 state.label = new lime.Label(txt).setAlign('center'). 35 setFontFamily('"Trebuchet MS"').setFontColor('#010101').setFontSize(17); 36 37 state.appendChild(state.inner); 38 state.inner.appendChild(state.label); 39 return state; 40 }; 41 42 /** 43 * Set button base color 44 * @param {*} clr New base color. 45 * @return {lime.GlossyButton} object itself. 46 */ 47 lime.GlossyButton.prototype.setColor = function(clr) { 48 clr = lime.fill.parse(clr); 49 goog.array.forEach([this.upstate, this.downstate], function(s) { 50 var c = s == this.downstate ? clr.clone().addSaturation(-.2) : clr; 51 s.setFill(c); 52 var grad = new lime.fill.LinearGradient().setDirection(0, 0, 0, 1); 53 grad.addColorStop(0, c.clone().addBrightness(.13)); 54 grad.addColorStop(.5, c.clone().addBrightness(.05)); 55 grad.addColorStop(.52, c); 56 grad.addColorStop(1, c); 57 s.inner.setFill(grad); 58 },this); 59 return this; 60 }; 61 62 /** 63 * Set button text. 64 * @param {string} txt Text. 65 * @return {lime.GlossyButton} object itself. 66 */ 67 lime.GlossyButton.prototype.setText = function(txt) { 68 this.upstate.label.setText(txt); 69 this.downstate.label.setText(txt); 70 return this; 71 }; 72 73 /** @inheritDoc */ 74 lime.GlossyButton.prototype.setSize = function(value, opt_height) { 75 if (this.upstate) { 76 this.upstate.setSize.apply(this.upstate, arguments); 77 var size = this.upstate.getSize(); 78 goog.array.forEach([this.upstate, this.downstate], function(s) { 79 s.setSize(size); 80 var innerSize = size.clone(); 81 innerSize.width -= this.borderWidth; 82 innerSize.height -= this.borderWidth; 83 s.inner.setSize(innerSize); 84 },this); 85 } 86 return this; 87 }; 88 89 /** @inheritDoc */ 90 lime.GlossyButton.prototype.getSize = function() { 91 return this.upstate.getSize(); 92 }; 93