2010-07-09 11:26:56 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2010-07-09 11:26:56 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCLAYER_H__
|
|
|
|
#define __CCLAYER_H__
|
|
|
|
|
2010-10-09 14:23:47 +08:00
|
|
|
#include "CCNode.h"
|
|
|
|
#include "CCProtocols.h"
|
|
|
|
#include "CCTouchDelegateProtocol.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCAccelerometerDelegate.h"
|
2010-12-13 14:10:39 +08:00
|
|
|
#include "CCKeypadDelegate.h"
|
2010-12-31 09:36:53 +08:00
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-10-09 14:23:47 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// CCLayer
|
|
|
|
//
|
|
|
|
/** @brief CCLayer is a subclass of CCNode that implements the TouchEventsDelegate protocol.
|
|
|
|
|
|
|
|
All features from CCNode are valid, plus the following new features:
|
|
|
|
- It can receive iPhone Touches
|
|
|
|
- It can receive Accelerometer input
|
|
|
|
*/
|
2011-04-11 11:24:10 +08:00
|
|
|
class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate
|
2010-10-09 14:23:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCLayer();
|
|
|
|
virtual ~CCLayer();
|
|
|
|
bool init();
|
|
|
|
static CCLayer *node(void);
|
|
|
|
|
|
|
|
virtual void onEnter();
|
|
|
|
virtual void onExit();
|
2010-12-27 09:40:45 +08:00
|
|
|
virtual void onEnterTransitionDidFinish();
|
2011-03-18 09:39:34 +08:00
|
|
|
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
|
2010-10-09 14:23:47 +08:00
|
|
|
virtual void destroy(void);
|
|
|
|
virtual void keep(void);
|
|
|
|
|
2011-03-08 13:49:58 +08:00
|
|
|
virtual void didAccelerate(CCAcceleration* pAccelerationValue) {}
|
2010-11-18 18:27:05 +08:00
|
|
|
virtual void AccelerometerDestroy(void);
|
|
|
|
virtual void AccelerometerKeep(void);
|
2010-11-10 16:29:52 +08:00
|
|
|
|
2010-12-13 14:10:39 +08:00
|
|
|
virtual void KeypadDestroy();
|
|
|
|
virtual void KeypadKeep();
|
|
|
|
|
2010-10-09 14:23:47 +08:00
|
|
|
/** If isTouchEnabled, this method is called onEnter. Override it to change the
|
|
|
|
way CCLayer receives touch events.
|
2010-11-16 15:12:09 +08:00
|
|
|
( Default: CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0); )
|
2010-10-09 14:23:47 +08:00
|
|
|
Example:
|
|
|
|
void CCLayer::registerWithTouchDispatcher()
|
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,INT_MIN+1,true);
|
2010-10-09 14:23:47 +08:00
|
|
|
}
|
|
|
|
@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
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(bool, m_bIsTouchEnabled, IsTouchEnabled)
|
2010-10-09 14:23:47 +08:00
|
|
|
/** whether or not it will receive Accelerometer events
|
|
|
|
You can enable / disable accelerometer events with this property.
|
|
|
|
@since v0.8.1
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(bool, m_bIsAccelerometerEnabled, IsAccelerometerEnabled)
|
2010-12-13 14:10:39 +08:00
|
|
|
/** whether or not it will receive keypad events
|
|
|
|
You can enable / disable accelerometer events with this property.
|
|
|
|
it's new in cocos2d-x
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(bool, m_bIsKeypadEnabled, IsKeypadEnabled)
|
2010-10-09 14:23:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2010-12-27 09:40:45 +08:00
|
|
|
// CCLayerColor
|
2010-10-09 14:23:47 +08:00
|
|
|
//
|
2010-12-27 09:40:45 +08:00
|
|
|
/** @brief CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol.
|
2010-10-09 14:23:47 +08:00
|
|
|
|
|
|
|
All features from CCLayer are valid, plus the following new features:
|
|
|
|
- opacity
|
|
|
|
- RGB colors
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCLayerColor : public CCLayer , public CCRGBAProtocol, public CCBlendProtocol
|
2010-10-09 14:23:47 +08:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
GLfloat m_pSquareVertices[4 * 2];
|
|
|
|
GLubyte m_pSquareColors[4 * 4];
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-12-27 09:40:45 +08:00
|
|
|
CCLayerColor();
|
|
|
|
virtual ~CCLayerColor();
|
2010-10-09 14:23:47 +08:00
|
|
|
|
|
|
|
virtual void draw();
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual void setContentSize(CCSize var);
|
2010-10-09 14:23:47 +08:00
|
|
|
|
2010-12-27 09:40:45 +08:00
|
|
|
/** creates a CCLayer with color, width and height in Points */
|
|
|
|
static CCLayerColor * layerWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height);
|
2010-10-09 14:23:47 +08:00
|
|
|
/** creates a CCLayer with color. Width and height are the window size. */
|
2010-12-27 09:40:45 +08:00
|
|
|
static CCLayerColor * layerWithColor(ccColor4B color);
|
2010-10-09 14:23:47 +08:00
|
|
|
|
2010-12-27 09:40:45 +08:00
|
|
|
/** initializes a CCLayer with color, width and height in Points */
|
|
|
|
virtual bool initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height);
|
2010-10-09 14:23:47 +08:00
|
|
|
/** initializes a CCLayer with color. Width and height are the window size. */
|
2010-12-27 09:40:45 +08:00
|
|
|
virtual bool initWithColor(ccColor4B color);
|
2010-10-09 14:23:47 +08:00
|
|
|
|
2010-12-27 09:40:45 +08:00
|
|
|
/** change width in Points*/
|
2010-10-09 14:23:47 +08:00
|
|
|
void changeWidth(GLfloat w);
|
2010-12-27 09:40:45 +08:00
|
|
|
/** change height in Points*/
|
2010-10-09 14:23:47 +08:00
|
|
|
void changeHeight(GLfloat h);
|
2010-12-27 09:40:45 +08:00
|
|
|
/** change width and height in Points
|
2010-10-09 14:23:47 +08:00
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
void changeWidthAndHeight(GLfloat w ,GLfloat h);
|
|
|
|
|
|
|
|
/** Opacity: conforms to CCRGBAProtocol protocol */
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(GLubyte, m_cOpacity, Opacity)
|
2010-10-09 14:23:47 +08:00
|
|
|
/** Opacity: conforms to CCRGBAProtocol protocol */
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(ccColor3B, m_tColor, Color)
|
2010-10-09 14:23:47 +08:00
|
|
|
/** BlendFunction. Conforms to CCBlendProtocol protocol */
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)
|
2010-10-09 14:23:47 +08:00
|
|
|
|
|
|
|
virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; }
|
|
|
|
|
2010-12-27 09:40:45 +08:00
|
|
|
protected:
|
|
|
|
virtual void updateColor();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** CCColorLayer
|
|
|
|
It is the same as CCLayerColor.
|
|
|
|
|
|
|
|
@deprecated Use CCLayerColor instead. This class will be removed in v1.0.1
|
|
|
|
*/
|
|
|
|
class CCColorLayer : public CCLayerColor
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// CCLayerGradient
|
|
|
|
//
|
|
|
|
/** CCLayerGradient is a subclass of CCLayerColor that draws gradients across
|
|
|
|
the background.
|
|
|
|
|
|
|
|
All features from CCLayerColor are valid, plus the following new features:
|
|
|
|
- direction
|
|
|
|
- final color
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Given the nature of
|
|
|
|
the interpolation, 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.
|
|
|
|
|
|
|
|
@since v0.99.5
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCLayerGradient : public CCLayerColor
|
2010-12-27 09:40:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Creates a full-screen CCLayer with a gradient between start and end. */
|
|
|
|
static CCLayerGradient* layerWithColor(ccColor4B start, ccColor4B end);
|
|
|
|
|
|
|
|
/** Creates a full-screen CCLayer with a gradient between start and end in the direction of v. */
|
2011-03-07 17:11:57 +08:00
|
|
|
static CCLayerGradient* layerWithColor(ccColor4B start, ccColor4B end, CCPoint v);
|
2010-12-27 09:40:45 +08:00
|
|
|
|
|
|
|
/** Initializes the CCLayer with a gradient between start and end. */
|
|
|
|
virtual bool initWithColor(ccColor4B start, ccColor4B end);
|
|
|
|
|
|
|
|
/** Initializes the CCLayer with a gradient between start and end in the direction of v. */
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual bool initWithColor(ccColor4B start, ccColor4B end, CCPoint v);
|
2010-12-27 09:40:45 +08:00
|
|
|
|
|
|
|
ccColor3B getStartColor();
|
|
|
|
void setStartColor(ccColor3B colors);
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(ccColor3B, m_endColor, EndColor)
|
|
|
|
CC_PROPERTY(GLubyte, m_cStartOpacity, StartOpacity)
|
|
|
|
CC_PROPERTY(GLubyte, m_cEndOpacity, EndOpacity)
|
|
|
|
CC_PROPERTY(CCPoint, m_AlongVector, Vector)
|
2010-12-27 09:40:45 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void updateColor();
|
2010-10-09 14:23:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief CCMultipleLayer is a CCLayer with the ability to multiplex it's children.
|
|
|
|
Features:
|
|
|
|
- It supports one or more children
|
|
|
|
- Only one children will be active a time
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCMultiplexLayer : public CCLayer
|
2010-10-09 14:23:47 +08:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
unsigned int m_nEnabledLayer;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCLayer *> * m_pLayers;
|
2010-10-09 14:23:47 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
CCMultiplexLayer();
|
|
|
|
virtual ~CCMultiplexLayer();
|
|
|
|
|
|
|
|
/** creates a CCMultiplexLayer with one or more layers using a variable argument list. */
|
|
|
|
static CCMultiplexLayer * layerWithLayers(CCLayer* layer, ... );
|
2011-05-31 14:04:14 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_LUA
|
|
|
|
static CCMultiplexLayer * layerWithLayer(CCLayer* layer);
|
|
|
|
void addLayer(CCLayer* layer);
|
|
|
|
bool initWithLayer(CCLayer* layer);
|
|
|
|
#endif
|
2010-10-09 14:23:47 +08:00
|
|
|
/** 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);
|
2010-07-09 11:26:56 +08:00
|
|
|
};
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|
2010-07-09 11:26:56 +08:00
|
|
|
|
2010-10-09 14:23:47 +08:00
|
|
|
// for the subclass of CCLayer, each has to implement the static "node" method
|
|
|
|
#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; \
|
|
|
|
} \
|
|
|
|
};
|
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
#endif // __CCLAYER_H__
|
|
|
|
|