objects_Line.js.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: objects/Line.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: objects/Line.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>import {Object2D} from "../Object2D.js";
  20. import {Vector2} from "../math/Vector2.js";
  21. /**
  22. * Line object draw a line from one point to another without any kind of interpolation.
  23. *
  24. * For drawing lines with interpolation check {BezierCurve}
  25. *
  26. * @class
  27. * @extends {Object2D}
  28. */
  29. function Line()
  30. {
  31. Object2D.call(this);
  32. /**
  33. * Initial point of the line.
  34. *
  35. * Can be equal to the position object of another object. Making it automatically follow that object.
  36. *
  37. * @type {Vector2}
  38. */
  39. this.from = new Vector2();
  40. /**
  41. * Final point of the line.
  42. *
  43. * Can be equal to the position object of another object. Making it automatically follow that object.
  44. *
  45. * @type {Vector2}
  46. */
  47. this.to = new Vector2();
  48. /**
  49. * Dash line pattern to be used, if empty draws a solid line.
  50. *
  51. * Dash pattern is defined as the size of dashes as pairs of space with no line and with line.
  52. *
  53. * E.g if the dash pattern is [1, 2] we get 1 point with line, 2 without line repeat infinitelly.
  54. *
  55. * @type {number[]}
  56. */
  57. this.dashPattern = [5, 5];
  58. /**
  59. * Style of the object line.
  60. *
  61. * @type {string}
  62. */
  63. this.strokeStyle = "#000000";
  64. /**
  65. * Line width of the line.
  66. *
  67. * @type {number}
  68. */
  69. this.lineWidth = 1;
  70. }
  71. Line.prototype = Object.create(Object2D.prototype);
  72. Line.prototype.constructor = Line;
  73. Line.prototype.type = "Line";
  74. Object2D.register(Line, "Line");
  75. Line.prototype.style = function(context, viewport, canvas)
  76. {
  77. context.lineWidth = this.lineWidth;
  78. context.strokeStyle = this.strokeStyle;
  79. context.setLineDash(this.dashPattern);
  80. };
  81. Line.prototype.draw = function(context, viewport, canvas)
  82. {
  83. context.beginPath();
  84. context.moveTo(this.from.x, this.from.y);
  85. context.lineTo(this.to.x, this.to.y);
  86. context.stroke();
  87. };
  88. Line.prototype.serialize = function(recursive)
  89. {
  90. var data = Object2D.prototype.serialize.call(this, recursive);
  91. data.from = this.from.toArray();
  92. data.to = this.to.toArray();
  93. data.dashPattern = this.dashPattern;
  94. data.strokeStyle = this.strokeStyle;
  95. data.lineWidth = this.lineWidth;
  96. return data;
  97. };
  98. Line.prototype.parse = function(data, root)
  99. {
  100. Object2D.prototype.parse.call(this, data, root);
  101. this.to.fromArray(data.to);
  102. this.from.fromArray(data.from);
  103. this.dashPattern = data.dashPattern;
  104. this.strokeStyle = data.strokeStyle;
  105. this.lineWidth = data.lineWidth;
  106. };
  107. export {Line};
  108. </code></pre>
  109. </article>
  110. </section>
  111. </div>
  112. <nav>
  113. <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="FileUtils.html">FileUtils</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="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="Pattern.html">Pattern</a></li><li><a href="Pointer.html">Pointer</a></li><li><a href="QuadraticCurve.html">QuadraticCurve</a></li><li><a href="Renderer.html">Renderer</a></li><li><a href="RoundedBox.html">RoundedBox</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>
  114. </nav>
  115. <br class="clear">
  116. <footer>
  117. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon May 18 2020 18:40:48 GMT+0100 (Western European Summer Time)
  118. </footer>
  119. <script> prettyPrint(); </script>
  120. <script src="scripts/linenumber.js"> </script>
  121. </body>
  122. </html>