Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- canvas.onmousemove = function(e)
- {
- var x = e.offsetX;
- var y = e.offsetY;
- var cx = canvas.width;
- var cy = canvas.height;
- if(x <= 0.1*cx && y <= 0.1*cy)
- {
- alert("Upper Left");
- //Move "viewport" to up and left (if possible)
- }
- //Additional Checks for location
- }
- var isDown = false; // whether mouse is pressed
- var startCoords = []; // 'grab' coordinates when pressing mouse
- var last = [0, 0]; // previous coordinates of mouse release
- canvas.onmousedown = function(e) {
- isDown = true;
- startCoords = [
- e.offsetX - last[0], // set start coordinates
- e.offsetY - last[1]
- ];
- };
- canvas.onmouseup = function(e) {
- isDown = false;
- last = [
- e.offsetX - startCoords[0], // set last coordinates
- e.offsetY - startCoords[1]
- ];
- };
- canvas.onmousemove = function(e)
- {
- if(!isDown) return; // don't pan if mouse is not pressed
- var x = e.offsetX;
- var y = e.offsetY;
- // set the canvas' transformation matrix by setting the amount of movement:
- // 1 0 dx
- // 0 1 dy
- // 0 0 1
- ctx.setTransform(1, 0, 0, 1,
- x - startCoords[0], y - startCoords[1]);
- render(); // render to show changes
- }
Add Comment
Please, Sign In to add comment