123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: controls/ViewportControls.js</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
- </head>
- <body>
- <div id="main">
- <h1 class="page-title">Source: controls/ViewportControls.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>import {Viewport} from "../Viewport.js";
- import {Pointer} from "../input/Pointer.js";
- import {Vector2} from "../math/Vector2.js";
- /**
- * Viewport controls are used to allow the user to control the viewport.
- *
- * The user controls the viewport using pointer input (e.g. mouse, touchscreen)
- *
- * @class
- * @param {Viewport} viewport
- */
- function ViewportControls(viewport)
- {
- /**
- * Viewport being controlled by this object.
- *
- * @type {Viewport}
- */
- this.viewport = viewport;
- /**
- * Button used to drag and viewport around.
- *
- * On touch enabled devices the touch event is represented as a LEFT button.
- *
- * @type {number}
- */
- this.dragButton = Pointer.RIGHT;
- /**
- * Button used to rotate the viewport.
- *
- * @type {number}
- */
- this.rotateButton = Pointer.MIDDLE;
- /**
- * Is set to true allow the viewport to be scalled.
- *
- * Scaling is performed using the pointer scroll.
- *
- * @type {boolean}
- */
- this.allowScale = true;
- /**
- * Flag to indicate if the viewport should automatically be recentered.
- *
- * This will cause the viewport center property to be automatically set based on an heuristic defined by the user.
- *
- * @type {number}
- */
- this.recenterViewport = ViewportControls.RECENTER_NONE;
- /**
- * If true allows the viewport to be rotated.
- *
- * Rotation is performed by holding the RIGHT and LEFT pointer buttons and rotating around the initial point.
- *
- * @type {boolean}
- */
- this.allowRotation = true;
- /**
- * Value of the initial point of rotation if the viewport is being rotated.
- *
- * Is the value of the pointer position when the rotation starts.
- *
- * Is set to null when the viewport is not being rotated.
- *
- * @type {Vector2 | null}
- */
- this.rotationPoint = null;
- /**
- * Initial rotation of the viewport.
- *
- * Is set to the current rotation of the viewport when the rotation starts.
- *
- * @type {number}
- */
- this.rotationInitial = 0;
- }
- /**
- * Viewport is not automatically recentered.
- *
- * The center point can be set manually by the developer.
- *
- * @type {number}
- */
- ViewportControls.RECENTER_NONE = 0;
- /**
- * Recenter the viewport automatically to the canvas.
- *
- * This will ensure that rotation and scaling will not cause the viewport to move around.
- *
- * @type {number}
- */
- ViewportControls.RECENTER_CANVAS = 1;
- /**
- * Viewport should automatically cente ron the pointer position.
- *
- * The viewport will simulataniously move to the pointer position while scalling.
- *
- * For some application its easier to focus the target if the viewport moves to the pointer location while scalling.
- *
- * @type {number}
- */
- ViewportControls.RECENTER_POINTER = 2;
- /**
- * Update the viewport controls using the pointer object.
- *
- * Should be called every frame before rendering.
- *
- * @param {Pointer} pointer Pointer used to control the viewport.
- */
- ViewportControls.prototype.update = function(pointer)
- {
- // Scale
- if(this.allowScale && pointer.wheel !== 0)
- {
- var scale = pointer.wheel * 1e-3 * this.viewport.scale;
- this.viewport.scale -= scale;
- this.viewport.matrixNeedsUpdate = true;
- }
- // Rotation
- if(this.allowRotation && pointer.buttonPressed(this.rotateButton))
- {
- // Rotation pivot
- if(this.rotationPoint === null)
- {
- this.rotationPoint = pointer.position.clone();
- this.rotationInitial = this.viewport.rotation;
- }
- else
- {
- var point = pointer.position.clone();
- point.sub(this.rotationPoint);
- this.viewport.rotation = this.rotationInitial + point.angle();
- this.viewport.matrixNeedsUpdate = true;
- }
- return;
- } else {
- this.rotationPoint = null;
- }
- // Drag
- if(pointer.buttonPressed(this.dragButton))
- {
- this.viewport.position.add(pointer.delta);
- this.viewport.matrixNeedsUpdate = true;
- }
- if (pointer.canvas === null) {
- return;
- }
- // Center viewport on canvas
- if (this.recenterViewport === ViewportControls.RECENTER_CANVAS) {
- var centerWorld = new Vector2(pointer.canvas.width / 2.0, pointer.canvas.height / 2.0);
- centerWorld = this.viewport.inverseMatrix.transformPoint(centerWorld);
- this.viewport.center.copy(centerWorld);
- this.viewport.matrixNeedsUpdate = true;
- }
- // Center viewport on pointer
- else if(this.recenterViewport === ViewportControls.RECENTER_POINTER)
- {
- var pointerWorld = this.viewport.inverseMatrix.transformPoint(pointer.position)
- this.viewport.center.copy(pointerWorld);
- this.viewport.matrixNeedsUpdate = true;
- }
- };
- export {ViewportControls};
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnimationTimer.html">AnimationTimer</a></li><li><a href="BarGraph.html">BarGraph</a></li><li><a href="BezierCurve.html">BezierCurve</a></li><li><a href="Box.html">Box</a></li><li><a href="Box2.html">Box2</a></li><li><a href="BoxMask.html">BoxMask</a></li><li><a href="Circle.html">Circle</a></li><li><a href="ColorStyle.html">ColorStyle</a></li><li><a href="DOM.html">DOM</a></li><li><a href="EventManager.html">EventManager</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="Gauge.html">Gauge</a></li><li><a href="GradientColorStop.html">GradientColorStop</a></li><li><a href="GradientStyle.html">GradientStyle</a></li><li><a href="Graph.html">Graph</a></li><li><a href="Helpers.html">Helpers</a></li><li><a href="Image.html">Image</a></li><li><a href="Key.html">Key</a></li><li><a href="Line.html">Line</a></li><li><a href="LinearGradientStyle.html">LinearGradientStyle</a></li><li><a href="Mask.html">Mask</a></li><li><a href="Matrix.html">Matrix</a></li><li><a href="MultiLineText.html">MultiLineText</a></li><li><a href="Node.html">Node</a></li><li><a href="NodeConnector.html">NodeConnector</a></li><li><a href="NodeGraph.html">NodeGraph</a></li><li><a href="NodeSocket.html">NodeSocket</a></li><li><a href="Object2D.html">Object2D</a></li><li><a href="Path.html">Path</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="PatternStyle.html">PatternStyle</a></li><li><a href="PieChart.html">PieChart</a></li><li><a href="Pointer.html">Pointer</a></li><li><a href="QuadraticCurve.html">QuadraticCurve</a></li><li><a href="RadialGradientStyle.html">RadialGradientStyle</a></li><li><a href="Renderer.html">Renderer</a></li><li><a href="RoundedBox.html">RoundedBox</a></li><li><a href="ScatterGraph.html">ScatterGraph</a></li><li><a href="Style.html">Style</a></li><li><a href="Text.html">Text</a></li><li><a href="UUID.html">UUID</a></li><li><a href="Vector2.html">Vector2</a></li><li><a href="Viewport.html">Viewport</a></li><li><a href="ViewportControls.html">ViewportControls</a></li></ul><h3>Global</h3><ul><li><a href="global.html#writeFile">writeFile</a></li></ul>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Sep 17 2022 14:24:36 GMT+0100 (Hora de verão da Europa Ocidental)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|