CCDevice-mac.mm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #include "platform/CCPlatformConfig.h"
  23. #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
  24. #include "platform/CCDevice.h"
  25. #include "platform/apple/CCDevice-apple.h"
  26. #include "base/ccTypes.h"
  27. #include "CCReachability.h"
  28. #include <Foundation/Foundation.h>
  29. #include <Cocoa/Cocoa.h>
  30. #include <sys/utsname.h>
  31. #include <string>
  32. NS_CC_BEGIN
  33. int Device::getDPI()
  34. {
  35. NSScreen *screen = [NSScreen mainScreen];
  36. NSDictionary *description = [screen deviceDescription];
  37. NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
  38. CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
  39. return ((displayPixelSize.width / displayPhysicalSize.width) * 25.4f);
  40. }
  41. void Device::setAccelerometerEnabled(bool isEnabled)
  42. {
  43. }
  44. void Device::setAccelerometerInterval(float interval)
  45. {
  46. }
  47. const Device::MotionValue& Device::getDeviceMotionValue()
  48. {
  49. static MotionValue __motionValue;
  50. return __motionValue;
  51. }
  52. Device::Rotation Device::getDeviceRotation()
  53. {
  54. return Device::Rotation::_0;
  55. }
  56. std::string Device::getDeviceModel()
  57. {
  58. struct utsname systemInfo;
  59. uname(&systemInfo);
  60. return systemInfo.machine;
  61. }
  62. void Device::setKeepScreenOn(bool value)
  63. {
  64. CC_UNUSED_PARAM(value);
  65. }
  66. void Device::vibrate(float duration)
  67. {
  68. CC_UNUSED_PARAM(duration);
  69. }
  70. float Device::getBatteryLevel()
  71. {
  72. return 1.0f;
  73. }
  74. Device::NetworkType Device::getNetworkType()
  75. {
  76. static Reachability* __reachability = nullptr;
  77. if (__reachability == nullptr)
  78. {
  79. __reachability = Reachability::createForInternetConnection();
  80. __reachability->retain();
  81. }
  82. NetworkType ret = NetworkType::NONE;
  83. Reachability::NetworkStatus status = __reachability->getCurrentReachabilityStatus();
  84. switch (status) {
  85. case Reachability::NetworkStatus::REACHABLE_VIA_WIFI:
  86. ret = NetworkType::LAN;
  87. break;
  88. case Reachability::NetworkStatus::REACHABLE_VIA_WWAN:
  89. ret = NetworkType::WWAN;
  90. default:
  91. ret = NetworkType::NONE;
  92. break;
  93. }
  94. return ret;
  95. }
  96. cocos2d::Vec4 Device::getSafeAreaEdge()
  97. {
  98. // no SafeArea concept on mac, return ZERO Vec4.
  99. return cocos2d::Vec4();
  100. }
  101. NS_CC_END
  102. #endif // CC_TARGET_PLATFORM == CC_PLATFORM_MAC