2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
|
|
|
|
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 __CCPROTOCOLS_H__
|
|
|
|
#define __CCPROTOCOLS_H__
|
|
|
|
|
|
|
|
#include "ccTypes.h"
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "textures/CCTexture2D.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* RGBA protocol that affects Node's color and opacity
|
2013-01-14 16:54:20 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL RGBAProtocol
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Changes the color with R,G,B bytes
|
|
|
|
*
|
2013-07-05 16:49:22 +08:00
|
|
|
* @param color Example: Color3B(255,100,0) means R=255, G=100, B=0
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
virtual void setColor(const Color3B& color) = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Returns color that is currently used.
|
|
|
|
*
|
2013-07-05 16:49:22 +08:00
|
|
|
* @return The Color3B contains R,G,B bytes.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
virtual const Color3B& getColor(void) const = 0;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the displayed color.
|
|
|
|
*
|
2013-07-05 16:49:22 +08:00
|
|
|
* @return The Color3B contains R,G,B bytes.
|
2013-02-27 09:38:30 +08:00
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
virtual const Color3B& getDisplayedColor(void) const = 0;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the displayed opacity.
|
|
|
|
*
|
|
|
|
* @return The opacity of sprite, from 0 ~ 255
|
|
|
|
*/
|
2013-07-04 08:22:15 +08:00
|
|
|
virtual GLubyte getDisplayedOpacity(void) const = 0;
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Returns the opacity.
|
|
|
|
*
|
2013-01-14 21:51:47 +08:00
|
|
|
* The opacity which indicates how transparent or opaque this node is.
|
2013-01-14 16:54:20 +08:00
|
|
|
* 0 indicates fully transparent and 255 is fully opaque.
|
|
|
|
*
|
|
|
|
* @return The opacity of sprite, from 0 ~ 255
|
|
|
|
*/
|
2013-07-04 08:22:15 +08:00
|
|
|
virtual GLubyte getOpacity(void) const = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Changes the opacity.
|
|
|
|
*
|
|
|
|
* @param value Goes from 0 to 255, where 255 means fully opaque and 0 means fully transparent.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
virtual void setOpacity(GLubyte opacity) = 0;
|
|
|
|
|
|
|
|
// optional
|
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
2013-01-14 21:51:47 +08:00
|
|
|
* Changes the OpacityModifyRGB property.
|
|
|
|
* If thie property is set to true, then the rendered color will be affected by opacity.
|
|
|
|
* Normally, r = r * opacity/255, g = g * opacity/255, b = b * opacity/255.
|
2013-01-14 16:54:20 +08:00
|
|
|
*
|
2013-01-14 21:51:47 +08:00
|
|
|
* @param bValue true then the opacity will be applied as: glColor(R,G,B,opacity);
|
|
|
|
* false then the opacity will be applied as: glColor(opacity, opacity, opacity, opacity);
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2012-06-15 15:10:40 +08:00
|
|
|
virtual void setOpacityModifyRGB(bool bValue) = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Returns whether or not the opacity will be applied using glColor(R,G,B,opacity)
|
|
|
|
* or glColor(opacity, opacity, opacity, opacity)
|
|
|
|
*
|
|
|
|
* @return Returns opacity modify flag.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-07-04 08:22:15 +08:00
|
|
|
virtual bool isOpacityModifyRGB(void) const = 0;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* whether or not color should be propagated to its children.
|
|
|
|
*/
|
2013-07-04 08:22:15 +08:00
|
|
|
virtual bool isCascadeColorEnabled(void) const = 0;
|
2013-02-27 15:30:49 +08:00
|
|
|
virtual void setCascadeColorEnabled(bool cascadeColorEnabled) = 0;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* recursive method that updates display color
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
virtual void updateDisplayedColor(const Color3B& color) = 0;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* whether or not opacity should be propagated to its children.
|
|
|
|
*/
|
2013-07-04 08:22:15 +08:00
|
|
|
virtual bool isCascadeOpacityEnabled(void) const = 0;
|
2013-02-27 15:30:49 +08:00
|
|
|
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) = 0;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* recursive method that updates the displayed opacity.
|
|
|
|
*/
|
|
|
|
virtual void updateDisplayedOpacity(GLubyte opacity) = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-14 16:54:20 +08:00
|
|
|
* Specify the blending function according glBlendFunc
|
|
|
|
* Please refer to glBlendFunc in OpenGL ES Manual
|
|
|
|
* http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml for more details.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL BlendProtocol
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
2013-01-14 21:51:47 +08:00
|
|
|
* Sets the source blending function.
|
2013-01-14 16:54:20 +08:00
|
|
|
*
|
|
|
|
* @param blendFunc A structure with source and destination factor to specify pixel arithmetic,
|
|
|
|
* e.g. {GL_ONE, GL_ONE}, {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}.
|
|
|
|
*
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
virtual void setBlendFunc(const BlendFunc &blendFunc) = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
2013-01-14 21:51:47 +08:00
|
|
|
* Returns the blending function that is currently being used.
|
2013-01-14 16:54:20 +08:00
|
|
|
*
|
2013-07-05 16:49:22 +08:00
|
|
|
* @return A BlendFunc structure with source and destination factor which specified pixel arithmetic.
|
2013-01-14 16:54:20 +08:00
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
virtual const BlendFunc &getBlendFunc(void) const = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* Node objects that uses a Texture2D to render the images.
|
2013-01-14 16:54:20 +08:00
|
|
|
* The texture can have a blending function.
|
|
|
|
* If the texture has alpha premultiplied the default blending function is:
|
|
|
|
* src=GL_ONE dst= GL_ONE_MINUS_SRC_ALPHA
|
|
|
|
* else
|
|
|
|
* src=GL_SRC_ALPHA dst= GL_ONE_MINUS_SRC_ALPHA
|
|
|
|
* But you can change the blending function at any time.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL TextureProtocol : public BlendProtocol
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Returns the currently used texture
|
|
|
|
*
|
|
|
|
* @return The texture that is currenlty being used.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual Texture2D* getTexture(void) = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Sets a new texuture. It will be retained.
|
|
|
|
*
|
2013-06-20 14:13:12 +08:00
|
|
|
* @param texture A valid Texture2D object, which will be applied to this sprite object.
|
2013-01-14 16:54:20 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual void setTexture(Texture2D *texture) = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Common interface for Labels
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL LabelProtocol
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Sets a new label using an string
|
|
|
|
*
|
|
|
|
* @param A null terminated string
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void setString(const char *label) = 0;
|
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* Returns the string that is currently being used in this label
|
|
|
|
*
|
|
|
|
* @return The string that is currently being used in this label
|
|
|
|
*/
|
2013-07-04 08:22:15 +08:00
|
|
|
virtual const char* getString(void) const = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
|
|
|
* OpenGL projection protocol
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL DirectorDelegate
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-01-14 16:54:20 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* Will be called by Director when the projection is updated, and "custom" projection is used
|
2013-01-14 16:54:20 +08:00
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void updateProjection(void) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __CCPROTOCOLS_H__
|