view_controller.mm 5.1 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. p_args[p_argc++] = "--path";
  41. [str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo
  42. p_args[p_argc++] = (char *)[str cString];
  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. [str retain]; // @todo delete these at some point
  55. p_args[p_argc++] = (char *)[str cString];
  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. printf("*********** did receive memory warning!\n");
  66. };
  67. - (void)viewDidLoad {
  68. [super viewDidLoad];
  69. if (@available(iOS 11.0, *)) {
  70. [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
  71. }
  72. }
  73. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
  74. return UIRectEdgeAll;
  75. }
  76. - (BOOL)shouldAutorotate {
  77. switch (OS::get_singleton()->get_screen_orientation()) {
  78. case OS::SCREEN_SENSOR:
  79. case OS::SCREEN_SENSOR_LANDSCAPE:
  80. case OS::SCREEN_SENSOR_PORTRAIT:
  81. return YES;
  82. default:
  83. return NO;
  84. }
  85. };
  86. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  87. switch (OS::get_singleton()->get_screen_orientation()) {
  88. case OS::SCREEN_PORTRAIT:
  89. return UIInterfaceOrientationMaskPortrait;
  90. case OS::SCREEN_REVERSE_LANDSCAPE:
  91. return UIInterfaceOrientationMaskLandscapeRight;
  92. case OS::SCREEN_REVERSE_PORTRAIT:
  93. return UIInterfaceOrientationMaskPortraitUpsideDown;
  94. case OS::SCREEN_SENSOR_LANDSCAPE:
  95. return UIInterfaceOrientationMaskLandscape;
  96. case OS::SCREEN_SENSOR_PORTRAIT:
  97. return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
  98. case OS::SCREEN_SENSOR:
  99. return UIInterfaceOrientationMaskAll;
  100. case OS::SCREEN_LANDSCAPE:
  101. return UIInterfaceOrientationMaskLandscapeLeft;
  102. }
  103. };
  104. - (BOOL)prefersStatusBarHidden {
  105. return YES;
  106. }
  107. - (BOOL)prefersHomeIndicatorAutoHidden {
  108. if (GLOBAL_GET("display/window/ios/hide_home_indicator")) {
  109. return YES;
  110. } else {
  111. return NO;
  112. }
  113. }
  114. #ifdef GAME_CENTER_ENABLED
  115. - (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController {
  116. //[gameCenterViewController dismissViewControllerAnimated:YES completion:^{GameCenter::get_singleton()->game_center_closed();}];//version for signaling when overlay is completely gone
  117. GameCenter::get_singleton()->game_center_closed();
  118. [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
  119. }
  120. #endif
  121. @end