utils_Helpers.js.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: utils/Helpers.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: utils/Helpers.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>"use strict";
  20. import {Circle} from "../objects/Circle.js";
  21. import {Object2D} from "../Object2D.js";
  22. function Helpers(){}
  23. /**
  24. * Create a rotation tool
  25. */
  26. Helpers.rotateTool = function(object)
  27. {
  28. var tool = new Circle();
  29. tool.radius = 4;
  30. tool.layer = object.layer + 1;
  31. tool.onPointerDrag = function(pointer, viewport, delta)
  32. {
  33. object.rotation += delta.x * 1e-3;
  34. };
  35. object.add(tool);
  36. };
  37. /**
  38. * Create a box resize helper and attach it to an object to change the size of the object box.
  39. *
  40. * Each helper is positioned on one corner of the box, and the value of the corner is copied to the boxes as they are dragged.
  41. *
  42. * This method required to object to have a box property.
  43. */
  44. Helpers.boxResizeTool = function(object)
  45. {
  46. if(object.box === undefined)
  47. {
  48. console.warn("trenette.js: Helpers.boxResizeTool(), object box property missing.");
  49. return;
  50. }
  51. function updateHelpers()
  52. {
  53. topRight.position.copy(object.box.min);
  54. bottomLeft.position.copy(object.box.max);
  55. topLeft.position.set(object.box.max.x, object.box.min.y);
  56. bottomRight.position.set(object.box.min.x, object.box.max.y);
  57. }
  58. var topRight = new Circle();
  59. topRight.radius = 4;
  60. topRight.layer = object.layer + 1;
  61. topRight.draggable = true;
  62. topRight.onPointerDrag = function(pointer, viewport, delta)
  63. {
  64. Object2D.prototype.onPointerDrag.call(this, pointer, viewport, delta);
  65. object.box.min.copy(topRight.position);
  66. updateHelpers();
  67. };
  68. object.add(topRight);
  69. var topLeft = new Circle();
  70. topLeft.radius = 4;
  71. topLeft.layer = object.layer + 1;
  72. topLeft.draggable = true;
  73. topLeft.onPointerDrag = function(pointer, viewport, delta)
  74. {
  75. Object2D.prototype.onPointerDrag.call(this, pointer, viewport, delta);
  76. object.box.max.x = topLeft.position.x;
  77. object.box.min.y = topLeft.position.y;
  78. updateHelpers();
  79. };
  80. object.add(topLeft);
  81. var bottomLeft = new Circle();
  82. bottomLeft.radius = 4;
  83. bottomLeft.layer = object.layer + 1;
  84. bottomLeft.draggable = true;
  85. bottomLeft.onPointerDrag = function(pointer, viewport, delta)
  86. {
  87. Object2D.prototype.onPointerDrag.call(this, pointer, viewport, delta);
  88. object.box.max.copy(bottomLeft.position);
  89. updateHelpers();
  90. };
  91. object.add(bottomLeft);
  92. var bottomRight = new Circle();
  93. bottomRight.radius = 4;
  94. bottomRight.layer = object.layer + 1;
  95. bottomRight.draggable = true;
  96. bottomRight.onPointerDrag = function(pointer, viewport, delta)
  97. {
  98. Object2D.prototype.onPointerDrag.call(this, pointer, viewport, delta);
  99. object.box.min.x = bottomRight.position.x;
  100. object.box.max.y = bottomRight.position.y;
  101. updateHelpers();
  102. };
  103. object.add(bottomRight);
  104. updateHelpers();
  105. };
  106. export {Helpers};</code></pre>
  107. </article>
  108. </section>
  109. </div>
  110. <nav>
  111. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Box.html">Box</a></li><li><a href="Box2.html">Box2</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="Image.html">Image</a></li><li><a href="Key.html">Key</a></li><li><a href="Line.html">Line</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="Stencil.html">Stencil</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></ul>
  112. </nav>
  113. <br class="clear">
  114. <footer>
  115. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.2</a> on Thu Jun 06 2019 12:11:39 GMT+0100 (Western European Summer Time)
  116. </footer>
  117. <script> prettyPrint(); </script>
  118. <script src="scripts/linenumber.js"> </script>
  119. </body>
  120. </html>