Switch all JavaScript variable names to firstWordLowerCase style to agree with the Style Guide.
svn path=/trunk/; revision=57
This commit is contained in:
parent
372021d05b
commit
5b31ce3415
@ -18,54 +18,54 @@ const PARTIAL_OPACITY = 0.4 * 255;
|
|||||||
|
|
||||||
const FULL_OPACITY = 255;
|
const FULL_OPACITY = 255;
|
||||||
|
|
||||||
function Button(text, button_color, pressed_button_color, min_width, min_height) {
|
function Button(text, buttonColor, pressedButtonColor, minWidth, minHeight) {
|
||||||
this._init(text, button_color, pressed_button_color, min_width, min_height);
|
this._init(text, buttonColor, pressedButtonColor, minWidth, minHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
Button.prototype = {
|
Button.prototype = {
|
||||||
_init : function(text, button_color, pressed_button_color, stays_pressed, min_width, min_height) {
|
_init : function(text, buttonColor, pressedButtonColor, staysPressed, minWidth, minHeight) {
|
||||||
|
|
||||||
this._button_color = button_color
|
this._buttonColor = buttonColor
|
||||||
if (button_color == null)
|
if (buttonColor == null)
|
||||||
this._button_color = DEFAULT_BUTTON_COLOR;
|
this._buttonColor = DEFAULT_BUTTON_COLOR;
|
||||||
|
|
||||||
this._pressed_button_color = pressed_button_color
|
this._pressedButtonColor = pressedButtonColor
|
||||||
if (pressed_button_color == null)
|
if (pressedButtonColor == null)
|
||||||
this._pressed_button_color = DEFAULT_PRESSED_BUTTON_COLOR;
|
this._pressedButtonColor = DEFAULT_PRESSED_BUTTON_COLOR;
|
||||||
|
|
||||||
if (stays_pressed == null)
|
if (staysPressed == null)
|
||||||
stays_pressed = false
|
staysPressed = false
|
||||||
if (min_width == null)
|
if (minWidth == null)
|
||||||
min_width = 0;
|
minWidth = 0;
|
||||||
if (min_height == null)
|
if (minHeight == null)
|
||||||
min_height = 0;
|
minHeight = 0;
|
||||||
|
|
||||||
// if stays_pressed is true, this.active will be true past the first release of a button, untill a subsequent one (the button
|
// if staysPressed is true, this.active will be true past the first release of a button, untill a subsequent one (the button
|
||||||
// is unpressed) or untill release() is called explicitly
|
// is unpressed) or untill release() is called explicitly
|
||||||
this._active = false;
|
this._active = false;
|
||||||
this._is_between_press_and_release = false;
|
this._isBetweenPressAndRelease = false;
|
||||||
this._mouse_is_over_button = false;
|
this._mouseIsOverButton = false;
|
||||||
|
|
||||||
this.button = new Clutter.Group({reactive: true});
|
this.button = new Clutter.Group({reactive: true});
|
||||||
this._background = new Clutter.Rectangle({ color: this._button_color});
|
this._background = new Clutter.Rectangle({ color: this._buttonColor});
|
||||||
this._pressed_background = new Clutter.Rectangle({ color: this._pressed_button_color, opacity: NO_OPACITY});
|
this._pressedBackground = new Clutter.Rectangle({ color: this._pressedButtonColor, opacity: NO_OPACITY});
|
||||||
this._label = new Clutter.Label({ font_name: "Sans Bold 16px",
|
this._label = new Clutter.Label({ font_name: "Sans Bold 16px",
|
||||||
text: text});
|
text: text});
|
||||||
this._label.set_position(5, 5);
|
this._label.set_position(5, 5);
|
||||||
let background_width = Math.max(this._label.get_width()+10, min_width);
|
let backgroundWidth = Math.max(this._label.get_width()+10, minWidth);
|
||||||
let background_height = Math.max(this._label.get_height()+10, min_height);
|
let backgroundHeight = Math.max(this._label.get_height()+10, minHeight);
|
||||||
this._background.set_width(background_width)
|
this._background.set_width(backgroundWidth)
|
||||||
this._background.set_height(background_height)
|
this._background.set_height(backgroundHeight)
|
||||||
this._pressed_background.set_width(background_width)
|
this._pressedBackground.set_width(backgroundWidth)
|
||||||
this._pressed_background.set_height(background_height)
|
this._pressedBackground.set_height(backgroundHeight)
|
||||||
this.button.add_actor(this._background);
|
this.button.add_actor(this._background);
|
||||||
this.button.add_actor(this._pressed_background);
|
this.button.add_actor(this._pressedBackground);
|
||||||
this.button.add_actor(this._label);
|
this.button.add_actor(this._label);
|
||||||
let me = this;
|
let me = this;
|
||||||
this.button.connect('button-press-event',
|
this.button.connect('button-press-event',
|
||||||
function(o, event) {
|
function(o, event) {
|
||||||
me._is_between_press_and_release = true;
|
me._isBetweenPressAndRelease = true;
|
||||||
Tweener.addTween(me._pressed_background,
|
Tweener.addTween(me._pressedBackground,
|
||||||
{ time: ANIMATION_TIME,
|
{ time: ANIMATION_TIME,
|
||||||
opacity: FULL_OPACITY,
|
opacity: FULL_OPACITY,
|
||||||
transition: "linear"
|
transition: "linear"
|
||||||
@ -74,8 +74,8 @@ Button.prototype = {
|
|||||||
});
|
});
|
||||||
this.button.connect('button-release-event',
|
this.button.connect('button-release-event',
|
||||||
function(o, event) {
|
function(o, event) {
|
||||||
me._is_between_press_and_release = false;
|
me._isBetweenPressAndRelease = false;
|
||||||
if (!stays_pressed || me._active) {
|
if (!staysPressed || me._active) {
|
||||||
me.release();
|
me.release();
|
||||||
} else {
|
} else {
|
||||||
me._active = true;
|
me._active = true;
|
||||||
@ -84,33 +84,33 @@ Button.prototype = {
|
|||||||
});
|
});
|
||||||
this.button.connect('enter-event',
|
this.button.connect('enter-event',
|
||||||
function(o, event) {
|
function(o, event) {
|
||||||
me._mouse_is_over_button = true;
|
me._mouseIsOverButton = true;
|
||||||
if (!me._active) {
|
if (!me._active) {
|
||||||
Tweener.removeTweens(me._pressed_background);
|
Tweener.removeTweens(me._pressedBackground);
|
||||||
me._pressed_background.set_opacity(PARTIAL_OPACITY);
|
me._pressedBackground.set_opacity(PARTIAL_OPACITY);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
this.button.connect('leave-event',
|
this.button.connect('leave-event',
|
||||||
function(o, event) {
|
function(o, event) {
|
||||||
me._is_between_press_and_release = false;
|
me._isBetweenPressAndRelease = false;
|
||||||
me._mouse_is_over_button = false;
|
me._mouseIsOverButton = false;
|
||||||
if (!me._active) {
|
if (!me._active) {
|
||||||
Tweener.removeTweens(me._pressed_background);
|
Tweener.removeTweens(me._pressedBackground);
|
||||||
me._pressed_background.set_opacity(NO_OPACITY);
|
me._pressedBackground.set_opacity(NO_OPACITY);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
release : function() {
|
release : function() {
|
||||||
if (!this._is_between_press_and_release) {
|
if (!this._isBetweenPressAndRelease) {
|
||||||
this._active = false;
|
this._active = false;
|
||||||
Tweener.removeTweens(this._pressed_background);
|
Tweener.removeTweens(this._pressedBackground);
|
||||||
if (this._mouse_is_over_button) {
|
if (this._mouseIsOverButton) {
|
||||||
this._pressed_background.set_opacity(PARTIAL_OPACITY);
|
this._pressedBackground.set_opacity(PARTIAL_OPACITY);
|
||||||
} else {
|
} else {
|
||||||
this._pressed_background.set_opacity(NO_OPACITY);
|
this._pressedBackground.set_opacity(NO_OPACITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ const WINDOW_OPACITY = 0.9 * 255;
|
|||||||
// counts we fall back to an algorithm. We need more schemes here
|
// counts we fall back to an algorithm. We need more schemes here
|
||||||
// unless we have a really good algorithm.
|
// unless we have a really good algorithm.
|
||||||
//
|
//
|
||||||
// Each triplet is [x_center, y_center, scale] where the scale
|
// Each triplet is [xCenter, yCenter, scale] where the scale
|
||||||
// is relative to the width of the desktop.
|
// is relative to the width of the desktop.
|
||||||
const POSITIONS = {
|
const POSITIONS = {
|
||||||
1: [[0.5, 0.5, 0.8]],
|
1: [[0.5, 0.5, 0.8]],
|
||||||
@ -55,7 +55,7 @@ Overlay.prototype = {
|
|||||||
this._group.hide();
|
this._group.hide();
|
||||||
global.overlay_group.add_actor(this._group);
|
global.overlay_group.add_actor(this._group);
|
||||||
|
|
||||||
this._window_clones = []
|
this._windowClones = []
|
||||||
},
|
},
|
||||||
|
|
||||||
show : function() {
|
show : function() {
|
||||||
@ -64,52 +64,52 @@ Overlay.prototype = {
|
|||||||
|
|
||||||
let global = Shell.global_get();
|
let global = Shell.global_get();
|
||||||
let windows = global.get_windows();
|
let windows = global.get_windows();
|
||||||
let desktop_window = null;
|
let desktopWindow = null;
|
||||||
|
|
||||||
let screen_width = global.screen_width
|
let screenWidth = global.screen_width
|
||||||
let screen_height = global.screen_height
|
let screenHeight = global.screen_height
|
||||||
|
|
||||||
for (let i = 0; i < windows.length; i++)
|
for (let i = 0; i < windows.length; i++)
|
||||||
if (windows[i].get_window_type() == Meta.WindowType.DESKTOP)
|
if (windows[i].get_window_type() == Meta.WindowType.DESKTOP)
|
||||||
desktop_window = windows[i];
|
desktopWindow = windows[i];
|
||||||
|
|
||||||
// The desktop windows are shown on top of a scaled down version of the
|
// The desktop windows are shown on top of a scaled down version of the
|
||||||
// desktop. This is positioned at the right side of the screen
|
// desktop. This is positioned at the right side of the screen
|
||||||
this._desktop_width = screen_width * DESKTOP_SCALE;
|
this._desktopWidth = screenWidth * DESKTOP_SCALE;
|
||||||
this._desktop_height = screen_height * DESKTOP_SCALE;
|
this._desktopHeight = screenHeight * DESKTOP_SCALE;
|
||||||
this._desktop_x = screen_width - this._desktop_width - 10;
|
this._desktopX = screenWidth - this._desktopWidth - 10;
|
||||||
this._desktop_y = Panel.PANEL_HEIGHT + (screen_height - this._desktop_height - Panel.PANEL_HEIGHT) / 2;
|
this._desktopY = Panel.PANEL_HEIGHT + (screenHeight - this._desktopHeight - Panel.PANEL_HEIGHT) / 2;
|
||||||
|
|
||||||
// If a file manager is displaying desktop icons, there will be a desktop window.
|
// If a file manager is displaying desktop icons, there will be a desktop window.
|
||||||
// This window will have the size of the whole desktop. When such window is not present
|
// This window will have the size of the whole desktop. When such window is not present
|
||||||
// (e.g. when the preference for showing icons on the desktop is disabled by the user
|
// (e.g. when the preference for showing icons on the desktop is disabled by the user
|
||||||
// or we are running inside a Xephyr window), we should create a desktop rectangle
|
// or we are running inside a Xephyr window), we should create a desktop rectangle
|
||||||
// to serve as the background.
|
// to serve as the background.
|
||||||
if (desktop_window)
|
if (desktopWindow)
|
||||||
this._createDesktopClone(desktop_window);
|
this._createDesktopClone(desktopWindow);
|
||||||
else
|
else
|
||||||
this._createDesktopRectangle();
|
this._createDesktopRectangle();
|
||||||
|
|
||||||
// Count the total number of windows so we know what layout scheme to use
|
// Count the total number of windows so we know what layout scheme to use
|
||||||
let n_windows = 0;
|
let numberOfWindows = 0;
|
||||||
for (let i = 0; i < windows.length; i++) {
|
for (let i = 0; i < windows.length; i++) {
|
||||||
let w = windows[i];
|
let w = windows[i];
|
||||||
if (w == desktop_window || w.is_override_redirect())
|
if (w == desktopWindow || w.is_override_redirect())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
n_windows++;
|
numberOfWindows++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now create actors for all the desktop windows. Do it in
|
// Now create actors for all the desktop windows. Do it in
|
||||||
// reverse order so that the active actor ends up on top
|
// reverse order so that the active actor ends up on top
|
||||||
let window_index = 0;
|
let windowIndex = 0;
|
||||||
for (let i = windows.length - 1; i >= 0; i--) {
|
for (let i = windows.length - 1; i >= 0; i--) {
|
||||||
let w = windows[i];
|
let w = windows[i];
|
||||||
if (w == desktop_window || w.is_override_redirect())
|
if (w == desktopWindow || w.is_override_redirect())
|
||||||
continue;
|
continue;
|
||||||
this._createWindowClone(w, n_windows - window_index - 1, n_windows);
|
this._createWindowClone(w, numberOfWindows - windowIndex - 1, numberOfWindows);
|
||||||
|
|
||||||
window_index++;
|
windowIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All the the actors in the window group are completely obscured,
|
// All the the actors in the window group are completely obscured,
|
||||||
@ -132,11 +132,11 @@ Overlay.prototype = {
|
|||||||
global.window_group.show()
|
global.window_group.show()
|
||||||
this._group.hide();
|
this._group.hide();
|
||||||
|
|
||||||
for (let i = 0; i < this._window_clones.length; i++) {
|
for (let i = 0; i < this._windowClones.length; i++) {
|
||||||
this._window_clones[i].destroy();
|
this._windowClones[i].destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._window_clones = [];
|
this._windowClones = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -156,22 +156,22 @@ Overlay.prototype = {
|
|||||||
// up identically.
|
// up identically.
|
||||||
// We are also using (0,0) coordinates in both cases which makes the background
|
// We are also using (0,0) coordinates in both cases which makes the background
|
||||||
// window animate out from behind the panel.
|
// window animate out from behind the panel.
|
||||||
let desktop_rectangle = new Clutter.Rectangle({ color: global.stage.color,
|
let desktopRectangle = new Clutter.Rectangle({ color: global.stage.color,
|
||||||
reactive: true,
|
reactive: true,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: global.screen_width,
|
width: global.screen_width,
|
||||||
height: global.screen_height });
|
height: global.screen_height });
|
||||||
this._addDesktop(desktop_rectangle);
|
this._addDesktop(desktopRectangle);
|
||||||
},
|
},
|
||||||
|
|
||||||
_addDesktop : function(desktop) {
|
_addDesktop : function(desktop) {
|
||||||
this._window_clones.push(desktop);
|
this._windowClones.push(desktop);
|
||||||
this._group.add_actor(desktop);
|
this._group.add_actor(desktop);
|
||||||
|
|
||||||
Tweener.addTween(desktop,
|
Tweener.addTween(desktop,
|
||||||
{ x: this._desktop_x,
|
{ x: this._desktopX,
|
||||||
y: this._desktop_y,
|
y: this._desktopY,
|
||||||
scale_x: DESKTOP_SCALE,
|
scale_x: DESKTOP_SCALE,
|
||||||
scale_y: DESKTOP_SCALE,
|
scale_y: DESKTOP_SCALE,
|
||||||
time: ANIMATION_TIME,
|
time: ANIMATION_TIME,
|
||||||
@ -185,26 +185,26 @@ Overlay.prototype = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// window_index == 0 => top in stacking order
|
// windowIndex == 0 => top in stacking order
|
||||||
_computeWindowPosition : function(window_index, n_windows) {
|
_computeWindowPosition : function(windowIndex, numberOfWindows) {
|
||||||
if (n_windows in POSITIONS)
|
if (numberOfWindows in POSITIONS)
|
||||||
return POSITIONS[n_windows][window_index];
|
return POSITIONS[numberOfWindows][windowIndex];
|
||||||
|
|
||||||
// If we don't have a predefined scheme for this window count, overlap the windows
|
// If we don't have a predefined scheme for this window count, overlap the windows
|
||||||
// along the diagonal of the desktop (improve this!)
|
// along the diagonal of the desktop (improve this!)
|
||||||
let fraction = Math.sqrt(1/n_windows);
|
let fraction = Math.sqrt(1/numberOfWindows);
|
||||||
|
|
||||||
// The top window goes at the lower right - this is different from the
|
// The top window goes at the lower right - this is different from the
|
||||||
// fixed position schemes where the windows are in "reading order"
|
// fixed position schemes where the windows are in "reading order"
|
||||||
// and the top window goes at the upper left.
|
// and the top window goes at the upper left.
|
||||||
let pos = (n_windows - window_index - 1) / (n_windows - 1);
|
let pos = (numberOfWindows - windowIndex - 1) / (numberOfWindows - 1);
|
||||||
let x_center = (fraction / 2) + (1 - fraction) * pos;
|
let xCenter = (fraction / 2) + (1 - fraction) * pos;
|
||||||
let y_center = x_center;
|
let yCenter = xCenter;
|
||||||
|
|
||||||
return [x_center, y_center, fraction];
|
return [xCenter, yCenter, fraction];
|
||||||
},
|
},
|
||||||
|
|
||||||
_createWindowClone : function(w, window_index, n_windows) {
|
_createWindowClone : function(w, windowIndex, numberOfWindows) {
|
||||||
// We show the window using "clones" of the texture .. separate
|
// We show the window using "clones" of the texture .. separate
|
||||||
// actors that mirror the original actors for the window. For
|
// actors that mirror the original actors for the window. For
|
||||||
// animation purposes, it may be better to actually move the
|
// animation purposes, it may be better to actually move the
|
||||||
@ -215,28 +215,28 @@ Overlay.prototype = {
|
|||||||
x: w.x,
|
x: w.x,
|
||||||
y: w.y });
|
y: w.y });
|
||||||
|
|
||||||
let [x_center, y_center, fraction] = this._computeWindowPosition(window_index, n_windows);
|
let [xCenter, yCenter, fraction] = this._computeWindowPosition(windowIndex, numberOfWindows);
|
||||||
|
|
||||||
let desired_size = this._desktop_width * fraction;
|
let desiredSize = this._desktopWidth * fraction;
|
||||||
|
|
||||||
x_center = this._desktop_x + x_center * this._desktop_width;
|
xCenter = this._desktopX + xCenter * this._desktopWidth;
|
||||||
y_center = this._desktop_y + y_center * this._desktop_height;
|
yCenter = this._desktopY + yCenter * this._desktopHeight;
|
||||||
|
|
||||||
let size = clone.width;
|
let size = clone.width;
|
||||||
if (clone.height > size)
|
if (clone.height > size)
|
||||||
size = clone.height;
|
size = clone.height;
|
||||||
|
|
||||||
// Never scale up
|
// Never scale up
|
||||||
let scale = desired_size / size;
|
let scale = desiredSize / size;
|
||||||
if (scale > 1)
|
if (scale > 1)
|
||||||
scale = 1;
|
scale = 1;
|
||||||
|
|
||||||
this._group.add_actor(clone);
|
this._group.add_actor(clone);
|
||||||
this._window_clones.push(clone);
|
this._windowClones.push(clone);
|
||||||
|
|
||||||
Tweener.addTween(clone,
|
Tweener.addTween(clone,
|
||||||
{ x: x_center - 0.5 * scale * w.width,
|
{ x: xCenter - 0.5 * scale * w.width,
|
||||||
y: y_center - 0.5 * scale * w.height,
|
y: yCenter - 0.5 * scale * w.height,
|
||||||
scale_x: scale,
|
scale_x: scale,
|
||||||
scale_y: scale,
|
scale_y: scale,
|
||||||
time: ANIMATION_TIME,
|
time: ANIMATION_TIME,
|
||||||
|
Loading…
Reference in New Issue
Block a user