view_controller.mm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*************************************************************************/
  2. /* view_controller.mm */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. extern "C" {
  33. int add_path(int, char **);
  34. int add_cmdline(int, char **);
  35. int add_path(int p_argc, char **p_args) {
  36. NSString *str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"];
  37. if (!str)
  38. return p_argc;
  39. p_args[p_argc++] = "--path";
  40. [str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo
  41. p_args[p_argc++] = (char *)[str cString];
  42. p_args[p_argc] = NULL;
  43. return p_argc;
  44. };
  45. int add_cmdline(int p_argc, char **p_args) {
  46. NSArray *arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_cmdline"];
  47. if (!arr)
  48. return p_argc;
  49. for (int i = 0; i < [arr count]; i++) {
  50. NSString *str = [arr objectAtIndex:i];
  51. if (!str)
  52. continue;
  53. [str retain]; // @todo delete these at some point
  54. p_args[p_argc++] = (char *)[str cString];
  55. };
  56. p_args[p_argc] = NULL;
  57. return p_argc;
  58. };
  59. }; // extern "C"
  60. @interface ViewController ()
  61. @end
  62. @implementation ViewController
  63. - (void)didReceiveMemoryWarning {
  64. printf("*********** did receive memory warning!\n");
  65. };
  66. - (BOOL)shouldAutorotate {
  67. switch (OS::get_singleton()->get_screen_orientation()) {
  68. case OS::SCREEN_SENSOR:
  69. case OS::SCREEN_SENSOR_LANDSCAPE:
  70. case OS::SCREEN_SENSOR_PORTRAIT:
  71. return YES;
  72. default:
  73. return NO;
  74. }
  75. };
  76. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  77. switch (OS::get_singleton()->get_screen_orientation()) {
  78. case OS::SCREEN_PORTRAIT:
  79. return UIInterfaceOrientationMaskPortrait;
  80. case OS::SCREEN_REVERSE_LANDSCAPE:
  81. return UIInterfaceOrientationMaskLandscapeRight;
  82. case OS::SCREEN_REVERSE_PORTRAIT:
  83. return UIInterfaceOrientationMaskPortraitUpsideDown;
  84. case OS::SCREEN_SENSOR_LANDSCAPE:
  85. return UIInterfaceOrientationMaskLandscape;
  86. case OS::SCREEN_SENSOR_PORTRAIT:
  87. return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
  88. case OS::SCREEN_SENSOR:
  89. return UIInterfaceOrientationMaskAll;
  90. case OS::SCREEN_LANDSCAPE:
  91. return UIInterfaceOrientationMaskLandscapeLeft;
  92. }
  93. };
  94. - (BOOL)prefersStatusBarHidden {
  95. return YES;
  96. }
  97. #ifdef GAME_CENTER_ENABLED
  98. - (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController {
  99. //[gameCenterViewController dismissViewControllerAnimated:YES completion:^{GameCenter::get_singleton()->game_center_closed();}];//version for signaling when overlay is completely gone
  100. GameCenter::get_singleton()->game_center_closed();
  101. [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
  102. }
  103. #endif
  104. @end