mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Move cursor layer, rather than redrawing cursor image.
This commit is contained in:
@@ -75,9 +75,17 @@ Guacamole.Client = function(tunnel) {
|
|||||||
|
|
||||||
// Create default layer
|
// Create default layer
|
||||||
var default_layer_container = new Guacamole.Client.LayerContainer(displayWidth, displayHeight);
|
var default_layer_container = new Guacamole.Client.LayerContainer(displayWidth, displayHeight);
|
||||||
|
var default_layer_container_element = default_layer_container.getElement();
|
||||||
|
default_layer_container_element.style.position = "absolute";
|
||||||
|
default_layer_container_element.style.left = "0px";
|
||||||
|
default_layer_container_element.style.top = "0px";
|
||||||
|
|
||||||
// Create cursor layer
|
// Create cursor layer
|
||||||
var cursor = new Guacamole.Client.LayerContainer(displayWidth, displayHeight);
|
var cursor = new Guacamole.Client.LayerContainer(0, 0);
|
||||||
|
var cursor_element = cursor.getElement();
|
||||||
|
cursor_element.style.position = "absolute";
|
||||||
|
cursor_element.style.left = "0px";
|
||||||
|
cursor_element.style.top = "0px";
|
||||||
|
|
||||||
// Add default layer and cursor to display
|
// Add default layer and cursor to display
|
||||||
display.appendChild(default_layer_container.getElement());
|
display.appendChild(default_layer_container.getElement());
|
||||||
@@ -107,18 +115,14 @@ Guacamole.Client = function(tunnel) {
|
|||||||
|| currentState == STATE_WAITING;
|
|| currentState == STATE_WAITING;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cursorImage = null;
|
|
||||||
var cursorHotspotX = 0;
|
var cursorHotspotX = 0;
|
||||||
var cursorHotspotY = 0;
|
var cursorHotspotY = 0;
|
||||||
|
|
||||||
var cursorRectX = 0;
|
|
||||||
var cursorRectY = 0;
|
|
||||||
var cursorRectW = 0;
|
|
||||||
var cursorRectH = 0;
|
|
||||||
|
|
||||||
var cursorHidden = 0;
|
var cursorHidden = 0;
|
||||||
|
|
||||||
function redrawCursor(x, y) {
|
function moveCursor(x, y) {
|
||||||
|
|
||||||
|
var element = cursor.getElement();
|
||||||
|
|
||||||
// Hide hardware cursor
|
// Hide hardware cursor
|
||||||
if (cursorHidden == 0) {
|
if (cursorHidden == 0) {
|
||||||
@@ -126,17 +130,9 @@ Guacamole.Client = function(tunnel) {
|
|||||||
cursorHidden = 1;
|
cursorHidden = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erase old cursor
|
|
||||||
cursor.clearRect(cursorRectX, cursorRectY, cursorRectW, cursorRectH);
|
|
||||||
|
|
||||||
// Update rect
|
// Update rect
|
||||||
cursorRectX = x - cursorHotspotX;
|
element.style.left = (x - cursorHotspotX) + "px";
|
||||||
cursorRectY = y - cursorHotspotY;
|
element.style.top = (y - cursorHotspotY) + "px";
|
||||||
cursorRectW = cursorImage.width;
|
|
||||||
cursorRectH = cursorImage.height;
|
|
||||||
|
|
||||||
// Draw new cursor
|
|
||||||
cursor.drawImage(cursorRectX, cursorRectY, cursorImage);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,13 +154,11 @@ Guacamole.Client = function(tunnel) {
|
|||||||
if (!isConnected())
|
if (!isConnected())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Draw client-side cursor
|
// Update client-side cursor
|
||||||
if (cursorImage != null) {
|
moveCursor(
|
||||||
redrawCursor(
|
mouseState.x,
|
||||||
mouseState.x,
|
mouseState.y
|
||||||
mouseState.y
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build mask
|
// Build mask
|
||||||
var buttonMask = 0;
|
var buttonMask = 0;
|
||||||
@@ -405,24 +399,12 @@ Guacamole.Client = function(tunnel) {
|
|||||||
|
|
||||||
"cursor": function(parameters) {
|
"cursor": function(parameters) {
|
||||||
|
|
||||||
var x = parseInt(parameters[0]);
|
cursorHotspotX = parseInt(parameters[0]);
|
||||||
var y = parseInt(parameters[1]);
|
cursorHotspotY = parseInt(parameters[1]);
|
||||||
var data = parameters[2];
|
var data = parameters[2];
|
||||||
|
|
||||||
// Start cursor image load
|
// Draw cursor to cursor layer
|
||||||
var image = new Image();
|
cursor.draw(0, 0, "data:image/png;base64," + data);
|
||||||
image.onload = function() {
|
|
||||||
cursorImage = image;
|
|
||||||
|
|
||||||
var cursorX = cursorRectX + cursorHotspotX;
|
|
||||||
var cursorY = cursorRectY + cursorHotspotY;
|
|
||||||
|
|
||||||
cursorHotspotX = x;
|
|
||||||
cursorHotspotY = y;
|
|
||||||
|
|
||||||
redrawCursor(cursorX, cursorY);
|
|
||||||
};
|
|
||||||
image.src = "data:image/png;base64," + data
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user