Commit 888d5813 authored by Joel Martin's avatar Joel Martin

Fix scrolled mouse position.

parent 4b4496ad
......@@ -17,32 +17,41 @@ prefer_js : false,
true_color : false,
colourMap : [],
c_x : 0,
c_y : 0,
c_wx : 0,
c_wy : 0,
ctx : null,
prevStyle: "",
getX: function() {
var c = $(Canvas.id);
return c.getPosition().x - document.getScroll().x;
},
getY: function() {
var c = $(Canvas.id);
return c.getPosition().y - document.getScroll().y;
},
mouseDown: function (e) {
var evt = e.event || window.event;
e.stop();
console.log('mouse ' + evt.which + '/' + evt.button + ' down:' +
(evt.clientX - Canvas.c_x) + "," + (evt.clientY - Canvas.c_y));
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY()));
},
mouseUp: function (e) {
var evt = e.event || window.event;
e.stop();
console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
(evt.clientX - Canvas.c_x) + "," + (evt.clientY - Canvas.c_y));
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY()));
},
mouseMove: function (e) {
var evt = e.event || window.event;
console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
(evt.clientX - Canvas.c_x) + "," + (evt.clientY - Canvas.c_y));
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY()));
},
mouseWheel: function (e) {
......@@ -50,7 +59,7 @@ mouseWheel: function (e) {
//e = e ? e : window.event;
var wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
console.log('mouse scroll by ' + wheelData + ':' +
(evt.clientX - Canvas.c_x) + "," + (evt.clientY - Canvas.c_y));
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY()));
},
......@@ -67,10 +76,10 @@ keyUp : function (e) {
ctxDisable: function (e) {
var evt = e.event || window.event;
/* Stop propagation if inside canvas area */
if ((evt.clientX >= Canvas.c_x) &&
(evt.clientY >= Canvas.c_y) &&
(evt.clientX < (Canvas.c_x + Canvas.c_wx)) &&
(evt.clientY < (Canvas.c_y + Canvas.c_wy))) {
if ((evt.clientX >= Canvas.getX()) &&
(evt.clientY >= Canvas.getY()) &&
(evt.clientX < (Canvas.getX() + Canvas.c_wx)) &&
(evt.clientY < (Canvas.getY() + Canvas.c_wy))) {
e.stop();
return false;
}
......@@ -103,8 +112,6 @@ init: function (id, width, height, true_color, keyDown, keyUp,
document.body.addEvent('contextmenu', Canvas.ctxDisable);
Canvas.resize(width, height);
Canvas.c_x = c.getPosition().x;
Canvas.c_y = c.getPosition().y;
Canvas.c_wx = c.getSize().x;
Canvas.c_wy = c.getSize().y;
Canvas.true_color = true_color;
......
......@@ -1274,8 +1274,8 @@ keyUp: function (e) {
mouseDown: function(e) {
var evt, x, y;
evt = e.event || window.event;
x = (evt.clientX - Canvas.c_x);
y = (evt.clientY - Canvas.c_y);
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
//console.log(">> mouseDown " + evt.which + "/" + evt.button +
// " " + x + "," + y);
RFB.mouse_buttonMask |= 1 << evt.button;
......@@ -1287,8 +1287,8 @@ mouseDown: function(e) {
mouseUp: function(e) {
var evt, x, y;
evt = e.event || window.event;
x = (evt.clientX - Canvas.c_x);
y = (evt.clientY - Canvas.c_y);
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
//console.log(">> mouseUp " + evt.which + "/" + evt.button +
// " " + x + "," + y);
RFB.mouse_buttonMask ^= 1 << evt.button;
......@@ -1300,8 +1300,8 @@ mouseUp: function(e) {
mouseMove: function(e) {
var evt, x, y;
evt = e.event || window.event;
x = (evt.clientX - Canvas.c_x);
y = (evt.clientY - Canvas.c_y);
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
//console.log('>> mouseMove ' + x + "," + y);
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
},
......@@ -1310,8 +1310,8 @@ mouseWheel: function (e) {
var evt, wheelData, bmask;
evt = e.event || window.event;
//e = e ? e : window.event;
x = (evt.clientX - Canvas.c_x);
y = (evt.clientY - Canvas.c_y);
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
//console.log('>> mouseWheel ' + wheelData +
// " " + x + "," + y);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment