CCDrawingPrimitives.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2010-2013 cocos2d-x.org
  4. Copyright (c) 2011 Zynga Inc.
  5. Copyright (c) 2013-2017 Chukong Technologies Inc.
  6. http://www.cocos2d-x.org
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. ****************************************************************************/
  23. /*
  24. *
  25. * IMPORTANT IMPORTANT IMPORTANT IMPORTANT
  26. *
  27. *
  28. * LEGACY FUNCTIONS
  29. *
  30. * USE DrawNode instead
  31. *
  32. */
  33. #ifndef __CCDRAWING_PRIMITIVES__
  34. #define __CCDRAWING_PRIMITIVES__
  35. #include "base/ccTypes.h"
  36. #include "base/ccMacros.h"
  37. #include "math/CCMath.h"
  38. /**
  39. @file
  40. Drawing OpenGL ES primitives.
  41. - drawPoint, drawPoints
  42. - drawLine
  43. - drawRect, drawSolidRect
  44. - drawPoly, drawSolidPoly
  45. - drawCircle
  46. - drawQuadBezier
  47. - drawCubicBezier
  48. - drawCatmullRom
  49. - drawCardinalSpline
  50. You can change the color, point size, width by calling:
  51. - drawColor4B(), drawColor4F()
  52. - ccPointSize()
  53. - glLineWidth()
  54. @warning These functions draws the Line, Vec2, Polygon, immediately. They aren't batched. If you are going to make a game that depends on these primitives, I suggest creating a batch. Instead you should use DrawNode
  55. */
  56. NS_CC_BEGIN
  57. /**
  58. * @addtogroup _2d
  59. * @{
  60. */
  61. class PointArray;
  62. /**
  63. * @js cc.DrawingPrimitiveCanvas/cc.DrawingPrimitiveWebGL
  64. */
  65. namespace DrawPrimitives
  66. {
  67. /**
  68. * Initializes the drawing primitives.
  69. * @js NA
  70. */
  71. CC_DEPRECATED_ATTRIBUTE void CC_DLL init();
  72. /**
  73. * Frees allocated resources by the drawing primitives.
  74. * @js NA
  75. */
  76. CC_DEPRECATED_ATTRIBUTE void CC_DLL free();
  77. /** Draws a point given x and y coordinate measured in points
  78. *
  79. * @param point A Vec2 with a point given x and y coordinate.
  80. */
  81. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawPoint(const Vec2& point);
  82. /** Draws an array of points.
  83. *
  84. * @param points A point coordinates.
  85. * @param numberOfPoints The number of points.
  86. * @since v0.7.2
  87. */
  88. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawPoints(const Vec2 *points, unsigned int numberOfPoints);
  89. /** Draws a line given the origin and destination point measured in points
  90. *
  91. * @param origin A Vec2 Type point used to the line origin.
  92. * @param destination A Vec2 Type point used to the line destination.
  93. */
  94. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawLine(const Vec2& origin, const Vec2& destination);
  95. /** Draws a rectangle given the origin and destination point measured in points.
  96. * The origin and the destination can not have the same x and y coordinate.
  97. *
  98. * @param origin The rectangle origin.
  99. * @param destination The rectangle destination.
  100. */
  101. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawRect(Vec2 origin, Vec2 destination);
  102. /** Draws a solid rectangle given the origin and destination point measured in points.
  103. * The origin and the destination can not have the same x and y coordinate.
  104. *
  105. * @param origin The rectangle origin.
  106. * @param destination The rectangle destination.
  107. * @param color The rectangle color.
  108. * @since 1.1
  109. */
  110. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidRect(Vec2 origin, Vec2 destination, Color4F color);
  111. /** Draws a polygon given a pointer to point coordinates and the number of vertices measured in points.
  112. * The polygon can be closed or open.
  113. *
  114. * @param vertices A pointer to point coordinates.
  115. * @param numOfVertices The number of vertices measured in points.
  116. * @param closePolygon The polygon can be closed or open.
  117. */
  118. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawPoly(const Vec2 *vertices, unsigned int numOfVertices, bool closePolygon);
  119. /** Draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color.
  120. *
  121. * @param poli A solid polygon given a pointer to CGPoint coordinates.
  122. * @param numberOfPoints The number of vertices measured in points.
  123. * @param color The solid polygon color.
  124. */
  125. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color);
  126. /** Draws a circle given the center, radius and number of segments.
  127. *
  128. * @param center The circle center point.
  129. * @param radius The circle rotate of radius.
  130. * @param angle The circle angle.
  131. * @param segments The number of segments.
  132. * @param drawLineToCenter Whether or not draw the line from the origin to center.
  133. * @param scaleX The scale value in x.
  134. * @param scaleY The scale value in y.
  135. */
  136. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
  137. /** Draws a circle given the center, radius and number of segments.
  138. *
  139. * @param center The circle center point.
  140. * @param radius The circle rotate of radius.
  141. * @param angle The circle angle.
  142. * @param segments The number of segments.
  143. * @param drawLineToCenter Whether or not draw the line from the origin to center.
  144. */
  145. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
  146. /** Draws a solid circle given the center, radius and number of segments.
  147. * @param center The circle center point.
  148. * @param radius The circle rotate of radius.
  149. * @param angle The circle angle.
  150. * @param segments The number of segments.
  151. * @param scaleX The scale value in x.
  152. * @param scaleY The scale value in y.
  153. * @js NA
  154. */
  155. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
  156. /** Draws a solid circle given the center, radius and number of segments.
  157. * @param center The circle center point.
  158. * @param radius The circle rotate of radius.
  159. * @param angle The circle angle.
  160. * @param segments The number of segments.
  161. * @js NA
  162. */
  163. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments);
  164. /** Draws a quad bezier path.
  165. *
  166. * @param origin The origin of the bezier path.
  167. * @param control The control of the bezier path.
  168. * @param destination The destination of the bezier path.
  169. * @param segments The number of segments.
  170. * @warning This function could be pretty slow. Use it only for debugging purposes.
  171. * @since v0.8
  172. */
  173. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawQuadBezier(const Vec2& origin, const Vec2& control, const Vec2& destination, unsigned int segments);
  174. /** Draws a cubic bezier path.
  175. *
  176. * @param origin The origin of the bezier path.
  177. * @param control1 The first control of the bezier path.
  178. * @param control2 The second control of the bezier path.
  179. * @param destination The destination of the bezier path.
  180. * @param segments The number of segments.
  181. * @warning This function could be pretty slow. Use it only for debugging purposes.
  182. * @since v0.8
  183. */
  184. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCubicBezier(const Vec2& origin, const Vec2& control1, const Vec2& control2, const Vec2& destination, unsigned int segments);
  185. /** Draws a Catmull Rom path.
  186. *
  187. * @param arrayOfControlPoints A point array of control point.
  188. * @param segments The number of segments.
  189. * @warning This function could be pretty slow. Use it only for debugging purposes.
  190. * @since v2.0
  191. */
  192. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCatmullRom(PointArray *arrayOfControlPoints, unsigned int segments);
  193. /** Draws a Cardinal Spline path.
  194. *
  195. * @param config A array point.
  196. * @param tension The tension of the spline.
  197. * @param segments The number of segments.
  198. * @warning This function could be pretty slow. Use it only for debugging purposes.
  199. * @since v2.0
  200. */
  201. CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCardinalSpline(PointArray *config, float tension, unsigned int segments);
  202. /** Set the drawing color with 4 unsigned bytes.
  203. *
  204. * @param r The red color with a unsigned bytes.
  205. * @param g The green color with a unsigned bytes.
  206. * @param b The blue color with a unsigned bytes.
  207. * @param a Alpha with a unsigned bytes.
  208. * @since v2.0
  209. * @js setDrawColor
  210. */
  211. CC_DEPRECATED_ATTRIBUTE void CC_DLL setDrawColor4B(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
  212. /** Set the drawing color with 4 floats.
  213. *
  214. * @param r The red color with an floats.
  215. * @param g The green color with an floats.
  216. * @param b The blue color with an floats.
  217. * @param a Alpha with an floats.
  218. * @since v2.0
  219. * @js setDrawColor
  220. */
  221. CC_DEPRECATED_ATTRIBUTE void CC_DLL setDrawColor4F(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
  222. /** Set the point size in points. Default 1.
  223. *
  224. * @param pointSize The point size with an float.
  225. * @since v2.0
  226. */
  227. CC_DEPRECATED_ATTRIBUTE void CC_DLL setPointSize(GLfloat pointSize);
  228. };
  229. // end of global group
  230. /** @} */
  231. NS_CC_END
  232. #endif // __CCDRAWING_PRIMITIVES__