view_controller.mm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*************************************************************************/
  2. /* view_controller.mm */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #import "view_controller.h"
  31. #include "os_iphone.h"
  32. #include "core/project_settings.h"
  33. extern "C" {
  34. int add_path(int, char **);
  35. int add_cmdline(int, char **);
  36. int add_path(int p_argc, char **p_args) {
  37. NSString *str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"];
  38. if (!str) {
  39. return p_argc;
  40. }
  41. p_args[p_argc++] = (char *)"--path";
  42. p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
  43. p_args[p_argc] = NULL;
  44. return p_argc;
  45. };
  46. int add_cmdline(int p_argc, char **p_args) {
  47. NSArray *arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_cmdline"];
  48. if (!arr)
  49. return p_argc;
  50. for (int i = 0; i < [arr count]; i++) {
  51. NSString *str = [arr objectAtIndex:i];
  52. if (!str) {
  53. continue;
  54. }
  55. p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
  56. };
  57. p_args[p_argc] = NULL;
  58. return p_argc;
  59. };
  60. }; // extern "C"
  61. @interface ViewController ()
  62. @end
  63. @implementation ViewController
  64. - (void)didReceiveMemoryWarning {
  65. [super didReceiveMemoryWarning];
  66. printf("*********** did receive memory warning!\n");
  67. };
  68. - (void)viewDidLoad {
  69. [super viewDidLoad];
  70. if (@available(iOS 11.0, *)) {
  71. [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
  72. }
  73. }
  74. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
  75. return UIRectEdgeAll;
  76. }
  77. - (BOOL)shouldAutorotate {
  78. switch (OS::get_singleton()->get_screen_orientation()) {
  79. case OS::SCREEN_SENSOR:
  80. case OS::SCREEN_SENSOR_LANDSCAPE:
  81. case OS::SCREEN_SENSOR_PORTRAIT:
  82. return YES;
  83. default:
  84. return NO;
  85. }
  86. };
  87. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  88. switch (OS::get_singleton()->get_screen_orientation()) {
  89. case OS::SCREEN_PORTRAIT:
  90. return UIInterfaceOrientationMaskPortrait;
  91. case OS::SCREEN_REVERSE_LANDSCAPE:
  92. return UIInterfaceOrientationMaskLandscapeRight;
  93. case OS::SCREEN_REVERSE_PORTRAIT:
  94. return UIInterfaceOrientationMaskPortraitUpsideDown;
  95. case OS::SCREEN_SENSOR_LANDSCAPE:
  96. return UIInterfaceOrientationMaskLandscape;
  97. case OS::SCREEN_SENSOR_PORTRAIT:
  98. return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
  99. case OS::SCREEN_SENSOR:
  100. return UIInterfaceOrientationMaskAll;
  101. case OS::SCREEN_LANDSCAPE:
  102. return UIInterfaceOrientationMaskLandscapeLeft;
  103. }
  104. };
  105. - (BOOL)prefersStatusBarHidden {
  106. return YES;
  107. }
  108. - (BOOL)prefersHomeIndicatorAutoHidden {
  109. if (GLOBAL_GET("display/window/ios/hide_home_indicator")) {
  110. return YES;
  111. } else {
  112. return NO;
  113. }
  114. }
  115. #ifdef GAME_CENTER_ENABLED
  116. - (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController {
  117. //[gameCenterViewController dismissViewControllerAnimated:YES completion:^{GameCenter::get_singleton()->game_center_closed();}];//version for signaling when overlay is completely gone
  118. GameCenter::get_singleton()->game_center_closed();
  119. [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
  120. }
  121. #endif
  122. @end