2010-07-09 11:26:56 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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__
|
|
|
|
|
|
|
|
#include "Cocos2dDefine.h"
|
|
|
|
#include "CCNode.h"
|
2010-07-20 13:49:13 +08:00
|
|
|
#include "CCTexture2D.h"
|
|
|
|
#include "CCProtocols.h"
|
2010-07-20 14:29:18 +08:00
|
|
|
#include "touch_dispatcher/CCTouchDelegateProtocol.h"
|
2010-07-09 11:26:56 +08:00
|
|
|
//
|
|
|
|
// CCLayer
|
|
|
|
//
|
|
|
|
/** 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
|
|
|
|
*/
|
2010-07-21 17:40:10 +08:00
|
|
|
/// @todo public UIAccelerometerDelegate
|
2010-07-20 13:49:13 +08:00
|
|
|
class CCLayer : public CCNode, public CCStandardTouchDelegate, public CCTargetedTouchDelegate//, public UIAccelerometerDelegate
|
2010-07-09 11:26:56 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-07-09 18:24:08 +08:00
|
|
|
CCLayer();
|
|
|
|
virtual ~CCLayer();
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
virtual void onEnter();
|
|
|
|
virtual void onExit();
|
|
|
|
|
2010-07-09 11:26:56 +08:00
|
|
|
/** If isTouchEnabled, this method is called onEnter. Override it to change the
|
|
|
|
way CCLayer receives touch events.
|
|
|
|
( Default: [[TouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0] )
|
|
|
|
Example:
|
|
|
|
-(void) registerWithTouchDispatcher
|
|
|
|
{
|
|
|
|
[[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];
|
|
|
|
}
|
|
|
|
@since v0.8.0
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
2010-07-09 18:24:08 +08:00
|
|
|
CCX_PROPERTY(bool, m_bIsTouchEnabled, IsTouchEnabled)
|
2010-07-09 11:26:56 +08:00
|
|
|
/** whether or not it will receive Accelerometer events
|
|
|
|
You can enable / disable accelerometer events with this property.
|
|
|
|
@since v0.8.1
|
|
|
|
*/
|
2010-07-09 17:02:00 +08:00
|
|
|
CCX_PROPERTY(bool, m_bIsAccelerometerEnabled, IsAccelerometerEnabled)
|
2010-07-09 11:26:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// CCColorLayer
|
|
|
|
//
|
|
|
|
/** CCColorLayer is a subclass of CCLayer that implements the CCRGBAProtocol protocol.
|
|
|
|
|
|
|
|
All features from CCLayer are valid, plus the following new features:
|
|
|
|
- opacity
|
|
|
|
- RGB colors
|
|
|
|
*/
|
2010-07-20 13:49:13 +08:00
|
|
|
class CCColorLayer : public CCLayer , public CCRGBAProtocol, public CCBlendProtocol
|
2010-07-09 11:26:56 +08:00
|
|
|
{
|
|
|
|
protected:
|
2010-07-21 11:13:32 +08:00
|
|
|
GLfloat m_pSquareVertices[4 * 2];
|
|
|
|
GLubyte m_pSquareColors[4 * 4];
|
2010-07-09 11:26:56 +08:00
|
|
|
|
|
|
|
public:
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
CCColorLayer();
|
|
|
|
virtual ~CCColorLayer();
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
virtual void draw();
|
|
|
|
virtual void setContentSize(CGSize var);
|
|
|
|
|
2010-07-09 11:26:56 +08:00
|
|
|
/** creates a CCLayer with color, width and height */
|
2010-07-09 18:24:08 +08:00
|
|
|
static CCColorLayer * layerWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height);
|
2010-07-09 11:26:56 +08:00
|
|
|
/** creates a CCLayer with color. Width and height are the window size. */
|
2010-07-09 18:24:08 +08:00
|
|
|
static CCColorLayer * layerWithColor(ccColor4B color);
|
2010-07-09 11:26:56 +08:00
|
|
|
|
|
|
|
/** initializes a CCLayer with color, width and height */
|
2010-07-09 18:24:08 +08:00
|
|
|
CCColorLayer * initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height);
|
2010-07-09 11:26:56 +08:00
|
|
|
/** initializes a CCLayer with color. Width and height are the window size. */
|
2010-07-09 18:24:08 +08:00
|
|
|
CCColorLayer * initWithColor(ccColor4B color);
|
2010-07-09 11:26:56 +08:00
|
|
|
|
|
|
|
/** change width */
|
|
|
|
void changeWidth(GLfloat w);
|
|
|
|
/** change height */
|
|
|
|
void changeHeight(GLfloat h);
|
|
|
|
/** change width and height
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
void changeWidthAndHeight(GLfloat w ,GLfloat h);
|
|
|
|
|
|
|
|
/** Opacity: conforms to CCRGBAProtocol protocol */
|
2010-07-12 17:56:06 +08:00
|
|
|
CCX_PROPERTY(GLubyte, m_cOpacity, Opacity)
|
2010-07-09 11:26:56 +08:00
|
|
|
/** Opacity: conforms to CCRGBAProtocol protocol */
|
2010-07-12 17:56:06 +08:00
|
|
|
CCX_PROPERTY(ccColor3B, m_tColor, Color)
|
2010-07-09 11:26:56 +08:00
|
|
|
/** BlendFunction. Conforms to CCBlendProtocol protocol */
|
2010-07-09 17:02:00 +08:00
|
|
|
CCX_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
private :
|
|
|
|
void updateColor();
|
2010-07-09 11:26:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
|
|
|
class CCMultiplexLayer : public CCLayer
|
|
|
|
{
|
|
|
|
protected:
|
2010-07-14 11:18:05 +08:00
|
|
|
unsigned int m_nEnabledLayer;
|
2010-07-20 13:49:13 +08:00
|
|
|
NSMutableArray<CCLayer *> * m_pLayers;
|
2010-07-09 11:26:56 +08:00
|
|
|
public:
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
CCMultiplexLayer();
|
|
|
|
virtual ~CCMultiplexLayer();
|
|
|
|
|
2010-07-09 11:26:56 +08:00
|
|
|
/** creates a CCMultiplexLayer with one or more layers using a variable argument list. */
|
2010-07-09 18:24:08 +08:00
|
|
|
static CCMultiplexLayer * layerWithLayers(CCLayer* layer, ... );
|
2010-07-09 11:26:56 +08:00
|
|
|
/** initializes a MultiplexLayer with one or more layers using a variable argument list. */
|
2010-07-09 18:24:08 +08:00
|
|
|
CCMultiplexLayer * initWithLayers(CCLayer* layer, va_list params);
|
2010-07-09 11:26:56 +08:00
|
|
|
/** 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 18:24:08 +08:00
|
|
|
#endif // __CCLAYER_H__
|
|
|
|
|