CCClippingNode

#ifndef __MISCNODE_CCCLIPPING_NODE_H__

#define __MISCNODE_CCCLIPPING_NODE_H__


#include "base_nodes/CCNode.h"

#include "CCGL.h"


NS_CC_BEGIN


/** CCClippingNode is a subclass of CCNode.

 It draws its content (childs) clipped using a stencil.

 The stencil is an other CCNode that will not be drawn.

 The clipping is done using the alpha part of the stencil (adjusted with an alphaThreshold).

 */

class CC_DLL CCClippingNode : public CCNode

{

protected:

    CCNode* m_pStencil;

    GLfloat m_fAlphaThreshold;

    bool    m_bInverted;

    

public:

    /** Creates and initializes a clipping node without a stencil.

     */

    static CCClippingNode* create();

    

    /** Creates and initializes a clipping node with an other node as its stencil.

     The stencil node will be retained.

     */

    static CCClippingNode* create(CCNode *pStencil);

    

    virtual ~CCClippingNode();

    

    /** Initializes a clipping node without a stencil.

     */

    virtual bool init();

    

    /** Initializes a clipping node with an other node as its stencil.

     The stencil node will be retained, and its parent will be set to this clipping node.

     */

    virtual bool init(CCNode *pStencil);

    

    virtual void onEnter();

    virtual void onEnterTransitionDidFinish();

    virtual void onExitTransitionDidStart();

    virtual void onExit();

    virtual void visit();

    

    /** The CCNode to use as a stencil to do the clipping.

     The stencil node will be retained.

     This default to nil.

     */

    CCNode* getStencil() const;

    void setStencil(CCNode *pStencil);

    

    /** The alpha threshold.

     The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold.

     Should be a float between 0 and 1.

     This default to 1 (so alpha test is disabled).

     */

    GLfloat getAlphaThreshold() const;

    void setAlphaThreshold(GLfloat fAlphaThreshold);

    

    /** Inverted. If this is set to YES,

     the stencil is inverted, so the content is drawn where the stencil is NOT drawn.

     This default to NO.

     */

    bool isInverted() const;

    void setInverted(bool bInverted);

    

private:

    CCClippingNode();

};


NS_CC_END


#endif // __MISCNODE_CCCLIPPING_NODE_H__


posted @ 2014-05-22 09:38  sssssnian  阅读(145)  评论(0)    收藏  举报