From 773f64762a29a141ee5c1de7adf95dc17bbc3b2d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 15 Jan 2014 16:03:09 -0800 Subject: [PATCH] Implement shade(). --- .../src/main/webapp/modules/Client.js | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Client.js b/guacamole-common-js/src/main/webapp/modules/Client.js index ee6ffddb4..22cb7bb7d 100644 --- a/guacamole-common-js/src/main/webapp/modules/Client.js +++ b/guacamole-common-js/src/main/webapp/modules/Client.js @@ -954,13 +954,8 @@ Guacamole.Client = function(tunnel) { // Only valid for visible layers (not buffers) if (layer_index >= 0) { - - // Get container element - var layer_container = getLayerContainer(layer_index).getElement(); - - // Set layer opacity - layer_container.style.opacity = a/255.0; - + var layer_container = getLayerContainer(layer_index); + layer_container.shade(a); } }, @@ -1315,18 +1310,22 @@ Guacamole.Client = function(tunnel) { // Draw all immediate children for (index in layers) { - var layer = layers[index]; - var context = canvas.getContext("2d"); + layer = layers[index]; + + context.globalAlpha = layer.alpha / 255.0; context.drawImage(layer.getLayer().getCanvas(), layer.x + x, layer.y + y); } // Draw all children of children for (layer in layers) { - var layer = layers[index]; + layer = layers[index]; draw_all(layer.children, layer.x + x, layer.y + y); } + // Restore alpha + context.globalAlpha = 1; + } // Draw all immediate children @@ -1368,6 +1367,12 @@ Guacamole.Client.LayerContainer = function(index, width, height) { */ this.index = index; + /** + * The opacity of the layer container, where 255 is fully opaque and 0 is + * fully transparent. + */ + this.alpha = 0xFF; + /** * X coordinate of the upper-left corner of this layer container within * its parent, in pixels. @@ -1518,8 +1523,6 @@ Guacamole.Client.LayerContainer = function(index, width, height) { */ this.move = function(parent, x, y, z) { - var layer_container_element = layer_container.getElement(); - // Set parent if necessary if (layer_container.parent !== parent) { @@ -1531,17 +1534,28 @@ Guacamole.Client.LayerContainer = function(index, width, height) { // Reparent element var parent_element = parent.getElement(); - parent_element.appendChild(layer_container_element); + parent_element.appendChild(div); } // Set location layer_container.translate(x, y); layer_container.z = z; - layer_container_element.style.zIndex = z; + div.style.zIndex = z; }; + /** + * Sets the opacity of this layer to the given value, where 255 is fully + * opaque and 0 is fully transparent. + * + * @param {Number} a The opacity to set. + */ + this.shade = function(a) { + layer_container.alpha = a; + div.style.opacity = a/255.0; + }; + /** * Applies the given affine transform (defined with six values from the * transform's matrix).