1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3  Copyright (c) 2008-2010 Ricardo Quesada
  4  Copyright (c) 2011      Zynga 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  * RGB color composed of bytes 3 bytes
 29  * @Class
 30  * @Construct
 31  * @param {Number|cc.Color3B} r1 red value (0 to 255) or destination color of new color
 32  * @param {Number} [g1] green value (0 to 255)
 33  * @param {Number} [b1] blue value (0 to 255)
 34  * @example
 35  * //create an empty color
 36  * var color1 = new cc.Color3B();
 37  *
 38  * //create a red color
 39  * var redColor = new cc.Color3B(255,0,0);
 40  *
 41  * //create a new color with color
 42  * var newColor = new cc.Color3B(redColor);
 43  */
 44 cc.Color3B = function (r1, g1, b1) {
 45     switch (arguments.length) {
 46         case 0:
 47             this.r = 0;
 48             this.g = 0;
 49             this.b = 0;
 50             break;
 51         case 1:
 52             if (r1 && r1 instanceof cc.Color3B) {
 53                 this.r = (0 | r1.r) || 0;
 54                 this.g = (0 | r1.g) || 0;
 55                 this.b = (0 | r1.b) || 0;
 56             } else {
 57                 this.r = 0;
 58                 this.g = 0;
 59                 this.b = 0;
 60             }
 61             break;
 62         case 3:
 63             this.r = (0 | r1) || 0;
 64             this.g = (0 | g1) || 0;
 65             this.b = (0 | b1) || 0;
 66             break;
 67         default:
 68             throw "unknown argument type";
 69             break;
 70     }
 71 };
 72 
 73 /**
 74  * helper macro that creates an ccColor3B type
 75  * @function
 76  * @param {Number} r red value (0 to 255)
 77  * @param {Number} g green value (0 to 255)
 78  * @param {Number} b blue value (0 to 255)
 79  * @return {Number,Number,Number}
 80  */
 81 cc.c3b = function (r, g, b) {
 82     return new cc.Color3B(r, g, b);
 83 };
 84 
 85 cc.integerToColor3B = function (intValue) {
 86     intValue = intValue || 0;
 87 
 88     var offset = 0xff;
 89     var retColor = new cc.Color3B();
 90     retColor.r = intValue & (offset);
 91     retColor.g = (intValue >> 8) & offset;
 92     retColor.b = (intValue >> 16) & offset;
 93     return retColor;
 94 };
 95 
 96 // compatibility
 97 cc.c3 = cc.c3b;
 98 
 99 /**
100  * returns true if both ccColor3B are equal. Otherwise it returns false.
101  * @param {cc.Color3B} color1
102  * @param {cc.Color3B} color2
103  * @return {Boolean}  true if both ccColor3B are equal. Otherwise it returns false.
104  */
105 cc.c3BEqual = function(color1, color2){
106     return color1.r === color2.r && color1.g === color2.g && color1.b === color2.b;
107 };
108 
109 //ccColor3B predefined colors
110 Object.defineProperties(cc, {
111     WHITE: {
112         get: function () {
113             return cc.c3b(255, 255, 255);
114         }
115     },
116     YELLOW: {
117         get: function () {
118             return cc.c3b(255, 255, 0);
119         }
120     },
121     BLUE: {
122         get: function () {
123             return cc.c3b(0, 0, 255);
124         }
125     },
126     GREEN: {
127         get: function () {
128             return cc.c3b(0, 255, 0);
129         }
130     },
131     RED: {
132         get: function () {
133             return cc.c3b(255, 0, 0);
134         }
135     },
136     MAGENTA: {
137         get: function () {
138             return cc.c3b(255, 0, 255);
139         }
140     },
141     BLACK: {
142         get: function () {
143             return cc.c3b(0, 0, 0);
144         }
145     },
146     ORANGE: {
147         get: function () {
148             return cc.c3b(255, 127, 0);
149         }
150     },
151     GRAY: {
152         get: function () {
153             return cc.c3b(166, 166, 166);
154         }
155     }
156 });
157 
158 /**
159  *  White color (255,255,255)
160  * @constant
161  * @type {Number,Number,Number}
162  */
163 cc.white = function () {
164     return new cc.Color3B(255, 255, 255);
165 };
166 
167 /**
168  *  Yellow color (255,255,0)
169  * @constant
170  * @type {Number,Number,Number}
171  */
172 cc.yellow = function () {
173     return new cc.Color3B(255, 255, 0);
174 };
175 
176 /**
177  *  Blue color (0,0,255)
178  * @constant
179  * @type {Number,Number,Number}
180  */
181 cc.blue = function () {
182     return new cc.Color3B(0, 0, 255);
183 };
184 
185 /**
186  *  Green Color (0,255,0)
187  * @constant
188  * @type {Number,Number,Number}
189  */
190 cc.green = function () {
191     return new cc.Color3B(0, 255, 0);
192 };
193 
194 /**
195  *  Red Color (255,0,0,)
196  * @constant
197  * @type {Number,Number,Number}
198  */
199 cc.red = function () {
200     return new cc.Color3B(255, 0, 0);
201 };
202 
203 /**
204  *  Magenta Color (255,0,255)
205  * @constant
206  * @type {Number,Number,Number}
207  */
208 cc.magenta = function () {
209     return new cc.Color3B(255, 0, 255);
210 };
211 
212 /**
213  *  Black Color (0,0,0)
214  * @constant
215  * @type {Number,Number,Number}
216  */
217 cc.black = function () {
218     return new cc.Color3B(0, 0, 0);
219 };
220 
221 /**
222  *  Orange Color (255,127,0)
223  * @constant
224  * @type {Number,Number,Number}
225  */
226 cc.orange = function () {
227     return new cc.Color3B(255, 127, 0);
228 };
229 
230 /**
231  *  Gray Color (166,166,166)
232  * @constant
233  * @type {Number,Number,Number}
234  */
235 cc.gray = function () {
236     return new cc.Color3B(166, 166, 166);
237 };
238 
239 /**
240  * RGBA color composed of 4 bytes
241  * @Class
242  * @Construct
243  * @param {Number} r1 red value (0 to 255)
244  * @param {Number} g1 green value (0 to 255)
245  * @param {Number} b1 blue value (0 to 255)
246  * @param {Number} a1 Alpha value (0 to 255)
247  * @example
248  * //create a red color
249  * var redColor = new cc.Color4B(255,0,0,255);
250  */
251 cc.Color4B = function (r1, g1, b1, a1) {
252     this.r = 0 | r1;
253     this.g = 0 | g1;
254     this.b = 0 | b1;
255     this.a = 0 | a1;
256 };
257 
258 /**
259  * helper macro that creates an ccColor4B type
260  * @function
261  * @param {Number} r red value (0 to 255)
262  * @param {Number} g green value (0 to 255)
263  * @param {Number} b blue value (0 to 255)
264  * @param {Number} a Alpha value (0 to 255)
265  * @return {Number,Number,Number,Number}
266  */
267 cc.c4b = function (r, g, b, a) {
268     return new cc.Color4B(r, g, b, a);
269 };
270 
271 // backwards compatibility
272 cc.c4 = cc.c4b;
273 
274 /**
275  * RGBA color composed of 4 floats
276  * @Class
277  * @Construct
278  * @param {Number} r1 red value (0 to 1)
279  * @param {Number} g1 green value (0 to 1)
280  * @param {Number} b1 blue value (0 to 1)
281  * @param {Number} a1 Alpha value (0 to 1)
282  * @example
283  * //create a red color
284  * var redColor = new cc.Color4F(1,0,0,1);
285  */
286 cc.Color4F = function (r1, g1, b1, a1) {
287     this.r = r1;
288     this.g = g1;
289     this.b = b1;
290     this.a = a1;
291 };
292 
293 
294 /**
295  * helper macro that creates an ccColor4F type
296  * @Class
297  * @Construct
298  * @param {Number} r red value (0 to 1)
299  * @param {Number} g green value (0 to 1)
300  * @param {Number} b blue value (0 to 1)
301  * @param {Number} a Alpha value (0 to 1)
302  * @example
303  * //create a red color
304  * var redColor = cc.c4f(1,0,0,1);
305  */
306 cc.c4f = function (r, g, b, a) {
307     return new cc.Color4F(r, g, b, a);
308 };
309 
310 /**
311  * Returns a cc.Color4F from a cc.Color3B. Alpha will be 1.
312  * @function
313  * @param {cc.Color3B} c color
314  * @return {cc.Color4F}
315  */
316 cc.c4FFromccc3B = function (c) {
317     return new cc.Color4F(c.r / 255.0, c.g / 255.0, c.b / 255.0, 1.0);
318 };
319 
320 /**
321  * Returns a cc.Color4F from a cc.Color4B.
322  * @function
323  * @param {cc.Color4B} c Color
324  * @return {cc.Color4F}
325  */
326 cc.c4FFromccc4B = function (c) {
327     return new cc.Color4F(c.r / 255.0, c.g / 255.0, c.b / 255.0, c.a / 255.0);
328 };
329 
330 /**
331  * Returns a cc.Color4B from a cc.Color4F.
332  * @param {cc.Color4F} c
333  * @return {cc.Color4B}
334  */
335 cc.c4BFromccc4F = function (c) {
336     return new cc.Color4B(0 | (c.r * 255), 0 | (c.g * 255), 0 | (c.b * 255), 0 | (c.a * 255));
337 };
338 
339 /**
340  * returns YES if both cc.Color4F are equal. Otherwise it returns NO.
341  * @param {cc.Color4F} a color1
342  * @param {cc.Color4F} b color2
343  * @return {Boolean}
344  */
345 cc.c4FEqual = function (a, b) {
346     return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
347 };
348 
349 /**
350  * A vertex composed of 2 floats: x, y
351  * @Class
352  * @Construct
353  * @param {Number} x1
354  * @param {Number} y1
355  */
356 cc.Vertex2F = function (x1, y1) {
357     this.x = x1 || 0;
358     this.y = y1 || 0;
359 };
360 
361 /**
362  * helper macro that creates an Vertex2F type
363  * @function
364  * @param {Number} x
365  * @param {Number} y
366  * @return {cc.Vertex2F}
367  */
368 cc.Vertex2 = function (x, y) {
369     return new cc.Vertex2F(x, y);
370 };
371 
372 /**
373  * A vertex composed of 3 floats: x, y, z
374  * @Class
375  * @Construct
376  * @param {Number} x1
377  * @param {Number} y1
378  * @param {Number} z1
379  */
380 cc.Vertex3F = function (x1, y1, z1) {
381     this.x = x1 || 0;
382     this.y = y1 || 0;
383     this.z = z1 || 0;
384 };
385 
386 /**
387  * helper macro that creates an Vertex3F type
388  * @function
389  * @param {Number} x
390  * @param {Number} y
391  * @param {Number} z
392  * @return {cc.Vertex3F}
393  */
394 cc.vertex3 = function (x, y, z) {
395     return new cc.Vertex3F(x, y, z);
396 };
397 
398 /**
399  * A texcoord composed of 2 floats: u, y
400  * @Class
401  * @Construct
402  * @param {Number} u1
403  * @param {Number} v1
404  */
405 cc.Tex2F = function (u1, v1) {
406     this.u = u1 || 0;
407     this.v = v1 || 0;
408 };
409 
410 /**
411  * helper macro that creates an Tex2F type
412  * @function
413  * @param {Number} u
414  * @param {Number} v
415  * @return {cc.Tex2F}
416  */
417 cc.tex2 = function (u, v) {
418     return new cc.Tex2F(u, v);
419 };
420 
421 /**
422  * Point Sprite component
423  * @Class
424  * @Construct
425  * @param {cc.Vertex2F} pos1
426  * @param {cc.Color4B} color1
427  * @param {Number} size1
428  */
429 cc.PointSprite = function (pos1, color1, size1) {
430     this.pos = pos1 || new cc.Vertex2F(0, 0);
431     this.color = color1 || new cc.Color4B(0, 0, 0, 0);
432     this.size = size1 || 0;
433 };
434 
435 /**
436  * A 2D Quad. 4 * 2 floats
437  * @Class
438  * @Construct
439  * @param {cc.Vertex2F} tl1
440  * @param {cc.Vertex2F} tr1
441  * @param {cc.Vertex2F} bl1
442  * @param {cc.Vertex2F} br1
443  */
444 cc.Quad2 = function (tl1, tr1, bl1, br1) {
445     this.tl = tl1 || new cc.Vertex2F(0, 0);
446     this.tr = tr1 || new cc.Vertex2F(0, 0);
447     this.bl = bl1 || new cc.Vertex2F(0, 0);
448     this.br = br1 || new cc.Vertex2F(0, 0);
449 };
450 
451 /**
452  * A 3D Quad. 4 * 3 floats
453  * @Class
454  * @Construct
455  * @param {cc.Vertex3F} bl1
456  * @param {cc.Vertex3F} br1
457  * @param {cc.Vertex3F} tl1
458  * @param {cc.Vertex3F} tr1
459  */
460 cc.Quad3 = function (bl1, br1, tl1, tr1) {
461     this.bl = bl1 || new cc.Vertex3F(0, 0, 0);
462     this.br = br1 || new cc.Vertex3F(0, 0, 0);
463     this.tl = tl1 || new cc.Vertex3F(0, 0, 0);
464     this.tr = tr1 || new cc.Vertex3F(0, 0, 0);
465 };
466 
467 /**
468  * A 2D grid size
469  * @Class
470  * @Construct
471  * @param {Number} x1
472  * @param {Number} y1
473  * @deprecated
474  */
475 cc.GridSize = function (x1, y1) {
476     this.x = x1;
477     this.y = y1;
478 };
479 
480 /**
481  * helper function to create a cc.GridSize
482  * @function
483  * @param {Number} x
484  * @param {Number} y
485  * @return {cc.GridSize}
486  * @deprecated
487  */
488 cc.g = function (x, y) {
489     return new cc.GridSize(x, y);
490 };
491 
492 /**
493  * a Point with a vertex point, a tex coord point and a color 4B
494  * @Class
495  * @Construct
496  * @param {cc.Vertex2F} vertices1
497  * @param {cc.Color4B} colors1
498  * @param {cc.Tex2F} texCoords1
499  */
500 cc.V2F_C4B_T2F = function (vertices1, colors1, texCoords1) {
501     this.vertices = vertices1 || new cc.Vertex2F(0, 0);
502     this.colors = colors1 || new cc.Color4B(0, 0, 0, 0);
503     this.texCoords = texCoords1 || new cc.Tex2F(0, 0);
504 };
505 
506 /**
507  * a Point with a vertex point, a tex coord point and a color 4F
508  * @Class
509  * @Construct
510  * @param {cc.Vertex2F} vertices1
511  * @param {cc.Color4F} colors1
512  * @param {cc.Tex2F} texCoords1
513  */
514 cc.V2F_C4F_T2F = function (vertices1, colors1, texCoords1) {
515     this.vertices = vertices1 || new cc.Vertex2F(0, 0);
516     this.colors = colors1 || new cc.Color4F(0, 0, 0, 0);
517     this.texCoords = texCoords1 || new cc.Tex2F(0, 0);
518 };
519 
520 /**
521  * a Point with a vertex point, a tex coord point and a color 4B
522  * @Class
523  * @Construct
524  * @param {cc.Vertex3F} vertices1
525  * @param {cc.Color4B} colors1
526  * @param {cc.Tex2F} texCoords1
527  */
528 cc.V3F_C4B_T2F = function (vertices1, colors1, texCoords1) {
529     this.vertices = vertices1 || new cc.Vertex3F(0, 0, 0);
530     this.colors = colors1 || new cc.Color4B(0, 0, 0, 0);
531     this.texCoords = texCoords1 || new cc.Tex2F(0, 0);
532 };
533 
534 /**
535  * A Triangle of ccV2F_C4B_T2F
536  * @Class
537  * @Construct
538  * @param {cc.V2F_C4B_T2F} a
539  * @param {cc.V2F_C4B_T2F} b
540  * @param {cc.V2F_C4B_T2F} c
541  */
542 cc.V2F_C4B_T2F_Triangle = function (a, b, c) {
543     this.a = a || new cc.V2F_C4B_T2F();
544     this.b = b || new cc.V2F_C4B_T2F();
545     this.c = c || new cc.V2F_C4B_T2F();
546 };
547 
548 /**
549  * 4 ccVertex2FTex2FColor4B Quad
550  * @Class
551  * @Construct
552  * @param {cc.V2F_C4B_T2F} bl1 bottom left
553  * @param {cc.V2F_C4B_T2F} br1 bottom right
554  * @param {cc.V2F_C4B_T2F} tl1 top left
555  * @param {cc.V2F_C4B_T2F} tr1 top right
556  */
557 cc.V2F_C4B_T2F_Quad = function (bl1, br1, tl1, tr1) {
558     this.bl = bl1 || new cc.V2F_C4B_T2F();
559     this.br = br1 || new cc.V2F_C4B_T2F();
560     this.tl = tl1 || new cc.V2F_C4B_T2F();
561     this.tr = tr1 || new cc.V2F_C4B_T2F();
562 };
563 
564 /**
565  * helper function to create a cc.V2F_C4B_T2F_Quad
566  * @function
567  * @return {cc.V2F_C4B_T2F_Quad}
568  */
569 cc.V2F_C4B_T2F_QuadZero = function () {
570     return new cc.V2F_C4B_T2F_Quad(
571         new cc.V2F_C4B_T2F(new cc.Vertex2F(0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0)),
572         new cc.V2F_C4B_T2F(new cc.Vertex2F(0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0)),
573         new cc.V2F_C4B_T2F(new cc.Vertex2F(0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0)),
574         new cc.V2F_C4B_T2F(new cc.Vertex2F(0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0))
575     );
576 };
577 
578 /**
579  * 4 ccVertex3FTex2FColor4B
580  * @Class
581  * @Construct
582  * @param {cc.V3F_C4B_T2F} tl1 top left
583  * @param {cc.V3F_C4B_T2F} bl1 bottom left
584  * @param {cc.V3F_C4B_T2F} tr1 top right
585  * @param {cc.V3F_C4B_T2F} br1 bottom right
586  */
587 cc.V3F_C4B_T2F_Quad = function (tl1, bl1, tr1, br1) {
588     this.tl = tl1 || new cc.V3F_C4B_T2F();
589     this.bl = bl1 || new cc.V3F_C4B_T2F();
590     this.tr = tr1 || new cc.V3F_C4B_T2F();
591     this.br = br1 || new cc.V3F_C4B_T2F();
592 };
593 
594 /**
595  * helper function to create a cc.V3F_C4B_T2F_Quad
596  * @function
597  * @return {cc.V3F_C4B_T2F_Quad}
598  */
599 cc.V3F_C4B_T2F_QuadZero = function () {
600     return new cc.V3F_C4B_T2F_Quad(
601         new cc.V3F_C4B_T2F(new cc.Vertex3F(0, 0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0)),
602         new cc.V3F_C4B_T2F(new cc.Vertex3F(0, 0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0)),
603         new cc.V3F_C4B_T2F(new cc.Vertex3F(0, 0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0)),
604         new cc.V3F_C4B_T2F(new cc.Vertex3F(0, 0, 0), new cc.Color4B(0, 0, 0, 255), new cc.Tex2F(0, 0)));
605 };
606 
607 cc.V3F_C4B_T2F_QuadCopy = function (sourceQuad) {
608     if (!sourceQuad)
609         return  cc.V3F_C4B_T2F_QuadZero();
610     var tl = sourceQuad.tl, bl = sourceQuad.bl, tr = sourceQuad.tr, br = sourceQuad.br;
611     return new cc.V3F_C4B_T2F_Quad(
612         new cc.V3F_C4B_T2F(new cc.Vertex3F(sourceQuad.tl.vertices.x, sourceQuad.tl.vertices.y, sourceQuad.tl.vertices.z),
613             new cc.Color4B(sourceQuad.tl.colors.r, sourceQuad.tl.colors.g, sourceQuad.tl.colors.b, sourceQuad.tl.colors.a),
614             new cc.Tex2F(sourceQuad.tl.texCoords.u, sourceQuad.tl.texCoords.v)),
615         new cc.V3F_C4B_T2F(new cc.Vertex3F(sourceQuad.bl.vertices.x, sourceQuad.bl.vertices.y, sourceQuad.bl.vertices.z),
616             new cc.Color4B(sourceQuad.bl.colors.r, sourceQuad.bl.colors.g, sourceQuad.bl.colors.b, sourceQuad.bl.colors.a),
617             new cc.Tex2F(sourceQuad.bl.texCoords.u, sourceQuad.bl.texCoords.v)),
618         new cc.V3F_C4B_T2F(new cc.Vertex3F(sourceQuad.tr.vertices.x, sourceQuad.tr.vertices.y, sourceQuad.tr.vertices.z),
619             new cc.Color4B(sourceQuad.tr.colors.r, sourceQuad.tr.colors.g, sourceQuad.tr.colors.b, sourceQuad.tr.colors.a),
620             new cc.Tex2F(sourceQuad.tr.texCoords.u, sourceQuad.tr.texCoords.v)),
621         new cc.V3F_C4B_T2F(new cc.Vertex3F(sourceQuad.br.vertices.x, sourceQuad.br.vertices.y, sourceQuad.br.vertices.z),
622             new cc.Color4B(sourceQuad.br.colors.r, sourceQuad.br.colors.g, sourceQuad.br.colors.b, sourceQuad.br.colors.a),
623             new cc.Tex2F(sourceQuad.br.texCoords.u, sourceQuad.br.texCoords.v)));
624 };
625 
626 cc.V3F_C4B_T2F_QuadsCopy = function (sourceQuads) {
627     if (!sourceQuads)
628         return [];
629 
630     var retArr = [];
631     for (var i = 0; i < sourceQuads.length; i++) {
632         retArr.push(cc.V3F_C4B_T2F_QuadCopy(sourceQuads[i]));
633     }
634     return retArr;
635 };
636 
637 /**
638  * 4 ccVertex2FTex2FColor4F Quad
639  * @Class
640  * @Construct
641  * @param {cc.V2F_C4F_T2F} bl1 bottom left
642  * @param {cc.V2F_C4F_T2F} br1 bottom right
643  * @param {cc.V2F_C4F_T2F} tl1 top left
644  * @param {cc.V2F_C4F_T2F} tr1 top right
645  * Constructor
646  */
647 cc.V2F_C4F_T2F_Quad = function (bl1, br1, tl1, tr1) {
648     this.bl = bl1 || new cc.V2F_C4F_T2F();
649     this.br = br1 || new cc.V2F_C4F_T2F();
650     this.tl = tl1 || new cc.V2F_C4F_T2F();
651     this.tr = tr1 || new cc.V2F_C4F_T2F();
652 };
653 
654 /**
655  * Blend Function used for textures
656  * @Class
657  * @Construct
658  * @param {Number} src1 source blend function
659  * @param {Number} dst1 destination blend function
660  */
661 cc.BlendFunc = function (src1, dst1) {
662     this.src = src1;
663     this.dst = dst1;
664 };
665 
666 cc.BlendFuncDisable = function () {
667     return new cc.BlendFunc(gl.ONE, gl.ZERO);
668 };
669 
670 /**
671  * texture coordinates for a quad
672  * @param {cc.Tex2F} bl
673  * @param {cc.Tex2F} br
674  * @param {cc.Tex2F} tl
675  * @param {cc.Tex2F} tr
676  * @constructor
677  */
678 cc.T2F_Quad = function(bl, br, tl, tr){
679     this.bl = bl;
680     this.br = br;
681     this.tl = tl;
682     this.tr = tr;
683 };
684 
685 /**
686  * struct that holds the size in pixels, texture coordinates and delays for animated cc.ParticleSystem
687  * @param {cc.T2F_Quad} texCoords
688  * @param delay
689  * @param size
690  * @constructor
691  */
692 cc.AnimationFrameData = function(texCoords, delay, size){
693     this.texCoords = texCoords;
694     this.delay = delay;
695     this.size = size;
696 };
697 
698 /**
699  * convert Color3B to a string of color for style.
700  * e.g.  Color3B(255,6,255)  to : "#ff06ff"
701  * @param clr
702  * @return {String}
703  */
704 cc.convertColor3BtoHexString = function (clr) {
705     var hR = clr.r.toString(16);
706     var hG = clr.g.toString(16);
707     var hB = clr.b.toString(16);
708     var stClr = "#" + (clr.r < 16 ? ("0" + hR) : hR) + (clr.g < 16 ? ("0" + hG) : hG) + (clr.b < 16 ? ("0" + hB) : hB);
709     return stClr;
710 };
711 
712 if(cc.Browser.supportWebGL){
713     //redefine some types with ArrayBuffer for WebGL
714 
715     //redefine cc.Color4B
716     cc.Color4B = function (r, g, b, a, arrayBuffer, offset) {
717         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Color4B.BYTES_PER_ELEMENT);
718         this._offset = offset || 0;
719 
720         var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = Uint8Array.BYTES_PER_ELEMENT;
721         this._rU8 = new Uint8Array(locArrayBuffer, locOffset, 1);
722         this._gU8 = new Uint8Array(locArrayBuffer, locOffset + locElementLen, 1);
723         this._bU8 = new Uint8Array(locArrayBuffer, locOffset + locElementLen * 2, 1);
724         this._aU8 = new Uint8Array(locArrayBuffer, locOffset + locElementLen * 3, 1);
725 
726         this._rU8[0] = r || 0;
727         this._gU8[0] = g || 0;
728         this._bU8[0] = b || 0;
729         this._aU8[0] = a || 0;
730     };
731     cc.Color4B.BYTES_PER_ELEMENT = 4;
732     Object.defineProperties(cc.Color4B.prototype, {
733         r: {
734             get: function () {
735                 return this._rU8[0];
736             },
737             set: function (xValue) {
738                 this._rU8[0] = xValue;
739             },
740             enumerable: true
741         },
742         g: {
743             get: function () {
744                 return this._gU8[0];
745             },
746             set: function (yValue) {
747                 this._gU8[0]= yValue;
748             },
749             enumerable: true
750         },
751         b: {
752             get: function () {
753                 return this._bU8[0];
754             },
755             set: function (xValue) {
756                 this._bU8[0] = xValue;
757             },
758             enumerable: true
759         },
760         a: {
761             get: function () {
762                 return this._aU8[0];
763             },
764             set: function (yValue) {
765                 this._aU8[0] = yValue;
766             },
767             enumerable: true
768         }
769     });
770 
771     //redefine cc.Color4F
772     cc.Color4F = function (r, g, b, a, arrayBuffer, offset) {
773         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Color4F.BYTES_PER_ELEMENT);
774         this._offset = offset || 0;
775 
776         var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = Float32Array.BYTES_PER_ELEMENT;
777         this._rF32 = new Float32Array(locArrayBuffer, locOffset, 1);
778         this._rF32[0] = r || 0;
779         this._gF32 = new Float32Array(locArrayBuffer, locOffset + locElementLen, 1);
780         this._gF32[0] = g || 0;
781         this._bF32 = new Float32Array(locArrayBuffer, locOffset + locElementLen * 2, 1);
782         this._bF32[0] = b || 0;
783         this._aF32 = new Float32Array(locArrayBuffer, locOffset + locElementLen * 3, 1);
784         this._aF32[0] = a || 0;
785     };
786     cc.Color4F.BYTES_PER_ELEMENT = 16;
787     Object.defineProperties(cc.Color4F.prototype, {
788         r: {
789             get: function () {
790                 return this._rF32[0];
791             },
792             set: function (rValue) {
793                 this._rF32[0]  = rValue;
794             },
795             enumerable: true
796         },
797         g: {
798             get: function () {
799                 return this._gF32[0];
800             },
801             set: function (rValue) {
802                 this._gF32[0]  = rValue;
803             },
804             enumerable: true
805         },
806         b: {
807             get: function () {
808                 return this._bF32[0];
809             },
810             set: function (rValue) {
811                 this._bF32[0]  = rValue;
812             },
813             enumerable: true
814         },
815         a: {
816             get: function () {
817                 return this._aF32[0];
818             },
819             set: function (rValue) {
820                 this._aF32[0]  = rValue;
821             },
822             enumerable: true
823         }
824     });
825 
826     //redefine cc.Vertex2F
827     cc.Vertex2F = function (x, y, arrayBuffer, offset) {
828         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Vertex2F.BYTES_PER_ELEMENT);
829         this._offset = offset || 0;
830 
831         this._xF32 = new Float32Array(this._arrayBuffer, this._offset, 1);
832         this._yF32 = new Float32Array(this._arrayBuffer, this._offset + 4, 1);
833         this._xF32[0] = x || 0;
834         this._yF32[0] = y || 0;
835     };
836     cc.Vertex2F.BYTES_PER_ELEMENT = 8;
837     Object.defineProperties(cc.Vertex2F.prototype, {
838         x: {
839             get: function () {
840                 return this._xF32[0];
841             },
842             set: function (xValue) {
843                 this._xF32[0] = xValue;
844             },
845             enumerable: true
846         },
847         y: {
848             get: function () {
849                 return this._yF32[0];
850             },
851             set: function (yValue) {
852                 this._yF32[0] = yValue;
853             },
854             enumerable: true
855         }
856     });
857 
858     // redefine cc.Vertex3F
859     cc.Vertex3F = function (x, y, z, arrayBuffer, offset) {
860         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Vertex3F.BYTES_PER_ELEMENT);
861         this._offset = offset || 0;
862 
863         var locArrayBuffer = this._arrayBuffer, locOffset = this._offset;
864         this._xF32 = new Float32Array(locArrayBuffer, locOffset, 1);
865         this._xF32[0] = x || 0;
866         this._yF32 = new Float32Array(locArrayBuffer, locOffset + Float32Array.BYTES_PER_ELEMENT, 1);
867         this._yF32[0] = y || 0;
868         this._zF32 = new Float32Array(locArrayBuffer, locOffset + Float32Array.BYTES_PER_ELEMENT * 2, 1);
869         this._zF32[0] = z || 0;
870     };
871     cc.Vertex3F.BYTES_PER_ELEMENT = 12;
872     Object.defineProperties(cc.Vertex3F.prototype, {
873         x: {
874             get: function () {
875                 return this._xF32[0];
876             },
877             set: function (xValue) {
878                 this._xF32[0] = xValue;
879             },
880             enumerable: true
881         },
882         y: {
883             get: function () {
884                 return this._yF32[0];
885             },
886             set: function (yValue) {
887                 this._yF32[0] = yValue;
888             },
889             enumerable: true
890         },
891         z: {
892             get: function () {
893                 return this._zF32[0];
894             },
895             set: function (zValue) {
896                 this._zF32[0] = zValue;
897             },
898             enumerable: true
899         }
900     });
901 
902     // redefine cc.Tex2F
903     cc.Tex2F = function (u, v, arrayBuffer, offset) {
904         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Tex2F.BYTES_PER_ELEMENT);
905         this._offset = offset || 0;
906 
907         this._uF32 = new Float32Array(this._arrayBuffer, this._offset, 1);
908         this._vF32 = new Float32Array(this._arrayBuffer, this._offset + 4, 1);
909         this._uF32[0] = u || 0;
910         this._vF32[0] = v || 0;
911     };
912     cc.Tex2F.BYTES_PER_ELEMENT = 8;
913     Object.defineProperties(cc.Tex2F.prototype, {
914         u: {
915             get: function () {
916                 return this._uF32[0];
917             },
918             set: function (xValue) {
919                 this._uF32[0] = xValue;
920             },
921             enumerable: true
922         },
923         v: {
924             get: function () {
925                 return this._vF32[0];
926             },
927             set: function (yValue) {
928                 this._vF32[0] = yValue;
929             },
930             enumerable: true
931         }
932     });
933 
934     //redefine cc.Quad2
935     cc.Quad2 = function (tl, tr, bl, br, arrayBuffer, offset) {
936         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Quad2.BYTES_PER_ELEMENT);
937         this._offset = offset || 0;
938 
939         var locArrayBuffer = this._arrayBuffer, locElementLen = cc.Vertex2F.BYTES_PER_ELEMENT;
940         this._tl = tl ? new cc.Vertex2F(tl.x, tl.y, locArrayBuffer, 0) : new cc.Vertex2F(0, 0, locArrayBuffer, 0);
941         this._tr = tr ? new cc.Vertex2F(tr.x, tr.y, locArrayBuffer, locElementLen) : new cc.Vertex2F(0, 0, locArrayBuffer, locElementLen);
942         this._bl = bl ? new cc.Vertex2F(bl.x, bl.y, locArrayBuffer, locElementLen * 2) : new cc.Vertex2F(0, 0, locArrayBuffer, locElementLen * 2);
943         this._br = br ? new cc.Vertex2F(br.x, br.y, locArrayBuffer, locElementLen * 3) : new cc.Vertex2F(0, 0, locArrayBuffer, locElementLen * 3);
944     };
945     cc.Quad2.BYTES_PER_ELEMENT = 32;
946     Object.defineProperties(cc.Quad2.prototype, {
947         tl: {
948             get: function () {
949                 return this._tl;
950             },
951             set: function (tlValue) {
952                 this._tl.x = tlValue.x;
953                 this._tl.y = tlValue.y;
954             },
955             enumerable: true
956         },
957         tr: {
958             get: function () {
959                 return this._tr;
960             },
961             set: function (trValue) {
962                 this._tr.x = trValue.x;
963                 this._tr.y = trValue.y;
964             },
965             enumerable: true
966         },
967         bl: {
968             get: function () {
969                 return this._bl;
970             },
971             set: function (blValue) {
972                 this._bl.x = blValue.x;
973                 this._bl.y = blValue.y;
974             },
975             enumerable: true
976         },
977         br: {
978             get: function () {
979                 return this._br;
980             },
981             set: function (brValue) {
982                 this._br.x = brValue.x;
983                 this._br.y = brValue.y;
984             },
985             enumerable: true
986         }
987     });
988 
989     //redefine cc.V3F_C4B_T2F
990     cc.V3F_C4B_T2F = function (vertices, colors, texCoords, arrayBuffer, offset) {
991         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V3F_C4B_T2F.BYTES_PER_ELEMENT);
992         this._offset = offset || 0;
993 
994         var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.Vertex3F.BYTES_PER_ELEMENT;
995         this._vertices = vertices ? new cc.Vertex3F(vertices.x, vertices.y, vertices.z, locArrayBuffer, locOffset) :
996             new cc.Vertex3F(0, 0, 0, locArrayBuffer, locOffset);
997         this._colors = colors ? new cc.Color4B(colors.r, colors.g, colors.b, colors.a, locArrayBuffer, locOffset + locElementLen) :
998             new cc.Color4B(0, 0, 0, 0, locArrayBuffer, locOffset + locElementLen);
999         this._texCoords = texCoords ? new cc.Tex2F(texCoords.u, texCoords.v, locArrayBuffer, locOffset + locElementLen + cc.Color4B.BYTES_PER_ELEMENT) :
1000             new cc.Tex2F(0, 0, locArrayBuffer, locOffset + locElementLen + cc.Color4B.BYTES_PER_ELEMENT);
1001     };
1002     cc.V3F_C4B_T2F.BYTES_PER_ELEMENT = 24;
1003     Object.defineProperties(cc.V3F_C4B_T2F.prototype, {
1004         vertices: {
1005             get: function () {
1006                 return this._vertices;
1007             },
1008             set: function (verticesValue) {
1009                 var locVertices = this._vertices;
1010                 locVertices.x = verticesValue.x;
1011                 locVertices.y = verticesValue.y;
1012                 locVertices.z = verticesValue.z;
1013             },
1014             enumerable: true
1015         },
1016         colors: {
1017             get: function () {
1018                 return this._colors;
1019             },
1020             set: function (colorValue) {
1021                 var locColors = this._colors;
1022                 locColors.r = colorValue.r;
1023                 locColors.g = colorValue.g;
1024                 locColors.b = colorValue.b;
1025                 locColors.a = colorValue.a;
1026             },
1027             enumerable: true
1028         },
1029         texCoords: {
1030             get: function () {
1031                 return this._texCoords;
1032             },
1033             set: function (texValue) {
1034                 this._texCoords.u = texValue.u;
1035                 this._texCoords.v = texValue.v;
1036             },
1037             enumerable: true
1038         }
1039     });
1040 
1041     //redefine cc.V3F_C4B_T2F_Quad
1042     cc.V3F_C4B_T2F_Quad = function (tl, bl, tr, br, arrayBuffer, offset) {
1043         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT);
1044         this._offset = offset || 0;
1045 
1046         var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.V3F_C4B_T2F.BYTES_PER_ELEMENT;
1047         this._tl = tl ? new cc.V3F_C4B_T2F(tl.vertices, tl.colors, tl.texCoords, locArrayBuffer, locOffset) :
1048             new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
1049         this._bl = bl ? new cc.V3F_C4B_T2F(bl.vertices, bl.colors, bl.texCoords, locArrayBuffer, locOffset + locElementLen) :
1050             new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen);
1051         this._tr = tr ? new cc.V3F_C4B_T2F(tr.vertices, tr.colors, tr.texCoords, locArrayBuffer, locOffset + locElementLen * 2) :
1052             new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen * 2);
1053         this._br = br ? new cc.V3F_C4B_T2F(br.vertices, br.colors, br.texCoords, locArrayBuffer, locOffset + locElementLen * 3) :
1054             new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen * 3);
1055     };
1056     cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT = 96;
1057     Object.defineProperties(cc.V3F_C4B_T2F_Quad.prototype, {
1058         tl:{
1059             get: function () {
1060                 return this._tl;
1061             },
1062             set: function (tlValue) {
1063                 var locTl = this._tl;
1064                 locTl.vertices = tlValue.vertices;
1065                 locTl.colors = tlValue.colors;
1066                 locTl.texCoords = tlValue.texCoords;
1067             },
1068             enumerable: true
1069         },
1070         bl:{
1071             get: function () {
1072                 return this._bl;
1073             },
1074             set: function (blValue) {
1075                 var locBl = this._bl;
1076                 locBl.vertices = blValue.vertices;
1077                 locBl.colors = blValue.colors;
1078                 locBl.texCoords = blValue.texCoords;
1079             },
1080             enumerable: true
1081         },
1082         tr:{
1083             get: function () {
1084                 return this._tr;
1085             },
1086             set: function (trValue) {
1087                 var locTr = this._tr;
1088                 locTr.vertices = trValue.vertices;
1089                 locTr.colors = trValue.colors;
1090                 locTr.texCoords = trValue.texCoords;
1091             },
1092             enumerable: true
1093         },
1094         br:{
1095             get: function () {
1096                 return this._br;
1097             },
1098             set: function (brValue) {
1099                 var locBr = this._br;
1100                 locBr.vertices = brValue.vertices;
1101                 locBr.colors = brValue.colors;
1102                 locBr.texCoords = brValue.texCoords;
1103             },
1104             enumerable: true
1105         },
1106         arrayBuffer:{
1107             get: function () {
1108                 return this._arrayBuffer;
1109             },
1110             enumerable: true
1111         }
1112     });
1113     cc.V3F_C4B_T2F_QuadZero = function(){
1114         return new cc.V3F_C4B_T2F_Quad();
1115     };
1116 
1117     cc.V3F_C4B_T2F_QuadCopy = function (sourceQuad) {
1118         if (!sourceQuad)
1119             return  cc.V3F_C4B_T2F_QuadZero();
1120 
1121         //return new cc.V3F_C4B_T2F_Quad(sourceQuad,tl,sourceQuad,bl,sourceQuad.tr,sourceQuad.br,null,0);
1122         var srcTL = sourceQuad.tl, srcBL = sourceQuad.bl, srcTR = sourceQuad.tr, srcBR = sourceQuad.br;
1123         return {
1124             tl: {vertices: {x: srcTL.vertices.x, y: srcTL.vertices.y, z: srcTL.vertices.z},
1125                 colors: {r: srcTL.colors.r, g: srcTL.colors.g, b: srcTL.colors.b, a: srcTL.colors.a},
1126                 texCoords: {u: srcTL.texCoords.u, v: srcTL.texCoords.v}},
1127             bl: {vertices: {x: srcBL.vertices.x, y: srcBL.vertices.y, z: srcBL.vertices.z},
1128                 colors: {r: srcBL.colors.r, g: srcBL.colors.g, b: srcBL.colors.b, a: srcBL.colors.a},
1129                 texCoords: {u: srcBL.texCoords.u, v: srcBL.texCoords.v}},
1130             tr: {vertices: {x: srcTR.vertices.x, y: srcTR.vertices.y, z: srcTR.vertices.z},
1131                 colors: {r: srcTR.colors.r, g: srcTR.colors.g, b: srcTR.colors.b, a: srcTR.colors.a},
1132                 texCoords: {u: srcTR.texCoords.u, v: srcTR.texCoords.v}},
1133             br: {vertices: {x: srcBR.vertices.x, y: srcBR.vertices.y, z: srcBR.vertices.z},
1134                 colors: {r: srcBR.colors.r, g: srcBR.colors.g, b: srcBR.colors.b, a: srcBR.colors.a},
1135                 texCoords: {u: srcBR.texCoords.u, v: srcBR.texCoords.v}}
1136         };
1137     };
1138 
1139     //redefine cc.V2F_C4B_T2F
1140     cc.V2F_C4B_T2F = function (vertices, colors, texCoords, arrayBuffer, offset) {
1141         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V2F_C4B_T2F.BYTES_PER_ELEMENT);
1142         this._offset = offset || 0;
1143 
1144         var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.Vertex2F.BYTES_PER_ELEMENT;
1145         this._vertices = vertices ? new cc.Vertex2F(vertices.x, vertices.y, locArrayBuffer, locOffset) :
1146             new cc.Vertex2F(0, 0, locArrayBuffer, locOffset);
1147         this._colors = colors ? new cc.Color4B(colors.r, colors.g, colors.b, colors.a, locArrayBuffer, locOffset + locElementLen) :
1148             new cc.Color4B(0, 0, 0, 0, locArrayBuffer, locOffset + locElementLen);
1149         this._texCoords = texCoords ? new cc.Tex2F(texCoords.u, texCoords.v, locArrayBuffer, locOffset + locElementLen + cc.Color4B.BYTES_PER_ELEMENT) :
1150             new cc.Tex2F(0, 0, locArrayBuffer, locOffset + locElementLen + cc.Color4B.BYTES_PER_ELEMENT);
1151     };
1152     cc.V2F_C4B_T2F.BYTES_PER_ELEMENT = 20;
1153     Object.defineProperties(cc.V2F_C4B_T2F.prototype, {
1154         vertices: {
1155             get: function () {
1156                 return this._vertices;
1157             },
1158             set: function (verticesValue) {
1159                 this._vertices.x = verticesValue.x;
1160                 this._vertices.y = verticesValue.y;
1161             },
1162             enumerable: true
1163         },
1164         colors: {
1165             get: function () {
1166                 return this._colors;
1167             },
1168             set: function (colorValue) {
1169                 var locColors = this._colors;
1170                 locColors.r = colorValue.r;
1171                 locColors.g = colorValue.g;
1172                 locColors.b = colorValue.b;
1173                 locColors.a = colorValue.a;
1174             },
1175             enumerable: true
1176         },
1177         texCoords: {
1178             get: function () {
1179                 return this._texCoords;
1180             },
1181             set: function (texValue) {
1182                 this._texCoords.u = texValue.u;
1183                 this._texCoords.v = texValue.v;
1184             },
1185             enumerable: true
1186         }
1187     });
1188 
1189     //redefine cc.V2F_C4B_T2F_Triangle
1190     cc.V2F_C4B_T2F_Triangle = function (a, b, c, arrayBuffer, offset) {
1191         this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT);
1192         this._offset = offset || 0;
1193 
1194         var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT;
1195         this._a = a ? new cc.V2F_C4B_T2F(a.vertices, a.colors, a.texCoords, locArrayBuffer, locOffset) :
1196             new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
1197         this._b = b ? new cc.V2F_C4B_T2F(b.vertices, b.colors, b.texCoords, locArrayBuffer, locOffset + locElementLen) :
1198             new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen);
1199         this._c = c ? new cc.V2F_C4B_T2F(c.vertices, c.colors, c.texCoords, locArrayBuffer, locOffset + locElementLen * 2) :
1200             new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset + locElementLen * 2);
1201     };
1202     cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT = 60;
1203     Object.defineProperties(cc.V2F_C4B_T2F_Triangle.prototype, {
1204         a:{
1205             get: function () {
1206                 return this._a;
1207             },
1208             set: function (aValue) {
1209                 var locA = this._a;
1210                 locA.vertices = aValue.vertices;
1211                 locA.colors = aValue.colors;
1212                 locA.texCoords = aValue.texCoords;
1213             },
1214             enumerable: true
1215         },
1216         b:{
1217             get: function () {
1218                 return this._b;
1219             },
1220             set: function (bValue) {
1221                 var locB = this._b;
1222                 locB.vertices = bValue.vertices;
1223                 locB.colors = bValue.colors;
1224                 locB.texCoords = bValue.texCoords;
1225             },
1226             enumerable: true
1227         },
1228         c:{
1229             get: function () {
1230                 return this._c;
1231             },
1232             set: function (cValue) {
1233                 var locC = this._c;
1234                 locC.vertices = cValue.vertices;
1235                 locC.colors = cValue.colors;
1236                 locC.texCoords = cValue.texCoords;
1237             },
1238             enumerable: true
1239         }
1240     });
1241 }
1242 
1243 /**
1244  * convert a string of color for style to Color3B.
1245  * e.g. "#ff06ff"  to : Color3B(255,6,255)
1246  * @param {String} clrSt
1247  * @return {cc.Color3B}
1248  */
1249 cc.convertHexNumToColor3B = function (clrSt) {
1250     var nAr = clrSt.substr(1).split("");
1251     var r = parseInt("0x" + nAr[0] + nAr[1]);
1252     var g = parseInt("0x" + nAr[2] + nAr[3]);
1253     var b = parseInt("0x" + nAr[4] + nAr[5]);
1254     return new cc.Color3B(r, g, b);
1255 };
1256 
1257 
1258 /**
1259  * text alignment : left
1260  * @constant
1261  * @type Number
1262  */
1263 cc.TEXT_ALIGNMENT_LEFT = 0;
1264 
1265 /**
1266  * text alignment : center
1267  * @constant
1268  * @type Number
1269  */
1270 cc.TEXT_ALIGNMENT_CENTER = 1;
1271 
1272 /**
1273  * text alignment : right
1274  * @constant
1275  * @type Number
1276  */
1277 cc.TEXT_ALIGNMENT_RIGHT = 2;
1278 
1279 /**
1280  * text alignment : top
1281  * @constant
1282  * @type Number
1283  */
1284 cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
1285 
1286 /**
1287  * text alignment : center
1288  * @constant
1289  * @type Number
1290  */
1291 cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
1292 
1293 /**
1294  * text alignment : bottom
1295  * @constant
1296  * @type Number
1297  */
1298 cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
1299 
1300 cc._Dictionary = cc.Class.extend({
1301     _keyMapTb: null,
1302     _valueMapTb: null,
1303     __currId: 0,
1304 
1305     ctor: function () {
1306         this._keyMapTb = {};
1307         this._valueMapTb = {};
1308         this.__currId = 2 << (0 | (Math.random() * 10));
1309     },
1310 
1311     __getKey: function () {
1312         this.__currId++;
1313         return "key_" + this.__currId;
1314     },
1315 
1316     setObject: function (value, key) {
1317         if (key == null)
1318             return;
1319 
1320         var keyId = this.__getKey();
1321         this._keyMapTb[keyId] = key;
1322         this._valueMapTb[keyId] = value;
1323     },
1324 
1325     objectForKey: function (key) {
1326         if (key == null)
1327             return null;
1328 
1329         var locKeyMapTb = this._keyMapTb;
1330         for (var keyId in locKeyMapTb) {
1331             if (locKeyMapTb[keyId] === key)
1332                 return this._valueMapTb[keyId];
1333         }
1334         return null;
1335     },
1336 
1337     valueForKey: function (key) {
1338         return this.objectForKey(key);
1339     },
1340 
1341     removeObjectForKey: function (key) {
1342         if (key == null)
1343             return;
1344 
1345         var locKeyMapTb = this._keyMapTb;
1346         for (var keyId in locKeyMapTb) {
1347             if (locKeyMapTb[keyId] === key) {
1348                 delete this._valueMapTb[keyId];
1349                 delete locKeyMapTb[keyId];
1350                 return;
1351             }
1352         }
1353     },
1354 
1355     removeObjectsForKeys: function (keys) {
1356         if (keys == null)
1357             return;
1358 
1359         for (var i = 0; i < keys.length; i++)
1360             this.removeObjectForKey(keys[i]);
1361     },
1362 
1363     allKeys: function () {
1364         var keyArr = [], locKeyMapTb = this._keyMapTb;
1365         for (var key in locKeyMapTb)
1366             keyArr.push(locKeyMapTb[key]);
1367         return keyArr;
1368     },
1369 
1370     removeAllObjects: function () {
1371         this._keyMapTb = {};
1372         this._valueMapTb = {};
1373     },
1374 
1375     count: function() {
1376         return this.allKeys().length;
1377     }
1378 });
1379 
1380 cc.FontDefinition = function(){
1381     this.fontName = "Arial";
1382     this.fontSize = 12;
1383     this.fontAlignmentH = cc.TEXT_ALIGNMENT_CENTER;
1384     this.fontAlignmentV = cc.VERTICAL_TEXT_ALIGNMENT_TOP;
1385     this.fontFillColor = cc.white();
1386     this.fontDimensions = cc.size(0,0);
1387 
1388     this.strokeEnabled = false;
1389     this.strokeColor = cc.white();
1390     this.strokeSize = 1;
1391 
1392     this.shadowEnabled = false;
1393     this.shadowOffset = cc.size(0,0);
1394     this.shadowBlur = 0;
1395     this.shadowOpacity = 1.0;
1396 };
1397