Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.onmousemove = e => {
- canvasViewCursor ( { x: e.pageX, y: e.pageY } );
- }
- window.onclick = e => {
- canvasViewCursor ( { x: e.pageX, y: e.pageY } );
- [ cx, cy ] = [ cx + viewCursor.hover.x, cy + viewCursor.hover.y ];
- }
- function canvasViewCursor ( coords ) {
- canvasCursor.x = coords.x;
- canvasCursor.y = coords.y;
- var viewRangeMinX = gutterW;
- var viewRangeMinY = gutterH;
- var viewRangeMaxX = gutterW + (viewConstraints.viewMaxX - viewConstraints.viewMinX + 1 ) * tileW;
- var viewRangeMaxY = gutterH + (viewConstraints.viewMaxY - viewConstraints.viewMinY + 1 ) * tileH;
- if (
- (canvasCursor.x > viewRangeMinX)
- &&
- (canvasCursor.x < viewRangeMaxX)
- &&
- (canvasCursor.y > viewRangeMinY)
- &&
- (canvasCursor.y < viewRangeMaxY)
- )
- {
- x = canvasCursor.x;
- y = canvasCursor.y;
- x -= gutterW;
- y -= gutterH;
- x /= tileW;
- y /= tileH;
- x = Math.round(x);
- y = Math.round(y);
- x += viewConstraints.viewMinX;
- y += viewConstraints.viewMinY;
- }else{
- x = 0;
- y = 0;
- }
- if (oobView([x,y]) !== true){
- [x,y] = oobView([x,y]);
- }
- [ viewCursor.hover.x, viewCursor.hover.y ] =
- [ x, y ];
- console.log({x: x, y: y});
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement