True layer and buffer support (not stub)

This commit is contained in:
Michael Jumper
2011-02-12 14:07:12 -08:00
parent 3d3aad76c9
commit 0ad9127a68
2 changed files with 70 additions and 22 deletions

View File

@@ -270,8 +270,9 @@ function GuacamoleClient(display, tunnelURL) {
disconnect(); disconnect();
// Show error by desaturating display // Show error by desaturating display
if (background) for (var i=0; i<layers.length; i++) {
background.filter(desaturateFilter); layers[i].filter(desaturateFilter);
}
if (errorHandler) if (errorHandler)
errorHandler(error); errorHandler(error);
@@ -440,25 +441,59 @@ function GuacamoleClient(display, tunnelURL) {
} }
// Layers // Layers
var displayWidth = null; var displayWidth = 0;
var displayHeight = null; var displayHeight = 0;
var background = null;
var layers = new Array();
var buffers = new Array();
var cursor = null; var cursor = null;
function getLayer(index) { function getLayer(index) {
// FIXME: Stub - does not actually handle layers or the layer index // If negative index, use buffer
if (index < 0) {
if (background == null) { index = -1 - index;
background = new Layer(displayWidth, displayHeight); var buffer = buffers[index];
if (cursor != null) // Create buffer if necessary
display.insertBefore(background, cursor); if (buffer == null) {
else buffer = new Layer(0, 0);
display.appendChild(background); buffers[index] = buffer;
}
return buffer;
} }
return background; // If non-negative, use visible layer
else {
var layer = layers[index];
if (layer == null) {
// Add new layer
layer = new Layer(displayWidth, displayHeight);
layers[index] = layer;
// Remove all children
display.innerHTML = "";
// Add existing layers in order
for (var i=0; i<layers.length; i++)
display.appendChild(layers[i]);
// Add cursor layer last
if (cursor != null)
display.appendChild(cursor);
}
else {
// Reset size
layer.resize(displayWidth, displayHeight);
}
return layer;
}
} }
@@ -487,7 +522,9 @@ function GuacamoleClient(display, tunnelURL) {
display.style.height = displayHeight + "px"; display.style.height = displayHeight + "px";
} }
// Set cursor layer width/height here // Set cursor layer width/height
if (cursor != null)
cursor.resize(displayWidth, displayHeight);
}, },

View File

@@ -21,16 +21,27 @@ function Layer(width, height) {
// Off-screen buffer // Off-screen buffer
var display = document.createElement("canvas"); var display = document.createElement("canvas");
display.style.position = "absolute";
display.style.left = "0px";
display.style.right = "0px";
display.width = width;
display.height = height;
var displayContext = display.getContext("2d"); var displayContext = display.getContext("2d");
function resize(newWidth, newHeight) {
display.style.position = "absolute";
display.style.left = "0px";
display.style.right = "0px";
display.width = newWidth;
display.height = newHeight;
width = newWidth;
height = newHeight;
}
display.resize = function(newWidth, newHeight) {
if (newWidth != width || newHeight != height)
resize(newWidth, newHeight);
}
resize(width, height);
var readyHandler = null; var readyHandler = null;
var nextUpdateToDraw = 0; var nextUpdateToDraw = 0;
var currentUpdate = 0; var currentUpdate = 0;