123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: Object2D.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: Object2D.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>"use strict";
- import {Vector2} from "./math/Vector2.js";
- import {Matrix} from "./math/Matrix.js";
- import {UUID} from "./math/UUID.js";
- /**
- * Base 2D object class, implements all the object positioning and scalling features.
- *
- * @class
- */
- function Object2D()
- {
- /**
- * UUID of the object.
- */
- this.uuid = UUID.generate();
- /**
- * List of children objects attached to the object.
- */
- this.children = [];
- /**
- * Parent object, the object position is affected by its parent position.
- */
- this.parent = null;
- /**
- * Depth level in the object tree, objects with higher depth are drawn on top.
- *
- * The layer value is considered first.
- */
- this.level = 0;
- /**
- * Position of the object.
- */
- this.position = new Vector2(0, 0);
- /**
- * Origin of the object used as point of rotation.
- */
- this.origin = new Vector2(0, 0);
- /**
- * Scale of the object.
- */
- this.scale = new Vector2(1, 1);
- /**
- * Rotation of the object relative to its center.
- */
- this.rotation = 0.0;
- /**
- * Indicates if the object is visible.
- */
- this.visible = true;
- /**
- * Layer of this object, objects are sorted by layer value.
- *
- * Lower layer value is draw first.
- */
- this.layer = 0;
- /**
- * Local transformation matrix applied to the object.
- */
- this.matrix = new Matrix();
- /**
- * Global transformation matrix multiplied by the parent matrix.
- *
- * Used to transform the object before projecting into screen coordinates.
- */
- this.globalMatrix = new Matrix();
- /**
- * Inverse of the global matrix.
- *
- * Used to convert pointer input points into object coordinates.
- */
- this.inverseGlobalMatrix = new Matrix();
- /**
- * Masks being applied to this object.
- *
- * Multiple masks can be used simultaneously.
- */
- this.masks = [];
- /**
- * If true the matrix is updated before rendering the object.
- */
- this.matrixNeedsUpdate = true;
- /**
- * Indicates if its possible to drag the object around.
- *
- * If true the onPointerDrag callback is used to update the state of the object.
- */
- this.draggable = false;
- /**
- * Indicates if this object uses pointer events.
- *
- * Can be set false to skip the pointer interaction events.
- */
- this.pointerEvents = true;
- /**
- * Flag to indicate wheter this objet ignores the viewport transformation.
- */
- this.ignoreViewport = false;
- /**
- * Flag to indicate if the context of canvas should be saved before render.
- */
- this.saveContextState = true;
- /**
- * Flag to indicate if the context of canvas should be restored after render.
- */
- this.restoreContextState = true;
- /**
- * Flag indicating if the pointer is inside of the element.
- *
- * Used to control object event.
- */
- this.pointerInside = false;
- /**
- * Flag to indicate if the object is currently being dragged.
- */
- this.beingDragged = false;
- }
- /**
- * Traverse the object tree and run a function for all objects.
- *
- * @param callback Callback function that receives the object as parameter.
- */
- Object2D.prototype.traverse = function(callback)
- {
- callback(this);
- var children = this.children;
- for(var i = 0; i < children.length; i++)
- {
- children[i].traverse(callback);
- }
- };
- /**
- * Attach a children to the object.
- *
- * @param object Object to attach to this object.
- */
- Object2D.prototype.add = function(object)
- {
- object.parent = this;
- object.level = this.level + 1;
- object.traverse(function(child)
- {
- if(child.onAdd !== null)
- {
- child.onAdd(this);
- }
- });
- this.children.push(object);
- };
- /**
- * Remove object from the children list.
- *
- * @param object Object to be removed.
- */
- Object2D.prototype.remove = function(object)
- {
- var index = this.children.indexOf(object);
-
- if(index !== -1)
- {
- var object = this.children[index];
- object.parent = null;
- object.level = 0;
- object.traverse(function(child)
- {
- if(child.onRemove !== null)
- {
- child.onRemove(this);
- }
- });
- this.children.splice(index, 1)
- }
- };
- /**
- * Check if a point is inside of the object.
- */
- Object2D.prototype.isInside = function(point)
- {
- return false;
- };
- /**
- * Update the transformation matrix of the object.
- */
- Object2D.prototype.updateMatrix = function(context)
- {
- if(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);
- if(this.parent !== null)
- {
- this.globalMatrix.premultiply(this.parent.globalMatrix);
- }
- this.inverseGlobalMatrix = this.globalMatrix.getInverse()
- //this.matrixNeedsUpdate = false;
- }
- };
- /**
- * Apply the transform to the rendering context.
- *
- * It is assumed that the viewport transform is pre-applied to the context.
- *
- * Can also be used for pre rendering logic.
- *
- * @param {CanvasContext} context Canvas 2d drawing context.
- * @param {Viewport} viewport Viewport applied to the canvas.
- */
- Object2D.prototype.transform = function(context, viewport)
- {
- this.globalMatrix.tranformContext(context);
- };
- /**
- * Draw the object into the canvas.
- *
- * Has to be implemented by underlying classes.
- *
- * @param {CanvasContext} context Canvas 2d drawing context.
- * @param {Viewport} viewport Viewport applied to the canvas.
- * @param {DOM} canvas DOM canvas element where the content is being drawn.
- */
- Object2D.prototype.draw = function(context, viewport, canvas){};
- /**
- * Callback method while the object is being dragged across the screen.
- *
- * By default is adds the delta value to the object position (making it follow the mouse movement).
- *
- * Delta is the movement of the pointer already translated into local object coordinates.
- *
- * Receives (pointer, viewport, delta) as arguments.
- */
- Object2D.prototype.onPointerDrag = function(pointer, viewport, delta)
- {
- this.position.add(delta);
- };
- /**
- * Method called when the object its added to a parent.
- *
- * Receives (parent) as arguments.
- */
- Object2D.prototype.onAdd = null;
- /**
- * Method called when the object gets removed from its parent
- *
- * Receives (parent) as arguments.
- */
- Object2D.prototype.onRemove = null;
- /**
- * Callback method called every time before the object is draw into the canvas.
- *
- * Can be used to run preparation code, move the object, etc.
- */
- Object2D.prototype.onUpdate = null;
- /**
- * Callback method called when the pointer enters the object.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onPointerEnter = null;
- /**
- * Callback method called when the was inside of the object and leaves the object.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onPointerLeave = null;
- /**
- * Callback method while the pointer is over (inside) of the object.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onPointerOver = null;
- /**
- * Callback method called while the pointer button is pressed.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onButtonPressed = null;
- /**
- * Callback method called when the pointer button is pressed down (single time).
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onButtonDown = null;
- /**
- * Callback method called when the pointer button is released (single time).
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onButtonUp = null;
- export {Object2D};
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><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="DOM.html">DOM</a></li><li><a href="EventManager.html">EventManager</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="Mask.html">Mask</a></li><li><a href="Matrix.html">Matrix</a></li><li><a href="Object2D.html">Object2D</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="Pointer.html">Pointer</a></li><li><a href="Renderer.html">Renderer</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>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.2</a> on Thu Jun 13 2019 09:46:06 GMT+0100 (Western European Summer Time)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|