CCDevice.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 __CCDEVICE_H__
  23. #define __CCDEVICE_H__
  24. #include "platform/CCPlatformMacros.h"
  25. #include "base/ccMacros.h"
  26. #include "base/CCData.h"
  27. NS_CC_BEGIN
  28. struct FontDefinition;
  29. /**
  30. * @addtogroup platform
  31. * @{
  32. */
  33. /**
  34. * @class Device
  35. * @brief
  36. */
  37. class CC_DLL Device
  38. {
  39. public:
  40. /** Defines the alignment of text. */
  41. enum class TextAlign
  42. {
  43. CENTER = 0x33, /** Horizontal center and vertical center. */
  44. TOP = 0x13, /** Horizontal center and vertical top. */
  45. TOP_RIGHT = 0x12, /** Horizontal right and vertical top. */
  46. RIGHT = 0x32, /** Horizontal right and vertical center. */
  47. BOTTOM_RIGHT = 0x22, /** Horizontal right and vertical bottom. */
  48. BOTTOM = 0x23, /** Horizontal center and vertical bottom. */
  49. BOTTOM_LEFT = 0x21, /** Horizontal left and vertical bottom. */
  50. LEFT = 0x31, /** Horizontal left and vertical center. */
  51. TOP_LEFT = 0x11, /** Horizontal left and vertical top. */
  52. };
  53. /**
  54. * Gets the DPI of device
  55. * @return The DPI of device.
  56. */
  57. static int getDPI();
  58. /**
  59. * To enable or disable accelerometer.
  60. */
  61. static void setAccelerometerEnabled(bool isEnabled);
  62. /**
  63. * Sets the interval of accelerometer.
  64. */
  65. static void setAccelerometerInterval(float interval);
  66. /**
  67. * Controls whether the screen should remain on.
  68. *
  69. * @param keepScreenOn One flag indicating that the screen should remain on.
  70. */
  71. static void setKeepScreenOn(bool keepScreenOn);
  72. /**
  73. * Vibrate for the specified amount of time.
  74. * If vibrate is not supported, then invoking this method has no effect.
  75. * Some platforms limit to a maximum duration of 5 seconds.
  76. * Duration is ignored on iOS due to API limitations.
  77. * @param duration The duration in seconds.
  78. */
  79. static void vibrate(float duration);
  80. /**
  81. * Gets texture data for text.
  82. */
  83. static Data getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha);
  84. private:
  85. CC_DISALLOW_IMPLICIT_CONSTRUCTORS(Device);
  86. };
  87. // end group
  88. /// @}
  89. NS_CC_END
  90. #endif /* __CCDEVICE_H__ */