Source: core/graphics/GraphicsData.js

core/graphics/GraphicsData.js

  1. /**
  2. * A GraphicsData object.
  3. *
  4. * @class
  5. * @memberof PIXI
  6. */
  7. export default class GraphicsData
  8. {
  9. /**
  10. *
  11. * @param {number} lineWidth - the width of the line to draw
  12. * @param {number} lineColor - the color of the line to draw
  13. * @param {number} lineAlpha - the alpha of the line to draw
  14. * @param {number} fillColor - the color of the fill
  15. * @param {number} fillAlpha - the alpha of the fill
  16. * @param {boolean} fill - whether or not the shape is filled with a colour
  17. * @param {boolean} nativeLines - the method for drawing lines
  18. * @param {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} shape - The shape object to draw.
  19. * @param {number} lineAlignment - the alignment of the line.
  20. */
  21. constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, nativeLines, shape, lineAlignment)
  22. {
  23. /**
  24. * the width of the line to draw
  25. * @member {number}
  26. */
  27. this.lineWidth = lineWidth;
  28. /**
  29. * The alignment of any lines drawn (0.5 = middle, 1 = outter, 0 = inner).
  30. *
  31. * @member {number}
  32. * @default 0
  33. */
  34. this.lineAlignment = lineAlignment;
  35. /**
  36. * if true the liens will be draw using LINES instead of TRIANGLE_STRIP
  37. * @member {boolean}
  38. */
  39. this.nativeLines = nativeLines;
  40. /**
  41. * the color of the line to draw
  42. * @member {number}
  43. */
  44. this.lineColor = lineColor;
  45. /**
  46. * the alpha of the line to draw
  47. * @member {number}
  48. */
  49. this.lineAlpha = lineAlpha;
  50. /**
  51. * cached tint of the line to draw
  52. * @member {number}
  53. * @private
  54. */
  55. this._lineTint = lineColor;
  56. /**
  57. * the color of the fill
  58. * @member {number}
  59. */
  60. this.fillColor = fillColor;
  61. /**
  62. * the alpha of the fill
  63. * @member {number}
  64. */
  65. this.fillAlpha = fillAlpha;
  66. /**
  67. * cached tint of the fill
  68. * @member {number}
  69. * @private
  70. */
  71. this._fillTint = fillColor;
  72. /**
  73. * whether or not the shape is filled with a colour
  74. * @member {boolean}
  75. */
  76. this.fill = fill;
  77. this.holes = [];
  78. /**
  79. * The shape object to draw.
  80. * @member {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle}
  81. */
  82. this.shape = shape;
  83. /**
  84. * The type of the shape, see the Const.Shapes file for all the existing types,
  85. * @member {number}
  86. */
  87. this.type = shape.type;
  88. }
  89. /**
  90. * Creates a new GraphicsData object with the same values as this one.
  91. *
  92. * @return {PIXI.GraphicsData} Cloned GraphicsData object
  93. */
  94. clone()
  95. {
  96. return new GraphicsData(
  97. this.lineWidth,
  98. this.lineColor,
  99. this.lineAlpha,
  100. this.fillColor,
  101. this.fillAlpha,
  102. this.fill,
  103. this.nativeLines,
  104. this.shape,
  105. this.lineAlignment
  106. );
  107. }
  108. /**
  109. * Adds a hole to the shape.
  110. *
  111. * @param {PIXI.Rectangle|PIXI.Circle} shape - The shape of the hole.
  112. */
  113. addHole(shape)
  114. {
  115. this.holes.push(shape);
  116. }
  117. /**
  118. * Destroys the Graphics data.
  119. */
  120. destroy()
  121. {
  122. this.shape = null;
  123. this.holes = null;
  124. }
  125. }