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 
  6  http://www.cocos2d-x.org
  7 
  8  Permission is hereby granted, free of charge, to any person obtaining a copy
  9  of this software and associated documentation files (the "Software"), to deal
 10  in the Software without restriction, including without limitation the rights
 11  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12  copies of the Software, and to permit persons to whom the Software is
 13  furnished to do so, subject to the following conditions:
 14 
 15  The above copyright notice and this permission notice shall be included in
 16  all copies or substantial portions of the Software.
 17 
 18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 24  THE SOFTWARE.
 25  ****************************************************************************/
 26 
 27 /**
 28  * Color class, please use cc.color() to construct a color
 29  * @class cc.Color
 30  * @param {Number} r
 31  * @param {Number} g
 32  * @param {Number} b
 33  * @param {Number} a
 34  * @see cc.color
 35  */
 36 cc.Color = function (r, g, b, a) {
 37     this.r = r || 0;
 38     this.g = g || 0;
 39     this.b = b || 0;
 40     this.a = (a == null) ? 255 : a;
 41 };
 42 
 43 /**
 44  * Generate a color object based on multiple forms of parameters
 45  * @example
 46  *
 47  * // 1. All channels separately as parameters
 48  * var color1 = cc.color(255, 255, 255, 255);
 49  *
 50  * // 2. Convert a hex string to a color
 51  * var color2 = cc.color("#000000");
 52  *
 53  * // 3. An color object as parameter
 54  * var color3 = cc.color({r: 255, g: 255, b: 255, a: 255});
 55  *
 56  * Alpha channel is optional. Default value is 255
 57  *
 58  * @param {Number|String|cc.Color} r
 59  * @param {Number} [g]
 60  * @param {Number} [b]
 61  * @param {Number} [a=255]
 62  * @return {cc.Color}
 63  */
 64 cc.color = function (r, g, b, a) {
 65     if (r === undefined)
 66         return {r: 0, g: 0, b: 0, a: 255};
 67     if (cc.isString(r))
 68         return cc.hexToColor(r);
 69     if (cc.isObject(r))
 70         return {r: r.r, g: r.g, b: r.b, a: (r.a == null) ? 255 : r.a};
 71     return  {r: r, g: g, b: b, a: (a == null ? 255 : a)};
 72 };
 73 
 74 /**
 75  * returns true if both ccColor3B are equal. Otherwise it returns false.
 76  * @function
 77  * @param {cc.Color} color1
 78  * @param {cc.Color} color2
 79  * @return {Boolean}  true if both ccColor3B are equal. Otherwise it returns false.
 80  */
 81 cc.colorEqual = function (color1, color2) {
 82     return color1.r === color2.r && color1.g === color2.g && color1.b === color2.b;
 83 };
 84 
 85 /**
 86  * the device accelerometer reports values for each axis in units of g-force
 87  * @class cc.Acceleration
 88  * @constructor
 89  * @param {Number} x
 90  * @param {Number} y
 91  * @param {Number} z
 92  * @param {Number} timestamp
 93  */
 94 cc.Acceleration = function (x, y, z, timestamp) {
 95     this.x = x || 0;
 96     this.y = y || 0;
 97     this.z = z || 0;
 98     this.timestamp = timestamp || 0;
 99 };
100 
101 /**
102  * @class cc.Vertex2F
103  * @param {Number} x
104  * @param {Number}y
105  * @param {Array} arrayBuffer
106  * @param {Number}offset
107  * @constructor
108  */
109 cc.Vertex2F = function (x, y, arrayBuffer, offset) {
110     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Vertex2F.BYTES_PER_ELEMENT);
111     this._offset = offset || 0;
112 
113     this._xF32 = new Float32Array(this._arrayBuffer, this._offset, 1);
114     this._yF32 = new Float32Array(this._arrayBuffer, this._offset + 4, 1);
115     this._xF32[0] = x || 0;
116     this._yF32[0] = y || 0;
117 };
118 /**
119  * @constant
120  * @type {number}
121  */
122 cc.Vertex2F.BYTES_PER_ELEMENT = 8;
123 
124 _p = cc.Vertex2F.prototype;
125 _p._getX = function () {
126     return this._xF32[0];
127 };
128 _p._setX = function (xValue) {
129     this._xF32[0] = xValue;
130 };
131 _p._getY = function () {
132     return this._yF32[0];
133 };
134 _p._setY = function (yValue) {
135     this._yF32[0] = yValue;
136 };
137 /** @expose */
138 _p.x;
139 cc.defineGetterSetter(_p, "x", _p._getX, _p._setX);
140 /** @expose */
141 _p.y;
142 cc.defineGetterSetter(_p, "y", _p._getY, _p._setY);
143 
144 /**
145  * @class cc.Vertex3F
146  * @param {Number} x
147  * @param {Number} y
148  * @param {Number}z
149  * @param {Array} arrayBuffer
150  * @param {Number} offset
151  * @constructor
152  */
153 cc.Vertex3F = function (x, y, z, arrayBuffer, offset) {
154     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Vertex3F.BYTES_PER_ELEMENT);
155     this._offset = offset || 0;
156 
157     var locArrayBuffer = this._arrayBuffer, locOffset = this._offset;
158     this._xF32 = new Float32Array(locArrayBuffer, locOffset, 1);
159     this._xF32[0] = x || 0;
160     this._yF32 = new Float32Array(locArrayBuffer, locOffset + Float32Array.BYTES_PER_ELEMENT, 1);
161     this._yF32[0] = y || 0;
162     this._zF32 = new Float32Array(locArrayBuffer, locOffset + Float32Array.BYTES_PER_ELEMENT * 2, 1);
163     this._zF32[0] = z || 0;
164 };
165 /**
166  * @constant
167  * @type {number}
168  */
169 cc.Vertex3F.BYTES_PER_ELEMENT = 12;
170 
171 _p = cc.Vertex3F.prototype;
172 _p._getX = function () {
173     return this._xF32[0];
174 };
175 _p._setX = function (xValue) {
176     this._xF32[0] = xValue;
177 };
178 _p._getY = function () {
179     return this._yF32[0];
180 };
181 _p._setY = function (yValue) {
182     this._yF32[0] = yValue;
183 };
184 _p._getZ = function () {
185     return this._zF32[0];
186 };
187 _p._setZ = function (zValue) {
188     this._zF32[0] = zValue;
189 };
190 /** @expose */
191 _p.x;
192 cc.defineGetterSetter(_p, "x", _p._getX, _p._setX);
193 /** @expose */
194 _p.y;
195 cc.defineGetterSetter(_p, "y", _p._getY, _p._setY);
196 /** @expose */
197 _p.z;
198 cc.defineGetterSetter(_p, "z", _p._getZ, _p._setZ);
199 
200 /**
201  * @class cc.Tex2F
202  * @param {Number} u
203  * @param {Number} v
204  * @param {Array} arrayBuffer
205  * @param {Number} offset
206  * @constructor
207  */
208 cc.Tex2F = function (u, v, arrayBuffer, offset) {
209     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Tex2F.BYTES_PER_ELEMENT);
210     this._offset = offset || 0;
211 
212     this._uF32 = new Float32Array(this._arrayBuffer, this._offset, 1);
213     this._vF32 = new Float32Array(this._arrayBuffer, this._offset + 4, 1);
214     this._uF32[0] = u || 0;
215     this._vF32[0] = v || 0;
216 };
217 /**
218  * @constants
219  * @type {number}
220  */
221 cc.Tex2F.BYTES_PER_ELEMENT = 8;
222 
223 _p = cc.Tex2F.prototype;
224 _p._getU = function () {
225     return this._uF32[0];
226 };
227 _p._setU = function (xValue) {
228     this._uF32[0] = xValue;
229 };
230 _p._getV = function () {
231     return this._vF32[0];
232 };
233 _p._setV = function (yValue) {
234     this._vF32[0] = yValue;
235 };
236 /** @expose */
237 _p.u;
238 cc.defineGetterSetter(_p, "u", _p._getU, _p._setU);
239 /** @expose */
240 _p.v;
241 cc.defineGetterSetter(_p, "v", _p._getV, _p._setV);
242 
243 /**
244  * @class cc.Quad2
245  * @param {cc.Vertex2F} tl
246  * @param {cc.Vertex2F} tr
247  * @param {cc.Vertex2F} bl
248  * @param {cc.Vertex2F} br
249  * @param {Array} arrayBuffer
250  * @param {Number} offset
251  * @constructor
252  */
253 cc.Quad2 = function (tl, tr, bl, br, arrayBuffer, offset) {
254     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Quad2.BYTES_PER_ELEMENT);
255     this._offset = offset || 0;
256 
257     var locArrayBuffer = this._arrayBuffer, locElementLen = cc.Vertex2F.BYTES_PER_ELEMENT;
258     this._tl = tl ? new cc.Vertex2F(tl.x, tl.y, locArrayBuffer, 0) : new cc.Vertex2F(0, 0, locArrayBuffer, 0);
259     this._tr = tr ? new cc.Vertex2F(tr.x, tr.y, locArrayBuffer, locElementLen) : new cc.Vertex2F(0, 0, locArrayBuffer, locElementLen);
260     this._bl = bl ? new cc.Vertex2F(bl.x, bl.y, locArrayBuffer, locElementLen * 2) : new cc.Vertex2F(0, 0, locArrayBuffer, locElementLen * 2);
261     this._br = br ? new cc.Vertex2F(br.x, br.y, locArrayBuffer, locElementLen * 3) : new cc.Vertex2F(0, 0, locArrayBuffer, locElementLen * 3);
262 };
263 /**
264  * @constant
265  * @type {number}
266  */
267 cc.Quad2.BYTES_PER_ELEMENT = 32;
268 
269 _p = cc.Quad2.prototype;
270 _p._getTL = function () {
271     return this._tl;
272 };
273 _p._setTL = function (tlValue) {
274     this._tl.x = tlValue.x;
275     this._tl.y = tlValue.y;
276 };
277 _p._getTR = function () {
278     return this._tr;
279 };
280 _p._setTR = function (trValue) {
281     this._tr.x = trValue.x;
282     this._tr.y = trValue.y;
283 };
284 _p._getBL = function() {
285     return this._bl;
286 };
287 _p._setBL = function (blValue) {
288     this._bl.x = blValue.x;
289     this._bl.y = blValue.y;
290 };
291 _p._getBR = function () {
292     return this._br;
293 };
294 _p._setBR = function (brValue) {
295     this._br.x = brValue.x;
296     this._br.y = brValue.y;
297 };
298 
299 /** @expose */
300 _p.tl;
301 cc.defineGetterSetter(_p, "tl", _p._getTL, _p._setTL);
302 /** @expose */
303 _p.tr;
304 cc.defineGetterSetter(_p, "tr", _p._getTR, _p._setTR);
305 /** @expose */
306 _p.bl;
307 cc.defineGetterSetter(_p, "bl", _p._getBL, _p._setBL);
308 /** @expose */
309 _p.br;
310 cc.defineGetterSetter(_p, "br", _p._getBR, _p._setBR);
311 
312 /**
313  * A 3D Quad. 4 * 3 floats
314  * @Class cc.Quad3
315  * @Construct
316  * @param {cc.Vertex3F} bl1
317  * @param {cc.Vertex3F} br1
318  * @param {cc.Vertex3F} tl1
319  * @param {cc.Vertex3F} tr1
320  */
321 cc.Quad3 = function (bl1, br1, tl1, tr1) {
322     this.bl = bl1 || new cc.Vertex3F(0, 0, 0);
323     this.br = br1 || new cc.Vertex3F(0, 0, 0);
324     this.tl = tl1 || new cc.Vertex3F(0, 0, 0);
325     this.tr = tr1 || new cc.Vertex3F(0, 0, 0);
326 };
327 
328 /**
329  * @class cc.V3F_C4B_T2F
330  * @param {cc.Vertex3F} vertices
331  * @param {cc.Color} colors
332  * @param {cc.Tex2F} texCoords
333  * @param {Array} arrayBuffer
334  * @param {Number} offset
335  * @constructor
336  */
337 cc.V3F_C4B_T2F = function (vertices, colors, texCoords, arrayBuffer, offset) {
338     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V3F_C4B_T2F.BYTES_PER_ELEMENT);
339     this._offset = offset || 0;
340 
341     var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.Vertex3F.BYTES_PER_ELEMENT;
342     this._vertices = vertices ? new cc.Vertex3F(vertices.x, vertices.y, vertices.z, locArrayBuffer, locOffset) :
343         new cc.Vertex3F(0, 0, 0, locArrayBuffer, locOffset);
344     this._colors = colors ? cc.color(colors.r, colors.g, colors.b, colors.a, locArrayBuffer, locOffset + locElementLen) :
345         cc.color(0, 0, 0, 0, locArrayBuffer, locOffset + locElementLen);
346     this._texCoords = texCoords ? new cc.Tex2F(texCoords.u, texCoords.v, locArrayBuffer, locOffset + locElementLen + cc.Color.BYTES_PER_ELEMENT) :
347         new cc.Tex2F(0, 0, locArrayBuffer, locOffset + locElementLen + cc.Color.BYTES_PER_ELEMENT);
348 };
349 /**
350  * @constant
351  * @type {number}
352  */
353 cc.V3F_C4B_T2F.BYTES_PER_ELEMENT = 24;
354 
355 _p = cc.V3F_C4B_T2F.prototype;
356 _p._getVertices = function () {
357     return this._vertices;
358 };
359 _p._setVertices = function (verticesValue) {
360     var locVertices = this._vertices;
361     locVertices.x = verticesValue.x;
362     locVertices.y = verticesValue.y;
363     locVertices.z = verticesValue.z;
364 };
365 _p._getColor = function () {
366     return this._colors;
367 };
368 _p._setColor = function (colorValue) {
369     var locColors = this._colors;
370     locColors.r = colorValue.r;
371     locColors.g = colorValue.g;
372     locColors.b = colorValue.b;
373     locColors.a = colorValue.a;
374 };
375 _p._getTexCoords = function () {
376     return this._texCoords;
377 };
378 _p._setTexCoords = function (texValue) {
379     this._texCoords.u = texValue.u;
380     this._texCoords.v = texValue.v;
381 };
382 /** @expose */
383 _p.vertices;
384 cc.defineGetterSetter(_p, "vertices", _p._getVertices, _p._setVertices);
385 /** @expose */
386 _p.colors;
387 cc.defineGetterSetter(_p, "colors", _p._getColor, _p._setColor);
388 /** @expose */
389 _p.texCoords;
390 cc.defineGetterSetter(_p, "texCoords", _p._getTexCoords, _p._setTexCoords);
391 
392 /**
393  * @cc.class cc.V3F_C4B_T2F_Quad
394  * @param {cc.V3F_C4B_T2F} tl
395  * @param {cc.V3F_C4B_T2F} bl
396  * @param {cc.V3F_C4B_T2F} tr
397  * @param {cc.V3F_C4B_T2F} br
398  * @param {Array} arrayBuffer
399  * @param {Number} offset
400  * @constructor
401  */
402 cc.V3F_C4B_T2F_Quad = function (tl, bl, tr, br, arrayBuffer, offset) {
403     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT);
404     this._offset = offset || 0;
405 
406     var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.V3F_C4B_T2F.BYTES_PER_ELEMENT;
407     this._tl = tl ? new cc.V3F_C4B_T2F(tl.vertices, tl.colors, tl.texCoords, locArrayBuffer, locOffset) :
408         new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
409     this._bl = bl ? new cc.V3F_C4B_T2F(bl.vertices, bl.colors, bl.texCoords, locArrayBuffer, locOffset + locElementLen) :
410         new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen);
411     this._tr = tr ? new cc.V3F_C4B_T2F(tr.vertices, tr.colors, tr.texCoords, locArrayBuffer, locOffset + locElementLen * 2) :
412         new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen * 2);
413     this._br = br ? new cc.V3F_C4B_T2F(br.vertices, br.colors, br.texCoords, locArrayBuffer, locOffset + locElementLen * 3) :
414         new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen * 3);
415 };
416 /**
417  * @constant
418  * @type {number}
419  */
420 cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT = 96;
421 _p = cc.V3F_C4B_T2F_Quad.prototype;
422 _p._getTL = function () {
423     return this._tl;
424 };
425 _p._setTL = function (tlValue) {
426     var locTl = this._tl;
427     locTl.vertices = tlValue.vertices;
428     locTl.colors = tlValue.colors;
429     locTl.texCoords = tlValue.texCoords;
430 };
431 _p._getBL = function () {
432     return this._bl;
433 };
434 _p._setBL = function (blValue) {
435     var locBl = this._bl;
436     locBl.vertices = blValue.vertices;
437     locBl.colors = blValue.colors;
438     locBl.texCoords = blValue.texCoords;
439 };
440 _p._getTR = function () {
441     return this._tr;
442 };
443 _p._setTR = function (trValue) {
444     var locTr = this._tr;
445     locTr.vertices = trValue.vertices;
446     locTr.colors = trValue.colors;
447     locTr.texCoords = trValue.texCoords;
448 };
449 _p._getBR = function () {
450     return this._br;
451 };
452 _p._setBR = function (brValue) {
453     var locBr = this._br;
454     locBr.vertices = brValue.vertices;
455     locBr.colors = brValue.colors;
456     locBr.texCoords = brValue.texCoords;
457 };
458 _p._getArrayBuffer = function () {
459     return this._arrayBuffer;
460 };
461 
462 /** @expose */
463 _p.tl;
464 cc.defineGetterSetter(_p, "tl", _p._getTL, _p._setTL);
465 /** @expose */
466 _p.tr;
467 cc.defineGetterSetter(_p, "tr", _p._getTR, _p._setTR);
468 /** @expose */
469 _p.bl;
470 cc.defineGetterSetter(_p, "bl", _p._getBL, _p._setBL);
471 /** @expose */
472 _p.br;
473 cc.defineGetterSetter(_p, "br", _p._getBR, _p._setBR);
474 /** @expose */
475 _p.arrayBuffer;
476 cc.defineGetterSetter(_p, "arrayBuffer", _p._getArrayBuffer, null);
477 
478 /**
479  * @function
480  * @returns {cc.V3F_C4B_T2F_Quad}
481  */
482 cc.V3F_C4B_T2F_QuadZero = function () {
483     return new cc.V3F_C4B_T2F_Quad();
484 };
485 
486 /**
487  * @function
488  * @param {cc.V3F_C4B_T2F_Quad} sourceQuad
489  * @return {cc.V3F_C4B_T2F_Quad}
490  */
491 cc.V3F_C4B_T2F_QuadCopy = function (sourceQuad) {
492     if (!sourceQuad)
493         return  cc.V3F_C4B_T2F_QuadZero();
494 
495     //return new cc.V3F_C4B_T2F_Quad(sourceQuad,tl,sourceQuad,bl,sourceQuad.tr,sourceQuad.br,null,0);
496     var srcTL = sourceQuad.tl, srcBL = sourceQuad.bl, srcTR = sourceQuad.tr, srcBR = sourceQuad.br;
497     return {
498         tl: {vertices: {x: srcTL.vertices.x, y: srcTL.vertices.y, z: srcTL.vertices.z},
499             colors: {r: srcTL.colors.r, g: srcTL.colors.g, b: srcTL.colors.b, a: srcTL.colors.a},
500             texCoords: {u: srcTL.texCoords.u, v: srcTL.texCoords.v}},
501         bl: {vertices: {x: srcBL.vertices.x, y: srcBL.vertices.y, z: srcBL.vertices.z},
502             colors: {r: srcBL.colors.r, g: srcBL.colors.g, b: srcBL.colors.b, a: srcBL.colors.a},
503             texCoords: {u: srcBL.texCoords.u, v: srcBL.texCoords.v}},
504         tr: {vertices: {x: srcTR.vertices.x, y: srcTR.vertices.y, z: srcTR.vertices.z},
505             colors: {r: srcTR.colors.r, g: srcTR.colors.g, b: srcTR.colors.b, a: srcTR.colors.a},
506             texCoords: {u: srcTR.texCoords.u, v: srcTR.texCoords.v}},
507         br: {vertices: {x: srcBR.vertices.x, y: srcBR.vertices.y, z: srcBR.vertices.z},
508             colors: {r: srcBR.colors.r, g: srcBR.colors.g, b: srcBR.colors.b, a: srcBR.colors.a},
509             texCoords: {u: srcBR.texCoords.u, v: srcBR.texCoords.v}}
510     };
511 };
512 
513 /**
514  * @function
515  * @param {Array} sourceQuads
516  * @returns {Array}
517  */
518 cc.V3F_C4B_T2F_QuadsCopy = function (sourceQuads) {
519     if (!sourceQuads)
520         return [];
521 
522     var retArr = [];
523     for (var i = 0; i < sourceQuads.length; i++) {
524         retArr.push(cc.V3F_C4B_T2F_QuadCopy(sourceQuads[i]));
525     }
526     return retArr;
527 };
528 
529 //redefine cc.V2F_C4B_T2F
530 /**
531  * @class cc.V2F_C4B_T2F
532  * @param {cc.Vertex2F} vertices
533  * @param {cc.Color} colors
534  * @param {cc.Tex2F} texCoords
535  * @param {Array} arrayBuffer
536  * @param {Number} offset
537  * @constructor
538  */
539 cc.V2F_C4B_T2F = function (vertices, colors, texCoords, arrayBuffer, offset) {
540     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V2F_C4B_T2F.BYTES_PER_ELEMENT);
541     this._offset = offset || 0;
542 
543     var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.Vertex2F.BYTES_PER_ELEMENT;
544     this._vertices = vertices ? new cc.Vertex2F(vertices.x, vertices.y, locArrayBuffer, locOffset) :
545         new cc.Vertex2F(0, 0, locArrayBuffer, locOffset);
546     this._colors = colors ? cc.color(colors.r, colors.g, colors.b, colors.a, locArrayBuffer, locOffset + locElementLen) :
547         cc.color(0, 0, 0, 0, locArrayBuffer, locOffset + locElementLen);
548     this._texCoords = texCoords ? new cc.Tex2F(texCoords.u, texCoords.v, locArrayBuffer, locOffset + locElementLen + cc.Color.BYTES_PER_ELEMENT) :
549         new cc.Tex2F(0, 0, locArrayBuffer, locOffset + locElementLen + cc.Color.BYTES_PER_ELEMENT);
550 };
551 
552 /**
553  * @constant
554  * @type {number}
555  */
556 cc.V2F_C4B_T2F.BYTES_PER_ELEMENT = 20;
557 _p = cc.V2F_C4B_T2F.prototype;
558 _p._getVertices = function () {
559     return this._vertices;
560 };
561 _p._setVertices = function (verticesValue) {
562     this._vertices.x = verticesValue.x;
563     this._vertices.y = verticesValue.y;
564 };
565 _p._getColor = function () {
566     return this._colors;
567 };
568 _p._setColor = function (colorValue) {
569     var locColors = this._colors;
570     locColors.r = colorValue.r;
571     locColors.g = colorValue.g;
572     locColors.b = colorValue.b;
573     locColors.a = colorValue.a;
574 };
575 _p._getTexCoords = function () {
576     return this._texCoords;
577 };
578 _p._setTexCoords = function (texValue) {
579     this._texCoords.u = texValue.u;
580     this._texCoords.v = texValue.v;
581 };
582 
583 /** @expose */
584 _p.vertices;
585 cc.defineGetterSetter(_p, "vertices", _p._getVertices, _p._setVertices);
586 /** @expose */
587 _p.colors;
588 cc.defineGetterSetter(_p, "colors", _p._getColor, _p._setColor);
589 /** @expose */
590 _p.texCoords;
591 cc.defineGetterSetter(_p, "texCoords", _p._getTexCoords, _p._setTexCoords);
592 
593 //redefine cc.V2F_C4B_T2F_Triangle
594 /**
595  * @class cc.V2F_C4B_T2F_Triangle
596  * @param {cc.V2F_C4B_T2F} a
597  * @param {cc.V2F_C4B_T2F} b
598  * @param {cc.V2F_C4B_T2F} c
599  * @param {Array} arrayBuffer
600  * @param {Number} offset
601  * @constructor
602  */
603 cc.V2F_C4B_T2F_Triangle = function (a, b, c, arrayBuffer, offset) {
604     this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT);
605     this._offset = offset || 0;
606 
607     var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT;
608     this._a = a ? new cc.V2F_C4B_T2F(a.vertices, a.colors, a.texCoords, locArrayBuffer, locOffset) :
609         new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
610     this._b = b ? new cc.V2F_C4B_T2F(b.vertices, b.colors, b.texCoords, locArrayBuffer, locOffset + locElementLen) :
611         new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen);
612     this._c = c ? new cc.V2F_C4B_T2F(c.vertices, c.colors, c.texCoords, locArrayBuffer, locOffset + locElementLen * 2) :
613         new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen * 2);
614 };
615 /**
616  * @constant
617  * @type {number}
618  */
619 cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT = 60;
620 _p = cc.V2F_C4B_T2F_Triangle.prototype;
621 _p._getA = function () {
622     return this._a;
623 };
624 _p._setA = function (aValue) {
625     var locA = this._a;
626     locA.vertices = aValue.vertices;
627     locA.colors = aValue.colors;
628     locA.texCoords = aValue.texCoords;
629 };
630 _p._getB = function () {
631     return this._b;
632 };
633 _p._setB = function (bValue) {
634     var locB = this._b;
635     locB.vertices = bValue.vertices;
636     locB.colors = bValue.colors;
637     locB.texCoords = bValue.texCoords;
638 };
639 _p._getC = function () {
640     return this._c;
641 };
642 _p._setC = function (cValue) {
643     var locC = this._c;
644     locC.vertices = cValue.vertices;
645     locC.colors = cValue.colors;
646     locC.texCoords = cValue.texCoords;
647 };
648 
649 /** @expose */
650 _p.a;
651 cc.defineGetterSetter(_p, "a", _p._getA, _p._setA);
652 /** @expose */
653 _p.b;
654 cc.defineGetterSetter(_p, "b", _p._getB, _p._setB);
655 /** @expose */
656 _p.c;
657 cc.defineGetterSetter(_p, "c", _p._getC, _p._setC);
658 
659 /**
660  * Helper macro that creates an Vertex2F type composed of 2 floats: x, y
661  * @function
662  * @param {Number} x
663  * @param {Number} y
664  * @return {cc.Vertex2F}
665  */
666 cc.vertex2 = function (x, y) {
667     return new cc.Vertex2F(x, y);
668 };
669 
670 /**
671  * Helper macro that creates an Vertex3F type composed of 3 floats: x, y, z
672  * @function
673  * @param {Number} x
674  * @param {Number} y
675  * @param {Number} z
676  * @return {cc.Vertex3F}
677  */
678 cc.vertex3 = function (x, y, z) {
679     return new cc.Vertex3F(x, y, z);
680 };
681 
682 /**
683  * Helper macro that creates an Tex2F type: A texcoord composed of 2 floats: u, y
684  * @function
685  * @param {Number} u
686  * @param {Number} v
687  * @return {cc.Tex2F}
688  */
689 cc.tex2 = function (u, v) {
690     return new cc.Tex2F(u, v);
691 };
692 
693 /**
694  * Blend Function used for textures
695  * @Class cc.BlendFunc
696  * @Constructor
697  * @param {Number} src1 source blend function
698  * @param {Number} dst1 destination blend function
699  */
700 cc.BlendFunc = function (src1, dst1) {
701     this.src = src1;
702     this.dst = dst1;
703 };
704 
705 /**
706  * @function
707  * @returns {cc.BlendFunc}
708  */
709 cc.blendFuncDisable = function () {
710     return new cc.BlendFunc(cc.ONE, cc.ZERO);
711 };
712 
713 /**
714  * convert a string of color for style to Color.
715  * e.g. "#ff06ff"  to : cc.color(255,6,255)
716  * @function
717  * @param {String} hex
718  * @return {cc.Color}
719  */
720 cc.hexToColor = function (hex) {
721     hex = hex.replace(/^#?/, "0x");
722     var c = parseInt(hex);
723     var r = c >> 16;
724     var g = (c >> 8) % 256;
725     var b = c % 256;
726     return cc.color(r, g, b);
727 };
728 
729 /**
730  * convert Color to a string of color for style.
731  * e.g.  cc.color(255,6,255)  to : "#ff06ff"
732  * @function
733  * @param {cc.Color} color
734  * @return {String}
735  */
736 cc.colorToHex = function (color) {
737     var hR = color.r.toString(16), hG = color.g.toString(16), hB = color.b.toString(16);
738     return "#" + (color.r < 16 ? ("0" + hR) : hR) + (color.g < 16 ? ("0" + hG) : hG) + (color.b < 16 ? ("0" + hB) : hB);
739 };
740 
741 /**
742  * text alignment : left
743  * @constant
744  * @type Number
745  */
746 cc.TEXT_ALIGNMENT_LEFT = 0;
747 
748 /**
749  * text alignment : center
750  * @constant
751  * @type Number
752  */
753 cc.TEXT_ALIGNMENT_CENTER = 1;
754 
755 /**
756  * text alignment : right
757  * @constant
758  * @type Number
759  */
760 cc.TEXT_ALIGNMENT_RIGHT = 2;
761 
762 /**
763  * text alignment : top
764  * @constant
765  * @type Number
766  */
767 cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
768 
769 /**
770  * text alignment : center
771  * @constant
772  * @type Number
773  */
774 cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
775 
776 /**
777  * text alignment : bottom
778  * @constant
779  * @type Number
780  */
781 cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
782 
783 cc._Dictionary = cc.Class.extend({
784     _keyMapTb: null,
785     _valueMapTb: null,
786     __currId: 0,
787 
788     ctor: function () {
789         this._keyMapTb = {};
790         this._valueMapTb = {};
791         this.__currId = 2 << (0 | (Math.random() * 10));
792     },
793 
794     __getKey: function () {
795         this.__currId++;
796         return "key_" + this.__currId;
797     },
798 
799     setObject: function (value, key) {
800         if (key == null)
801             return;
802 
803         var keyId = this.__getKey();
804         this._keyMapTb[keyId] = key;
805         this._valueMapTb[keyId] = value;
806     },
807 
808     objectForKey: function (key) {
809         if (key == null)
810             return null;
811 
812         var locKeyMapTb = this._keyMapTb;
813         for (var keyId in locKeyMapTb) {
814             if (locKeyMapTb[keyId] === key)
815                 return this._valueMapTb[keyId];
816         }
817         return null;
818     },
819 
820     valueForKey: function (key) {
821         return this.objectForKey(key);
822     },
823 
824     removeObjectForKey: function (key) {
825         if (key == null)
826             return;
827 
828         var locKeyMapTb = this._keyMapTb;
829         for (var keyId in locKeyMapTb) {
830             if (locKeyMapTb[keyId] === key) {
831                 delete this._valueMapTb[keyId];
832                 delete locKeyMapTb[keyId];
833                 return;
834             }
835         }
836     },
837 
838     removeObjectsForKeys: function (keys) {
839         if (keys == null)
840             return;
841 
842         for (var i = 0; i < keys.length; i++)
843             this.removeObjectForKey(keys[i]);
844     },
845 
846     allKeys: function () {
847         var keyArr = [], locKeyMapTb = this._keyMapTb;
848         for (var key in locKeyMapTb)
849             keyArr.push(locKeyMapTb[key]);
850         return keyArr;
851     },
852 
853     removeAllObjects: function () {
854         this._keyMapTb = {};
855         this._valueMapTb = {};
856     },
857 
858     count: function () {
859         return this.allKeys().length;
860     }
861 });
862 
863 /**
864  * Common usage:
865  *
866  * var fontDef = new cc.FontDefinition();
867  * fontDef.fontName = "Arial";
868  * fontDef.fontSize = 12;
869  * ...
870  *
871  * OR using inline definition useful for constructor injection
872  *
873  * var fontDef = new cc.FontDefinition({
874  *  fontName: "Arial",
875  *  fontSize: 12
876  * });
877  *
878  *
879  *
880  * @class cc.FontDefinition
881  * @param {Object} properties - (OPTIONAL) Allow inline FontDefinition
882  * @constructor
883  */
884 cc.FontDefinition = function (properties) {
885     var _t = this;
886     _t.fontName = "Arial";
887     _t.fontSize = 12;
888     _t.textAlign = cc.TEXT_ALIGNMENT_CENTER;
889     _t.verticalAlign = cc.VERTICAL_TEXT_ALIGNMENT_TOP;
890     _t.fillStyle = cc.color(255, 255, 255, 255);
891     _t.boundingWidth = 0;
892     _t.boundingHeight = 0;
893 
894     _t.strokeEnabled = false;
895     _t.strokeStyle = cc.color(255, 255, 255, 255);
896     _t.lineWidth = 1;
897     _t.lineHeight = "normal";
898     _t.fontStyle = "normal";
899     _t.fontWeight = "normal";
900 
901     _t.shadowEnabled = false;
902     _t.shadowOffsetX = 0;
903     _t.shadowOffsetY = 0;
904     _t.shadowBlur = 0;
905     _t.shadowOpacity = 1.0;
906 
907     //properties mapping:
908     if(properties && properties instanceof Object){
909          for(var key in properties){
910              _t[key] = properties[key];
911          }
912     }
913 };
914 /**
915  * Web ONLY
916  * */
917 cc.FontDefinition.prototype._getCanvasFontStr = function(){
918     var lineHeight = !this.lineHeight.charAt ? this.lineHeight+"px" : this.lineHeight;
919     return this.fontStyle + " " + this.fontWeight + " " + this.fontSize + "px/"+lineHeight+" '" + this.fontName + "'";
920 };
921 
922 cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
923     if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
924         cc.assert(cc.isFunction(cc._tmp.PrototypeColor), cc._LogInfos.MissingFile, "CCTypesPropertyDefine.js");
925         cc._tmp.PrototypeColor();
926         delete cc._tmp.PrototypeColor;
927     }
928 });
929