2012-02-01 16:45:23 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-02-01 16:45:23 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2012-02-01 16:45:23 +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__
|
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCNode.h"
|
2012-02-01 16:45:23 +08:00
|
|
|
#include "CCProtocols.h"
|
2014-02-20 16:40:46 +08:00
|
|
|
#include "CCEventTouch.h"
|
2013-04-13 05:51:29 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCGLBufferedNode.h"
|
2013-04-13 05:51:29 +08:00
|
|
|
#endif // EMSCRIPTEN
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCEventKeyboard.h"
|
2013-12-26 21:19:12 +08:00
|
|
|
#include "renderer/CCCustomCommand.h"
|
2013-09-15 17:48:29 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup layer
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-04-09 22:30:49 +08:00
|
|
|
class __Set;
|
2013-06-20 14:13:12 +08:00
|
|
|
class TouchScriptHandlerEntry;
|
2012-02-07 11:43:29 +08:00
|
|
|
|
2013-11-19 13:56:30 +08:00
|
|
|
class EventListenerTouch;
|
|
|
|
class EventListenerKeyboard;
|
|
|
|
class EventListenerAcceleration;
|
|
|
|
|
2012-02-01 16:45:23 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
// Layer
|
2012-02-01 16:45:23 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief Layer is a subclass of Node that implements the TouchEventsDelegate protocol.
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
All features from Node are valid, plus the following new features:
|
2012-02-01 16:45:23 +08:00
|
|
|
- It can receive iPhone Touches
|
|
|
|
- It can receive Accelerometer input
|
|
|
|
*/
|
2013-09-03 18:22:03 +08:00
|
|
|
class CC_DLL Layer : public Node
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
2013-07-26 10:06:32 +08:00
|
|
|
public:
|
2013-07-18 07:56:19 +08:00
|
|
|
/** creates a fullscreen black layer */
|
2013-11-14 07:55:36 +08:00
|
|
|
static Layer *create();
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
// Deprecated touch callbacks.
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent); return false;};
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesBegan(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesMoved(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesEnded(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesCancelled(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2014-04-09 22:30:49 +08:00
|
|
|
/* Callback function should not be deprecated, it will generate lots of warnings.
|
|
|
|
Since 'setTouchEnabled' was deprecated, it will make warnings if developer overrides onTouchXXX and invokes setTouchEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
|
2013-11-20 11:19:51 +08:00
|
|
|
*/
|
2014-04-09 22:30:49 +08:00
|
|
|
virtual bool onTouchBegan(Touch *touch, Event *unused_event);
|
2013-11-20 10:26:00 +08:00
|
|
|
virtual void onTouchMoved(Touch *touch, Event *unused_event);
|
|
|
|
virtual void onTouchEnded(Touch *touch, Event *unused_event);
|
|
|
|
virtual void onTouchCancelled(Touch *touch, Event *unused_event);
|
2013-11-19 16:06:27 +08:00
|
|
|
|
2013-11-20 11:19:51 +08:00
|
|
|
virtual void onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event);
|
|
|
|
virtual void onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event);
|
|
|
|
virtual void onTouchesEnded(const std::vector<Touch*>& touches, Event *unused_event);
|
|
|
|
virtual void onTouchesCancelled(const std::vector<Touch*>&touches, Event *unused_event);
|
2013-09-03 18:22:03 +08:00
|
|
|
/** @deprecated Please override onAcceleration */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void didAccelerate(Acceleration* accelerationValue) final {};
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-11-20 11:19:51 +08:00
|
|
|
/* Callback function should not be deprecated, it will generate lots of warnings.
|
|
|
|
Since 'setAccelerometerEnabled' was deprecated, it will make warnings if developer overrides onAcceleration and invokes setAccelerometerEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
|
|
|
|
*/
|
|
|
|
virtual void onAcceleration(Acceleration* acc, Event* unused_event);
|
2013-11-19 13:56:30 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** If isTouchEnabled, this method is called onEnter. Override it to change the
|
2013-06-20 14:13:12 +08:00
|
|
|
way Layer receives touch events.
|
|
|
|
( Default: TouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0); )
|
2012-04-19 14:35:52 +08:00
|
|
|
Example:
|
2013-06-20 14:13:12 +08:00
|
|
|
void Layer::registerWithTouchDispatcher()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,INT_MIN+1,true);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
@since v0.8.0
|
|
|
|
*/
|
2013-09-03 18:22:03 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void registerWithTouchDispatcher() final {};
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-11-19 13:56:30 +08:00
|
|
|
/** 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
|
|
|
|
*/
|
2013-11-20 11:35:04 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE bool isTouchEnabled() const;
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void setTouchEnabled(bool value);
|
2013-09-17 23:21:45 +08:00
|
|
|
|
2013-11-19 13:56:30 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setTouchMode(Touch::DispatchMode mode);
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual Touch::DispatchMode getTouchMode() const;
|
|
|
|
|
|
|
|
/** swallowsTouches of the touch events. Default is true */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setSwallowsTouches(bool swallowsTouches);
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual bool isSwallowsTouches() const;
|
|
|
|
|
|
|
|
/** whether or not it will receive Accelerometer events
|
|
|
|
You can enable / disable accelerometer events with this property.
|
|
|
|
@since v0.8.1
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual bool isAccelerometerEnabled() const;
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setAccelerometerEnabled(bool value);
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setAccelerometerInterval(double interval);
|
|
|
|
|
|
|
|
/** whether or not it will receive keyboard or keypad events
|
|
|
|
You can enable / disable accelerometer events with this property.
|
|
|
|
it's new in cocos2d-x
|
|
|
|
*/
|
|
|
|
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual bool isKeyboardEnabled() const;
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setKeyboardEnabled(bool value);
|
|
|
|
|
2013-09-17 23:21:45 +08:00
|
|
|
/** Please use onKeyPressed instead. */
|
2013-11-20 11:19:51 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void keyPressed(int keyCode) final {};
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2013-09-17 23:21:45 +08:00
|
|
|
/** Please use onKeyReleased instead. */
|
2013-11-20 11:19:51 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void keyReleased(int keyCode) final {};
|
2013-07-01 16:48:42 +08:00
|
|
|
|
2013-11-20 11:19:51 +08:00
|
|
|
/* Callback function should not be deprecated, it will generate lots of warnings.
|
|
|
|
Since 'setKeyboardEnabled' was deprecated, it will make warnings if developer overrides onKeyXXX and invokes setKeyboardEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
|
|
|
|
*/
|
|
|
|
virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
|
|
|
|
virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
|
2013-11-19 13:56:30 +08:00
|
|
|
|
2013-11-20 10:26:00 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual bool isKeypadEnabled() const final { return _keyboardEnabled; }
|
2013-11-19 13:56:30 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setKeypadEnabled(bool value);
|
2012-12-02 15:17:34 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
/** @deprecated Please override onKeyReleased and check the keycode of KeyboardEvent::KeyCode::Menu(KEY_BACKSPACE) instead. */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void keyBackClicked() final {};
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void keyMenuClicked() final {};
|
2013-11-14 07:55:36 +08:00
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
// Overrides
|
|
|
|
virtual std::string getDescription() const override;
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-14 07:55:36 +08:00
|
|
|
Layer();
|
|
|
|
virtual ~Layer();
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
protected:
|
2013-11-21 03:23:03 +08:00
|
|
|
//add the api for avoid use deprecated api
|
|
|
|
void _addTouchListener();
|
2013-11-20 05:13:57 +08:00
|
|
|
|
2013-11-19 15:41:22 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void addTouchListener() { _addTouchListener();};
|
2014-03-04 13:42:06 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE int executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch, Event* event);
|
|
|
|
CC_DEPRECATED_ATTRIBUTE int executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector<Touch*>& touches, Event* event);
|
2013-11-19 13:56:30 +08:00
|
|
|
|
|
|
|
bool _touchEnabled;
|
|
|
|
bool _accelerometerEnabled;
|
|
|
|
bool _keyboardEnabled;
|
|
|
|
EventListener* _touchListener;
|
|
|
|
EventListenerKeyboard* _keyboardListener;
|
|
|
|
EventListenerAcceleration* _accelerationListener;
|
2013-11-19 15:41:22 +08:00
|
|
|
|
2013-11-19 13:56:30 +08:00
|
|
|
Touch::DispatchMode _touchMode;
|
|
|
|
bool _swallowsTouches;
|
|
|
|
|
2013-11-14 07:55:36 +08:00
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(Layer);
|
2013-11-20 05:13:57 +08:00
|
|
|
|
2012-02-01 16:45:23 +08:00
|
|
|
};
|
2012-07-13 09:53:38 +08:00
|
|
|
|
2013-12-09 11:32:28 +08:00
|
|
|
|
|
|
|
/** LayerRGBA is a subclass of Layer that implements the RGBAProtocol protocol using a solid color as the background.
|
|
|
|
|
|
|
|
All features from Layer are valid, plus the following new features that propagate into children that conform to the RGBAProtocol:
|
|
|
|
- opacity
|
|
|
|
- RGB colors
|
|
|
|
@since 2.1
|
|
|
|
*/
|
2013-12-13 10:10:49 +08:00
|
|
|
class CC_DLL __LayerRGBA : public Layer, public __RGBAProtocol
|
2013-12-09 11:32:28 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-12-13 10:10:49 +08:00
|
|
|
CREATE_FUNC(__LayerRGBA);
|
2013-12-09 11:32:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
|
|
|
virtual GLubyte getOpacity() const override { return Layer::getOpacity(); }
|
|
|
|
virtual GLubyte getDisplayedOpacity() const override { return Layer::getDisplayedOpacity(); }
|
|
|
|
virtual void setOpacity(GLubyte opacity) override { return Layer::setOpacity(opacity); }
|
|
|
|
virtual void updateDisplayedOpacity(GLubyte parentOpacity) override { return Layer::updateDisplayedOpacity(parentOpacity); }
|
|
|
|
virtual bool isCascadeOpacityEnabled() const override { return Layer::isCascadeOpacityEnabled(); }
|
|
|
|
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) override { return Layer::setCascadeOpacityEnabled(cascadeOpacityEnabled); }
|
|
|
|
|
|
|
|
virtual const Color3B& getColor() const override { return Layer::getColor(); }
|
|
|
|
virtual const Color3B& getDisplayedColor() const override { return Layer::getDisplayedColor(); }
|
|
|
|
virtual void setColor(const Color3B& color) override { return Layer::setColor(color); }
|
|
|
|
virtual void updateDisplayedColor(const Color3B& parentColor) override { return Layer::updateDisplayedColor(parentColor); }
|
|
|
|
virtual bool isCascadeColorEnabled() const override { return Layer::isCascadeOpacityEnabled(); }
|
|
|
|
virtual void setCascadeColorEnabled(bool cascadeColorEnabled) override { return Layer::setCascadeColorEnabled(cascadeColorEnabled); }
|
|
|
|
|
|
|
|
virtual void setOpacityModifyRGB(bool bValue) override { return Layer::setOpacityModifyRGB(bValue); }
|
|
|
|
virtual bool isOpacityModifyRGB() const override { return Layer::isOpacityModifyRGB(); }
|
|
|
|
|
|
|
|
protected:
|
2013-12-16 03:42:54 +08:00
|
|
|
__LayerRGBA();
|
2013-12-13 10:10:49 +08:00
|
|
|
virtual ~__LayerRGBA() {}
|
2013-12-09 11:32:28 +08:00
|
|
|
|
|
|
|
private:
|
2013-12-13 10:10:49 +08:00
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(__LayerRGBA);
|
2013-12-09 11:32:28 +08:00
|
|
|
};
|
|
|
|
|
2012-02-01 16:45:23 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
// LayerColor
|
2012-02-01 16:45:23 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief LayerColor is a subclass of Layer that implements the RGBAProtocol protocol.
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
All features from Layer are valid, plus the following new features:
|
2012-02-01 16:45:23 +08:00
|
|
|
- opacity
|
|
|
|
- RGB colors
|
|
|
|
*/
|
2013-12-06 18:07:16 +08:00
|
|
|
class CC_DLL LayerColor : public Layer, public BlendProtocol
|
2013-04-13 05:51:29 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
2013-06-20 14:13:12 +08:00
|
|
|
, public GLBufferedNode
|
2013-04-13 05:51:29 +08:00
|
|
|
#endif // EMSCRIPTEN
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-29 10:02:10 +08:00
|
|
|
/** creates a fullscreen black layer */
|
2013-06-20 14:13:12 +08:00
|
|
|
static LayerColor* create();
|
|
|
|
/** creates a Layer with color, width and height in Points */
|
2013-07-05 16:49:22 +08:00
|
|
|
static LayerColor * create(const Color4B& color, GLfloat width, GLfloat height);
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates a Layer with color. Width and height are the window size. */
|
2013-07-05 16:49:22 +08:00
|
|
|
static LayerColor * create(const Color4B& color);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
2013-07-16 03:43:22 +08:00
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2014-04-08 22:07:35 +08:00
|
|
|
virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override;
|
2014-03-06 07:49:08 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setContentSize(const Size & var) override;
|
2013-07-23 21:51:19 +08:00
|
|
|
/** BlendFunction. Conforms to BlendProtocol protocol */
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-23 21:51:19 +08:00
|
|
|
virtual const BlendFunc& getBlendFunc() const override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
*@code
|
|
|
|
*When this function bound into js or lua,the parameter will be changed
|
|
|
|
*In js: var setBlendFunc(var src, var dst)
|
|
|
|
*In lua: local setBlendFunc(local src, local dst)
|
|
|
|
*@endcode
|
|
|
|
*/
|
2013-07-23 21:51:19 +08:00
|
|
|
virtual void setBlendFunc(const BlendFunc& blendFunc) override;
|
2012-11-01 22:17:12 +08:00
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-14 07:55:36 +08:00
|
|
|
LayerColor();
|
|
|
|
virtual ~LayerColor();
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2014-03-06 07:49:08 +08:00
|
|
|
bool init();
|
2013-11-14 07:55:36 +08:00
|
|
|
bool initWithColor(const Color4B& color, GLfloat width, GLfloat height);
|
|
|
|
bool initWithColor(const Color4B& color);
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2014-04-09 10:37:41 +08:00
|
|
|
void onDraw(const Matrix& transform, bool transformUpdated);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-12-11 16:12:14 +08:00
|
|
|
virtual void updateColor() override;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2013-07-23 18:26:26 +08:00
|
|
|
BlendFunc _blendFunc;
|
2014-04-02 15:25:37 +08:00
|
|
|
Vector2 _squareVertices[4];
|
2013-07-18 07:56:19 +08:00
|
|
|
Color4F _squareColors[4];
|
2013-12-26 21:19:12 +08:00
|
|
|
CustomCommand _customCommand;
|
2014-04-02 15:06:16 +08:00
|
|
|
Vector3 _noMVPVertices[4];
|
2013-11-14 07:55:36 +08:00
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(LayerColor);
|
|
|
|
|
2012-02-01 16:45:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
// LayerGradient
|
2012-02-01 16:45:23 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief LayerGradient is a subclass of LayerColor that draws gradients across the background.
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
All features from LayerColor are valid, plus the following new features:
|
2012-02-01 16:45:23 +08:00
|
|
|
- direction
|
|
|
|
- final color
|
|
|
|
- interpolation mode
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
If ' compressedInterpolation' is enabled (default mode) you will see both the start and end colors of the gradient.
|
|
|
|
|
|
|
|
@since v0.99.5
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL LayerGradient : public LayerColor
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-29 10:02:10 +08:00
|
|
|
/** Creates a fullscreen black layer */
|
|
|
|
static LayerGradient* create();
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Creates a full-screen Layer with a gradient between start and end. */
|
2013-07-05 16:49:22 +08:00
|
|
|
static LayerGradient* create(const Color4B& start, const Color4B& end);
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Creates a full-screen Layer with a gradient between start and end in the direction of v. */
|
2014-04-15 18:08:29 +08:00
|
|
|
static LayerGradient* create(const Color4B& start, const Color4B& end, const Vector2& v);
|
2013-07-04 12:50:17 +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
|
2013-08-01 16:39:42 +08:00
|
|
|
Default: true
|
2013-07-04 12:50:17 +08:00
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
void setCompressedInterpolation(bool compressedInterpolation);
|
2013-07-20 04:16:38 +08:00
|
|
|
bool isCompressedInterpolation() const;
|
|
|
|
|
|
|
|
/** Sets the start color of the gradient */
|
|
|
|
void setStartColor( const Color3B& startColor );
|
|
|
|
/** Returns the start color of the gradient */
|
|
|
|
const Color3B& getStartColor() const;
|
|
|
|
|
|
|
|
/** Sets the end color of the gradient */
|
|
|
|
void setEndColor( const Color3B& endColor );
|
|
|
|
/** Returns the end color of the gradient */
|
|
|
|
const Color3B& getEndColor() const;
|
|
|
|
|
|
|
|
/** Returns the start opacity of the gradient */
|
|
|
|
void setStartOpacity( GLubyte startOpacity );
|
|
|
|
/** Returns the start opacity of the gradient */
|
|
|
|
GLubyte getStartOpacity() const;
|
|
|
|
|
|
|
|
/** Returns the end opacity of the gradient */
|
|
|
|
void setEndOpacity( GLubyte endOpacity );
|
|
|
|
/** Returns the end opacity of the gradient */
|
|
|
|
GLubyte getEndOpacity() const;
|
|
|
|
|
|
|
|
/** Sets the directional vector that will be used for the gradient.
|
|
|
|
The default value is vertical direction (0,-1).
|
|
|
|
*/
|
2014-04-15 18:08:29 +08:00
|
|
|
void setVector(const Vector2& alongVector);
|
2013-07-20 04:16:38 +08:00
|
|
|
/** Returns the directional vector used for the gradient */
|
2014-04-15 18:08:29 +08:00
|
|
|
const Vector2& getVector() const;
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2014-03-26 18:45:08 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
LayerGradient();
|
|
|
|
virtual ~LayerGradient();
|
2014-03-27 10:55:41 +08:00
|
|
|
|
|
|
|
virtual bool init();
|
|
|
|
/** Initializes the Layer with a gradient between start and end.
|
|
|
|
* @js init
|
|
|
|
* @lua init
|
|
|
|
*/
|
|
|
|
bool initWithColor(const Color4B& start, const Color4B& end);
|
|
|
|
|
|
|
|
/** Initializes the Layer with a gradient between start and end in the direction of v.
|
|
|
|
* @js init
|
|
|
|
* @lua init
|
|
|
|
*/
|
2014-04-15 18:08:29 +08:00
|
|
|
bool initWithColor(const Color4B& start, const Color4B& end, const Vector2& v);
|
2013-12-13 06:30:22 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
protected:
|
|
|
|
virtual void updateColor() override;
|
|
|
|
|
2013-07-20 04:16:38 +08:00
|
|
|
Color3B _startColor;
|
|
|
|
Color3B _endColor;
|
|
|
|
GLubyte _startOpacity;
|
|
|
|
GLubyte _endOpacity;
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 _alongVector;
|
2013-07-20 04:16:38 +08:00
|
|
|
bool _compressedInterpolation;
|
2012-02-01 16:45:23 +08:00
|
|
|
};
|
|
|
|
|
2012-07-13 09:53:38 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief MultipleLayer is a Layer with the ability to multiplex it's children.
|
2012-02-01 16:45:23 +08:00
|
|
|
Features:
|
|
|
|
- It supports one or more children
|
|
|
|
- Only one children will be active a time
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL LayerMultiplex : public Layer
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 11:41:20 +08:00
|
|
|
/** creates and initializes a LayerMultiplex object
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static LayerMultiplex* create();
|
2013-07-18 07:56:19 +08:00
|
|
|
|
|
|
|
/** creates a LayerMultiplex with an array of layers.
|
2013-02-27 18:21:35 +08:00
|
|
|
@since v2.1
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
2013-02-27 18:21:35 +08:00
|
|
|
*/
|
2013-11-29 11:36:42 +08:00
|
|
|
static LayerMultiplex* createWithArray(const Vector<Layer*>& arrayOfLayers);
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** creates a LayerMultiplex with one or more layers using a variable argument list.
|
|
|
|
* @code
|
|
|
|
* When this function bound to lua or js,the input params are changed.
|
|
|
|
* In js:var create(...)
|
|
|
|
* In lua:local create(...)
|
|
|
|
* @endcode
|
|
|
|
*/
|
2014-03-25 06:09:24 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
|
|
|
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported
|
|
|
|
typedef Layer* M;
|
|
|
|
static LayerMultiplex* create(M m1, std::nullptr_t listEnd) { return createVariadic(m1, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, std::nullptr_t listEnd) { return createVariadic(m1, m2, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, m4, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, m4, m5, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, m4, m5, m6, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, m4, m5, m6, m7, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, m4, m5, m6, m7, m8, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); }
|
|
|
|
static LayerMultiplex* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return createVariadic(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); }
|
|
|
|
|
|
|
|
// On WP8 for variable argument lists longer than 10 items, use createWithArray or createVariadic with NULL as the last argument
|
|
|
|
static LayerMultiplex* createVariadic(Layer* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
|
|
|
#else
|
2013-06-20 14:13:12 +08:00
|
|
|
static LayerMultiplex * create(Layer* layer, ... );
|
2014-03-25 06:09:24 +08:00
|
|
|
#endif
|
2012-02-01 16:45:23 +08:00
|
|
|
|
|
|
|
/**
|
2012-04-19 14:35:52 +08:00
|
|
|
* lua script can not init with undetermined number of variables
|
2012-09-17 15:02:24 +08:00
|
|
|
* so add these functions to be used with lua.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static LayerMultiplex * createWithLayer(Layer* layer);
|
2013-11-29 11:36:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
void addLayer(Layer* layer);
|
|
|
|
|
|
|
|
/** switches to a certain layer indexed by n.
|
|
|
|
The current (old) layer will be removed from it's parent with 'cleanup=true'.
|
|
|
|
*/
|
|
|
|
void switchTo(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=true'.
|
|
|
|
*/
|
|
|
|
void switchToAndReleaseMe(int n);
|
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2013-11-29 11:36:42 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
LayerMultiplex();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual ~LayerMultiplex();
|
2013-11-29 11:36:42 +08:00
|
|
|
|
2013-08-26 19:38:23 +08:00
|
|
|
virtual bool init();
|
2013-11-29 11:36:42 +08:00
|
|
|
/** initializes a MultiplexLayer with one or more layers using a variable argument list.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
bool initWithLayers(Layer* layer, va_list params);
|
2013-11-29 11:36:42 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** initializes a MultiplexLayer with an array of layers
|
2013-07-18 07:56:19 +08:00
|
|
|
@since v2.1
|
|
|
|
*/
|
2013-11-29 11:36:42 +08:00
|
|
|
bool initWithArray(const Vector<Layer*>& arrayOfLayers);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
protected:
|
2013-07-18 07:56:19 +08:00
|
|
|
unsigned int _enabledLayer;
|
2013-11-29 11:36:42 +08:00
|
|
|
Vector<Layer*> _layers;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(LayerMultiplex);
|
2012-02-01 16:45:23 +08:00
|
|
|
};
|
|
|
|
|
2012-07-13 09:53:38 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of layer group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2012-02-01 16:45:23 +08:00
|
|
|
|
|
|
|
#endif // __CCLAYER_H__
|
|
|
|
|