Merge branch 'statusmenu'

svn path=/trunk/; revision=183
This commit is contained in:
Colin Walters
2009-02-04 18:45:38 +00:00
parent 48e578ddaa
commit b7a0a5e769
15 changed files with 4799 additions and 44 deletions

View File

@ -1,29 +1,21 @@
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
const Clutter = imports.gi.Clutter;
const Big = imports.gi.Big;
const Tweener = imports.tweener.tweener;
const DEFAULT_BUTTON_COLOR = new Clutter.Color();
DEFAULT_BUTTON_COLOR.from_pixel(0xeeddccff);
DEFAULT_BUTTON_COLOR.from_pixel(0xeeddcc66);
const DEFAULT_PRESSED_BUTTON_COLOR = new Clutter.Color();
DEFAULT_PRESSED_BUTTON_COLOR.from_pixel(0xccbbaaff);
DEFAULT_PRESSED_BUTTON_COLOR.from_pixel(0xccbbaa66);
// Time for animation making the button darker
const ANIMATION_TIME = 0.3;
const NO_OPACITY = 0;
const PARTIAL_OPACITY = 0.4 * 255;
const FULL_OPACITY = 255;
function Button(text, buttonColor, pressedButtonColor, staysPressed, minWidth, minHeight) {
this._init(text, buttonColor, pressedButtonColor, staysPressed, minWidth, minHeight);
function Button(widget, buttonColor, pressedButtonColor, staysPressed, minWidth, minHeight) {
this._init(widget, buttonColor, pressedButtonColor, staysPressed, minWidth, minHeight);
}
Button.prototype = {
_init : function(text, buttonColor, pressedButtonColor, staysPressed, minWidth, minHeight) {
_init : function(widgetOrText, buttonColor, pressedButtonColor, staysPressed, minWidth, minHeight) {
let me = this;
this._buttonColor = buttonColor
@ -47,29 +39,29 @@ Button.prototype = {
this._isBetweenPressAndRelease = false;
this._mouseIsOverButton = false;
this.button = new Clutter.Group({reactive: true});
this._background = new Clutter.Rectangle({ color: this._buttonColor});
this._pressedBackground = new Clutter.Rectangle({ color: this._pressedButtonColor, opacity: NO_OPACITY});
this._label = new Clutter.Label({ font_name: "Sans Bold 16px",
text: text});
this._label.set_position(5, 5);
let backgroundWidth = Math.max(this._label.get_width()+10, minWidth);
let backgroundHeight = Math.max(this._label.get_height()+10, minHeight);
this._background.set_width(backgroundWidth)
this._background.set_height(backgroundHeight)
this._pressedBackground.set_width(backgroundWidth)
this._pressedBackground.set_height(backgroundHeight)
this.button.add_actor(this._background);
this.button.add_actor(this._pressedBackground);
this.button.add_actor(this._label);
this.button = new Big.Box({ reactive: true,
corner_radius: 5,
padding_left: 4,
padding_right: 4,
orientation: Big.BoxOrientation.HORIZONTAL,
y_align: Big.BoxAlignment.CENTER
});
if (typeof widgetOrText == 'string') {
this._widget = new Clutter.Label({ font_name: "Sans Bold 16px",
text: widgetOrText });
} else {
this._widget = widgetOrText;
}
this.button.append(this._widget, Big.BoxPackFlags.EXPAND);
this._minWidth = minWidth;
this._minHeight = minHeight;
this.button.connect('button-press-event',
function(o, event) {
me._isBetweenPressAndRelease = true;
Tweener.addTween(me._pressedBackground,
{ time: ANIMATION_TIME,
opacity: FULL_OPACITY,
transition: "linear"
});
me.button.backgroundColor = me._pressedButtonColor;
return false;
});
this.button.connect('button-release-event',
@ -86,8 +78,7 @@ Button.prototype = {
function(o, event) {
me._mouseIsOverButton = true;
if (!me._active) {
Tweener.removeTweens(me._pressedBackground);
me._pressedBackground.set_opacity(PARTIAL_OPACITY);
me.button.backgroundColor = me._buttonColor;
}
return false;
});
@ -96,8 +87,7 @@ Button.prototype = {
me._isBetweenPressAndRelease = false;
me._mouseIsOverButton = false;
if (!me._active) {
Tweener.removeTweens(me._pressedBackground);
me._pressedBackground.set_opacity(NO_OPACITY);
me.button.backgroundColor = null;
}
return false;
});
@ -106,11 +96,10 @@ Button.prototype = {
release : function() {
if (!this._isBetweenPressAndRelease) {
this._active = false;
Tweener.removeTweens(this._pressedBackground);
if (this._mouseIsOverButton) {
this._pressedBackground.set_opacity(PARTIAL_OPACITY);
this.button.backgroundColor = this._buttonColor;
} else {
this._pressedBackground.set_opacity(NO_OPACITY);
this.button.backgroundColor = null;
}
}
}