waltheri/wgo.js

There is difference between cursor and stone position when edit mode of BasicPlayer.

swdrsk opened this issue · 1 comments

I think getMousePos() in wgo.js is incorrect.
(wgo.js (line: 1151))
e.layerX, e.layerY get negative values or huge values, depended on browser expansion rate and element width.
It may be bug.

thanks

var getMousePos = function(e) {
	// new hopefully better translation of coordinates
	var element = this.element, offsetX = 0, offsetY = 0;

	if (element.offsetParent) {
		do {
			offsetX += element.offsetLeft;
			offsetY += element.offsetTop;
		} while ((element = element.offsetParent));
	}

	var mx = e.pageX - offsetX;
	var my = e.pageY - offsetY

	var x, y;

	x = mx * this.pixelRatio;
	x -= this.left;
	x /= this.fieldWidth;
	x = Math.round(x);

	y = my * this.pixelRatio;
	y -= this.top;
	y /= this.fieldHeight;
	y = Math.round(y);

	return {
		x: x >= this.size ? -1 : x,
		y: y >= this.size ? -1 : y
	};
}

This will be better, I think.
https://stackoverflow.com/questions/3584357/incorrect-layerx-layery-values