CCApplicationProtocol.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CC_APPLICATION_PROTOCOL_H__
  22. #define __CC_APPLICATION_PROTOCOL_H__
  23. #include "platform/CCPlatformMacros.h"
  24. #include "base/CCScriptSupport.h"
  25. #include "base/CCAutoreleasePool.h"
  26. #include "base/ccTypes.h"
  27. NS_CC_BEGIN
  28. /**
  29. * @addtogroup platform
  30. * @{
  31. */
  32. class CC_DLL ApplicationProtocol
  33. {
  34. public:
  35. /** Since WINDOWS and ANDROID are defined as macros, we could not just use these keywords in enumeration(Platform).
  36. * Therefore, 'OS_' prefix is added to avoid conflicts with the definitions of system macros.
  37. */
  38. enum class Platform
  39. {
  40. OS_WINDOWS, /**< Windows */
  41. OS_LINUX, /**< Linux */
  42. OS_MAC, /**< Mac OS X*/
  43. OS_ANDROID, /**< Android */
  44. OS_IPHONE, /**< iPhone */
  45. OS_IPAD, /**< iPad */
  46. OS_BLACKBERRY, /**< BlackBerry */
  47. OS_NACL, /**< Native Client in Chrome */
  48. OS_EMSCRIPTEN, /**< Emscripten */
  49. OS_TIZEN, /**< Tizen */
  50. OS_WINRT, /**< Windows Runtime Applications */
  51. OS_WP8 /**< Windows Phone 8 Applications */
  52. };
  53. /**
  54. * @js NA
  55. * @lua NA
  56. */
  57. virtual ~ApplicationProtocol(){
  58. #if CC_ENABLE_SCRIPT_BINDING
  59. ScriptEngineManager::destroyInstance();
  60. #endif
  61. /** clean auto release pool. */
  62. PoolManager::destroyInstance();
  63. }
  64. /**
  65. * @brief Implement Director and Scene init code here.
  66. * @return true Initialize success, app continue.
  67. * @return false Initialize failed, app terminate.
  68. * @js NA
  69. * @lua NA
  70. */
  71. virtual bool applicationDidFinishLaunching() = 0;
  72. /**
  73. * @brief This function will be called when the application enters background.
  74. * @js NA
  75. * @lua NA
  76. */
  77. virtual void applicationDidEnterBackground() = 0;
  78. /**
  79. * @brief This function will be called when the application enters foreground.
  80. * @js NA
  81. * @lua NA
  82. */
  83. virtual void applicationWillEnterForeground() = 0;
  84. /**
  85. * @brief Callback by Director for limit FPS.
  86. * @param interval The time, expressed in seconds, between current frame and next.
  87. * @js NA
  88. * @lua NA
  89. */
  90. virtual void setAnimationInterval(float interval) = 0;
  91. virtual void setAnimationInterval(float interval, SetIntervalReason reason) = 0;
  92. /** Subclass override the function to set OpenGL context attribution instead of use default value.
  93. * And now can only set six attributions:redBits,greenBits,blueBits,alphaBits,depthBits,stencilBits.
  94. * Default value are(5,6,5,0,16,0), usually use as follows:
  95. * void AppDelegate::initGLContextAttrs(){
  96. * GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
  97. * GLView::setGLContextAttrs(glContextAttrs);
  98. * }
  99. */
  100. virtual void initGLContextAttrs() {}
  101. /**
  102. @brief Get current language config.
  103. @return Current language config.
  104. * @js NA
  105. * @lua NA
  106. */
  107. virtual LanguageType getCurrentLanguage() = 0;
  108. /**
  109. @brief Get current language iso 639-1 code.
  110. @return Current language iso 639-1 code.
  111. * @js NA
  112. * @lua NA
  113. */
  114. virtual const char * getCurrentLanguageCode() = 0;
  115. /**
  116. @brief Get target platform.
  117. * @js NA
  118. * @lua NA
  119. */
  120. virtual Platform getTargetPlatform() = 0;
  121. /**
  122. @brief Get application version.
  123. * @js NA
  124. * @lua NA
  125. */
  126. virtual std::string getVersion() = 0;
  127. /**
  128. @brief Open url in default browser.
  129. @param String with url to open.
  130. @return True if the resource located by the URL was successfully opened; otherwise false.
  131. * @js NA
  132. * @lua NA
  133. */
  134. virtual bool openURL(const std::string &url) = 0;
  135. };
  136. // end of platform group
  137. /** @} */
  138. NS_CC_END
  139. #endif // __CC_APPLICATION_PROTOCOL_H__