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

Fix scrolled mouse position.

parent 4b4496ad
...@@ -17,32 +17,41 @@ prefer_js : false, ...@@ -17,32 +17,41 @@ prefer_js : false,
true_color : false, true_color : false,
colourMap : [], colourMap : [],
c_x : 0,
c_y : 0,
c_wx : 0, c_wx : 0,
c_wy : 0, c_wy : 0,
ctx : null, ctx : null,
prevStyle: "", 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) { mouseDown: function (e) {
var evt = e.event || window.event; var evt = e.event || window.event;
e.stop(); e.stop();
console.log('mouse ' + evt.which + '/' + evt.button + ' down:' + 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) { mouseUp: function (e) {
var evt = e.event || window.event; var evt = e.event || window.event;
e.stop(); e.stop();
console.log('mouse ' + evt.which + '/' + evt.button + ' up:' + 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) { mouseMove: function (e) {
var evt = e.event || window.event; var evt = e.event || window.event;
console.log('mouse ' + evt.which + '/' + evt.button + ' up:' + 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) { mouseWheel: function (e) {
...@@ -50,7 +59,7 @@ mouseWheel: function (e) { ...@@ -50,7 +59,7 @@ mouseWheel: function (e) {
//e = e ? e : window.event; //e = e ? e : window.event;
var wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40; var wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
console.log('mouse scroll by ' + wheelData + ':' + 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) { ...@@ -67,10 +76,10 @@ keyUp : function (e) {
ctxDisable: function (e) { ctxDisable: function (e) {
var evt = e.event || window.event; var evt = e.event || window.event;
/* Stop propagation if inside canvas area */ /* Stop propagation if inside canvas area */
if ((evt.clientX >= Canvas.c_x) && if ((evt.clientX >= Canvas.getX()) &&
(evt.clientY >= Canvas.c_y) && (evt.clientY >= Canvas.getY()) &&
(evt.clientX < (Canvas.c_x + Canvas.c_wx)) && (evt.clientX < (Canvas.getX() + Canvas.c_wx)) &&
(evt.clientY < (Canvas.c_y + Canvas.c_wy))) { (evt.clientY < (Canvas.getY() + Canvas.c_wy))) {
e.stop(); e.stop();
return false; return false;
} }
...@@ -103,8 +112,6 @@ init: function (id, width, height, true_color, keyDown, keyUp, ...@@ -103,8 +112,6 @@ init: function (id, width, height, true_color, keyDown, keyUp,
document.body.addEvent('contextmenu', Canvas.ctxDisable); document.body.addEvent('contextmenu', Canvas.ctxDisable);
Canvas.resize(width, height); Canvas.resize(width, height);
Canvas.c_x = c.getPosition().x;
Canvas.c_y = c.getPosition().y;
Canvas.c_wx = c.getSize().x; Canvas.c_wx = c.getSize().x;
Canvas.c_wy = c.getSize().y; Canvas.c_wy = c.getSize().y;
Canvas.true_color = true_color; Canvas.true_color = true_color;
......
...@@ -1274,8 +1274,8 @@ keyUp: function (e) { ...@@ -1274,8 +1274,8 @@ keyUp: function (e) {
mouseDown: function(e) { mouseDown: function(e) {
var evt, x, y; var evt, x, y;
evt = e.event || window.event; evt = e.event || window.event;
x = (evt.clientX - Canvas.c_x); x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.c_y); y = (evt.clientY - Canvas.getY());
//console.log(">> mouseDown " + evt.which + "/" + evt.button + //console.log(">> mouseDown " + evt.which + "/" + evt.button +
// " " + x + "," + y); // " " + x + "," + y);
RFB.mouse_buttonMask |= 1 << evt.button; RFB.mouse_buttonMask |= 1 << evt.button;
...@@ -1287,8 +1287,8 @@ mouseDown: function(e) { ...@@ -1287,8 +1287,8 @@ mouseDown: function(e) {
mouseUp: function(e) { mouseUp: function(e) {
var evt, x, y; var evt, x, y;
evt = e.event || window.event; evt = e.event || window.event;
x = (evt.clientX - Canvas.c_x); x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.c_y); y = (evt.clientY - Canvas.getY());
//console.log(">> mouseUp " + evt.which + "/" + evt.button + //console.log(">> mouseUp " + evt.which + "/" + evt.button +
// " " + x + "," + y); // " " + x + "," + y);
RFB.mouse_buttonMask ^= 1 << evt.button; RFB.mouse_buttonMask ^= 1 << evt.button;
...@@ -1300,8 +1300,8 @@ mouseUp: function(e) { ...@@ -1300,8 +1300,8 @@ mouseUp: function(e) {
mouseMove: function(e) { mouseMove: function(e) {
var evt, x, y; var evt, x, y;
evt = e.event || window.event; evt = e.event || window.event;
x = (evt.clientX - Canvas.c_x); x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.c_y); y = (evt.clientY - Canvas.getY());
//console.log('>> mouseMove ' + x + "," + y); //console.log('>> mouseMove ' + x + "," + y);
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) ); RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
}, },
...@@ -1310,8 +1310,8 @@ mouseWheel: function (e) { ...@@ -1310,8 +1310,8 @@ mouseWheel: function (e) {
var evt, wheelData, bmask; var evt, wheelData, bmask;
evt = e.event || window.event; evt = e.event || window.event;
//e = e ? e : window.event; //e = e ? e : window.event;
x = (evt.clientX - Canvas.c_x); x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.c_y); y = (evt.clientY - Canvas.getY());
wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40; wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
//console.log('>> mouseWheel ' + wheelData + //console.log('>> mouseWheel ' + wheelData +
// " " + x + "," + y); // " " + 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