JS bitwise operators use all 32-bits, added mask to keep bitwise NOT to 8-bits
[guacamole-common-js.git] / src / main / resources / guacamole.js
index a9fcbed..aee7fae 100644 (file)
@@ -123,6 +123,9 @@ Guacamole.Client = function(tunnel) {
     var cursorHotspotX = 0;
     var cursorHotspotY = 0;
 
+    var cursorX = 0;
+    var cursorY = 0;
+
     function moveCursor(x, y) {
 
         var element = cursor.getElement();
@@ -131,6 +134,10 @@ Guacamole.Client = function(tunnel) {
         element.style.left = (x - cursorHotspotX) + "px";
         element.style.top  = (y - cursorHotspotY) + "px";
 
+        // Update stored position
+        cursorX = x;
+        cursorY = y;
+
     }
 
     guac_client.getDisplay = function() {
@@ -308,6 +315,32 @@ Guacamole.Client = function(tunnel) {
 
         },
 
+        "dispose": function(parameters) {
+            
+            var layer_index = parseInt(parameters[0]);
+
+            // If visible layer, remove from parent
+            if (layer_index > 0) {
+
+                // Get container element
+                var layer_container = getLayerContainer(layer_index).getElement();
+
+                // Remove from parent
+                layer_container.parentNode.removeChild(layer_container);
+
+                // Delete reference
+                delete layers[layer_index];
+
+            }
+
+            // If buffer, just delete reference
+            else if (layer_index < 0)
+                delete buffers[-1 - layer_index];
+
+            // Attempting to dispose the root layer currently has no effect.
+
+        },
+
         "png": function(parameters) {
 
             var channelMask = parseInt(parameters[0]);
@@ -356,6 +389,31 @@ Guacamole.Client = function(tunnel) {
 
         },
 
+        "transfer": function(parameters) {
+
+            var srcL = getLayer(parseInt(parameters[0]));
+            var srcX = parseInt(parameters[1]);
+            var srcY = parseInt(parameters[2]);
+            var srcWidth = parseInt(parameters[3]);
+            var srcHeight = parseInt(parameters[4]);
+            var transferFunction = Guacamole.Client.DefaultTransferFunction[parameters[5]];
+            var dstL = getLayer(parseInt(parameters[6]));
+            var dstX = parseInt(parameters[7]);
+            var dstY = parseInt(parameters[8]);
+
+            dstL.transfer(
+                srcL,
+                srcX,
+                srcY,
+                srcWidth, 
+                srcHeight, 
+                dstX,
+                dstY,
+                transferFunction
+            );
+
+        },
+
         "rect": function(parameters) {
 
             var channelMask = parseInt(parameters[0]);
@@ -414,7 +472,8 @@ Guacamole.Client = function(tunnel) {
                 0 
             );
 
-            // FIXME: Update cursor position when hotspot changes
+            // Update cursor position (hotspot may have changed)
+            moveCursor(cursorX, cursorY);
 
         },
 
@@ -588,4 +647,120 @@ Guacamole.Client.LayerContainer = function(width, height) {
         return div;
     };
 
-};
\ No newline at end of file
+};
+
+/**
+ * Map of all Guacamole binary raster operations to transfer functions.
+ * @private
+ */
+Guacamole.Client.DefaultTransferFunction = {
+
+    /* BLACK */
+    0x0: function (src, dst) {
+        dst.red = dst.green = dst.blue = 0x00;
+    },
+
+    /* WHITE */
+    0xF: function (src, dst) {
+        dst.red = dst.green = dst.blue = 0xFF;
+    },
+
+    /* SRC */
+    0x3: function (src, dst) {
+        dst.red   = src.red;
+        dst.green = src.green;
+        dst.blue  = src.blue;
+        dst.alpha = src.alpha;
+    },
+
+    /* DEST (no-op) */
+    0x5: function (src, dst) {
+        // Do nothing
+    },
+
+    /* Invert SRC */
+    0xC: function (src, dst) {
+        dst.red   = 0xFF & ~src.red;
+        dst.green = 0xFF & ~src.green;
+        dst.blue  = 0xFF & ~src.blue;
+        dst.alpha =  src.alpha;
+    },
+    
+    /* Invert DEST */
+    0xA: function (src, dst) {
+        dst.red   = 0xFF & ~dst.red;
+        dst.green = 0xFF & ~dst.green;
+        dst.blue  = 0xFF & ~dst.blue;
+    },
+
+    /* AND */
+    0x1: function (src, dst) {
+        dst.red   =  ( src.red   &  dst.red);
+        dst.green =  ( src.green &  dst.green);
+        dst.blue  =  ( src.blue  &  dst.blue);
+    },
+
+    /* NAND */
+    0xE: function (src, dst) {
+        dst.red   = 0xFF & ~( src.red   &  dst.red);
+        dst.green = 0xFF & ~( src.green &  dst.green);
+        dst.blue  = 0xFF & ~( src.blue  &  dst.blue);
+    },
+
+    /* OR */
+    0x7: function (src, dst) {
+        dst.red   =  ( src.red   |  dst.red);
+        dst.green =  ( src.green |  dst.green);
+        dst.blue  =  ( src.blue  |  dst.blue);
+    },
+
+    /* NOR */
+    0x8: function (src, dst) {
+        dst.red   = 0xFF & ~( src.red   |  dst.red);
+        dst.green = 0xFF & ~( src.green |  dst.green);
+        dst.blue  = 0xFF & ~( src.blue  |  dst.blue);
+    },
+
+    /* XOR */
+    0x6: function (src, dst) {
+        dst.red   =  ( src.red   ^  dst.red);
+        dst.green =  ( src.green ^  dst.green);
+        dst.blue  =  ( src.blue  ^  dst.blue);
+    },
+
+    /* XNOR */
+    0x9: function (src, dst) {
+        dst.red   = 0xFF & ~( src.red   ^  dst.red);
+        dst.green = 0xFF & ~( src.green ^  dst.green);
+        dst.blue  = 0xFF & ~( src.blue  ^  dst.blue);
+    },
+
+    /* AND inverted source */
+    0x4: function (src, dst) {
+        dst.red   =  0xFF & (~src.red   &  dst.red);
+        dst.green =  0xFF & (~src.green &  dst.green);
+        dst.blue  =  0xFF & (~src.blue  &  dst.blue);
+    },
+
+    /* OR inverted source */
+    0xD: function (src, dst) {
+        dst.red   =  0xFF & (~src.red   |  dst.red);
+        dst.green =  0xFF & (~src.green |  dst.green);
+        dst.blue  =  0xFF & (~src.blue  |  dst.blue);
+    },
+
+    /* AND inverted destination */
+    0x2: function (src, dst) {
+        dst.red   =  0xFF & ( src.red   & ~dst.red);
+        dst.green =  0xFF & ( src.green & ~dst.green);
+        dst.blue  =  0xFF & ( src.blue  & ~dst.blue);
+    },
+
+    /* OR inverted destination */
+    0xB: function (src, dst) {
+        dst.red   =  0xFF & ( src.red   | ~dst.red);
+        dst.green =  0xFF & ( src.green | ~dst.green);
+        dst.blue  =  0xFF & ( src.blue  | ~dst.blue);
+    }
+
+};