123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- "use strict";
- function ViewportControls(viewport)
- {
- this.viewport = viewport;
- var pressed = -1;
- var x = 0, y = 0;
- var dx = 0, dy = 0;
- var self = this;
-
- this.manager = new EventManager();
- this.manager.add(canvas, "contextmenu", function(event)
- {
- event.preventDefault();
- return false;
- });
- this.manager.add(canvas, "mousedown", function(event)
- {
- pressed = event.which;
- });
- this.manager.add(canvas, "mouseup", function(event)
- {
- pressed = -1;
- });
-
- this.manager.add(canvas, "mousemove", function(event)
- {
- dx = event.clientX - x;
- dy = event.clientY - y;
- x = event.clientX;
- y = event.clientY;
- // Mouse
- if(pressed === 3)
- {
- self.viewport.position.x += dx;
- self.viewport.position.y += dy;
- }
- });
- this.manager.add(canvas, "wheel", function(event)
- {
- self.viewport.scale -= (event.deltaY * 0.001) * self.viewport.scale;
- });
- }
- ViewportControls.prototype.create = function()
- {
- this.manager.create();
- };
- ViewportControls.prototype.destroy = function()
- {
- this.manager.destroy();
- };
|