GUAC-676: Implement Guacamole.Display. Perform initial refactor.

This commit is contained in:
Michael Jumper
2014-05-11 22:18:51 -07:00
parent 84ac5cad99
commit 299c341ce0
4 changed files with 1621 additions and 1294 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -49,22 +49,14 @@ Guacamole.Layer = function(width, height) {
* The canvas element backing this Layer.
* @private
*/
var display = document.createElement("canvas");
var canvas = document.createElement("canvas");
/**
* The 2D display context of the canvas element backing this Layer.
* @private
*/
var displayContext = display.getContext("2d");
displayContext.save();
/**
* The queue of all pending Tasks. Tasks will be run in order, with new
* tasks added at the end of the queue and old tasks removed from the
* front of the queue (FIFO).
* @private
*/
var tasks = new Array();
var context = canvas.getContext("2d");
context.save();
/**
* Whether a new path should be started with the next path drawing
@@ -120,7 +112,7 @@ Guacamole.Layer = function(width, height) {
// Only preserve old data if width/height are both non-zero
var oldData = null;
if (width != 0 && height != 0) {
if (width !== 0 && height !== 0) {
// Create canvas and context for holding old data
oldData = document.createElement("canvas");
@@ -130,34 +122,34 @@ Guacamole.Layer = function(width, height) {
var oldDataContext = oldData.getContext("2d");
// Copy image data from current
oldDataContext.drawImage(display,
oldDataContext.drawImage(canvas,
0, 0, width, height,
0, 0, width, height);
}
// Preserve composite operation
var oldCompositeOperation = displayContext.globalCompositeOperation;
var oldCompositeOperation = context.globalCompositeOperation;
// Resize canvas
display.width = newWidth;
display.height = newHeight;
canvas.width = newWidth;
canvas.height = newHeight;
// Redraw old data, if any
if (oldData)
displayContext.drawImage(oldData,
context.drawImage(oldData,
0, 0, width, height,
0, 0, width, height);
// Restore composite operation
displayContext.globalCompositeOperation = oldCompositeOperation;
context.globalCompositeOperation = oldCompositeOperation;
width = newWidth;
height = newHeight;
// Acknowledge reset of stack (happens on resize of canvas)
stackSize = 0;
displayContext.save();
context.save();
}
@@ -198,192 +190,11 @@ Guacamole.Layer = function(width, height) {
resizeHeight = height;
// Resize if necessary
if (resizeWidth != width || resizeHeight != height)
if (resizeWidth !== width || resizeHeight !== height)
resize(resizeWidth, resizeHeight);
}
/**
* A container for an task handler. Each operation which must be ordered
* is associated with a Task that goes into a task queue. Tasks in this
* queue are executed in order once their handlers are set, while Tasks
* without handlers block themselves and any following Tasks from running.
*
* @constructor
* @private
* @param {function} taskHandler The function to call when this task
* runs, if any.
* @param {boolean} blocked Whether this task should start blocked.
*/
function Task(taskHandler, blocked) {
var task = this;
/**
* Whether this Task is blocked.
*
* @type boolean
*/
this.blocked = blocked;
/**
* The handler this Task is associated with, if any.
*
* @type function
*/
this.handler = taskHandler;
/**
* Unblocks this Task, allowing it to run.
*/
this.unblock = function() {
if (task.blocked) {
task.blocked = false;
// Flush automatically if enabled
if (layer.autoflush || !flushComplete)
layer.flush();
}
}
}
/**
* If no tasks are pending or running, run the provided handler immediately,
* if any. Otherwise, schedule a task to run immediately after all currently
* running or pending tasks are complete.
*
* @private
* @param {function} handler The function to call when possible, if any.
* @param {boolean} blocked Whether the task should start blocked.
* @returns {Task} The Task created and added to the queue for future
* running, if any, or null if the handler was run
* immediately and no Task needed to be created.
*/
function scheduleTask(handler, blocked) {
// If no pending tasks, just call (if available) and exit
if (layer.autoflush && layer.isReady() && !blocked) {
if (handler) handler();
return null;
}
// If tasks are pending/executing, schedule a pending task
// and return a reference to it.
var task = new Task(handler, blocked);
tasks.push(task);
return task;
}
/**
* Whether all previous calls to flush() have completed. If a task was
* waiting in the queue when flush() was called but still blocked, the
* queue will continue to flush outside the original flush() call until
* the queue is empty.
*
* @private
*/
var flushComplete = true;
/**
* Whether tasks are currently being actively flushed. As flush() is not
* reentrant, this flag prevents calls of flush() from overlapping.
* @private
*/
var tasksInProgress = false;
/**
* Run any Tasks which were pending but are now ready to run and are not
* blocked by other Tasks.
*/
this.flush = function() {
if (tasksInProgress)
return;
tasksInProgress = true;
flushComplete = false;
// Draw all pending tasks.
var task;
while ((task = tasks[0]) != null && !task.blocked) {
tasks.shift();
if (task.handler) task.handler();
}
// If all pending draws have been flushed
if (layer.isReady())
flushComplete = true;
tasksInProgress = false;
};
/**
* Schedules a task within the current layer just as scheduleTast() does,
* except that another specified layer will be blocked until this task
* completes, and this task will not start until the other layer is
* ready.
*
* Essentially, a task is scheduled in both layers, and the specified task
* will only be performed once both layers are ready, and neither layer may
* proceed until this task completes.
*
* Note that there is no way to specify whether the task starts blocked,
* as whether the task is blocked depends completely on whether the
* other layer is currently ready.
*
* @private
* @param {Guacamole.Layer} otherLayer The other layer which must be blocked
* until this task completes.
* @param {function} handler The function to call when possible.
*/
function scheduleTaskSynced(otherLayer, handler) {
// If we ARE the other layer, no need to sync.
// Syncing would result in deadlock.
if (layer === otherLayer)
scheduleTask(handler);
// Otherwise synchronize operation with other layer
else {
var drawComplete = false;
var layerLock = null;
function performTask() {
// Perform task
handler();
// Unblock the other layer now that draw is complete
if (layerLock != null)
layerLock.unblock();
// Flag operation as done
drawComplete = true;
}
// Currently blocked draw task
var task = scheduleTask(performTask, true);
// Unblock draw task once source layer is ready
otherLayer.sync(task.unblock);
// Block other layer until draw completes
// Note that the draw MAY have already been performed at this point,
// in which case creating a lock on the other layer will lead to
// deadlock (the draw task has already run and will thus never
// clear the lock)
if (!drawComplete)
layerLock = otherLayer.sync(null, true);
}
}
/**
* Set to true if this Layer should resize itself to accomodate the
* dimensions of any drawing operation, and false (the default) otherwise.
@@ -405,32 +216,12 @@ Guacamole.Layer = function(width, height) {
*/
this.autosize = false;
/**
* Set to true to allow operations to flush automatically, instantly
* affecting the layer. By default, operations are buffered and only
* drawn when flush() is called.
*
* @type Boolean
* @default false
*/
this.autoflush = false;
/**
* Returns the canvas element backing this Layer.
* @returns {Element} The canvas element backing this Layer.
*/
this.getCanvas = function() {
return display;
};
/**
* Returns whether this Layer is ready. A Layer is ready if it has no
* pending operations and no operations in-progress.
*
* @returns {Boolean} true if this Layer is ready, false otherwise.
*/
this.isReady = function() {
return tasks.length == 0;
return canvas;
};
/**
@@ -442,10 +233,8 @@ Guacamole.Layer = function(width, height) {
* @param {Number} newHeight The new height to assign to this Layer.
*/
this.resize = function(newWidth, newHeight) {
scheduleTask(function() {
if (newWidth != width || newHeight != height)
if (newWidth !== width || newHeight !== height)
resize(newWidth, newHeight);
});
};
/**
@@ -458,94 +247,10 @@ Guacamole.Layer = function(width, height) {
* object - not a URL.
*/
this.drawImage = function(x, y, image) {
scheduleTask(function() {
if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
displayContext.drawImage(image, x, y);
});
if (layer.autosize) fitRect(x, y, image.width, image.height);
context.drawImage(image, x, y);
};
/**
* Draws the image at the specified URL at the given coordinates. The image
* will be loaded automatically, and this and any future operations will
* wait for the image to finish loading.
*
* @param {Number} x The destination X coordinate.
* @param {Number} y The destination Y coordinate.
* @param {String} url The URL of the image to draw.
*/
this.draw = function(x, y, url) {
var task = scheduleTask(function() {
if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
displayContext.drawImage(image, x, y);
}, true);
var image = new Image();
image.onload = task.unblock;
image.src = url;
};
/**
* Plays the video at the specified URL within this layer. The video
* will be loaded automatically, and this and any future operations will
* wait for the video to finish loading. Future operations will not be
* executed until the video finishes playing.
*
* @param {String} mimetype The mimetype of the video to play.
* @param {Number} duration The duration of the video in milliseconds.
* @param {String} url The URL of the video to play.
*/
this.play = function(mimetype, duration, url) {
// Start loading the video
var video = document.createElement("video");
video.type = mimetype;
video.src = url;
// Main task - playing the video
var task = scheduleTask(function() {
video.play();
}, true);
// Lock which will be cleared after video ends
var lock = scheduleTask(null, true);
// Start copying frames when playing
video.addEventListener("play", function() {
function render_callback() {
displayContext.drawImage(video, 0, 0, width, height);
if (!video.ended)
window.setTimeout(render_callback, 20);
else
lock.unblock();
}
render_callback();
}, false);
// Unblock future operations after an error
video.addEventListener("error", lock.unblock, false);
// Play video as soon as current tasks are complete, now that the
// lock has been set up.
task.unblock();
};
/**
* Run an arbitrary function as soon as currently pending operations
* are complete.
*
* @function
* @param {function} handler The function to call once all currently
* pending operations are complete.
* @param {boolean} blocked Whether the task should start blocked.
*/
this.sync = scheduleTask;
/**
* Transfer a rectangle of image data from one Layer to this Layer using the
* specified transfer function.
@@ -568,7 +273,6 @@ Guacamole.Layer = function(width, height) {
* destination.
*/
this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) {
scheduleTaskSynced(srcLayer, function() {
var srcCanvas = srcLayer.getCanvas();
@@ -583,13 +287,13 @@ Guacamole.Layer = function(width, height) {
srch = srcCanvas.height - srcy;
// Stop if nothing to draw.
if (srcw == 0 || srch == 0) return;
if (srcw === 0 || srch === 0) return;
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
if (layer.autosize) fitRect(x, y, srcw, srch);
// Get image data from src and dst
var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
var dst = displayContext.getImageData(x , y, srcw, srch);
var dst = context.getImageData(x , y, srcw, srch);
// Apply transfer for each pixel
for (var i=0; i<srcw*srch*4; i+=4) {
@@ -622,9 +326,8 @@ Guacamole.Layer = function(width, height) {
}
// Draw image data
displayContext.putImageData(dst, x, y);
context.putImageData(dst, x, y);
});
};
/**
@@ -646,7 +349,6 @@ Guacamole.Layer = function(width, height) {
* @param {Number} y The destination Y coordinate.
*/
this.put = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
scheduleTaskSynced(srcLayer, function() {
var srcCanvas = srcLayer.getCanvas();
@@ -661,15 +363,14 @@ Guacamole.Layer = function(width, height) {
srch = srcCanvas.height - srcy;
// Stop if nothing to draw.
if (srcw == 0 || srch == 0) return;
if (srcw === 0 || srch === 0) return;
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
if (layer.autosize) fitRect(x, y, srcw, srch);
// Get image data from src and dst
var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
displayContext.putImageData(src, x, y);
context.putImageData(src, x, y);
});
};
/**
@@ -694,7 +395,6 @@ Guacamole.Layer = function(width, height) {
* @param {Number} y The destination Y coordinate.
*/
this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
scheduleTaskSynced(srcLayer, function() {
var srcCanvas = srcLayer.getCanvas();
@@ -709,12 +409,11 @@ Guacamole.Layer = function(width, height) {
srch = srcCanvas.height - srcy;
// Stop if nothing to draw.
if (srcw == 0 || srch == 0) return;
if (srcw === 0 || srch === 0) return;
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
if (layer.autosize) fitRect(x, y, srcw, srch);
context.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
});
};
/**
@@ -724,18 +423,16 @@ Guacamole.Layer = function(width, height) {
* @param {Number} y The Y coordinate of the point to draw.
*/
this.moveTo = function(x, y) {
scheduleTask(function() {
// Start a new path if current path is closed
if (pathClosed) {
displayContext.beginPath();
context.beginPath();
pathClosed = false;
}
if (layer.autosize != 0) fitRect(x, y, 0, 0);
displayContext.moveTo(x, y);
if (layer.autosize) fitRect(x, y, 0, 0);
context.moveTo(x, y);
});
};
/**
@@ -745,18 +442,16 @@ Guacamole.Layer = function(width, height) {
* @param {Number} y The Y coordinate of the endpoint of the line to draw.
*/
this.lineTo = function(x, y) {
scheduleTask(function() {
// Start a new path if current path is closed
if (pathClosed) {
displayContext.beginPath();
context.beginPath();
pathClosed = false;
}
if (layer.autosize != 0) fitRect(x, y, 0, 0);
displayContext.lineTo(x, y);
if (layer.autosize) fitRect(x, y, 0, 0);
context.lineTo(x, y);
});
};
/**
@@ -773,18 +468,16 @@ Guacamole.Layer = function(width, height) {
* decreasing angle.
*/
this.arc = function(x, y, radius, startAngle, endAngle, negative) {
scheduleTask(function() {
// Start a new path if current path is closed
if (pathClosed) {
displayContext.beginPath();
context.beginPath();
pathClosed = false;
}
if (layer.autosize != 0) fitRect(x, y, 0, 0);
displayContext.arc(x, y, radius, startAngle, endAngle, negative);
if (layer.autosize) fitRect(x, y, 0, 0);
context.arc(x, y, radius, startAngle, endAngle, negative);
});
};
/**
@@ -798,18 +491,16 @@ Guacamole.Layer = function(width, height) {
* @param {Number} y The Y coordinate of the endpoint of the curve.
*/
this.curveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {
scheduleTask(function() {
// Start a new path if current path is closed
if (pathClosed) {
displayContext.beginPath();
context.beginPath();
pathClosed = false;
}
if (layer.autosize != 0) fitRect(x, y, 0, 0);
displayContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
if (layer.autosize) fitRect(x, y, 0, 0);
context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
});
};
/**
@@ -817,13 +508,8 @@ Guacamole.Layer = function(width, height) {
* point (if any) with a straight line.
*/
this.close = function() {
scheduleTask(function() {
// Close path
displayContext.closePath();
context.closePath();
pathClosed = true;
});
};
/**
@@ -837,18 +523,16 @@ Guacamole.Layer = function(width, height) {
* @param {Number} h The height of the rectangle to draw.
*/
this.rect = function(x, y, w, h) {
scheduleTask(function() {
// Start a new path if current path is closed
if (pathClosed) {
displayContext.beginPath();
context.beginPath();
pathClosed = false;
}
if (layer.autosize != 0) fitRect(x, y, w, h);
displayContext.rect(x, y, w, h);
if (layer.autosize) fitRect(x, y, w, h);
context.rect(x, y, w, h);
});
};
/**
@@ -858,15 +542,13 @@ Guacamole.Layer = function(width, height) {
* once a path drawing operation (path() or rect()) is used.
*/
this.clip = function() {
scheduleTask(function() {
// Set new clipping region
displayContext.clip();
context.clip();
// Path now implicitly closed
pathClosed = true;
});
};
/**
@@ -886,19 +568,17 @@ Guacamole.Layer = function(width, height) {
* @param {Number} a The alpha component of the color to fill.
*/
this.strokeColor = function(cap, join, thickness, r, g, b, a) {
scheduleTask(function() {
// Stroke with color
displayContext.lineCap = cap;
displayContext.lineJoin = join;
displayContext.lineWidth = thickness;
displayContext.strokeStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
displayContext.stroke();
context.lineCap = cap;
context.lineJoin = join;
context.lineWidth = thickness;
context.strokeStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
context.stroke();
// Path now implicitly closed
pathClosed = true;
});
};
/**
@@ -913,16 +593,14 @@ Guacamole.Layer = function(width, height) {
* @param {Number} a The alpha component of the color to fill.
*/
this.fillColor = function(r, g, b, a) {
scheduleTask(function() {
// Fill with color
displayContext.fillStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
displayContext.fill();
context.fillStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
context.fill();
// Path now implicitly closed
pathClosed = true;
});
};
/**
@@ -941,22 +619,20 @@ Guacamole.Layer = function(width, height) {
* within the stroke.
*/
this.strokeLayer = function(cap, join, thickness, srcLayer) {
scheduleTaskSynced(srcLayer, function() {
// Stroke with image data
displayContext.lineCap = cap;
displayContext.lineJoin = join;
displayContext.lineWidth = thickness;
displayContext.strokeStyle = displayContext.createPattern(
context.lineCap = cap;
context.lineJoin = join;
context.lineWidth = thickness;
context.strokeStyle = context.createPattern(
srcLayer.getCanvas(),
"repeat"
);
displayContext.stroke();
context.stroke();
// Path now implicitly closed
pathClosed = true;
});
};
/**
@@ -970,47 +646,41 @@ Guacamole.Layer = function(width, height) {
* within the fill.
*/
this.fillLayer = function(srcLayer) {
scheduleTask(function() {
// Fill with image data
displayContext.fillStyle = displayContext.createPattern(
context.fillStyle = context.createPattern(
srcLayer.getCanvas(),
"repeat"
);
displayContext.fill();
context.fill();
// Path now implicitly closed
pathClosed = true;
});
};
/**
* Push current layer state onto stack.
*/
this.push = function() {
scheduleTask(function() {
// Save current state onto stack
displayContext.save();
context.save();
stackSize++;
});
};
/**
* Pop layer state off stack.
*/
this.pop = function() {
scheduleTask(function() {
// Restore current state from stack
if (stackSize > 0) {
displayContext.restore();
context.restore();
stackSize--;
}
});
};
/**
@@ -1018,23 +688,21 @@ Guacamole.Layer = function(width, height) {
* matrix.
*/
this.reset = function() {
scheduleTask(function() {
// Clear stack
while (stackSize > 0) {
displayContext.restore();
context.restore();
stackSize--;
}
// Restore to initial state
displayContext.restore();
displayContext.save();
context.restore();
context.save();
// Clear path
displayContext.beginPath();
context.beginPath();
pathClosed = false;
});
};
/**
@@ -1049,16 +717,11 @@ Guacamole.Layer = function(width, height) {
* @param {Number} f The sixth value in the affine transform's matrix.
*/
this.setTransform = function(a, b, c, d, e, f) {
scheduleTask(function() {
// Set transform
displayContext.setTransform(
context.setTransform(
a, b, c,
d, e, f
/*0, 0, 1*/
);
});
};
/**
@@ -1073,16 +736,11 @@ Guacamole.Layer = function(width, height) {
* @param {Number} f The sixth value in the affine transform's matrix.
*/
this.transform = function(a, b, c, d, e, f) {
scheduleTask(function() {
// Apply transform
displayContext.transform(
context.transform(
a, b, c,
d, e, f
/*0, 0, 1*/
);
});
};
/**
@@ -1098,9 +756,7 @@ Guacamole.Layer = function(width, height) {
* Layer.
*/
this.setChannelMask = function(mask) {
scheduleTask(function() {
displayContext.globalCompositeOperation = compositeOperation[mask];
});
context.globalCompositeOperation = compositeOperation[mask];
};
/**
@@ -1113,19 +769,17 @@ Guacamole.Layer = function(width, height) {
* miter join.
*/
this.setMiterLimit = function(limit) {
scheduleTask(function() {
displayContext.miterLimit = limit;
});
context.miterLimit = limit;
};
// Initialize canvas dimensions
display.width = width;
display.height = height;
canvas.width = width;
canvas.height = height;
// Explicitly render canvas below other elements in the layer (such as
// child layers). Chrome and others may fail to render layers properly
// without this.
display.style.zIndex = -1;
canvas.style.zIndex = -1;
};
@@ -1237,3 +891,7 @@ Guacamole.Layer.Pixel = function(r, g, b, a) {
this.alpha = a;
};
// FIXME: Declaration order hack
Guacamole.Display.VisibleLayer.prototype = new Guacamole.Layer(0, 0);

View File

@@ -742,7 +742,7 @@ GuacUI.Client.Pinch = function(element) {
GuacUI.Client.updateThumbnail = function() {
// Get screenshot
var canvas = GuacUI.Client.attachedClient.flatten();
var canvas = GuacUI.Client.attachedClient.getDisplay().flatten();
// Calculate scale of thumbnail (max 320x240, max zoom 100%)
var scale = Math.min(
@@ -781,7 +781,7 @@ GuacUI.Client.setScale = function(new_scale) {
new_scale = Math.min(new_scale, GuacUI.Client.max_zoom);
if (GuacUI.Client.attachedClient)
GuacUI.Client.attachedClient.scale(new_scale);
GuacUI.Client.attachedClient.getDisplay().scale(new_scale);
GuacUI.Client.zoom_state.textContent = Math.round(new_scale * 100) + "%";
@@ -809,22 +809,22 @@ GuacUI.Client.updateDisplayScale = function() {
// Determine whether display is currently fit to the screen
var guac = GuacUI.Client.attachedClient;
var auto_fit = (guac.getScale() === GuacUI.Client.min_zoom);
var auto_fit = (guac.getDisplay().getScale() === GuacUI.Client.min_zoom);
// Calculate scale to fit screen
GuacUI.Client.min_zoom = Math.min(
window.innerWidth / Math.max(guac.getWidth(), 1),
window.innerHeight / Math.max(guac.getHeight(), 1)
window.innerWidth / Math.max(guac.getDisplay().getWidth(), 1),
window.innerHeight / Math.max(guac.getDisplay().getHeight(), 1)
);
// Calculate appropriate maximum zoom level
GuacUI.Client.max_zoom = Math.max(GuacUI.Client.min_zoom, 3);
// Clamp zoom level, maintain auto-fit
if (guac.getScale() < GuacUI.Client.min_zoom || auto_fit)
if (guac.getDisplay().getScale() < GuacUI.Client.min_zoom || auto_fit)
GuacUI.Client.setScale(GuacUI.Client.min_zoom);
else if (guac.getScale() > GuacUI.Client.max_zoom)
else if (guac.getDisplay().getScale() > GuacUI.Client.max_zoom)
GuacUI.Client.setScale(GuacUI.Client.max_zoom);
};
@@ -1055,7 +1055,7 @@ GuacUI.Client.setMouseEmulationAbsolute = function(absolute) {
if (!guac) return;
// Determine mouse position within view
var guac_display = guac.getDisplay();
var guac_display = guac.getDisplay().getElement();
var mouse_view_x = mouseState.x + guac_display.offsetLeft - GuacUI.Client.main.scrollLeft;
var mouse_view_y = mouseState.y + guac_display.offsetTop - GuacUI.Client.main.scrollTop;
@@ -1087,8 +1087,8 @@ GuacUI.Client.setMouseEmulationAbsolute = function(absolute) {
// Scale event by current scale
var scaledState = new Guacamole.Mouse.State(
mouseState.x / guac.getScale(),
mouseState.y / guac.getScale(),
mouseState.x / guac.getDisplay().getScale(),
mouseState.y / guac.getDisplay().getScale(),
mouseState.left,
mouseState.middle,
mouseState.right,
@@ -1147,13 +1147,13 @@ GuacUI.Client.attach = function(guac) {
GuacUI.Client.attachedClient = guac;
// Get display element
var guac_display = guac.getDisplay();
var guac_display = guac.getDisplay().getElement();
/*
* Update the scale of the display when the client display size changes.
*/
guac.onresize = function(width, height) {
guac.getDisplay().onresize = function(width, height) {
GuacUI.Client.updateDisplayScale();
};
@@ -1332,8 +1332,8 @@ GuacUI.Client.attach = function(guac) {
// Scale event by current scale
var scaledState = new Guacamole.Mouse.State(
mouseState.x / guac.getScale(),
mouseState.y / guac.getScale(),
mouseState.x / guac.getDisplay().getScale(),
mouseState.y / guac.getDisplay().getScale(),
mouseState.left,
mouseState.middle,
mouseState.right,
@@ -1353,8 +1353,8 @@ GuacUI.Client.attach = function(guac) {
GuacUI.Client.display.innerHTML = "";
// Add client to UI
guac.getDisplay().className = "software-cursor";
GuacUI.Client.display.appendChild(guac.getDisplay());
guac.getDisplay().getElement().className = "software-cursor";
GuacUI.Client.display.appendChild(guac.getDisplay().getElement());
};
@@ -1698,7 +1698,7 @@ GuacUI.Client.attach = function(guac) {
if (!guac)
return;
initial_scale = guac.getScale();
initial_scale = guac.getDisplay().getScale();
initial_center_x = (x + GuacUI.Client.main.scrollLeft) / initial_scale;
initial_center_y = (y + GuacUI.Client.main.scrollTop) / initial_scale;
};
@@ -2031,7 +2031,7 @@ GuacUI.Client.attach = function(guac) {
// Zoom in by 10%
var guac = GuacUI.Client.attachedClient;
if (guac)
GuacUI.Client.setScale(guac.getScale() + 0.1);
GuacUI.Client.setScale(guac.getDisplay().getScale() + 0.1);
};
@@ -2040,7 +2040,7 @@ GuacUI.Client.attach = function(guac) {
// Zoom out by 10%
var guac = GuacUI.Client.attachedClient;
if (guac)
GuacUI.Client.setScale(guac.getScale() - 0.1);
GuacUI.Client.setScale(guac.getDisplay().getScale() - 0.1);
};