trenette.js
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -1,1 +0,1 @@ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).Trenette={})}(this,function(t){"use strict";function n(){this.events=[]}function s(t,i){this.x=t||0,this.y=i||0}function l(t){void 0!==t?this.m=t:this.identity()}function i(){}function p(){this.uuid=i.generate(),this.children=[],this.parent=null,this.level=0,this.position=new s(0,0),this.origin=new s(0,0),this.scale=new s(1,1),this.rotation=0,this.visible=!0,this.layer=0,this.matrix=new l,this.globalMatrix=new l,this.inverseGlobalMatrix=new l,this.masks=[],this.matrixNeedsUpdate=!0,this.draggable=!1,this.pointerEvents=!0,this.ignoreViewport=!1,this.saveContextState=!0,this.restoreContextState=!0,this.pointerInside=!1,this.beingDragged=!1}function r(){this.pressed=!1,this.justPressed=!1,this.justReleased=!1}function y(t){this._keys=new Array(5),this._position=new s(0,0),this._positionUpdated=!1,this._delta=new s(0,0),this._wheel=0,this._wheelUpdated=!1,this._doubleClicked=new Array(5),this.keys=new Array(5),this.position=new s(0,0),this.delta=new s(0,0),this.wheel=0,this.doubleClicked=new Array(5),this.domElement=void 0!==t?t:window,this.canvas=null,this.events=new n;for(var i=0;i<5;i++)this._doubleClicked[i]=!1,this.doubleClicked[i]=!1,this._keys[i]=new r,this.keys[i]=new r;var e=this;if(void 0!==window.onmousewheel?this.events.add(this.domElement,"mousewheel",function(t){e._wheel=t.deltaY,e._wheelUpdated=!0}):void 0!==window.addEventListener?this.events.add(this.domElement,"DOMMouseScroll",function(t){e._wheel=30*t.detail,e._wheelUpdated=!0}):this.events.add(this.domElement,"wheel",function(t){e._wheel=t.deltaY,e._wheelUpdated=!0}),void 0!==window.ontouchstart||0<navigator.msMaxTouchPoints){var o=new s(0,0);this.events.add(this.domElement,"touchstart",function(t){var i=t.touches[0];e.updatePosition(i.clientX,i.clientY,0,0),e.updateKey(y.LEFT,r.DOWN),o.set(i.clientX,i.clientY)}),this.events.add(this.domElement,"touchend",function(t){e.updateKey(y.LEFT,r.UP)}),this.events.add(this.domElement,"touchcancel",function(t){e.updateKey(y.LEFT,r.UP)}),this.events.add(document.body,"touchmove",function(t){var i=t.touches[0];e.updatePosition(i.clientX,i.clientY,i.clientX-o.x,i.clientY-o.y),o.set(i.clientX,i.clientY)})}this.events.add(this.domElement,"mousemove",function(t){e.updatePosition(t.clientX,t.clientY,t.movementX,t.movementY)}),this.events.add(this.domElement,"mousedown",function(t){e.updateKey(t.which-1,r.DOWN)}),this.events.add(this.domElement,"mouseup",function(t){e.updateKey(t.which-1,r.UP)}),this.events.add(this.domElement,"dragstart",function(t){e.updateKey(t.which-1,r.UP)}),this.events.add(this.domElement,"dblclick",function(t){e._doubleClicked[t.which-1]=!0}),this.create()}function e(t,i){void 0===i&&(i={alpha:!0}),this.canvas=t,this.context=t.getContext("2d",{alpha:i.alpha}),this.context.imageSmoothingEnabled=!0,this.context.globalCompositeOperation="source-over",this.pointer=new y,this.pointer.setCanvas(t),this.autoClear=!0}function o(){this.uuid=i.generate(),this.position=new s(0,0),this.scale=1,this.rotation=0,this.matrix=new l,this.inverseMatrix=new l,this.matrixNeedsUpdate=!0,this.moveOnScale=!0,this.rotationPoint=null}function h(t,i){this.min=void 0!==t?t:new s,this.max=void 0!==i?i:new s}function a(){p.call(this)}function m(){a.call(this),this.box=new h(new s(-50,-35),new s(50,35)),this.invert=!1}function c(){p.call(this),this.radius=10,this.strokeStyle="#000000",this.lineWidth=1,this.fillStyle="#FFFFFF"}function u(){}function d(){p.call(this),this.box=new h(new s(-50,-35),new s(50,35)),this.strokeStyle="#000000",this.lineWidth=1,this.fillStyle="#FFFFFF"}function x(){p.call(this),this.from=new s,this.to=new s,this.strokeStyle="#000000",this.dashPattern=[5,5],this.lineWidth=1}function f(){p.call(this),this.text="",this.font="16px Arial",this.color="#000000",this.textAlign="center"}function v(t){p.call(this),this.box=new h,this.image=document.createElement("img"),void 0!==t&&this.setImage(t)}function b(t,i){p.call(this),this.parentDOM=t,this.element=document.createElement("div"),this.element.style.transformStyle="preserve-3d",this.element.style.position="absolute",this.element.style.top="0px",this.element.style.bottom="0px",this.element.style.transformOrigin="0px 0px",this.element.style.overflow="auto",this.element.style.pointerEvents="none",this.size=new s(100,100)}function g(t){p.call(this),this.box=new h,this.image=document.createElement("img"),this.repetition="repeat",void 0!==t&&this.setImage(t)}function w(){p.call(this),this.box=new h(new s(-50,-35),new s(50,35)),this.strokeStyle="rgb(0, 153, 255)",this.lineWidth=1,this.fillStyle="rgba(0, 153, 255, 0.3)",this.min=0,this.max=10,this.data=[]}function P(){p.call(this),this.from=new s,this.fromCp=new s,this.to=new s,this.toCp=new s,this.strokeStyle="#000000",this.dashPattern=[5,5],this.lineWidth=1}n.prototype.add=function(t,i,e){this.events.push([t,i,e,!1])},n.prototype.clear=function(){this.destroy(),this.events=[]},n.prototype.create=function(){for(var t=0;t<this.events.length;t++){var i=this.events[t];i[0].addEventListener(i[1],i[2]),i[3]=!0}},n.prototype.destroy=function(){for(var t=0;t<this.events.length;t++){var i=this.events[t];i[0].removeEventListener(i[1],i[2]),i[3]=!1}},s.prototype.set=function(t,i){this.x=t,this.y=i},s.prototype.setScalar=function(t){this.x=t,this.y=t},s.prototype.clone=function(){return new s(this.x,this.y)},s.prototype.copy=function(t){this.x=t.x,this.y=t.y},s.prototype.add=function(t){this.x+=t.x,this.y+=t.y},s.prototype.addScalar=function(t){this.x+=t,this.y+=t},s.prototype.addVectors=function(t,i){this.x=t.x+i.x,this.y=t.y+i.y},s.prototype.addScaledVector=function(t,i){this.x+=t.x*i,this.y+=t.y*i},s.prototype.sub=function(t){this.x-=t.x,this.y-=t.y},s.prototype.subScalar=function(t){this.x-=t,this.y-=t},s.prototype.subVectors=function(t,i){this.x=t.x-i.x,this.y=t.y-i.y},s.prototype.multiply=function(t){this.x*=t.x,this.y*=t.y},s.prototype.multiplyScalar=function(t){this.x*=t,this.y*=t},s.prototype.divide=function(t){this.x/=t.x,this.y/=t.y},s.prototype.divideScalar=function(t){return this.multiplyScalar(1/t)},s.prototype.min=function(t){this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y)},s.prototype.max=function(t){this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y)},s.prototype.clamp=function(t,i){this.x=Math.max(t.x,Math.min(i.x,this.x)),this.y=Math.max(t.y,Math.min(i.y,this.y))},s.prototype.clampScalar=function(t,i){this.x=Math.max(t,Math.min(i,this.x)),this.y=Math.max(t,Math.min(i,this.y))},s.prototype.clampLength=function(t,i){var e=this.length();return this.divideScalar(e||1).multiplyScalar(Math.max(t,Math.min(i,e)))},s.prototype.floor=function(){this.x=Math.floor(this.x),this.y=Math.floor(this.y)},s.prototype.ceil=function(){this.x=Math.ceil(this.x),this.y=Math.ceil(this.y)},s.prototype.round=function(){this.x=Math.round(this.x),this.y=Math.round(this.y)},s.prototype.roundToZero=function(){this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y)},s.prototype.negate=function(){return this.x=-this.x,this.y=-this.y,this},s.prototype.dot=function(t){return this.x*t.x+this.y*t.y},s.prototype.cross=function(t){return this.x*t.y-this.y*t.x},s.prototype.lengthSq=function(){return this.x*this.x+this.y*this.y},s.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},s.prototype.manhattanLength=function(){return Math.abs(this.x)+Math.abs(this.y)},s.prototype.normalize=function(){return this.divideScalar(this.length()||1)},s.prototype.angle=function(){var t=Math.atan2(this.y,this.x);return t<0&&(t+=2*Math.PI),t},s.prototype.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},s.prototype.distanceToSquared=function(t){var i=this.x-t.x,e=this.y-t.y;return i*i+e*e},s.prototype.manhattanDistanceTo=function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)},s.prototype.setLength=function(t){return this.normalize().multiplyScalar(t)},s.prototype.lerp=function(t,i){this.x+=(t.x-this.x)*i,this.y+=(t.y-this.y)*i},s.prototype.lerpVectors=function(t,i,e){return this.subVectors(i,t).multiplyScalar(e).add(t)},s.prototype.equals=function(t){return t.x===this.x&&t.y===this.y},s.prototype.fromArray=function(t,i){void 0===i&&(i=0),this.x=t[i],this.y=t[i+1]},s.prototype.toArray=function(t,i){return void 0===t&&(t=[]),void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t},s.prototype.rotateAround=function(t,i){var e=Math.cos(i),o=Math.sin(i),n=this.x-t.x,s=this.y-t.y;this.x=n*e-s*o+t.x,this.y=n*o+s*e+t.y},l.prototype.copy=function(t){this.m=t.m.slice(0)},l.prototype.clone=function(){return new l(this.m.slice(0))},l.prototype.identity=function(){this.m=[1,0,0,1,0,0]},l.prototype.multiply=function(t){var i=this.m[0]*t.m[0]+this.m[2]*t.m[1],e=this.m[1]*t.m[0]+this.m[3]*t.m[1],o=this.m[0]*t.m[2]+this.m[2]*t.m[3],n=this.m[1]*t.m[2]+this.m[3]*t.m[3],s=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],r=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];this.m=[i,e,o,n,s,r]},l.prototype.premultiply=function(t){var i=t.m[0]*this.m[0]+t.m[2]*this.m[1],e=t.m[1]*this.m[0]+t.m[3]*this.m[1],o=t.m[0]*this.m[2]+t.m[2]*this.m[3],n=t.m[1]*this.m[2]+t.m[3]*this.m[3],s=t.m[0]*this.m[4]+t.m[2]*this.m[5]+t.m[4],r=t.m[1]*this.m[4]+t.m[3]*this.m[5]+t.m[5];this.m=[i,e,o,n,s,r]},l.prototype.compose=function(t,i,e,o,n,s,r){if(this.m=[1,0,0,1,t,i],0!==r){var h=Math.cos(r),a=Math.sin(r);this.multiply(new l([h,a,-a,h,0,0]))}0===n&&0===s||this.multiply(new l([1,0,0,1,-n,-s])),1===e&&1===o||this.scale(e,o)},l.prototype.translate=function(t,i){this.m[4]+=this.m[0]*t+this.m[2]*i,this.m[5]+=this.m[1]*t+this.m[3]*i},l.prototype.rotate=function(t){var i=Math.cos(t),e=Math.sin(t),o=this.m[0]*i+this.m[2]*e,n=this.m[1]*i+this.m[3]*e,s=this.m[0]*-e+this.m[2]*i,r=this.m[1]*-e+this.m[3]*i;this.m[0]=o,this.m[1]=n,this.m[2]=s,this.m[3]=r},l.prototype.scale=function(t,i){this.m[0]*=t,this.m[1]*=t,this.m[2]*=i,this.m[3]*=i},l.prototype.setPosition=function(t,i){this.m[4]=t,this.m[5]=i},l.prototype.getScale=function(){return new s(this.m[0],this.m[3])},l.prototype.getPosition=function(){return new s(this.m[4],this.m[5])},l.prototype.skew=function(t,i){this.multiply(new l([1,Math.tan(i),Math.tan(t),1,0,0]))},l.prototype.determinant=function(){return 1/(this.m[0]*this.m[3]-this.m[1]*this.m[2])},l.prototype.getInverse=function(){var t=this.determinant();return new l([this.m[3]*t,-this.m[1]*t,-this.m[2]*t,this.m[0]*t,t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),t*(this.m[1]*this.m[4]-this.m[0]*this.m[5])])},l.prototype.transformPoint=function(t){return new s(t.x*this.m[0]+t.y*this.m[2]+this.m[4],t.x*this.m[1]+t.y*this.m[3]+this.m[5])},l.prototype.setContextTransform=function(t){t.setTransform(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5])},l.prototype.tranformContext=function(t){t.transform(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5])},l.prototype.cssTransform=function(){return"matrix("+this.m[0]+","+this.m[1]+","+this.m[2]+","+this.m[3]+","+this.m[4]+","+this.m[5]+")"},i.generate=function(){for(var n=[],t=0;t<256;t++)n[t]=(t<16?"0":"")+t.toString(16);return function(){var t=4294967295*Math.random()|0,i=4294967295*Math.random()|0,e=4294967295*Math.random()|0,o=4294967295*Math.random()|0;return(n[255&t]+n[t>>8&255]+n[t>>16&255]+n[t>>24&255]+"-"+n[255&i]+n[i>>8&255]+"-"+n[i>>16&15|64]+n[i>>24&255]+"-"+n[63&e|128]+n[e>>8&255]+"-"+n[e>>16&255]+n[e>>24&255]+n[255&o]+n[o>>8&255]+n[o>>16&255]+n[o>>24&255]).toUpperCase()}}(),p.prototype.traverse=function(t){t(this);for(var i=this.children,e=0;e<i.length;e++)i[e].traverse(t)},p.prototype.add=function(t){t.parent=this,t.level=this.level+1,t.traverse(function(t){null!==t.onAdd&&t.onAdd(this)}),this.children.push(t)},p.prototype.remove=function(t){var i=this.children.indexOf(t);-1!==i&&((t=this.children[i]).parent=null,t.level=0,t.traverse(function(t){null!==t.onRemove&&t.onRemove(this)}),this.children.splice(i,1))},p.prototype.isInside=function(t){return!1},p.prototype.updateMatrix=function(t){this.matrixNeedsUpdate&&(this.matrix.compose(this.position.x,this.position.y,this.scale.x,this.scale.y,this.origin.x,this.origin.y,this.rotation),this.globalMatrix.copy(this.matrix),null!==this.parent&&this.globalMatrix.premultiply(this.parent.globalMatrix),this.inverseGlobalMatrix=this.globalMatrix.getInverse())},p.prototype.transform=function(t,i){this.globalMatrix.tranformContext(t)},p.prototype.draw=function(t,i,e){},p.prototype.onPointerDrag=function(t,i,e){this.position.add(e)},p.prototype.onAdd=null,p.prototype.onRemove=null,p.prototype.onUpdate=null,p.prototype.onPointerEnter=null,p.prototype.onPointerLeave=null,p.prototype.onPointerOver=null,p.prototype.onButtonPressed=null,p.prototype.onButtonDown=null,p.prototype.onButtonUp=null,r.DOWN=-1,r.UP=1,r.RESET=0,(r.prototype.constructor=r).prototype.update=function(t){this.justPressed=!1,this.justReleased=!1,t===r.DOWN?(!1===this.pressed&&(this.justPressed=!0),this.pressed=!0):t===r.UP?(this.pressed&&(this.justReleased=!0),this.pressed=!1):t===r.RESET&&(this.justReleased=!1,this.justPressed=!1)},r.prototype.set=function(t,i,e){this.justPressed=t,this.pressed=i,this.justReleased=e},r.prototype.reset=function(){this.justPressed=!1,this.pressed=!1,this.justReleased=!1},((y.prototype=y).constructor=y).LEFT=0,y.MIDDLE=1,y.RIGHT=2,y.BACK=3,y.FORWARD=4,y.setCanvas=function(t){(this.canvas=t).pointerInside=!1,t.addEventListener("mouseenter",function(){this.pointerInside=!0}),t.addEventListener("mouseleave",function(){this.pointerInside=!1})},y.insideCanvas=function(){return null!==this.canvas&&this.canvas.pointerInside},y.buttonPressed=function(t){return this.keys[t].pressed},y.buttonDoubleClicked=function(t){return this.doubleClicked[t]},y.buttonJustPressed=function(t){return this.keys[t].justPressed},y.buttonJustReleased=function(t){return this.keys[t].justReleased},y.updatePosition=function(t,i,e,o){if(null!==this.canvas){var n=this.canvas.getBoundingClientRect();t-=n.left,i-=n.top}this._position.set(t,i),this._delta.x+=e,this._delta.y+=o,this._positionUpdated=!0},y.updateKey=function(t,i){-1<t&&this._keys[t].update(i)},y.update=function(){for(var t=0;t<5;t++)this._keys[t].justPressed&&this.keys[t].justPressed&&(this._keys[t].justPressed=!1),this._keys[t].justReleased&&this.keys[t].justReleased&&(this._keys[t].justReleased=!1),this.keys[t].set(this._keys[t].justPressed,this._keys[t].pressed,this._keys[t].justReleased),!0===this._doubleClicked[t]?(this.doubleClicked[t]=!0,this._doubleClicked[t]=!1):this.doubleClicked[t]=!1;this._wheelUpdated?(this.wheel=this._wheel,this._wheelUpdated=!1):this.wheel=0,this._positionUpdated?(this.delta.copy(this._delta),this.position.copy(this._position),this._delta.set(0,0),this._positionUpdated=!1):(this.delta.x=0,this.delta.y=0)},y.create=function(){this.events.create()},y.dispose=function(){this.events.destroy()},e.prototype.createRenderLoop=function(i,e,o){var n=this;!function t(){void 0!==o&&o(),n.update(i,e),requestAnimationFrame(t)}()},e.prototype.update=function(t,i){var e=[];t.traverse(function(t){t.visible&&e.push(t)}),e.sort(function(t,i){return i.layer===t.layer?i.level-t.level:i.layer-t.layer});var o=this.pointer;o.update(),i.updateControls(o),i.updateMatrix();for(var n=o.position.clone(),s=i.inverseMatrix.transformPoint(n),r=0;r<e.length;r++){if((a=e[r]).pointerEvents){var h=a.inverseGlobalMatrix.transformPoint(a.ignoreViewport?n:s);if(a.isInside(h)){if(a.pointerInside||null===a.onPointerEnter||a.onPointerEnter(o,i),null!==a.onPointerOver&&a.onPointerOver(o,i),o.buttonPressed(y.LEFT)&&null!==a.onButtonPressed&&a.onButtonPressed(o,i),o.buttonJustReleased(y.LEFT)&&null!==a.onButtonUp&&a.onButtonUp(o,i),o.buttonJustPressed(y.LEFT)&&(null!==a.onButtonDown&&a.onButtonDown(o,i),a.draggable)){a.beingDragged=!0;break}a.pointerInside=!0}else a.pointerInside&&(null!==a.onPointerLeave&&a.onPointerLeave(o,i),a.pointerInside=!1);o.buttonJustReleased(y.LEFT)&&a.draggable&&(a.beingDragged=!1)}}for(r=0;r<e.length;r++){var a;if((a=e[r]).beingDragged){var l=o.position.clone();l.sub(o.delta);var p=i.inverseMatrix.transformPoint(o.position),m=i.inverseMatrix.transformPoint(l);p.sub(m),null!==a.onPointerDrag&&a.onPointerDrag(o,i,p)}null!==a.onUpdate&&a.onUpdate()}t.traverse(function(t){t.updateMatrix()}),this.context.setTransform(1,0,0,1,0,0),this.autoClear&&this.context.clearRect(0,0,this.canvas.width,this.canvas.height);for(r=e.length-1;0<=r;r--)if(!e[r].isMask){e[r].saveContextState&&this.context.save();for(var c=e[r].masks,u=0;u<c.length;u++)c[u].ignoreViewport||i.matrix.setContextTransform(this.context),c[u].transform(this.context,i,this.canvas),c[u].clip(this.context,i,this.canvas);e[r].ignoreViewport?0<c.length&&this.context.setTransform(1,0,0,1,0,0):i.matrix.setContextTransform(this.context),e[r].transform(this.context,i,this.canvas),e[r].draw(this.context,i,this.canvas),e[r].restoreContextState&&this.context.restore()}},o.prototype.updateControls=function(t){if(0!==t.wheel&&(this.scale-=.001*t.wheel*this.scale,this.moveOnScale)){var i=t.wheel,e=t.canvas.width/2,o=t.canvas.height/2;this.position.x+=(t.position.x-e)/e*i,this.position.y+=(t.position.y-o)/o*i}t.buttonPressed(y.RIGHT)&&t.buttonPressed(y.LEFT)?this.rotation+=.001*t.delta.angle():t.buttonPressed(y.RIGHT)&&(this.position.x+=t.delta.x,this.position.y+=t.delta.y)},o.prototype.updateMatrix=function(){this.matrixNeedsUpdate&&(this.matrix.compose(this.position.x,this.position.y,this.scale,this.scale,0,0,this.rotation),this.inverseMatrix=this.matrix.getInverse())},o.prototype.centerObject=function(t,i){var e=t.globalMatrix.transformPoint(new s);e.multiplyScalar(-this.scale),e.x+=i.width/2,e.y+=i.height/2,this.position.copy(e)},h.prototype.set=function(t,i){return this.min.copy(t),this.max.copy(i),this},h.prototype.setFromPoints=function(t){this.min=new s(1/0,1/0),this.max=new s(-1/0,-1/0);for(var i=0,e=t.length;i<e;i++)this.expandByPoint(t[i]);return this},h.prototype.setFromCenterAndSize=function(t,i){var e=(new s).copy(i).multiplyScalar(.5);return this.min.copy(t).sub(e),this.max.copy(t).add(e),this},h.prototype.clone=function(){var t=new h;return t.copy(this),t},h.prototype.copy=function(t){this.min.copy(t.min),this.max.copy(t.max)},h.prototype.isEmpty=function(){return this.max.x<this.min.x||this.max.y<this.min.y},h.prototype.getCenter=function(t){return void 0===t&&(t=new s),this.isEmpty()?t.set(0,0):t.addVectors(this.min,this.max).multiplyScalar(.5),t},h.prototype.getSize=function(t){return void 0===t&&(t=new s),this.isEmpty()?t.set(0,0):t.subVectors(this.max,this.min),t},h.prototype.expandByPoint=function(t){return this.min.min(t),this.max.max(t),this},h.prototype.expandByVector=function(t){this.min.sub(t),this.max.add(t)},h.prototype.expandByScalar=function(t){this.min.addScalar(-t),this.max.addScalar(t)},h.prototype.containsPoint=function(t){return!(t.x<this.min.x||t.x>this.max.x||t.y<this.min.y||t.y>this.max.y)},h.prototype.containsBox=function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y},h.prototype.intersectsBox=function(t){return!(t.max.x<this.min.x||t.min.x>this.max.x||t.max.y<this.min.y||t.min.y>this.max.y)},h.prototype.clampPoint=function(t,i){return void 0===i&&(i=new s),i.copy(t).clamp(this.min,this.max),i},h.prototype.distanceToPoint=function(t){return(new s).copy(t).clamp(this.min,this.max).sub(t).length()},h.prototype.intersect=function(t){this.min.max(t.min),this.max.min(t.max)},h.prototype.union=function(t){this.min.min(t.min),this.max.max(t.max)},h.prototype.translate=function(t){this.min.add(t),this.max.add(t)},h.prototype.equals=function(t){return t.min.equals(this.min)&&t.max.equals(this.max)},(a.prototype=Object.create(p.prototype)).isMask=!0,a.prototype.clip=function(t,i,e){},(m.prototype=Object.create(a.prototype)).isInside=function(t){return this.box.containsPoint(t)},m.prototype.clip=function(t,i,e){t.beginPath();var o=this.box.max.x-this.box.min.x;if(this.invert)t.rect(this.box.min.x-1e4,-5e3,1e4,1e4),t.rect(this.box.max.x,-5e3,1e4,1e4),t.rect(this.box.min.x,this.box.min.y-1e4,o,1e4),t.rect(this.box.min.x,this.box.max.y,o,1e4);else{var n=this.box.max.y-this.box.min.y;t.fillRect(this.box.min.x,this.box.min.y,o,n)}t.clip()},(c.prototype=Object.create(p.prototype)).isInside=function(t){return t.length()<=this.radius},c.prototype.onPointerEnter=function(t,i){this.fillStyle="#CCCCCC"},c.prototype.onPointerLeave=function(t,i){this.fillStyle="#FFFFFF"},c.prototype.draw=function(t,i,e){t.beginPath(),t.arc(0,0,this.radius,0,2*Math.PI),t.fillStyle=this.fillStyle,t.fill(),t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.stroke()},u.rotateTool=function(o){var t=new c;t.radius=4,t.layer=o.layer+1,t.onPointerDrag=function(t,i,e){o.rotation+=.001*e.x},o.add(t)},u.boxResizeTool=function(o){if(void 0!==o.box){var n=new c;n.radius=4,n.layer=o.layer+1,n.draggable=!0,n.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.min.copy(n.position),a()},o.add(n);var s=new c;s.radius=4,s.layer=o.layer+1,s.draggable=!0,s.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.max.x=s.position.x,o.box.min.y=s.position.y,a()},o.add(s);var r=new c;r.radius=4,r.layer=o.layer+1,r.draggable=!0,r.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.max.copy(r.position),a()},o.add(r);var h=new c;h.radius=4,h.layer=o.layer+1,h.draggable=!0,h.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.min.x=h.position.x,o.box.max.y=h.position.y,a()},o.add(h),a()}else console.warn("trenette.js: Helpers.boxResizeTool(), object box property missing.");function a(){n.position.copy(o.box.min),r.position.copy(o.box.max),s.position.set(o.box.max.x,o.box.min.y),h.position.set(o.box.min.x,o.box.max.y)}},(d.prototype=Object.create(p.prototype)).onPointerEnter=function(t,i){this.fillStyle="#CCCCCC"},d.prototype.onPointerLeave=function(t,i){this.fillStyle="#FFFFFF"},d.prototype.isInside=function(t){return this.box.containsPoint(t)},d.prototype.draw=function(t,i,e){var o=this.box.max.x-this.box.min.x,n=this.box.max.y-this.box.min.y;t.fillStyle=this.fillStyle,t.fillRect(this.box.min.x,this.box.min.y,o,n),t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.strokeRect(this.box.min.x,this.box.min.y,o,n)},(x.prototype=Object.create(p.prototype)).draw=function(t,i,e){t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.setLineDash(this.dashPattern),t.beginPath(),t.moveTo(this.from.x,this.from.y),t.lineTo(this.to.x,this.to.y),t.stroke()},(f.prototype=Object.create(p.prototype)).draw=function(t,i,e){t.font=this.font,t.textAlign=this.textAlign,t.fillStyle=this.color,t.textBaseline="middle",t.fillText(this.text,0,0)},(v.prototype=Object.create(p.prototype)).setImage=function(t){var i=this;this.image.onload=function(){i.box.min.set(0,0),i.box.max.set(this.naturalWidth,this.naturalHeight)},this.image.src=t},v.prototype.isInside=function(t){return this.box.containsPoint(t)},v.prototype.draw=function(t,i,e){0<this.image.src.length&&t.drawImage(this.image,0,0,this.image.naturalWidth,this.image.naturalHeight,this.box.min.x,this.box.min.y,this.box.max.x-this.box.min.x,this.box.max.y-this.box.min.y)},(b.prototype=Object.create(p.prototype)).onAdd=function(){this.parentDOM.appendChild(this.element)},b.prototype.onRemove=function(){this.parentDOM.removeChild(this.element)},b.prototype.transform=function(t,i,e){var o=i.matrix.clone();o.multiply(this.globalMatrix),this.element.style.transform=o.cssTransform(),this.element.style.width=this.size.x+"px",this.element.style.height=this.size.y+"px",this.element.style.display=this.visible?"block":"none"},(g.prototype=Object.create(p.prototype)).setImage=function(t){var i=this;this.image.onload=function(){i.box.min.set(0,0),i.box.max.set(this.naturalWidth,this.naturalHeight)},this.image.src=t},g.prototype.isInside=function(t){return this.box.containsPoint(t)},g.prototype.draw=function(t,i,e){var o=this.box.max.x-this.box.min.x,n=this.box.max.y-this.box.min.y;if(0<this.image.src.length){var s=t.createPattern(this.image,this.repetition);t.fillStyle=s,t.fillRect(this.box.min.x,this.box.min.y,o,n)}},(w.prototype=Object.create(p.prototype)).isInside=function(t){return this.box.containsPoint(t)},w.prototype.draw=function(t,i,e){if(0!==this.data.length){var o=this.box.max.x-this.box.min.x,n=this.box.max.y-this.box.min.y;t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.beginPath();var s=o/(this.data.length-1),r=this.max-this.min;t.moveTo(this.box.min.x,this.box.max.y-(this.data[0]-this.min)/r*n);for(var h=1,a=s;h<this.data.length;a+=s,h++)t.lineTo(this.box.min.x+a,this.box.max.y-(this.data[h]-this.min)/r*n);t.stroke(),null!==this.fillStyle&&(t.fillStyle=this.fillStyle,t.lineTo(this.box.max.x,this.box.max.y),t.lineTo(this.box.min.x,this.box.max.y),t.fill())}},P.prototype=Object.create(p.prototype),P.curveHelper=function(o){var n=new c;n.radius=3,n.layer=o.layer+1,n.draggable=!0,n.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.fromCp.copy(n.position)},o.parent.add(n);var t=new x;t.from=o.from,t.to=o.fromCp,o.parent.add(t);var s=new c;s.radius=3,s.layer=o.layer+1,s.draggable=!0,s.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.toCp.copy(s.position)},o.parent.add(s);var i=new x;i.from=o.to,i.to=o.toCp,o.parent.add(i)},P.prototype.draw=function(t,i,e){t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.setLineDash(this.dashPattern),t.beginPath(),t.moveTo(this.from.x,this.from.y),t.bezierCurveTo(this.fromCp.x,this.fromCp.y,this.toCp.x,this.toCp.y,this.to.x,this.to.y),t.stroke()},t.BezierCurve=P,t.Box=d,t.Box2=h,t.BoxMask=m,t.Circle=c,t.DOM=b,t.EventManager=n,t.Graph=w,t.Helpers=u,t.Image=v,t.Key=r,t.Line=x,t.Mask=a,t.Matrix=l,t.Object2D=p,t.Pattern=g,t.Pointer=y,t.Renderer=e,t.Text=f,t.UUID=i,t.Vector2=s,t.Viewport=o,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).Trenette={})}(this,function(t){"use strict";function n(){this.events=[]}function s(t,i){this.x=t||0,this.y=i||0}function l(t){void 0!==t?this.m=t:this.identity()}function i(){}function p(){this.uuid=i.generate(),this.children=[],this.parent=null,this.level=0,this.position=new s(0,0),this.origin=new s(0,0),this.scale=new s(1,1),this.rotation=0,this.visible=!0,this.layer=0,this.matrix=new l,this.globalMatrix=new l,this.inverseGlobalMatrix=new l,this.masks=[],this.matrixNeedsUpdate=!0,this.draggable=!1,this.pointerEvents=!0,this.ignoreViewport=!1,this.saveContextState=!0,this.restoreContextState=!0,this.pointerInside=!1,this.beingDragged=!1}function r(){this.pressed=!1,this.justPressed=!1,this.justReleased=!1}function y(t){this._keys=new Array(5),this._position=new s(0,0),this._positionUpdated=!1,this._delta=new s(0,0),this._wheel=0,this._wheelUpdated=!1,this._doubleClicked=new Array(5),this.keys=new Array(5),this.position=new s(0,0),this.delta=new s(0,0),this.wheel=0,this.doubleClicked=new Array(5),this.domElement=void 0!==t?t:window,this.canvas=null,this.events=new n;for(var i=0;i<5;i++)this._doubleClicked[i]=!1,this.doubleClicked[i]=!1,this._keys[i]=new r,this.keys[i]=new r;var e=this;if(void 0!==window.onmousewheel?this.events.add(this.domElement,"mousewheel",function(t){e._wheel=t.deltaY,e._wheelUpdated=!0}):void 0!==window.addEventListener?this.events.add(this.domElement,"DOMMouseScroll",function(t){e._wheel=30*t.detail,e._wheelUpdated=!0}):this.events.add(this.domElement,"wheel",function(t){e._wheel=t.deltaY,e._wheelUpdated=!0}),void 0!==window.ontouchstart||0<navigator.msMaxTouchPoints){var o=new s(0,0);this.events.add(this.domElement,"touchstart",function(t){var i=t.touches[0];e.updatePosition(i.clientX,i.clientY,0,0),e.updateKey(y.LEFT,r.DOWN),o.set(i.clientX,i.clientY)}),this.events.add(this.domElement,"touchend",function(t){e.updateKey(y.LEFT,r.UP)}),this.events.add(this.domElement,"touchcancel",function(t){e.updateKey(y.LEFT,r.UP)}),this.events.add(document.body,"touchmove",function(t){var i=t.touches[0];e.updatePosition(i.clientX,i.clientY,i.clientX-o.x,i.clientY-o.y),o.set(i.clientX,i.clientY)})}this.events.add(this.domElement,"mousemove",function(t){e.updatePosition(t.clientX,t.clientY,t.movementX,t.movementY)}),this.events.add(this.domElement,"mousedown",function(t){e.updateKey(t.which-1,r.DOWN)}),this.events.add(this.domElement,"mouseup",function(t){e.updateKey(t.which-1,r.UP)}),this.events.add(this.domElement,"dragstart",function(t){e.updateKey(t.which-1,r.UP)}),this.events.add(this.domElement,"dblclick",function(t){e._doubleClicked[t.which-1]=!0}),this.create()}function e(){this.uuid=i.generate(),this.position=new s(0,0),this.scale=1,this.rotation=0,this.matrix=new l,this.inverseMatrix=new l,this.matrixNeedsUpdate=!0,this.moveOnScale=!0,this.rotationPoint=null}function h(t){this.viewport=t,this.dragButton=y.RIGHT,this.allowScale=!0,this.moveOnScale=!0,this.allowRotation=!1,this.rotationPoint=null,this.rotationInitial=0}function o(t,i){void 0===i&&(i={alpha:!0}),this.canvas=t,this.context=t.getContext("2d",{alpha:i.alpha}),this.context.imageSmoothingEnabled=!0,this.context.globalCompositeOperation="source-over",this.pointer=new y,this.pointer.setCanvas(t),this.autoClear=!0}function a(t,i){this.min=void 0!==t?t:new s,this.max=void 0!==i?i:new s}function m(){p.call(this)}function c(){m.call(this),this.box=new a(new s(-50,-35),new s(50,35)),this.invert=!1}function u(){p.call(this),this.radius=10,this.strokeStyle="#000000",this.lineWidth=1,this.fillStyle="#FFFFFF"}function d(){}function x(){p.call(this),this.box=new a(new s(-50,-35),new s(50,35)),this.strokeStyle="#000000",this.lineWidth=1,this.fillStyle="#FFFFFF"}function f(){p.call(this),this.from=new s,this.to=new s,this.strokeStyle="#000000",this.dashPattern=[5,5],this.lineWidth=1}function v(){p.call(this),this.text="",this.font="16px Arial",this.color="#000000",this.textAlign="center"}function b(t){p.call(this),this.box=new a,this.image=document.createElement("img"),void 0!==t&&this.setImage(t)}function g(t,i){p.call(this),this.parentDOM=t,this.element=document.createElement("div"),this.element.style.transformStyle="preserve-3d",this.element.style.position="absolute",this.element.style.top="0px",this.element.style.bottom="0px",this.element.style.transformOrigin="0px 0px",this.element.style.overflow="auto",this.element.style.pointerEvents="none",this.size=new s(100,100)}function w(t){p.call(this),this.box=new a,this.image=document.createElement("img"),this.repetition="repeat",void 0!==t&&this.setImage(t)}function P(){p.call(this),this.box=new a(new s(-50,-35),new s(50,35)),this.strokeStyle="rgb(0, 153, 255)",this.lineWidth=1,this.fillStyle="rgba(0, 153, 255, 0.3)",this.min=0,this.max=10,this.data=[]}function M(){p.call(this),this.from=new s,this.fromCp=new s,this.to=new s,this.toCp=new s,this.strokeStyle="#000000",this.dashPattern=[5,5],this.lineWidth=1}n.prototype.add=function(t,i,e){this.events.push([t,i,e,!1])},n.prototype.clear=function(){this.destroy(),this.events=[]},n.prototype.create=function(){for(var t=0;t<this.events.length;t++){var i=this.events[t];i[0].addEventListener(i[1],i[2]),i[3]=!0}},n.prototype.destroy=function(){for(var t=0;t<this.events.length;t++){var i=this.events[t];i[0].removeEventListener(i[1],i[2]),i[3]=!1}},s.prototype.set=function(t,i){this.x=t,this.y=i},s.prototype.setScalar=function(t){this.x=t,this.y=t},s.prototype.clone=function(){return new s(this.x,this.y)},s.prototype.copy=function(t){this.x=t.x,this.y=t.y},s.prototype.add=function(t){this.x+=t.x,this.y+=t.y},s.prototype.addScalar=function(t){this.x+=t,this.y+=t},s.prototype.addVectors=function(t,i){this.x=t.x+i.x,this.y=t.y+i.y},s.prototype.addScaledVector=function(t,i){this.x+=t.x*i,this.y+=t.y*i},s.prototype.sub=function(t){this.x-=t.x,this.y-=t.y},s.prototype.subScalar=function(t){this.x-=t,this.y-=t},s.prototype.subVectors=function(t,i){this.x=t.x-i.x,this.y=t.y-i.y},s.prototype.multiply=function(t){this.x*=t.x,this.y*=t.y},s.prototype.multiplyScalar=function(t){this.x*=t,this.y*=t},s.prototype.divide=function(t){this.x/=t.x,this.y/=t.y},s.prototype.divideScalar=function(t){return this.multiplyScalar(1/t)},s.prototype.min=function(t){this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y)},s.prototype.max=function(t){this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y)},s.prototype.clamp=function(t,i){this.x=Math.max(t.x,Math.min(i.x,this.x)),this.y=Math.max(t.y,Math.min(i.y,this.y))},s.prototype.clampScalar=function(t,i){this.x=Math.max(t,Math.min(i,this.x)),this.y=Math.max(t,Math.min(i,this.y))},s.prototype.clampLength=function(t,i){var e=this.length();return this.divideScalar(e||1).multiplyScalar(Math.max(t,Math.min(i,e)))},s.prototype.floor=function(){this.x=Math.floor(this.x),this.y=Math.floor(this.y)},s.prototype.ceil=function(){this.x=Math.ceil(this.x),this.y=Math.ceil(this.y)},s.prototype.round=function(){this.x=Math.round(this.x),this.y=Math.round(this.y)},s.prototype.negate=function(){return this.x=-this.x,this.y=-this.y,this},s.prototype.dot=function(t){return this.x*t.x+this.y*t.y},s.prototype.cross=function(t){return this.x*t.y-this.y*t.x},s.prototype.lengthSq=function(){return this.x*this.x+this.y*this.y},s.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},s.prototype.manhattanLength=function(){return Math.abs(this.x)+Math.abs(this.y)},s.prototype.normalize=function(){return this.divideScalar(this.length()||1)},s.prototype.angle=function(){var t=Math.atan2(this.y,this.x);return t<0&&(t+=2*Math.PI),t},s.prototype.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},s.prototype.distanceToSquared=function(t){var i=this.x-t.x,e=this.y-t.y;return i*i+e*e},s.prototype.manhattanDistanceTo=function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)},s.prototype.setLength=function(t){return this.normalize().multiplyScalar(t)},s.prototype.lerp=function(t,i){this.x+=(t.x-this.x)*i,this.y+=(t.y-this.y)*i},s.prototype.lerpVectors=function(t,i,e){return this.subVectors(i,t).multiplyScalar(e).add(t)},s.prototype.equals=function(t){return t.x===this.x&&t.y===this.y},s.prototype.fromArray=function(t,i){void 0===i&&(i=0),this.x=t[i],this.y=t[i+1]},s.prototype.toArray=function(t,i){return void 0===t&&(t=[]),void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t},s.prototype.rotateAround=function(t,i){var e=Math.cos(i),o=Math.sin(i),n=this.x-t.x,s=this.y-t.y;this.x=n*e-s*o+t.x,this.y=n*o+s*e+t.y},l.prototype.copy=function(t){this.m=t.m.slice(0)},l.prototype.clone=function(){return new l(this.m.slice(0))},l.prototype.identity=function(){this.m=[1,0,0,1,0,0]},l.prototype.multiply=function(t){var i=this.m[0]*t.m[0]+this.m[2]*t.m[1],e=this.m[1]*t.m[0]+this.m[3]*t.m[1],o=this.m[0]*t.m[2]+this.m[2]*t.m[3],n=this.m[1]*t.m[2]+this.m[3]*t.m[3],s=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],r=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];this.m=[i,e,o,n,s,r]},l.prototype.premultiply=function(t){var i=t.m[0]*this.m[0]+t.m[2]*this.m[1],e=t.m[1]*this.m[0]+t.m[3]*this.m[1],o=t.m[0]*this.m[2]+t.m[2]*this.m[3],n=t.m[1]*this.m[2]+t.m[3]*this.m[3],s=t.m[0]*this.m[4]+t.m[2]*this.m[5]+t.m[4],r=t.m[1]*this.m[4]+t.m[3]*this.m[5]+t.m[5];this.m=[i,e,o,n,s,r]},l.prototype.compose=function(t,i,e,o,n,s,r){if(this.m=[1,0,0,1,t,i],0!==r){var h=Math.cos(r),a=Math.sin(r);this.multiply(new l([h,a,-a,h,0,0]))}0===n&&0===s||this.multiply(new l([1,0,0,1,-n,-s])),1===e&&1===o||this.scale(e,o)},l.prototype.translate=function(t,i){this.m[4]+=this.m[0]*t+this.m[2]*i,this.m[5]+=this.m[1]*t+this.m[3]*i},l.prototype.rotate=function(t){var i=Math.cos(t),e=Math.sin(t),o=this.m[0]*i+this.m[2]*e,n=this.m[1]*i+this.m[3]*e,s=this.m[0]*-e+this.m[2]*i,r=this.m[1]*-e+this.m[3]*i;this.m[0]=o,this.m[1]=n,this.m[2]=s,this.m[3]=r},l.prototype.scale=function(t,i){this.m[0]*=t,this.m[1]*=t,this.m[2]*=i,this.m[3]*=i},l.prototype.setPosition=function(t,i){this.m[4]=t,this.m[5]=i},l.prototype.getScale=function(){return new s(this.m[0],this.m[3])},l.prototype.getPosition=function(){return new s(this.m[4],this.m[5])},l.prototype.skew=function(t,i){this.multiply(new l([1,Math.tan(i),Math.tan(t),1,0,0]))},l.prototype.determinant=function(){return 1/(this.m[0]*this.m[3]-this.m[1]*this.m[2])},l.prototype.getInverse=function(){var t=this.determinant();return new l([this.m[3]*t,-this.m[1]*t,-this.m[2]*t,this.m[0]*t,t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),t*(this.m[1]*this.m[4]-this.m[0]*this.m[5])])},l.prototype.transformPoint=function(t){return new s(t.x*this.m[0]+t.y*this.m[2]+this.m[4],t.x*this.m[1]+t.y*this.m[3]+this.m[5])},l.prototype.setContextTransform=function(t){t.setTransform(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5])},l.prototype.tranformContext=function(t){t.transform(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5])},l.prototype.cssTransform=function(){return"matrix("+this.m[0]+","+this.m[1]+","+this.m[2]+","+this.m[3]+","+this.m[4]+","+this.m[5]+")"},i.generate=function(){for(var n=[],t=0;t<256;t++)n[t]=(t<16?"0":"")+t.toString(16);return function(){var t=4294967295*Math.random()|0,i=4294967295*Math.random()|0,e=4294967295*Math.random()|0,o=4294967295*Math.random()|0;return(n[255&t]+n[t>>8&255]+n[t>>16&255]+n[t>>24&255]+"-"+n[255&i]+n[i>>8&255]+"-"+n[i>>16&15|64]+n[i>>24&255]+"-"+n[63&e|128]+n[e>>8&255]+"-"+n[e>>16&255]+n[e>>24&255]+n[255&o]+n[o>>8&255]+n[o>>16&255]+n[o>>24&255]).toUpperCase()}}(),p.prototype.traverse=function(t){t(this);for(var i=this.children,e=0;e<i.length;e++)i[e].traverse(t)},p.prototype.add=function(t){t.parent=this,t.level=this.level+1,t.traverse(function(t){null!==t.onAdd&&t.onAdd(this)}),this.children.push(t)},p.prototype.remove=function(t){var i=this.children.indexOf(t);-1!==i&&((t=this.children[i]).parent=null,t.level=0,t.traverse(function(t){null!==t.onRemove&&t.onRemove(this)}),this.children.splice(i,1))},p.prototype.isInside=function(t){return!1},p.prototype.updateMatrix=function(t){this.matrixNeedsUpdate&&(this.matrix.compose(this.position.x,this.position.y,this.scale.x,this.scale.y,this.origin.x,this.origin.y,this.rotation),this.globalMatrix.copy(this.matrix),null!==this.parent&&this.globalMatrix.premultiply(this.parent.globalMatrix),this.inverseGlobalMatrix=this.globalMatrix.getInverse())},p.prototype.transform=function(t,i){this.globalMatrix.tranformContext(t)},p.prototype.draw=function(t,i,e){},p.prototype.onPointerDrag=function(t,i,e){this.position.add(e)},p.prototype.onAdd=null,p.prototype.onRemove=null,p.prototype.onUpdate=null,p.prototype.onPointerEnter=null,p.prototype.onPointerLeave=null,p.prototype.onPointerOver=null,p.prototype.onButtonPressed=null,p.prototype.onButtonDown=null,p.prototype.onButtonUp=null,r.DOWN=-1,r.UP=1,r.RESET=0,(r.prototype.constructor=r).prototype.update=function(t){this.justPressed=!1,this.justReleased=!1,t===r.DOWN?(!1===this.pressed&&(this.justPressed=!0),this.pressed=!0):t===r.UP?(this.pressed&&(this.justReleased=!0),this.pressed=!1):t===r.RESET&&(this.justReleased=!1,this.justPressed=!1)},r.prototype.set=function(t,i,e){this.justPressed=t,this.pressed=i,this.justReleased=e},r.prototype.reset=function(){this.justPressed=!1,this.pressed=!1,this.justReleased=!1},((y.prototype=y).constructor=y).LEFT=0,y.MIDDLE=1,y.RIGHT=2,y.BACK=3,y.FORWARD=4,y.setCanvas=function(t){(this.canvas=t).pointerInside=!1,t.addEventListener("mouseenter",function(){this.pointerInside=!0}),t.addEventListener("mouseleave",function(){this.pointerInside=!1})},y.insideCanvas=function(){return null!==this.canvas&&this.canvas.pointerInside},y.buttonPressed=function(t){return this.keys[t].pressed},y.buttonDoubleClicked=function(t){return this.doubleClicked[t]},y.buttonJustPressed=function(t){return this.keys[t].justPressed},y.buttonJustReleased=function(t){return this.keys[t].justReleased},y.updatePosition=function(t,i,e,o){if(null!==this.canvas){var n=this.canvas.getBoundingClientRect();t-=n.left,i-=n.top}this._position.set(t,i),this._delta.x+=e,this._delta.y+=o,this._positionUpdated=!0},y.updateKey=function(t,i){-1<t&&this._keys[t].update(i)},y.update=function(){for(var t=0;t<5;t++)this._keys[t].justPressed&&this.keys[t].justPressed&&(this._keys[t].justPressed=!1),this._keys[t].justReleased&&this.keys[t].justReleased&&(this._keys[t].justReleased=!1),this.keys[t].set(this._keys[t].justPressed,this._keys[t].pressed,this._keys[t].justReleased),!0===this._doubleClicked[t]?(this.doubleClicked[t]=!0,this._doubleClicked[t]=!1):this.doubleClicked[t]=!1;this._wheelUpdated?(this.wheel=this._wheel,this._wheelUpdated=!1):this.wheel=0,this._positionUpdated?(this.delta.copy(this._delta),this.position.copy(this._position),this._delta.set(0,0),this._positionUpdated=!1):(this.delta.x=0,this.delta.y=0)},y.create=function(){this.events.create()},y.dispose=function(){this.events.destroy()},e.prototype.updateMatrix=function(){this.matrixNeedsUpdate&&(this.matrix.compose(this.position.x,this.position.y,this.scale,this.scale,0,0,this.rotation),this.inverseMatrix=this.matrix.getInverse())},e.prototype.centerObject=function(t,i){var e=t.globalMatrix.transformPoint(new s);e.multiplyScalar(-this.scale),e.x+=i.width/2,e.y+=i.height/2,this.position.copy(e)},h.prototype.update=function(t){if(this.allowScale&&0!==t.wheel&&(this.viewport.scale-=.001*t.wheel*this.viewport.scale,this.moveOnScale)){var i=t.wheel,e=t.canvas.width/2,o=t.canvas.height/2;this.viewport.position.x+=(t.position.x-e)/e*i,this.viewport.position.y+=(t.position.y-o)/o*i}this.allowRotation&&t.buttonPressed(y.RIGHT)&&t.buttonPressed(y.LEFT)?null===this.rotationPoint?(this.rotationPoint=t.position.clone(),this.rotationInitial=this.viewport.rotation):((t=t.position.clone()).sub(this.rotationPoint),this.viewport.rotation=this.rotationInitial+t.angle()):(this.rotationPoint=null,t.buttonPressed(this.dragButton)&&(this.viewport.position.x+=t.delta.x,this.viewport.position.y+=t.delta.y))},o.prototype.createRenderLoop=function(i,e,o){var n=this,s=new h(e);!function t(){void 0!==o&&o(),s.update(n.pointer),n.update(i,e),requestAnimationFrame(t)}()},o.prototype.update=function(t,i){var e=[];t.traverse(function(t){t.visible&&e.push(t)}),e.sort(function(t,i){return i.layer===t.layer?i.level-t.level:i.layer-t.layer});var o=this.pointer;o.update(),i.updateMatrix();for(var n=o.position.clone(),s=i.inverseMatrix.transformPoint(n),r=0;r<e.length;r++){if((a=e[r]).pointerEvents){var h=a.inverseGlobalMatrix.transformPoint(a.ignoreViewport?n:s);if(a.isInside(h)){if(a.pointerInside||null===a.onPointerEnter||a.onPointerEnter(o,i),null!==a.onPointerOver&&a.onPointerOver(o,i),o.buttonPressed(y.LEFT)&&null!==a.onButtonPressed&&a.onButtonPressed(o,i),o.buttonJustReleased(y.LEFT)&&null!==a.onButtonUp&&a.onButtonUp(o,i),o.buttonJustPressed(y.LEFT)&&(null!==a.onButtonDown&&a.onButtonDown(o,i),a.draggable)){a.beingDragged=!0;break}a.pointerInside=!0}else a.pointerInside&&(null!==a.onPointerLeave&&a.onPointerLeave(o,i),a.pointerInside=!1);o.buttonJustReleased(y.LEFT)&&a.draggable&&(a.beingDragged=!1)}}for(r=0;r<e.length;r++){var a;if((a=e[r]).beingDragged){var l=o.position.clone();l.sub(o.delta);var p=i.inverseMatrix.transformPoint(o.position),m=i.inverseMatrix.transformPoint(l);p.sub(m),null!==a.onPointerDrag&&a.onPointerDrag(o,i,p)}null!==a.onUpdate&&a.onUpdate()}t.traverse(function(t){t.updateMatrix()}),this.context.setTransform(1,0,0,1,0,0),this.autoClear&&this.context.clearRect(0,0,this.canvas.width,this.canvas.height);for(r=e.length-1;0<=r;r--)if(!e[r].isMask){e[r].saveContextState&&this.context.save();for(var c=e[r].masks,u=0;u<c.length;u++)c[u].ignoreViewport||i.matrix.setContextTransform(this.context),c[u].transform(this.context,i,this.canvas),c[u].clip(this.context,i,this.canvas);e[r].ignoreViewport?0<c.length&&this.context.setTransform(1,0,0,1,0,0):i.matrix.setContextTransform(this.context),e[r].transform(this.context,i,this.canvas),e[r].draw(this.context,i,this.canvas),e[r].restoreContextState&&this.context.restore()}},a.prototype.set=function(t,i){return this.min.copy(t),this.max.copy(i),this},a.prototype.setFromPoints=function(t){this.min=new s(1/0,1/0),this.max=new s(-1/0,-1/0);for(var i=0,e=t.length;i<e;i++)this.expandByPoint(t[i]);return this},a.prototype.setFromCenterAndSize=function(t,i){var e=(new s).copy(i).multiplyScalar(.5);return this.min.copy(t).sub(e),this.max.copy(t).add(e),this},a.prototype.clone=function(){var t=new a;return t.copy(this),t},a.prototype.copy=function(t){this.min.copy(t.min),this.max.copy(t.max)},a.prototype.isEmpty=function(){return this.max.x<this.min.x||this.max.y<this.min.y},a.prototype.getCenter=function(t){return void 0===t&&(t=new s),this.isEmpty()?t.set(0,0):t.addVectors(this.min,this.max).multiplyScalar(.5),t},a.prototype.getSize=function(t){return void 0===t&&(t=new s),this.isEmpty()?t.set(0,0):t.subVectors(this.max,this.min),t},a.prototype.expandByPoint=function(t){return this.min.min(t),this.max.max(t),this},a.prototype.expandByVector=function(t){this.min.sub(t),this.max.add(t)},a.prototype.expandByScalar=function(t){this.min.addScalar(-t),this.max.addScalar(t)},a.prototype.containsPoint=function(t){return!(t.x<this.min.x||t.x>this.max.x||t.y<this.min.y||t.y>this.max.y)},a.prototype.containsBox=function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y},a.prototype.intersectsBox=function(t){return!(t.max.x<this.min.x||t.min.x>this.max.x||t.max.y<this.min.y||t.min.y>this.max.y)},a.prototype.distanceToPoint=function(t){return(new s).copy(t).clamp(this.min,this.max).sub(t).length()},a.prototype.intersect=function(t){this.min.max(t.min),this.max.min(t.max)},a.prototype.union=function(t){this.min.min(t.min),this.max.max(t.max)},a.prototype.translate=function(t){this.min.add(t),this.max.add(t)},a.prototype.equals=function(t){return t.min.equals(this.min)&&t.max.equals(this.max)},(m.prototype=Object.create(p.prototype)).isMask=!0,m.prototype.clip=function(t,i,e){},(c.prototype=Object.create(m.prototype)).isInside=function(t){return this.box.containsPoint(t)},c.prototype.clip=function(t,i,e){t.beginPath();var o=this.box.max.x-this.box.min.x;if(this.invert)t.rect(this.box.min.x-1e4,-5e3,1e4,1e4),t.rect(this.box.max.x,-5e3,1e4,1e4),t.rect(this.box.min.x,this.box.min.y-1e4,o,1e4),t.rect(this.box.min.x,this.box.max.y,o,1e4);else{var n=this.box.max.y-this.box.min.y;t.fillRect(this.box.min.x,this.box.min.y,o,n)}t.clip()},(u.prototype=Object.create(p.prototype)).isInside=function(t){return t.length()<=this.radius},u.prototype.onPointerEnter=function(t,i){this.fillStyle="#CCCCCC"},u.prototype.onPointerLeave=function(t,i){this.fillStyle="#FFFFFF"},u.prototype.draw=function(t,i,e){t.beginPath(),t.arc(0,0,this.radius,0,2*Math.PI),t.fillStyle=this.fillStyle,t.fill(),t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.stroke()},d.rotateTool=function(o){var t=new u;t.radius=4,t.layer=o.layer+1,t.onPointerDrag=function(t,i,e){o.rotation+=.001*e.x},o.add(t)},d.boxResizeTool=function(o){if(void 0!==o.box){var n=new u;n.radius=4,n.layer=o.layer+1,n.draggable=!0,n.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.min.copy(n.position),a()},o.add(n);var s=new u;s.radius=4,s.layer=o.layer+1,s.draggable=!0,s.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.max.x=s.position.x,o.box.min.y=s.position.y,a()},o.add(s);var r=new u;r.radius=4,r.layer=o.layer+1,r.draggable=!0,r.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.max.copy(r.position),a()},o.add(r);var h=new u;h.radius=4,h.layer=o.layer+1,h.draggable=!0,h.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.min.x=h.position.x,o.box.max.y=h.position.y,a()},o.add(h),a()}else console.warn("trenette.js: Helpers.boxResizeTool(), object box property missing.");function a(){n.position.copy(o.box.min),r.position.copy(o.box.max),s.position.set(o.box.max.x,o.box.min.y),h.position.set(o.box.min.x,o.box.max.y)}},(x.prototype=Object.create(p.prototype)).onPointerEnter=function(t,i){this.fillStyle="#CCCCCC"},x.prototype.onPointerLeave=function(t,i){this.fillStyle="#FFFFFF"},x.prototype.isInside=function(t){return this.box.containsPoint(t)},x.prototype.draw=function(t,i,e){var o=this.box.max.x-this.box.min.x,n=this.box.max.y-this.box.min.y;t.fillStyle=this.fillStyle,t.fillRect(this.box.min.x,this.box.min.y,o,n),t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.strokeRect(this.box.min.x,this.box.min.y,o,n)},(f.prototype=Object.create(p.prototype)).draw=function(t,i,e){t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.setLineDash(this.dashPattern),t.beginPath(),t.moveTo(this.from.x,this.from.y),t.lineTo(this.to.x,this.to.y),t.stroke()},(v.prototype=Object.create(p.prototype)).draw=function(t,i,e){t.font=this.font,t.textAlign=this.textAlign,t.fillStyle=this.color,t.textBaseline="middle",t.fillText(this.text,0,0)},(b.prototype=Object.create(p.prototype)).setImage=function(t){var i=this;this.image.onload=function(){i.box.min.set(0,0),i.box.max.set(this.naturalWidth,this.naturalHeight)},this.image.src=t},b.prototype.isInside=function(t){return this.box.containsPoint(t)},b.prototype.draw=function(t,i,e){0<this.image.src.length&&t.drawImage(this.image,0,0,this.image.naturalWidth,this.image.naturalHeight,this.box.min.x,this.box.min.y,this.box.max.x-this.box.min.x,this.box.max.y-this.box.min.y)},(g.prototype=Object.create(p.prototype)).onAdd=function(){this.parentDOM.appendChild(this.element)},g.prototype.onRemove=function(){this.parentDOM.removeChild(this.element)},g.prototype.transform=function(t,i,e){var o=i.matrix.clone();o.multiply(this.globalMatrix),this.element.style.transform=o.cssTransform(),this.element.style.width=this.size.x+"px",this.element.style.height=this.size.y+"px",this.element.style.display=this.visible?"block":"none"},(w.prototype=Object.create(p.prototype)).setImage=function(t){var i=this;this.image.onload=function(){i.box.min.set(0,0),i.box.max.set(this.naturalWidth,this.naturalHeight)},this.image.src=t},w.prototype.isInside=function(t){return this.box.containsPoint(t)},w.prototype.draw=function(t,i,e){var o=this.box.max.x-this.box.min.x,n=this.box.max.y-this.box.min.y;if(0<this.image.src.length){var s=t.createPattern(this.image,this.repetition);t.fillStyle=s,t.fillRect(this.box.min.x,this.box.min.y,o,n)}},(P.prototype=Object.create(p.prototype)).isInside=function(t){return this.box.containsPoint(t)},P.prototype.draw=function(t,i,e){if(0!==this.data.length){var o=this.box.max.x-this.box.min.x,n=this.box.max.y-this.box.min.y;t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.beginPath();var s=o/(this.data.length-1),r=this.max-this.min;t.moveTo(this.box.min.x,this.box.max.y-(this.data[0]-this.min)/r*n);for(var h=1,a=s;h<this.data.length;a+=s,h++)t.lineTo(this.box.min.x+a,this.box.max.y-(this.data[h]-this.min)/r*n);t.stroke(),null!==this.fillStyle&&(t.fillStyle=this.fillStyle,t.lineTo(this.box.max.x,this.box.max.y),t.lineTo(this.box.min.x,this.box.max.y),t.fill())}},M.prototype=Object.create(p.prototype),M.curveHelper=function(o){var n=new u;n.radius=3,n.layer=o.layer+1,n.draggable=!0,n.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.fromCp.copy(n.position)},o.parent.add(n);var t=new f;t.from=o.from,t.to=o.fromCp,o.parent.add(t);var s=new u;s.radius=3,s.layer=o.layer+1,s.draggable=!0,s.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.toCp.copy(s.position)},o.parent.add(s);var i=new f;i.from=o.to,i.to=o.toCp,o.parent.add(i)},M.prototype.draw=function(t,i,e){t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.setLineDash(this.dashPattern),t.beginPath(),t.moveTo(this.from.x,this.from.y),t.bezierCurveTo(this.fromCp.x,this.fromCp.y,this.toCp.x,this.toCp.y,this.to.x,this.to.y),t.stroke()},t.BezierCurve=M,t.Box=x,t.Box2=a,t.BoxMask=c,t.Circle=u,t.DOM=g,t.EventManager=n,t.Graph=P,t.Helpers=d,t.Image=b,t.Key=r,t.Line=f,t.Mask=m,t.Matrix=l,t.Object2D=p,t.Pattern=w,t.Pointer=y,t.Renderer=o,t.Text=v,t.UUID=i,t.Vector2=s,t.Viewport=e,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "trenette.js", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "trenette.js is a web library for building interactive diagrams and graphs.", | ||
@@ -5,0 +5,0 @@ "main": "build/trenette.min.js", |
@@ -11,2 +11,4 @@ "use strict"; | ||
* @class | ||
* @param {Vector2} min | ||
* @param {Vector2} max | ||
*/ | ||
@@ -21,2 +23,5 @@ function Box2(min, max) | ||
* Set the box values. | ||
* | ||
* @param {Vector2} min | ||
* @param {Vector2} max | ||
*/ | ||
@@ -33,2 +38,4 @@ Box2.prototype.set = function(min, max) | ||
* Set the box from a list of Vector2 points. | ||
* | ||
* @param {Array} points | ||
*/ | ||
@@ -50,2 +57,5 @@ Box2.prototype.setFromPoints = function(points) | ||
* Set the box minimum and maximum from center point and size. | ||
* | ||
* @param {Vector2} center | ||
* @param {Vector2} size | ||
*/ | ||
@@ -64,2 +74,6 @@ Box2.prototype.setFromCenterAndSize = function(center, size) | ||
* Clone the box into a new object. | ||
* | ||
* Should be used when it it necessary to make operations to this box. | ||
* | ||
* @return {Box2} New box object with the copy of this object. | ||
*/ | ||
@@ -75,2 +89,4 @@ Box2.prototype.clone = function() | ||
* Copy the box value from another box. | ||
* | ||
* @param {Box2} point | ||
*/ | ||
@@ -87,2 +103,4 @@ Box2.prototype.copy = function(box) | ||
* The box size is condireded valid on two negative axis. | ||
* | ||
* @return {boolean} True if the box is empty. | ||
*/ | ||
@@ -96,2 +114,5 @@ Box2.prototype.isEmpty = function() | ||
* Calculate the center point of the box. | ||
* | ||
* @param {Vector2} [target] Vector to store the result. | ||
* @return {Vector2} Central point of the box. | ||
*/ | ||
@@ -111,3 +132,6 @@ Box2.prototype.getCenter = function(target) | ||
/** | ||
* Get the size of the box. | ||
* Get the size of the box from its min and max points. | ||
* | ||
* @param {Vector2} [target] Vector to store the result. | ||
* @return {Vector2} Vector with the calculated size. | ||
*/ | ||
@@ -128,2 +152,4 @@ Box2.prototype.getSize = function(target) | ||
* Expand the box to contain a new point. | ||
* | ||
* @param {Vector2} point | ||
*/ | ||
@@ -142,2 +168,4 @@ Box2.prototype.expandByPoint = function(point) | ||
* Vector is subtracted from min and added to the max points. | ||
* | ||
* @param {Vector2} vector | ||
*/ | ||
@@ -152,2 +180,4 @@ Box2.prototype.expandByVector = function(vector) | ||
* Expand the box by adding a border with the scalar value. | ||
* | ||
* @param {number} scalar | ||
*/ | ||
@@ -195,14 +225,2 @@ Box2.prototype.expandByScalar = function(scalar) | ||
Box2.prototype.clampPoint = function(point, target) | ||
{ | ||
if(target === undefined) | ||
{ | ||
target = new Vector2(); | ||
} | ||
target.copy(point).clamp(this.min, this.max); | ||
return target; | ||
}; | ||
/** | ||
@@ -212,2 +230,3 @@ * Calculate the distance to a point. | ||
* @param {Vector2} point | ||
* @return {number} Distance to point calculated. | ||
*/ | ||
@@ -214,0 +233,0 @@ Box2.prototype.distanceToPoint = function(point) |
@@ -8,3 +8,6 @@ "use strict"; | ||
* | ||
* The values of the matrix are stored in a numeric array. | ||
* | ||
* @class | ||
* @param {array} [values] | ||
*/ | ||
@@ -11,0 +14,0 @@ function Matrix(values) |
@@ -227,2 +227,5 @@ "use strict"; | ||
/** | ||
* Round the vector coordinates to integer by flooring to the smaller integer. | ||
*/ | ||
Vector2.prototype.floor = function() | ||
@@ -234,2 +237,5 @@ { | ||
/** | ||
* Round the vector coordinates to integer by ceiling to the bigger integer. | ||
*/ | ||
Vector2.prototype.ceil = function() | ||
@@ -241,2 +247,5 @@ { | ||
/** | ||
* Round the vector coordinates to their closest integer. | ||
*/ | ||
Vector2.prototype.round = function() | ||
@@ -248,8 +257,5 @@ { | ||
Vector2.prototype.roundToZero = function() | ||
{ | ||
this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x); | ||
this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y); | ||
}; | ||
/** | ||
* Negate the coordinates of this vector. | ||
*/ | ||
Vector2.prototype.negate = function() | ||
@@ -263,2 +269,8 @@ { | ||
/** | ||
* Dot multiplication between this vector and another vector. | ||
* | ||
* @param {Vector2} vector | ||
* @return {number} Result of the dot multiplication. | ||
*/ | ||
Vector2.prototype.dot = function(v) | ||
@@ -269,2 +281,8 @@ { | ||
/** | ||
* Cross multiplication between this vector and another vector. | ||
* | ||
* @param {Vector2} vector | ||
* @return {number} Result of the cross multiplication. | ||
*/ | ||
Vector2.prototype.cross = function(v) | ||
@@ -275,2 +293,7 @@ { | ||
/** | ||
* Squared length of the vector. | ||
* | ||
* Faster for comparions. | ||
*/ | ||
Vector2.prototype.lengthSq = function() | ||
@@ -281,2 +304,5 @@ { | ||
/** | ||
* Length of the vector. | ||
*/ | ||
Vector2.prototype.length = function() | ||
@@ -287,2 +313,5 @@ { | ||
/** | ||
* Manhattan length of the vector. | ||
*/ | ||
Vector2.prototype.manhattanLength = function() | ||
@@ -293,2 +322,5 @@ { | ||
/** | ||
* Normalize the vector (make it length one). | ||
*/ | ||
Vector2.prototype.normalize = function() | ||
@@ -314,2 +346,5 @@ { | ||
/** | ||
* Distance between two vector positions. | ||
*/ | ||
Vector2.prototype.distanceTo = function(v) | ||
@@ -320,2 +355,7 @@ { | ||
/** | ||
* Distance between two vector positions squared. | ||
* | ||
* Faster for comparisons. | ||
*/ | ||
Vector2.prototype.distanceToSquared = function(v) | ||
@@ -329,2 +369,5 @@ { | ||
/** | ||
* Manhattan distance between two vector positions. | ||
*/ | ||
Vector2.prototype.manhattanDistanceTo = function(v) | ||
@@ -335,2 +378,5 @@ { | ||
/** | ||
* Scale the vector to have a defined length value. | ||
*/ | ||
Vector2.prototype.setLength = function(length) | ||
@@ -337,0 +383,0 @@ { |
"use strict"; | ||
import {Pointer} from "./input/Pointer.js"; | ||
import {ViewportControls} from "./controls/ViewportControls.js"; | ||
@@ -49,3 +50,3 @@ /** | ||
* | ||
* The render loop cannot be destroyed. | ||
* The render loop cannot be destroyed, and it automatically creates a viewport controls object. | ||
* | ||
@@ -60,2 +61,4 @@ * @param {Object2D} group Group to be rendererd. | ||
var controls = new ViewportControls(viewport); | ||
function loop() | ||
@@ -68,2 +71,3 @@ { | ||
controls.update(self.pointer); | ||
self.update(group, viewport); | ||
@@ -116,3 +120,2 @@ requestAnimationFrame(loop); | ||
// Viewport transform matrix | ||
viewport.updateControls(pointer); | ||
viewport.updateMatrix(); | ||
@@ -119,0 +122,0 @@ |
@@ -65,35 +65,3 @@ "use strict"; | ||
/** | ||
* Update the viewport controls using the pointer object. | ||
*/ | ||
Viewport.prototype.updateControls = function(pointer) | ||
{ | ||
if(pointer.wheel !== 0) | ||
{ | ||
this.scale -= pointer.wheel * 1e-3 * this.scale; | ||
if(this.moveOnScale) | ||
{ | ||
var speed = pointer.wheel; | ||
var halfWidth = pointer.canvas.width / 2; | ||
var halfWeight = pointer.canvas.height / 2; | ||
this.position.x += ((pointer.position.x - halfWidth) / halfWidth) * speed; | ||
this.position.y += ((pointer.position.y - halfWeight) / halfWeight) * speed; | ||
} | ||
} | ||
if(pointer.buttonPressed(Pointer.RIGHT) && pointer.buttonPressed(Pointer.LEFT)) | ||
{ | ||
this.rotation += pointer.delta.angle() * 1e-3; | ||
} | ||
else if(pointer.buttonPressed(Pointer.RIGHT)) | ||
{ | ||
this.position.x += pointer.delta.x; | ||
this.position.y += pointer.delta.y; | ||
} | ||
}; | ||
/** | ||
@@ -100,0 +68,0 @@ * Calculate and update the viewport transformation matrix. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2468246
121
8795