CCApplicationProtocol.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  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 __CC_APPLICATION_PROTOCOL_H__
  23. #define __CC_APPLICATION_PROTOCOL_H__
  24. #include "platform/CCPlatformMacros.h"
  25. #include "base/CCScriptSupport.h"
  26. #include "base/CCAutoreleasePool.h"
  27. #include "base/ccTypes.h"
  28. NS_CC_BEGIN
  29. /**
  30. * @addtogroup platform
  31. * @{
  32. */
  33. class CC_DLL ApplicationProtocol
  34. {
  35. public:
  36. /** Since WINDOWS and ANDROID are defined as macros, we could not just use these keywords in enumeration(Platform).
  37. * Therefore, 'OS_' prefix is added to avoid conflicts with the definitions of system macros.
  38. */
  39. enum class Platform
  40. {
  41. OS_WINDOWS, /**< Windows */
  42. OS_LINUX, /**< Linux */
  43. OS_MAC, /**< Mac OS X*/
  44. OS_ANDROID, /**< Android */
  45. OS_IPHONE, /**< iPhone */
  46. OS_IPAD, /**< iPad */
  47. OS_BLACKBERRY, /**< BlackBerry */
  48. OS_NACL, /**< Native Client in Chrome */
  49. OS_EMSCRIPTEN, /**< Emscripten */
  50. OS_TIZEN, /**< Tizen */
  51. OS_WINRT, /**< Windows Runtime Applications */
  52. OS_WP8 /**< Windows Phone 8 Applications */
  53. };
  54. /**
  55. * @js NA
  56. * @lua NA
  57. */
  58. virtual ~ApplicationProtocol(){
  59. #if CC_ENABLE_SCRIPT_BINDING
  60. ScriptEngineManager::destroyInstance();
  61. #endif
  62. /** clean auto release pool. */
  63. PoolManager::destroyInstance();
  64. }
  65. /**
  66. * @brief Implement Director and Scene init code here.
  67. * @return true Initialize success, app continue.
  68. * @return false Initialize failed, app terminate.
  69. * @js NA
  70. * @lua NA
  71. */
  72. virtual bool applicationDidFinishLaunching() = 0;
  73. /**
  74. * @brief This function will be called when the application enters background.
  75. * @js NA
  76. * @lua NA
  77. */
  78. virtual void applicationDidEnterBackground() = 0;
  79. /**
  80. * @brief This function will be called when the application enters foreground.
  81. * @js NA
  82. * @lua NA
  83. */
  84. virtual void applicationWillEnterForeground() = 0;
  85. /**
  86. * @brief Callback by Director for limit FPS.
  87. * @param interval The time, expressed in seconds, between current frame and next.
  88. * @js NA
  89. * @lua NA
  90. */
  91. virtual void setAnimationInterval(float interval) = 0;
  92. virtual void setAnimationInterval(float interval, SetIntervalReason reason) = 0;
  93. /** Subclass override the function to set OpenGL context attribution instead of use default value.
  94. * And now can only set six attributions:redBits,greenBits,blueBits,alphaBits,depthBits,stencilBits.
  95. * Default value are(5,6,5,0,16,0), usually use as follows:
  96. * void AppDelegate::initGLContextAttrs(){
  97. * GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
  98. * GLView::setGLContextAttrs(glContextAttrs);
  99. * }
  100. */
  101. virtual void initGLContextAttrs() {}
  102. /**
  103. @brief Get current language config.
  104. @return Current language config.
  105. * @js NA
  106. * @lua NA
  107. */
  108. virtual LanguageType getCurrentLanguage() = 0;
  109. /**
  110. @brief Get current language iso 639-1 code.
  111. @return Current language iso 639-1 code.
  112. * @js NA
  113. * @lua NA
  114. */
  115. virtual const char * getCurrentLanguageCode() = 0;
  116. /**
  117. @brief Get target platform.
  118. * @js NA
  119. * @lua NA
  120. */
  121. virtual Platform getTargetPlatform() = 0;
  122. /**
  123. @brief Get application version.
  124. * @js NA
  125. * @lua NA
  126. */
  127. virtual std::string getVersion() = 0;
  128. /**
  129. @brief Open url in default browser.
  130. @param String with url to open.
  131. @return True if the resource located by the URL was successfully opened; otherwise false.
  132. * @js NA
  133. * @lua NA
  134. */
  135. virtual bool openURL(const std::string &url) = 0;
  136. };
  137. // end of platform group
  138. /** @} */
  139. NS_CC_END
  140. #endif // __CC_APPLICATION_PROTOCOL_H__