view_controller.mm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)p_orientation {
  67. if (/*OSIPhone::get_singleton() == NULL*/ TRUE) {
  68. printf("checking on info.plist\n");
  69. NSArray *arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
  70. switch (p_orientation) {
  71. case UIInterfaceOrientationLandscapeLeft:
  72. return [arr indexOfObject:@"UIInterfaceOrientationLandscapeLeft"] != NSNotFound ? YES : NO;
  73. case UIInterfaceOrientationLandscapeRight:
  74. return [arr indexOfObject:@"UIInterfaceOrientationLandscapeRight"] != NSNotFound ? YES : NO;
  75. case UIInterfaceOrientationPortrait:
  76. return [arr indexOfObject:@"UIInterfaceOrientationPortrait"] != NSNotFound ? YES : NO;
  77. case UIInterfaceOrientationPortraitUpsideDown:
  78. return [arr indexOfObject:@"UIInterfaceOrientationPortraitUpsideDown"] != NSNotFound ? YES : NO;
  79. default:
  80. return NO;
  81. }
  82. };
  83. uint8_t supported = OSIPhone::get_singleton()->get_orientations();
  84. switch (p_orientation) {
  85. case UIInterfaceOrientationLandscapeLeft:
  86. return supported & (1 << OSIPhone::LandscapeLeft) ? YES : NO;
  87. case UIInterfaceOrientationLandscapeRight:
  88. return supported & (1 << OSIPhone::LandscapeRight) ? YES : NO;
  89. case UIInterfaceOrientationPortrait:
  90. return supported & (1 << OSIPhone::PortraitDown) ? YES : NO;
  91. case UIInterfaceOrientationPortraitUpsideDown:
  92. return supported & (1 << OSIPhone::PortraitUp) ? YES : NO;
  93. default:
  94. return NO;
  95. }
  96. };
  97. - (BOOL)prefersStatusBarHidden {
  98. return YES;
  99. }
  100. #ifdef GAME_CENTER_ENABLED
  101. - (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController {
  102. //[gameCenterViewController dismissViewControllerAnimated:YES completion:^{GameCenter::get_singleton()->game_center_closed();}];//version for signaling when overlay is completely gone
  103. GameCenter::get_singleton()->game_center_closed();
  104. [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
  105. }
  106. #endif
  107. @end