CCProtocols.h 7.6 KB

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