2011-11-18 21:23:54 +08:00
|
|
|
/****************************************************************************
|
2011-11-29 19:56:20 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
#ifndef __CCLAYER_H__
|
|
|
|
#define __CCLAYER_H__
|
|
|
|
|
|
|
|
#include "CCNode.h"
|
|
|
|
#include "CCProtocols.h"
|
|
|
|
#include "CCTouchDelegateProtocol.h"
|
|
|
|
#include "CCAccelerometerDelegate.h"
|
|
|
|
#include "CCKeypadDelegate.h"
|
2011-11-29 19:56:20 +08:00
|
|
|
#include "CCMutableArray.h"
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
namespace cocos2d
|
|
|
|
{
|
|
|
|
|
|
|
|
//
|
|
|
|
// CCLayer
|
|
|
|
//
|
|
|
|
/** @brief CCLayer is a subclass of CCNode that implements the TouchEventsDelegate protocol.
|
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
All features from CCNode are valid, plus the following new features:
|
|
|
|
- It can receive iPhone Touches
|
|
|
|
- It can receive Accelerometer input
|
|
|
|
*/
|
2011-11-18 21:23:54 +08:00
|
|
|
class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate
|
|
|
|
{
|
|
|
|
public:
|
2011-11-29 19:56:20 +08:00
|
|
|
CCLayer();
|
|
|
|
virtual ~CCLayer();
|
|
|
|
bool init();
|
|
|
|
static CCLayer *node(void);
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
virtual void onEnter();
|
|
|
|
virtual void onExit();
|
2011-11-18 21:23:54 +08:00
|
|
|
virtual void onEnterTransitionDidFinish();
|
2011-11-29 19:56:20 +08:00
|
|
|
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
// default implements are used to call script callback if exist
|
|
|
|
virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
|
|
|
|
virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
|
|
|
|
virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
|
|
|
|
virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent);
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
virtual void destroy(void);
|
|
|
|
virtual void keep(void);
|
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
virtual void didAccelerate(CCAcceleration* pAccelerationValue) {
|
|
|
|
CC_UNUSED_PARAM(pAccelerationValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void KeypadDestroy();
|
|
|
|
virtual void KeypadKeep();
|
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
/** If isTouchEnabled, this method is called onEnter. Override it to change the
|
|
|
|
way CCLayer receives touch events.
|
|
|
|
( Default: CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0); )
|
|
|
|
Example:
|
|
|
|
void CCLayer::registerWithTouchDispatcher()
|
|
|
|
{
|
|
|
|
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,INT_MIN+1,true);
|
|
|
|
}
|
|
|
|
@since v0.8.0
|
|
|
|
*/
|
|
|
|
virtual void registerWithTouchDispatcher(void);
|
|
|
|
|
|
|
|
/** whether or not it will receive Touch events.
|
|
|
|
You can enable / disable touch events with this property.
|
|
|
|
Only the touches of this node will be affected. This "method" is not propagated to it's children.
|
|
|
|
@since v0.8.1
|
|
|
|
*/
|
|
|
|
CC_PROPERTY(bool, m_bIsTouchEnabled, IsTouchEnabled)
|
|
|
|
/** whether or not it will receive Accelerometer events
|
|
|
|
You can enable / disable accelerometer events with this property.
|
|
|
|
@since v0.8.1
|
|
|
|
*/
|
|
|
|
CC_PROPERTY(bool, m_bIsAccelerometerEnabled, IsAccelerometerEnabled)
|
2011-11-18 21:23:54 +08:00
|
|
|
/** whether or not it will receive keypad events
|
2011-11-29 19:56:20 +08:00
|
|
|
You can enable / disable accelerometer events with this property.
|
|
|
|
it's new in cocos2d-x
|
|
|
|
*/
|
2011-11-18 21:23:54 +08:00
|
|
|
CC_PROPERTY(bool, m_bIsKeypadEnabled, IsKeypadEnabled)
|
|
|
|
};
|
2011-11-29 19:56:20 +08:00
|
|
|
|
|
|
|
// for the subclass of CCLayer, each has to implement the static "node" method
|
2011-11-18 21:23:54 +08:00
|
|
|
#define LAYER_NODE_FUNC(layer) \
|
|
|
|
static layer* node() \
|
|
|
|
{ \
|
|
|
|
layer *pRet = new layer(); \
|
|
|
|
if (pRet && pRet->init()) \
|
|
|
|
{ \
|
|
|
|
pRet->autorelease(); \
|
|
|
|
return pRet; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
delete pRet; \
|
|
|
|
pRet = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
2011-11-29 19:56:20 +08:00
|
|
|
};
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
#define LAYER_NODE_FUNC_PARAM(layer,__PARAMTYPE__,__PARAM__) \
|
2011-11-29 19:56:20 +08:00
|
|
|
static layer* node(__PARAMTYPE__ __PARAM__) \
|
2011-11-18 21:23:54 +08:00
|
|
|
{ \
|
2011-11-29 19:56:20 +08:00
|
|
|
layer *pRet = new layer(); \
|
|
|
|
if (pRet && pRet->init(__PARAM__)) \
|
2011-11-18 21:23:54 +08:00
|
|
|
{ \
|
2011-11-29 19:56:20 +08:00
|
|
|
pRet->autorelease(); \
|
|
|
|
return pRet; \
|
|
|
|
} \
|
2011-11-18 21:23:54 +08:00
|
|
|
else \
|
|
|
|
{ \
|
2011-11-29 19:56:20 +08:00
|
|
|
delete pRet; \
|
|
|
|
pRet = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
};
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CCLayerColor
|
|
|
|
//
|
|
|
|
/** @brief CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol.
|
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
All features from CCLayer are valid, plus the following new features:
|
|
|
|
- opacity
|
|
|
|
- RGB colors
|
|
|
|
*/
|
2011-11-18 21:23:54 +08:00
|
|
|
class CC_DLL CCLayerColor : public CCLayer , public CCRGBAProtocol, public CCBlendProtocol
|
|
|
|
{
|
|
|
|
protected:
|
2011-11-29 19:56:20 +08:00
|
|
|
ccVertex2F m_pSquareVertices[4];
|
|
|
|
ccColor4B m_pSquareColors[4];
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
CCLayerColor();
|
|
|
|
virtual ~CCLayerColor();
|
|
|
|
|
|
|
|
virtual void draw();
|
|
|
|
virtual void setContentSize(const CCSize& var);
|
|
|
|
|
|
|
|
/** creates a CCLayer with color, width and height in Points */
|
|
|
|
static CCLayerColor * layerWithColorWidthHeight(const ccColor4B& color, GLfloat width, GLfloat height);
|
|
|
|
/** creates a CCLayer with color. Width and height are the window size. */
|
|
|
|
static CCLayerColor * layerWithColor(const ccColor4B& color);
|
|
|
|
|
|
|
|
/** initializes a CCLayer with color, width and height in Points */
|
|
|
|
virtual bool initWithColorWidthHeight(const ccColor4B& color, GLfloat width, GLfloat height);
|
|
|
|
/** initializes a CCLayer with color. Width and height are the window size. */
|
|
|
|
virtual bool initWithColor(const ccColor4B& color);
|
|
|
|
|
|
|
|
/** change width in Points*/
|
|
|
|
void changeWidth(GLfloat w);
|
|
|
|
/** change height in Points*/
|
|
|
|
void changeHeight(GLfloat h);
|
|
|
|
/** change width and height in Points
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
void changeWidthAndHeight(GLfloat w ,GLfloat h);
|
|
|
|
|
|
|
|
/** Opacity: conforms to CCRGBAProtocol protocol */
|
|
|
|
CC_PROPERTY(GLubyte, m_cOpacity, Opacity)
|
|
|
|
/** Color: conforms to CCRGBAProtocol protocol */
|
|
|
|
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color)
|
|
|
|
/** BlendFunction. Conforms to CCBlendProtocol protocol */
|
|
|
|
CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
virtual CCRGBAProtocol* convertToRGBAProtocol() {
|
|
|
|
return (CCRGBAProtocol*)this;
|
|
|
|
}
|
|
|
|
LAYER_NODE_FUNC(CCLayerColor);
|
2011-11-29 19:56:20 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
protected:
|
2011-11-29 19:56:20 +08:00
|
|
|
virtual void updateColor();
|
2011-11-18 21:23:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// CCLayerGradient
|
|
|
|
//
|
|
|
|
/** CCLayerGradient is a subclass of CCLayerColor that draws gradients across
|
2011-11-29 19:56:20 +08:00
|
|
|
the background.
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
All features from CCLayerColor are valid, plus the following new features:
|
|
|
|
- direction
|
|
|
|
- final color
|
|
|
|
- interpolation mode
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
Color is interpolated between the startColor and endColor along the given
|
|
|
|
vector (starting at the origin, ending at the terminus). If no vector is
|
|
|
|
supplied, it defaults to (0, -1) -- a fade from top to bottom.
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
If 'compressedInterpolation' is disabled, you will not see either the start or end color for
|
|
|
|
non-cardinal vectors; a smooth gradient implying both end points will be still
|
|
|
|
be drawn, however.
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
If ' compressedInterpolation' is enabled (default mode) you will see both the start and end colors of the gradient.
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
@since v0.99.5
|
|
|
|
*/
|
2011-11-18 21:23:54 +08:00
|
|
|
class CC_DLL CCLayerGradient : public CCLayerColor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Creates a full-screen CCLayer with a gradient between start and end. */
|
|
|
|
static CCLayerGradient* layerWithColor(const ccColor4B& start, const ccColor4B& end);
|
|
|
|
|
|
|
|
/** Creates a full-screen CCLayer with a gradient between start and end in the direction of v. */
|
|
|
|
static CCLayerGradient* layerWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);
|
|
|
|
|
|
|
|
/** Initializes the CCLayer with a gradient between start and end. */
|
|
|
|
virtual bool initWithColor(const ccColor4B& start, const ccColor4B& end);
|
|
|
|
|
|
|
|
/** Initializes the CCLayer with a gradient between start and end in the direction of v. */
|
|
|
|
virtual bool initWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);
|
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_startColor, StartColor)
|
|
|
|
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_endColor, EndColor)
|
2011-11-18 21:23:54 +08:00
|
|
|
CC_PROPERTY(GLubyte, m_cStartOpacity, StartOpacity)
|
|
|
|
CC_PROPERTY(GLubyte, m_cEndOpacity, EndOpacity)
|
2011-11-29 19:56:20 +08:00
|
|
|
CC_PROPERTY_PASS_BY_REF(CCPoint, m_AlongVector, Vector)
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
/** Whether or not the interpolation will be compressed in order to display all the colors of the gradient both in canonical and non canonical vectors
|
2011-11-29 19:56:20 +08:00
|
|
|
Default: YES
|
|
|
|
*/
|
2011-11-18 21:23:54 +08:00
|
|
|
CC_PROPERTY(bool, m_bCompressedInterpolation, IsCompressedInterpolation)
|
|
|
|
|
|
|
|
LAYER_NODE_FUNC(CCLayerGradient);
|
|
|
|
protected:
|
|
|
|
virtual void updateColor();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief CCMultipleLayer is a CCLayer with the ability to multiplex it's children.
|
2011-11-29 19:56:20 +08:00
|
|
|
Features:
|
|
|
|
- It supports one or more children
|
|
|
|
- Only one children will be active a time
|
|
|
|
*/
|
2011-11-18 21:23:54 +08:00
|
|
|
class CC_DLL CCLayerMultiplex : public CCLayer
|
|
|
|
{
|
|
|
|
protected:
|
2011-11-29 19:56:20 +08:00
|
|
|
unsigned int m_nEnabledLayer;
|
|
|
|
CCMutableArray<CCLayer *> * m_pLayers;
|
2011-11-18 21:23:54 +08:00
|
|
|
public:
|
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
CCLayerMultiplex();
|
|
|
|
virtual ~CCLayerMultiplex();
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
/** creates a CCLayerMultiplex with one or more layers using a variable argument list. */
|
|
|
|
static CCLayerMultiplex * layerWithLayers(CCLayer* layer, ... );
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
/**
|
2011-11-29 19:56:20 +08:00
|
|
|
* lua script can not init with undetermined number of variables
|
|
|
|
* so add these functinons to be used with lua.
|
|
|
|
*/
|
|
|
|
static CCLayerMultiplex * layerWithLayer(CCLayer* layer);
|
|
|
|
void addLayer(CCLayer* layer);
|
|
|
|
bool initWithLayer(CCLayer* layer);
|
|
|
|
|
|
|
|
/** initializes a MultiplexLayer with one or more layers using a variable argument list. */
|
|
|
|
bool initWithLayers(CCLayer* layer, va_list params);
|
|
|
|
/** switches to a certain layer indexed by n.
|
|
|
|
The current (old) layer will be removed from it's parent with 'cleanup:YES'.
|
|
|
|
*/
|
|
|
|
void switchTo(unsigned int n);
|
|
|
|
/** release the current layer and switches to another layer indexed by n.
|
|
|
|
The current (old) layer will be removed from it's parent with 'cleanup:YES'.
|
|
|
|
*/
|
|
|
|
void switchToAndReleaseMe(unsigned int n);
|
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
LAYER_NODE_FUNC(CCLayerMultiplex);
|
|
|
|
};
|
|
|
|
|
2011-11-29 19:56:20 +08:00
|
|
|
}//namespace cocos2d
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
#endif // __CCLAYER_H__
|
|
|
|
|