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  * <p>NodeGrid class is a class serves as a decorator of cc.Node,<br/>
 29  * Grid node can run grid actions over all its children   (WebGL only)
 30  * </p>
 31  * @type {Class}
 32  *
 33  * @property {cc.GridBase}  grid    - Grid object that is used when applying effects
 34  * @property {cc.Node}      target  - <@writeonly>Target
 35  */
 36 cc.NodeGrid = cc.Node.extend(/** @lends cc.NodeGrid# */{
 37     grid: null,
 38     _target: null,
 39     _gridRect:null,
 40 
 41     ctor: function (rect) {
 42         cc.Node.prototype.ctor.call(this);
 43         if(rect === undefined) rect = cc.rect();
 44         this._gridRect = rect;
 45     },
 46     /**
 47      * Gets the grid object.
 48      * @returns {cc.GridBase}
 49      */
 50     getGrid: function () {
 51         return this.grid;
 52     },
 53 
 54     /**
 55      * Set the grid object.
 56      * @param {cc.GridBase} grid
 57      */
 58     setGrid: function (grid) {
 59         this.grid = grid;
 60     },
 61 
 62     /**
 63      * @brief Set the effect grid rect.
 64      * @param {cc.Rect} rect
 65      */
 66     setGridRect: function (rect) {
 67         this._gridRect = rect;
 68     },
 69     /**
 70      * @brief Get the effect grid rect.
 71      * @return {cc.Rect} rect.
 72     */
 73     getGridRect: function () {
 74         return this._gridRect;
 75     },
 76 
 77     /**
 78      * Set the target
 79      * @param {cc.Node} target
 80      */
 81     setTarget: function (target) {
 82         this._target = target;
 83     },
 84 
 85     _createRenderCmd: function(){
 86         if (cc._renderType === cc.game.RENDER_TYPE_WEBGL)
 87             return new cc.NodeGrid.WebGLRenderCmd(this);
 88         else
 89             return new cc.Node.CanvasRenderCmd(this);            // cc.NodeGrid doesn't support Canvas mode.
 90     }
 91 });
 92 
 93 var _p = cc.NodeGrid.prototype;
 94 // Extended property
 95 /** @expose */
 96 _p.grid;
 97 /** @expose */
 98 _p.target;
 99 cc.defineGetterSetter(_p, "target", null, _p.setTarget);
100 
101 
102 /**
103  * Creates a NodeGrid. <br />
104  * Implementation cc.NodeGrid
105  * @deprecated since v3.0 please new cc.NodeGrid instead.
106  * @return {cc.NodeGrid}
107  */
108 cc.NodeGrid.create = function () {
109     return new cc.NodeGrid();
110 };
111