1
0

CCProtocols.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2013-2017 Chukong Technologies Inc.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #ifndef __BASE_CCPROTOCOLS_H__
  23. #define __BASE_CCPROTOCOLS_H__
  24. /// @cond DO_NOT_SHOW
  25. #include <string>
  26. #include "base/ccTypes.h"
  27. #include "renderer/CCTexture2D.h"
  28. NS_CC_BEGIN
  29. /**
  30. * RGBA protocol that affects Node's color and opacity
  31. */
  32. class CC_DLL __RGBAProtocol
  33. {
  34. public:
  35. virtual ~__RGBAProtocol() {}
  36. /**
  37. * Changes the color with R,G,B bytes
  38. *
  39. * @param color Example: Color3B(255,100,0) means R=255, G=100, B=0
  40. * @js NA
  41. * @lua NA
  42. */
  43. virtual void setColor(const Color3B& color) = 0;
  44. /**
  45. * Returns color that is currently used.
  46. *
  47. * @return The Color3B contains R,G,B bytes.
  48. * @js NA
  49. * @lua NA
  50. */
  51. virtual const Color3B& getColor() const = 0;
  52. /**
  53. * Returns the displayed color.
  54. *
  55. * @return The Color3B contains R,G,B bytes.
  56. * @js NA
  57. * @lua NA
  58. */
  59. virtual const Color3B& getDisplayedColor() const = 0;
  60. /**
  61. * Returns the displayed opacity.
  62. *
  63. * @return The opacity of sprite, from 0 ~ 255
  64. * @js NA
  65. * @lua NA
  66. */
  67. virtual GLubyte getDisplayedOpacity() const = 0;
  68. /**
  69. * Returns the opacity.
  70. *
  71. * The opacity which indicates how transparent or opaque this node is.
  72. * 0 indicates fully transparent and 255 is fully opaque.
  73. *
  74. * @return The opacity of sprite, from 0 ~ 255
  75. * @js NA
  76. * @lua NA
  77. */
  78. virtual GLubyte getOpacity() const = 0;
  79. /**
  80. * Changes the opacity.
  81. *
  82. * @param opacity Goes from 0 to 255, where 255 means fully opaque and 0 means fully transparent.
  83. * @js NA
  84. * @lua NA
  85. */
  86. virtual void setOpacity(GLubyte opacity) = 0;
  87. // optional
  88. /**
  89. * Changes the OpacityModifyRGB property.
  90. * If this property is set to true, then the rendered color will be affected by opacity.
  91. * Normally, r = r * opacity/255, g = g * opacity/255, b = b * opacity/255.
  92. *
  93. * @param value If true, then the opacity will be applied as: glColor(R,G,B,opacity);
  94. * If false, then the opacity will be applied as: glColor(opacity, opacity, opacity, opacity);
  95. * @js NA
  96. * @lua NA
  97. */
  98. virtual void setOpacityModifyRGB(bool value) = 0;
  99. /**
  100. * Returns whether or not the opacity will be applied using glColor(R,G,B,opacity)
  101. * or glColor(opacity, opacity, opacity, opacity)
  102. *
  103. * @return Returns opacity modify flag.
  104. * @js NA
  105. * @lua NA
  106. */
  107. virtual bool isOpacityModifyRGB() const = 0;
  108. /**
  109. * whether or not color should be propagated to its children.
  110. * @js NA
  111. * @lua NA
  112. */
  113. virtual bool isCascadeColorEnabled() const = 0;
  114. /**
  115. * @js NA
  116. * @lua NA
  117. */
  118. virtual void setCascadeColorEnabled(bool cascadeColorEnabled) = 0;
  119. /**
  120. * recursive method that updates display color
  121. * @js NA
  122. * @lua NA
  123. */
  124. virtual void updateDisplayedColor(const Color3B& color) = 0;
  125. /**
  126. * whether or not opacity should be propagated to its children.
  127. * @js NA
  128. * @lua NA
  129. */
  130. virtual bool isCascadeOpacityEnabled() const = 0;
  131. /**
  132. * @js NA
  133. * @lua NA
  134. */
  135. virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) = 0;
  136. /**
  137. * recursive method that updates the displayed opacity.
  138. * @js NA
  139. * @lua NA
  140. */
  141. virtual void updateDisplayedOpacity(GLubyte opacity) = 0;
  142. };
  143. /**
  144. * Specify the blending function according glBlendFunc
  145. * Please refer to glBlendFunc in OpenGL ES Manual
  146. * http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml for more details.
  147. */
  148. class CC_DLL BlendProtocol
  149. {
  150. public:
  151. virtual ~BlendProtocol() {}
  152. /**
  153. * Sets the source blending function.
  154. *
  155. * @param blendFunc A structure with source and destination factor to specify pixel arithmetic,
  156. * e.g. {GL_ONE, GL_ONE}, {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}.
  157. * @js NA
  158. * @lua NA
  159. */
  160. virtual void setBlendFunc(const BlendFunc &blendFunc) = 0;
  161. /**
  162. * Returns the blending function that is currently being used.
  163. *
  164. * @return A BlendFunc structure with source and destination factor which specified pixel arithmetic.
  165. * @js NA
  166. * @lua NA
  167. */
  168. virtual const BlendFunc &getBlendFunc() const = 0;
  169. };
  170. /**
  171. * Node objects that uses a Texture2D to render the images.
  172. * The texture can have a blending function.
  173. * If the texture has alpha premultiplied the default blending function is:
  174. * src=GL_ONE dst= GL_ONE_MINUS_SRC_ALPHA
  175. * else
  176. * src=GL_SRC_ALPHA dst= GL_ONE_MINUS_SRC_ALPHA
  177. * But you can change the blending function at any time.
  178. */
  179. class CC_DLL TextureProtocol : public BlendProtocol
  180. {
  181. public:
  182. virtual ~TextureProtocol() {}
  183. /**
  184. * Returns the currently used texture
  185. *
  186. * @return The texture that is currently being used.
  187. * @js NA
  188. * @lua NA
  189. */
  190. virtual Texture2D* getTexture() const = 0;
  191. /**
  192. * Sets a new texture. It will be retained.
  193. *
  194. * @param texture A valid Texture2D object, which will be applied to this sprite object.
  195. * @js NA
  196. * @lua NA
  197. */
  198. virtual void setTexture(Texture2D *texture) = 0;
  199. };
  200. /**
  201. * Common interface for Labels
  202. */
  203. class CC_DLL LabelProtocol
  204. {
  205. public:
  206. virtual ~LabelProtocol() {}
  207. /**
  208. * Sets a new label using a string
  209. *
  210. * @param label A null terminated string
  211. * @js NA
  212. * @lua NA
  213. */
  214. virtual void setString(const std::string &label) = 0;
  215. /**
  216. * Returns the string that is currently being used in this label
  217. *
  218. * @return The string that is currently being used in this label
  219. * @js NA
  220. * @lua NA
  221. */
  222. virtual const std::string& getString() const = 0;
  223. };
  224. /**
  225. * OpenGL projection protocol
  226. */
  227. class CC_DLL DirectorDelegate
  228. {
  229. public:
  230. virtual ~DirectorDelegate() {}
  231. /**
  232. * Will be called by Director when the projection is updated, and "custom" projection is used
  233. * @js NA
  234. * @lua NA
  235. */
  236. virtual void updateProjection() = 0;
  237. };
  238. /**
  239. * interface for playable items
  240. */
  241. class CC_DLL PlayableProtocol
  242. {
  243. public:
  244. virtual ~PlayableProtocol(){}
  245. virtual void start() = 0;
  246. virtual void stop() = 0;
  247. };
  248. NS_CC_END
  249. /// @endcond
  250. #endif // __BASE_CCPROTOCOLS_H__