CCDrawNode.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2011-2012 cocos2d-x.org
  4. Copyright (c) 2013-2014 Chukong Technologies Inc.
  5. Copyright (c) 2012 Scott Lembcke and Howling Moon Software
  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. * Code copied & pasted from SpacePatrol game https://github.com/slembcke/SpacePatrol
  25. *
  26. * Renamed and added some changes for cocos2d
  27. *
  28. */
  29. cc.v2fzero = function () {
  30. return {x: 0, y: 0};
  31. };
  32. cc.v2f = function (x, y) {
  33. return {x: x, y: y};
  34. };
  35. cc.v2fadd = function (v0, v1) {
  36. return cc.v2f(v0.x + v1.x, v0.y + v1.y);
  37. };
  38. cc.v2fsub = function (v0, v1) {
  39. return cc.v2f(v0.x - v1.x, v0.y - v1.y);
  40. };
  41. cc.v2fmult = function (v, s) {
  42. return cc.v2f(v.x * s, v.y * s);
  43. };
  44. cc.v2fperp = function (p0) {
  45. return cc.v2f(-p0.y, p0.x);
  46. };
  47. cc.v2fneg = function (p0) {
  48. return cc.v2f(-p0.x, -p0.y);
  49. };
  50. cc.v2fdot = function (p0, p1) {
  51. return p0.x * p1.x + p0.y * p1.y;
  52. };
  53. cc.v2fforangle = function (_a_) {
  54. return cc.v2f(Math.cos(_a_), Math.sin(_a_));
  55. };
  56. cc.v2fnormalize = function (p) {
  57. var r = cc.pNormalize(cc.p(p.x, p.y));
  58. return cc.v2f(r.x, r.y);
  59. };
  60. cc.__v2f = function (v) {
  61. return cc.v2f(v.x, v.y);
  62. };
  63. cc.__t = function (v) {
  64. return {u: v.x, v: v.y};
  65. };
  66. /**
  67. * <p>CCDrawNode <br/>
  68. * Node that draws dots, segments and polygons. <br/>
  69. * Faster than the "drawing primitives" since they it draws everything in one single batch.</p>
  70. * @class
  71. * @name cc.DrawNode
  72. * @extends cc.Node
  73. */
  74. cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNode# */{
  75. _buffer: null,
  76. _blendFunc: null,
  77. _lineWidth: 1,
  78. _drawColor: null,
  79. _className:"DrawNodeCanvas",
  80. /**
  81. * <p>The cc.DrawNodeCanvas's constructor. <br/>
  82. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.DrawNodeCanvas()".<br/>
  83. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  84. */
  85. ctor: function () {
  86. cc.Node.prototype.ctor.call(this);
  87. this._buffer = [];
  88. this._drawColor = cc.color(255, 255, 255, 255);
  89. this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST);
  90. this.init();
  91. },
  92. // ----common function start ----
  93. /**
  94. * Gets the blend func
  95. * @returns {Object}
  96. */
  97. getBlendFunc: function () {
  98. return this._blendFunc;
  99. },
  100. /**
  101. * Set the blend func
  102. * @param blendFunc
  103. * @param dst
  104. */
  105. setBlendFunc: function (blendFunc, dst) {
  106. if (dst === undefined) {
  107. this._blendFunc.src = blendFunc.src;
  108. this._blendFunc.dst = blendFunc.dst;
  109. } else {
  110. this._blendFunc.src = blendFunc;
  111. this._blendFunc.dst = dst;
  112. }
  113. },
  114. /**
  115. * line width setter
  116. * @param {Number} width
  117. */
  118. setLineWidth: function (width) {
  119. this._lineWidth = width;
  120. },
  121. /**
  122. * line width getter
  123. * @returns {Number}
  124. */
  125. getLineWidth: function () {
  126. return this._lineWidth;
  127. },
  128. /**
  129. * draw color setter
  130. * @param {cc.Color} color
  131. */
  132. setDrawColor: function (color) {
  133. var locDrawColor = this._drawColor;
  134. locDrawColor.r = color.r;
  135. locDrawColor.g = color.g;
  136. locDrawColor.b = color.b;
  137. locDrawColor.a = (color.a == null) ? 255 : color.a;
  138. },
  139. /**
  140. * draw color getter
  141. * @returns {cc.Color}
  142. */
  143. getDrawColor: function () {
  144. return cc.color(this._drawColor.r, this._drawColor.g, this._drawColor.b, this._drawColor.a);
  145. },
  146. // ----common function end ----
  147. /**
  148. * draws a rectangle given the origin and destination point measured in points.
  149. * @param {cc.Point} origin
  150. * @param {cc.Point} destination
  151. * @param {cc.Color} fillColor
  152. * @param {Number} lineWidth
  153. * @param {cc.Color} lineColor
  154. */
  155. drawRect: function (origin, destination, fillColor, lineWidth, lineColor) {
  156. lineWidth = lineWidth || this._lineWidth;
  157. lineColor = lineColor || this.getDrawColor();
  158. if(lineColor.a == null)
  159. lineColor.a = 255;
  160. var vertices = [
  161. origin,
  162. cc.p(destination.x, origin.y),
  163. destination,
  164. cc.p(origin.x, destination.y)
  165. ];
  166. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
  167. element.verts = vertices;
  168. element.lineWidth = lineWidth;
  169. element.lineColor = lineColor;
  170. element.isClosePolygon = true;
  171. element.isStroke = true;
  172. element.lineCap = "butt";
  173. element.fillColor = fillColor;
  174. if (fillColor) {
  175. if(fillColor.a == null)
  176. fillColor.a = 255;
  177. element.isFill = true;
  178. }
  179. this._buffer.push(element);
  180. },
  181. /**
  182. * draws a circle given the center, radius and number of segments.
  183. * @override
  184. * @param {cc.Point} center center of circle
  185. * @param {Number} radius
  186. * @param {Number} angle angle in radians
  187. * @param {Number} segments
  188. * @param {Boolean} drawLineToCenter
  189. * @param {Number} lineWidth
  190. * @param {cc.Color} color
  191. */
  192. drawCircle: function (center, radius, angle, segments, drawLineToCenter, lineWidth, color) {
  193. lineWidth = lineWidth || this._lineWidth;
  194. color = color || this.getDrawColor();
  195. if (color.a == null)
  196. color.a = 255;
  197. var coef = 2.0 * Math.PI / segments;
  198. var vertices = [];
  199. for (var i = 0; i <= segments; i++) {
  200. var rads = i * coef;
  201. var j = radius * Math.cos(rads + angle) + center.x;
  202. var k = radius * Math.sin(rads + angle) + center.y;
  203. vertices.push(cc.p(j, k));
  204. }
  205. if (drawLineToCenter) {
  206. vertices.push(cc.p(center.x, center.y));
  207. }
  208. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
  209. element.verts = vertices;
  210. element.lineWidth = lineWidth;
  211. element.lineColor = color;
  212. element.isClosePolygon = true;
  213. element.isStroke = true;
  214. this._buffer.push(element);
  215. },
  216. /**
  217. * draws a quad bezier path
  218. * @override
  219. * @param {cc.Point} origin
  220. * @param {cc.Point} control
  221. * @param {cc.Point} destination
  222. * @param {Number} segments
  223. * @param {Number} lineWidth
  224. * @param {cc.Color} color
  225. */
  226. drawQuadBezier: function (origin, control, destination, segments, lineWidth, color) {
  227. lineWidth = lineWidth || this._lineWidth;
  228. color = color || this.getDrawColor();
  229. if (color.a == null)
  230. color.a = 255;
  231. var vertices = [], t = 0.0;
  232. for (var i = 0; i < segments; i++) {
  233. var x = Math.pow(1 - t, 2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x;
  234. var y = Math.pow(1 - t, 2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y;
  235. vertices.push(cc.p(x, y));
  236. t += 1.0 / segments;
  237. }
  238. vertices.push(cc.p(destination.x, destination.y));
  239. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
  240. element.verts = vertices;
  241. element.lineWidth = lineWidth;
  242. element.lineColor = color;
  243. element.isStroke = true;
  244. element.lineCap = "round";
  245. this._buffer.push(element);
  246. },
  247. /**
  248. * draws a cubic bezier path
  249. * @override
  250. * @param {cc.Point} origin
  251. * @param {cc.Point} control1
  252. * @param {cc.Point} control2
  253. * @param {cc.Point} destination
  254. * @param {Number} segments
  255. * @param {Number} lineWidth
  256. * @param {cc.Color} color
  257. */
  258. drawCubicBezier: function (origin, control1, control2, destination, segments, lineWidth, color) {
  259. lineWidth = lineWidth || this._lineWidth;
  260. color = color || this.getDrawColor();
  261. if (color.a == null)
  262. color.a = 255;
  263. var vertices = [], t = 0;
  264. for (var i = 0; i < segments; i++) {
  265. var x = Math.pow(1 - t, 3) * origin.x + 3.0 * Math.pow(1 - t, 2) * t * control1.x + 3.0 * (1 - t) * t * t * control2.x + t * t * t * destination.x;
  266. var y = Math.pow(1 - t, 3) * origin.y + 3.0 * Math.pow(1 - t, 2) * t * control1.y + 3.0 * (1 - t) * t * t * control2.y + t * t * t * destination.y;
  267. vertices.push(cc.p(x, y));
  268. t += 1.0 / segments;
  269. }
  270. vertices.push(cc.p(destination.x, destination.y));
  271. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
  272. element.verts = vertices;
  273. element.lineWidth = lineWidth;
  274. element.lineColor = color;
  275. element.isStroke = true;
  276. element.lineCap = "round";
  277. this._buffer.push(element);
  278. },
  279. /**
  280. * draw a CatmullRom curve
  281. * @override
  282. * @param {Array} points
  283. * @param {Number} segments
  284. * @param {Number} lineWidth
  285. * @param {cc.Color} color
  286. */
  287. drawCatmullRom: function (points, segments, lineWidth, color) {
  288. this.drawCardinalSpline(points, 0.5, segments, lineWidth, color);
  289. },
  290. /**
  291. * draw a cardinal spline path
  292. * @override
  293. * @param {Array} config
  294. * @param {Number} tension
  295. * @param {Number} segments
  296. * @param {Number} lineWidth
  297. * @param {cc.Color} color
  298. */
  299. drawCardinalSpline: function (config, tension, segments, lineWidth, color) {
  300. lineWidth = lineWidth || this._lineWidth;
  301. color = color || this.getDrawColor();
  302. if(color.a == null)
  303. color.a = 255;
  304. var vertices = [], p, lt, deltaT = 1.0 / config.length;
  305. for (var i = 0; i < segments + 1; i++) {
  306. var dt = i / segments;
  307. // border
  308. if (dt == 1) {
  309. p = config.length - 1;
  310. lt = 1;
  311. } else {
  312. p = 0 | (dt / deltaT);
  313. lt = (dt - deltaT * p) / deltaT;
  314. }
  315. // Interpolate
  316. var newPos = cc.cardinalSplineAt(
  317. cc.getControlPointAt(config, p - 1),
  318. cc.getControlPointAt(config, p - 0),
  319. cc.getControlPointAt(config, p + 1),
  320. cc.getControlPointAt(config, p + 2),
  321. tension, lt);
  322. vertices.push(newPos);
  323. }
  324. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
  325. element.verts = vertices;
  326. element.lineWidth = lineWidth;
  327. element.lineColor = color;
  328. element.isStroke = true;
  329. element.lineCap = "round";
  330. this._buffer.push(element);
  331. },
  332. /**
  333. * draw a dot at a position, with a given radius and color
  334. * @param {cc.Point} pos
  335. * @param {Number} radius
  336. * @param {cc.Color} color
  337. */
  338. drawDot: function (pos, radius, color) {
  339. color = color || this.getDrawColor();
  340. if (color.a == null)
  341. color.a = 255;
  342. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_DOT);
  343. element.verts = [pos];
  344. element.lineWidth = radius;
  345. element.fillColor = color;
  346. this._buffer.push(element);
  347. },
  348. /**
  349. * draws an array of points.
  350. * @override
  351. * @param {Array} points point of array
  352. * @param {Number} radius
  353. * @param {cc.Color} color
  354. */
  355. drawDots: function(points, radius, color){
  356. if(!points || points.length == 0)
  357. return;
  358. color = color || this.getDrawColor();
  359. if (color.a == null)
  360. color.a = 255;
  361. for(var i = 0, len = points.length; i < len; i++)
  362. this.drawDot(points[i], radius, color);
  363. },
  364. /**
  365. * draw a segment with a radius and color
  366. * @param {cc.Point} from
  367. * @param {cc.Point} to
  368. * @param {Number} lineWidth
  369. * @param {cc.Color} color
  370. */
  371. drawSegment: function (from, to, lineWidth, color) {
  372. lineWidth = lineWidth || this._lineWidth;
  373. color = color || this.getDrawColor();
  374. if (color.a == null)
  375. color.a = 255;
  376. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
  377. element.verts = [from, to];
  378. element.lineWidth = lineWidth * 2;
  379. element.lineColor = color;
  380. element.isStroke = true;
  381. element.lineCap = "round";
  382. this._buffer.push(element);
  383. },
  384. /**
  385. * draw a polygon with a fill color and line color without copying the vertex list
  386. * @param {Array} verts
  387. * @param {cc.Color} fillColor
  388. * @param {Number} lineWidth
  389. * @param {cc.Color} color
  390. */
  391. drawPoly_: function (verts, fillColor, lineWidth, color) {
  392. lineWidth = lineWidth || this._lineWidth;
  393. color = color || this.getDrawColor();
  394. if (color.a == null)
  395. color.a = 255;
  396. var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
  397. element.verts = verts;
  398. element.fillColor = fillColor;
  399. element.lineWidth = lineWidth;
  400. element.lineColor = color;
  401. element.isClosePolygon = true;
  402. element.isStroke = true;
  403. element.lineCap = "round";
  404. if (fillColor)
  405. element.isFill = true;
  406. this._buffer.push(element);
  407. },
  408. /**
  409. * draw a polygon with a fill color and line color, copying the vertex list
  410. * @param {Array} verts
  411. * @param {cc.Color} fillColor
  412. * @param {Number} lineWidth
  413. * @param {cc.Color} color
  414. */
  415. drawPoly: function (verts, fillColor, lineWidth, color) {
  416. var vertsCopy = [];
  417. for (var i=0; i < verts.length; i++) {
  418. vertsCopy.push(cc.p(verts[i].x, verts[i].y));
  419. }
  420. return this.drawPoly_(vertsCopy, fillColor, lineWidth, color);
  421. },
  422. /**
  423. * Render function using the canvas 2d context or WebGL context, internal usage only, please do not call this function
  424. * @param {CanvasRenderingContext2D | WebGLRenderingContext} ctx The render context
  425. */
  426. draw: function (ctx) {
  427. var context = ctx || cc._renderContext, _t = this;
  428. if ((_t._blendFunc && (_t._blendFunc.src == cc.SRC_ALPHA) && (_t._blendFunc.dst == cc.ONE)))
  429. context.globalCompositeOperation = 'lighter';
  430. for (var i = 0; i < _t._buffer.length; i++) {
  431. var element = _t._buffer[i];
  432. switch (element.type) {
  433. case cc.DrawNode.TYPE_DOT:
  434. _t._drawDot(context, element);
  435. break;
  436. case cc.DrawNode.TYPE_SEGMENT:
  437. _t._drawSegment(context, element);
  438. break;
  439. case cc.DrawNode.TYPE_POLY:
  440. _t._drawPoly(context, element);
  441. break;
  442. }
  443. }
  444. },
  445. _drawDot: function (ctx, element) {
  446. var locColor = element.fillColor, locPos = element.verts[0], locRadius = element.lineWidth;
  447. var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
  448. ctx.fillStyle = "rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")";
  449. ctx.beginPath();
  450. ctx.arc(locPos.x * locScaleX, -locPos.y * locScaleY, locRadius * locScaleX, 0, Math.PI * 2, false);
  451. ctx.closePath();
  452. ctx.fill();
  453. },
  454. _drawSegment: function (ctx, element) {
  455. var locColor = element.lineColor;
  456. var locFrom = element.verts[0];
  457. var locTo = element.verts[1];
  458. var locLineWidth = element.lineWidth;
  459. var locLineCap = element.lineCap;
  460. var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
  461. ctx.strokeStyle = "rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")";
  462. ctx.lineWidth = locLineWidth * locScaleX;
  463. ctx.beginPath();
  464. ctx.lineCap = locLineCap;
  465. ctx.moveTo(locFrom.x * locScaleX, -locFrom.y * locScaleY);
  466. ctx.lineTo(locTo.x * locScaleX, -locTo.y * locScaleY);
  467. ctx.stroke();
  468. },
  469. _drawPoly: function (ctx, element) {
  470. var locVertices = element.verts;
  471. var locLineCap = element.lineCap;
  472. var locFillColor = element.fillColor;
  473. var locLineWidth = element.lineWidth;
  474. var locLineColor = element.lineColor;
  475. var locIsClosePolygon = element.isClosePolygon;
  476. var locIsFill = element.isFill;
  477. var locIsStroke = element.isStroke;
  478. if (locVertices == null)
  479. return;
  480. var firstPoint = locVertices[0];
  481. var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
  482. ctx.lineCap = locLineCap;
  483. if (locFillColor) {
  484. ctx.fillStyle = "rgba(" + (0 | locFillColor.r) + "," + (0 | locFillColor.g) + ","
  485. + (0 | locFillColor.b) + "," + locFillColor.a / 255 + ")";
  486. }
  487. if (locLineWidth) {
  488. ctx.lineWidth = locLineWidth * locScaleX;
  489. }
  490. if (locLineColor) {
  491. ctx.strokeStyle = "rgba(" + (0 | locLineColor.r) + "," + (0 | locLineColor.g) + ","
  492. + (0 | locLineColor.b) + "," + locLineColor.a / 255 + ")";
  493. }
  494. ctx.beginPath();
  495. ctx.moveTo(firstPoint.x * locScaleX, -firstPoint.y * locScaleY);
  496. for (var i = 1, len = locVertices.length; i < len; i++)
  497. ctx.lineTo(locVertices[i].x * locScaleX, -locVertices[i].y * locScaleY);
  498. if (locIsClosePolygon)
  499. ctx.closePath();
  500. if (locIsFill)
  501. ctx.fill();
  502. if (locIsStroke)
  503. ctx.stroke();
  504. },
  505. /**
  506. * Clear the geometry in the node's buffer.
  507. */
  508. clear: function () {
  509. this._buffer.length = 0;
  510. }
  511. });
  512. //Just only a note
  513. cc.DrawNodeWebGL = cc.Node.extend({
  514. _bufferCapacity:0,
  515. _buffer:null,
  516. _trianglesArrayBuffer:null,
  517. _trianglesWebBuffer:null,
  518. _trianglesReader:null,
  519. _lineWidth: 1,
  520. _drawColor: null,
  521. _blendFunc:null,
  522. _dirty:false,
  523. _className:"DrawNodeWebGL",
  524. // ----common function start ----
  525. getBlendFunc:function () {
  526. return this._blendFunc;
  527. },
  528. setBlendFunc:function (blendFunc, dst) {
  529. if (dst === undefined) {
  530. this._blendFunc.src = blendFunc.src;
  531. this._blendFunc.dst = blendFunc.dst;
  532. } else {
  533. this._blendFunc.src = blendFunc;
  534. this._blendFunc.dst = dst;
  535. }
  536. },
  537. // ----common function end ----
  538. ctor:function () {
  539. cc.Node.prototype.ctor.call(this);
  540. this._buffer = [];
  541. this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST);
  542. this._drawColor = cc.color(255,255,255,255);
  543. this.init();
  544. },
  545. init:function () {
  546. if (cc.Node.prototype.init.call(this)) {
  547. this.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_LENGTHTEXTURECOLOR);
  548. this._ensureCapacity(64);
  549. this._trianglesWebBuffer = cc._renderContext.createBuffer();
  550. this._dirty = true;
  551. return true;
  552. }
  553. return false;
  554. },
  555. setLineWidth: function (width) {
  556. this._lineWidth = width;
  557. },
  558. getLineWidth: function () {
  559. return this._lineWidth;
  560. },
  561. setDrawColor: function (color) {
  562. var locDrawColor = this._drawColor;
  563. locDrawColor.r = color.r;
  564. locDrawColor.g = color.g;
  565. locDrawColor.b = color.b;
  566. locDrawColor.a = color.a;
  567. },
  568. getDrawColor: function () {
  569. return cc.color(this._drawColor.r, this._drawColor.g, this._drawColor.b, this._drawColor.a);
  570. },
  571. drawRect: function (origin, destination, fillColor, lineWidth, lineColor) {
  572. lineWidth = lineWidth || this._lineWidth;
  573. lineColor = lineColor || this.getDrawColor();
  574. if (lineColor.a == null)
  575. lineColor.a = 255;
  576. var vertices = [origin, cc.p(destination.x, origin.y), destination, cc.p(origin.x, destination.y)];
  577. if(fillColor == null)
  578. this._drawSegments(vertices, lineWidth, lineColor, true);
  579. else
  580. this.drawPoly(vertices, fillColor, lineWidth, lineColor);
  581. },
  582. drawCircle: function (center, radius, angle, segments, drawLineToCenter, lineWidth, color) {
  583. lineWidth = lineWidth || this._lineWidth;
  584. color = color || this.getDrawColor();
  585. if (color.a == null)
  586. color.a = 255;
  587. var coef = 2.0 * Math.PI / segments, vertices = [], i, len;
  588. for (i = 0; i <= segments; i++) {
  589. var rads = i * coef;
  590. var j = radius * Math.cos(rads + angle) + center.x;
  591. var k = radius * Math.sin(rads + angle) + center.y;
  592. vertices.push(cc.p(j, k));
  593. }
  594. if (drawLineToCenter)
  595. vertices.push(cc.p(center.x, center.y));
  596. lineWidth *= 0.5;
  597. for (i = 0, len = vertices.length; i < len - 1; i++)
  598. this.drawSegment(vertices[i], vertices[i + 1], lineWidth, color);
  599. },
  600. drawQuadBezier: function (origin, control, destination, segments, lineWidth, color) {
  601. lineWidth = lineWidth || this._lineWidth;
  602. color = color || this.getDrawColor();
  603. if (color.a == null)
  604. color.a = 255;
  605. var vertices = [], t = 0.0;
  606. for (var i = 0; i < segments; i++) {
  607. var x = Math.pow(1 - t, 2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x;
  608. var y = Math.pow(1 - t, 2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y;
  609. vertices.push(cc.p(x, y));
  610. t += 1.0 / segments;
  611. }
  612. vertices.push(cc.p(destination.x, destination.y));
  613. this._drawSegments(vertices, lineWidth, color, false);
  614. },
  615. drawCubicBezier: function (origin, control1, control2, destination, segments, lineWidth, color) {
  616. lineWidth = lineWidth || this._lineWidth;
  617. color = color || this.getDrawColor();
  618. if (color.a == null)
  619. color.a = 255;
  620. var vertices = [], t = 0;
  621. for (var i = 0; i < segments; i++) {
  622. var x = Math.pow(1 - t, 3) * origin.x + 3.0 * Math.pow(1 - t, 2) * t * control1.x + 3.0 * (1 - t) * t * t * control2.x + t * t * t * destination.x;
  623. var y = Math.pow(1 - t, 3) * origin.y + 3.0 * Math.pow(1 - t, 2) * t * control1.y + 3.0 * (1 - t) * t * t * control2.y + t * t * t * destination.y;
  624. vertices.push(cc.p(x, y));
  625. t += 1.0 / segments;
  626. }
  627. vertices.push(cc.p(destination.x, destination.y));
  628. this._drawSegments(vertices, lineWidth, color, false);
  629. },
  630. drawCatmullRom: function (points, segments, lineWidth, color) {
  631. this.drawCardinalSpline(points, 0.5, segments, lineWidth, color);
  632. },
  633. drawCardinalSpline: function (config, tension, segments, lineWidth, color) {
  634. lineWidth = lineWidth || this._lineWidth;
  635. color = color || this.getDrawColor();
  636. if (color.a == null)
  637. color.a = 255;
  638. var vertices = [], p, lt, deltaT = 1.0 / config.length;
  639. for (var i = 0; i < segments + 1; i++) {
  640. var dt = i / segments;
  641. // border
  642. if (dt == 1) {
  643. p = config.length - 1;
  644. lt = 1;
  645. } else {
  646. p = 0 | (dt / deltaT);
  647. lt = (dt - deltaT * p) / deltaT;
  648. }
  649. // Interpolate
  650. var newPos = cc.cardinalSplineAt(
  651. cc.getControlPointAt(config, p - 1),
  652. cc.getControlPointAt(config, p - 0),
  653. cc.getControlPointAt(config, p + 1),
  654. cc.getControlPointAt(config, p + 2),
  655. tension, lt);
  656. vertices.push(newPos);
  657. }
  658. lineWidth *= 0.5;
  659. for (var j = 0, len = vertices.length; j < len - 1; j++)
  660. this.drawSegment(vertices[j], vertices[j + 1], lineWidth, color);
  661. },
  662. _render:function () {
  663. var gl = cc._renderContext;
  664. cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
  665. gl.bindBuffer(gl.ARRAY_BUFFER, this._trianglesWebBuffer);
  666. if (this._dirty) {
  667. gl.bufferData(gl.ARRAY_BUFFER, this._trianglesArrayBuffer, gl.STREAM_DRAW);
  668. this._dirty = false;
  669. }
  670. var triangleSize = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT;
  671. // vertex
  672. gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, triangleSize, 0);
  673. // color
  674. gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, triangleSize, 8);
  675. // texcood
  676. gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, triangleSize, 12);
  677. gl.drawArrays(gl.TRIANGLES, 0, this._buffer.length * 3);
  678. cc.incrementGLDraws(1);
  679. //cc.checkGLErrorDebug();
  680. },
  681. _ensureCapacity:function(count){
  682. var _t = this;
  683. var locBuffer = _t._buffer;
  684. if(locBuffer.length + count > _t._bufferCapacity){
  685. var TriangleLength = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT;
  686. _t._bufferCapacity += Math.max(_t._bufferCapacity, count);
  687. //re alloc
  688. if((locBuffer == null) || (locBuffer.length === 0)){
  689. //init
  690. _t._buffer = [];
  691. _t._trianglesArrayBuffer = new ArrayBuffer(TriangleLength * _t._bufferCapacity);
  692. _t._trianglesReader = new Uint8Array(_t._trianglesArrayBuffer);
  693. } else {
  694. var newTriangles = [];
  695. var newArrayBuffer = new ArrayBuffer(TriangleLength * _t._bufferCapacity);
  696. for(var i = 0; i < locBuffer.length;i++){
  697. newTriangles[i] = new cc.V2F_C4B_T2F_Triangle(locBuffer[i].a,locBuffer[i].b,locBuffer[i].c,
  698. newArrayBuffer, i * TriangleLength);
  699. }
  700. _t._trianglesReader = new Uint8Array(newArrayBuffer);
  701. _t._trianglesArrayBuffer = newArrayBuffer;
  702. _t._buffer = newTriangles;
  703. }
  704. }
  705. },
  706. draw:function () {
  707. cc.glBlendFunc(this._blendFunc.src, this._blendFunc.dst);
  708. this._shaderProgram.use();
  709. this._shaderProgram.setUniformsForBuiltins();
  710. this._render();
  711. },
  712. drawDot:function (pos, radius, color) {
  713. color = color || this.getDrawColor();
  714. if (color.a == null)
  715. color.a = 255;
  716. var c4bColor = {r: 0 | color.r, g: 0 | color.g, b: 0 | color.b, a: 0 | color.a};
  717. var a = {vertices: {x: pos.x - radius, y: pos.y - radius}, colors: c4bColor, texCoords: {u: -1.0, v: -1.0}};
  718. var b = {vertices: {x: pos.x - radius, y: pos.y + radius}, colors: c4bColor, texCoords: {u: -1.0, v: 1.0}};
  719. var c = {vertices: {x: pos.x + radius, y: pos.y + radius}, colors: c4bColor, texCoords: {u: 1.0, v: 1.0}};
  720. var d = {vertices: {x: pos.x + radius, y: pos.y - radius}, colors: c4bColor, texCoords: {u: 1.0, v: -1.0}};
  721. this._ensureCapacity(2*3);
  722. this._buffer.push(new cc.V2F_C4B_T2F_Triangle(a, b, c, this._trianglesArrayBuffer, this._buffer.length * cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT));
  723. this._buffer.push(new cc.V2F_C4B_T2F_Triangle(a, c, d, this._trianglesArrayBuffer, this._buffer.length * cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT));
  724. this._dirty = true;
  725. },
  726. drawDots: function(points, radius,color) {
  727. if(!points || points.length == 0)
  728. return;
  729. color = color || this.getDrawColor();
  730. if (color.a == null)
  731. color.a = 255;
  732. for(var i = 0, len = points.length; i < len; i++)
  733. this.drawDot(points[i], radius, color);
  734. },
  735. drawSegment:function (from, to, radius, color) {
  736. color = color || this.getDrawColor();
  737. if (color.a == null)
  738. color.a = 255;
  739. radius = radius || (this._lineWidth * 0.5);
  740. var vertexCount = 6*3;
  741. this._ensureCapacity(vertexCount);
  742. var c4bColor = {r: 0 | color.r, g: 0 | color.g, b: 0 | color.b, a: 0 | color.a};
  743. var a = cc.__v2f(from), b = cc.__v2f(to);
  744. var n = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(b, a))), t = cc.v2fperp(n);
  745. var nw = cc.v2fmult(n, radius), tw = cc.v2fmult(t, radius);
  746. var v0 = cc.v2fsub(b, cc.v2fadd(nw, tw));
  747. var v1 = cc.v2fadd(b, cc.v2fsub(nw, tw));
  748. var v2 = cc.v2fsub(b, nw);
  749. var v3 = cc.v2fadd(b, nw);
  750. var v4 = cc.v2fsub(a, nw);
  751. var v5 = cc.v2fadd(a, nw);
  752. var v6 = cc.v2fsub(a, cc.v2fsub(nw, tw));
  753. var v7 = cc.v2fadd(a, cc.v2fadd(nw, tw));
  754. var TriangleLength = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, triangleBuffer = this._trianglesArrayBuffer, locBuffer = this._buffer;
  755. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(cc.v2fadd(n, t)))},
  756. {vertices: v1, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))},
  757. triangleBuffer, locBuffer.length * TriangleLength));
  758. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: cc.__t(n)},
  759. {vertices: v1, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))},
  760. triangleBuffer, locBuffer.length * TriangleLength));
  761. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: cc.__t(n)},
  762. {vertices: v4, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))}, {vertices: v2, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))},
  763. triangleBuffer, locBuffer.length * TriangleLength));
  764. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: cc.__t(n)},
  765. {vertices: v4, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))}, {vertices: v5, colors: c4bColor, texCoords: cc.__t(n)},
  766. triangleBuffer, locBuffer.length * TriangleLength));
  767. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(t, n))},
  768. {vertices: v4, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))}, {vertices: v5, colors: c4bColor, texCoords: cc.__t(n)},
  769. triangleBuffer, locBuffer.length * TriangleLength));
  770. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(t, n))},
  771. {vertices: v7, colors: c4bColor, texCoords: cc.__t(cc.v2fadd(n, t))}, {vertices: v5, colors: c4bColor, texCoords: cc.__t(n)},
  772. triangleBuffer, locBuffer.length * TriangleLength));
  773. this._dirty = true;
  774. },
  775. drawPoly:function (verts, fillColor, borderWidth, borderColor) {
  776. if(fillColor == null){
  777. this._drawSegments(verts, borderWidth, borderColor, true);
  778. return;
  779. }
  780. if (fillColor.a == null)
  781. fillColor.a = 255;
  782. if (borderColor.a == null)
  783. borderColor.a = 255;
  784. borderWidth = borderWidth || this._lineWidth;
  785. borderWidth *= 0.5;
  786. var c4bFillColor = {r: 0 | fillColor.r, g: 0 | fillColor.g, b: 0 | fillColor.b, a: 0 | fillColor.a};
  787. var c4bBorderColor = {r: 0 | borderColor.r, g: 0 | borderColor.g, b: 0 | borderColor.b, a: 0 | borderColor.a};
  788. var extrude = [], i, v0, v1, v2, count = verts.length;
  789. for (i = 0; i < count; i++) {
  790. v0 = cc.__v2f(verts[(i - 1 + count) % count]);
  791. v1 = cc.__v2f(verts[i]);
  792. v2 = cc.__v2f(verts[(i + 1) % count]);
  793. var n1 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v1, v0)));
  794. var n2 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v2, v1)));
  795. var offset = cc.v2fmult(cc.v2fadd(n1, n2), 1.0 / (cc.v2fdot(n1, n2) + 1.0));
  796. extrude[i] = {offset: offset, n: n2};
  797. }
  798. var outline = (borderWidth > 0.0), triangleCount = 3 * count - 2, vertexCount = 3 * triangleCount;
  799. this._ensureCapacity(vertexCount);
  800. var triangleBytesLen = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, trianglesBuffer = this._trianglesArrayBuffer;
  801. var locBuffer = this._buffer;
  802. var inset = (outline == false ? 0.5 : 0.0);
  803. for (i = 0; i < count - 2; i++) {
  804. v0 = cc.v2fsub(cc.__v2f(verts[0]), cc.v2fmult(extrude[0].offset, inset));
  805. v1 = cc.v2fsub(cc.__v2f(verts[i + 1]), cc.v2fmult(extrude[i + 1].offset, inset));
  806. v2 = cc.v2fsub(cc.__v2f(verts[i + 2]), cc.v2fmult(extrude[i + 2].offset, inset));
  807. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
  808. {vertices: v1, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())}, {vertices: v2, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
  809. trianglesBuffer, locBuffer.length * triangleBytesLen));
  810. }
  811. for (i = 0; i < count; i++) {
  812. var j = (i + 1) % count;
  813. v0 = cc.__v2f(verts[i]);
  814. v1 = cc.__v2f(verts[j]);
  815. var n0 = extrude[i].n;
  816. var offset0 = extrude[i].offset;
  817. var offset1 = extrude[j].offset;
  818. var inner0 = outline ? cc.v2fsub(v0, cc.v2fmult(offset0, borderWidth)) : cc.v2fsub(v0, cc.v2fmult(offset0, 0.5));
  819. var inner1 = outline ? cc.v2fsub(v1, cc.v2fmult(offset1, borderWidth)) : cc.v2fsub(v1, cc.v2fmult(offset1, 0.5));
  820. var outer0 = outline ? cc.v2fadd(v0, cc.v2fmult(offset0, borderWidth)) : cc.v2fadd(v0, cc.v2fmult(offset0, 0.5));
  821. var outer1 = outline ? cc.v2fadd(v1, cc.v2fmult(offset1, borderWidth)) : cc.v2fadd(v1, cc.v2fmult(offset1, 0.5));
  822. if (outline) {
  823. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
  824. {vertices: inner1, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
  825. trianglesBuffer, locBuffer.length * triangleBytesLen));
  826. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
  827. {vertices: outer0, colors: c4bBorderColor, texCoords: cc.__t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
  828. trianglesBuffer, locBuffer.length * triangleBytesLen));
  829. } else {
  830. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
  831. {vertices: inner1, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())}, {vertices: outer1, colors: c4bFillColor, texCoords: cc.__t(n0)},
  832. trianglesBuffer, locBuffer.length * triangleBytesLen));
  833. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
  834. {vertices: outer0, colors: c4bFillColor, texCoords: cc.__t(n0)}, {vertices: outer1, colors: c4bFillColor, texCoords: cc.__t(n0)},
  835. trianglesBuffer, locBuffer.length * triangleBytesLen));
  836. }
  837. }
  838. extrude = null;
  839. this._dirty = true;
  840. },
  841. _drawSegments: function(verts, borderWidth, borderColor, closePoly){
  842. borderWidth = borderWidth || this._lineWidth;
  843. borderColor = borderColor || this._drawColor;
  844. if(borderColor.a == null)
  845. borderColor.a = 255;
  846. borderWidth *= 0.5;
  847. if (borderWidth <= 0)
  848. return;
  849. var c4bBorderColor = {r: 0 | borderColor.r, g: 0 | borderColor.g, b: 0 | borderColor.b, a: 0 | borderColor.a };
  850. var extrude = [], i, v0, v1, v2, count = verts.length;
  851. for (i = 0; i < count; i++) {
  852. v0 = cc.__v2f(verts[(i - 1 + count) % count]);
  853. v1 = cc.__v2f(verts[i]);
  854. v2 = cc.__v2f(verts[(i + 1) % count]);
  855. var n1 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v1, v0)));
  856. var n2 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v2, v1)));
  857. var offset = cc.v2fmult(cc.v2fadd(n1, n2), 1.0 / (cc.v2fdot(n1, n2) + 1.0));
  858. extrude[i] = {offset: offset, n: n2};
  859. }
  860. var triangleCount = 3 * count - 2, vertexCount = 3 * triangleCount;
  861. this._ensureCapacity(vertexCount);
  862. var triangleBytesLen = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, trianglesBuffer = this._trianglesArrayBuffer;
  863. var locBuffer = this._buffer;
  864. var len = closePoly ? count : count - 1;
  865. for (i = 0; i < len; i++) {
  866. var j = (i + 1) % count;
  867. v0 = cc.__v2f(verts[i]);
  868. v1 = cc.__v2f(verts[j]);
  869. var n0 = extrude[i].n;
  870. var offset0 = extrude[i].offset;
  871. var offset1 = extrude[j].offset;
  872. var inner0 = cc.v2fsub(v0, cc.v2fmult(offset0, borderWidth));
  873. var inner1 = cc.v2fsub(v1, cc.v2fmult(offset1, borderWidth));
  874. var outer0 = cc.v2fadd(v0, cc.v2fmult(offset0, borderWidth));
  875. var outer1 = cc.v2fadd(v1, cc.v2fmult(offset1, borderWidth));
  876. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
  877. {vertices: inner1, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
  878. trianglesBuffer, locBuffer.length * triangleBytesLen));
  879. locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
  880. {vertices: outer0, colors: c4bBorderColor, texCoords: cc.__t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
  881. trianglesBuffer, locBuffer.length * triangleBytesLen));
  882. }
  883. extrude = null;
  884. this._dirty = true;
  885. },
  886. clear:function () {
  887. this._buffer.length = 0;
  888. this._dirty = true;
  889. }
  890. });
  891. cc.DrawNode = cc._renderType == cc._RENDER_TYPE_WEBGL ? cc.DrawNodeWebGL : cc.DrawNodeCanvas;
  892. /**
  893. * Creates a DrawNode
  894. * @deprecated since v3.0 please use new cc.DrawNode() instead.
  895. * @return {cc.DrawNode}
  896. */
  897. cc.DrawNode.create = function () {
  898. return new cc.DrawNode();
  899. };
  900. cc._DrawNodeElement = function (type, verts, fillColor, lineWidth, lineColor, lineCap, isClosePolygon, isFill, isStroke) {
  901. var _t = this;
  902. _t.type = type;
  903. _t.verts = verts || null;
  904. _t.fillColor = fillColor || null;
  905. _t.lineWidth = lineWidth || 0;
  906. _t.lineColor = lineColor || null;
  907. _t.lineCap = lineCap || "butt";
  908. _t.isClosePolygon = isClosePolygon || false;
  909. _t.isFill = isFill || false;
  910. _t.isStroke = isStroke || false;
  911. };
  912. cc.DrawNode.TYPE_DOT = 0;
  913. cc.DrawNode.TYPE_SEGMENT = 1;
  914. cc.DrawNode.TYPE_POLY = 2;