view_controller.mm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*************************************************************************/
  2. /* view_controller.mm */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #import "view_controller.h"
  30. #include "os_iphone.h"
  31. extern "C" {
  32. int add_path(int p_argc, char** p_args) {
  33. NSString* str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"];
  34. if (!str)
  35. return p_argc;
  36. p_args[p_argc++] = "-path";
  37. [str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo
  38. p_args[p_argc++] = (char*)[str cString];
  39. p_args[p_argc] = NULL;
  40. return p_argc;
  41. };
  42. int add_cmdline(int p_argc, char** p_args) {
  43. NSArray* arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_cmdline"];
  44. if (!arr)
  45. return p_argc;
  46. for (int i=0; i < [arr count]; i++) {
  47. NSString* str = [arr objectAtIndex:i];
  48. if (!str)
  49. continue;
  50. [str retain]; // @todo delete these at some point
  51. p_args[p_argc++] = (char*)[str cString];
  52. };
  53. p_args[p_argc] = NULL;
  54. return p_argc;
  55. };
  56. };
  57. @interface ViewController ()
  58. @end
  59. @implementation ViewController
  60. - (void)didReceiveMemoryWarning {
  61. printf("*********** did receive memory warning!\n");
  62. };
  63. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)p_orientation {
  64. if (/*OSIPhone::get_singleton() == NULL*/TRUE) {
  65. printf("checking on info.plist\n");
  66. NSArray* arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
  67. switch(p_orientation) {
  68. case UIInterfaceOrientationLandscapeLeft:
  69. return [arr indexOfObject:@"UIInterfaceOrientationLandscapeLeft"] != NSNotFound ? YES : NO;
  70. case UIInterfaceOrientationLandscapeRight:
  71. return [arr indexOfObject:@"UIInterfaceOrientationLandscapeRight"] != NSNotFound ? YES : NO;
  72. case UIInterfaceOrientationPortrait:
  73. return [arr indexOfObject:@"UIInterfaceOrientationPortrait"] != NSNotFound ? YES : NO;
  74. case UIInterfaceOrientationPortraitUpsideDown:
  75. return [arr indexOfObject:@"UIInterfaceOrientationPortraitUpsideDown"] != NSNotFound ? YES : NO;
  76. default:
  77. return NO;
  78. }
  79. };
  80. uint8_t supported = OSIPhone::get_singleton()->get_orientations();
  81. switch(p_orientation) {
  82. case UIInterfaceOrientationLandscapeLeft:
  83. return supported & (1<<OSIPhone::LandscapeLeft) ? YES : NO;
  84. case UIInterfaceOrientationLandscapeRight:
  85. return supported & (1<<OSIPhone::LandscapeRight) ? YES : NO;
  86. case UIInterfaceOrientationPortrait:
  87. return supported & (1<<OSIPhone::PortraitDown) ? YES : NO;
  88. case UIInterfaceOrientationPortraitUpsideDown:
  89. return supported & (1<<OSIPhone::PortraitUp) ? YES : NO;
  90. default:
  91. return NO;
  92. }
  93. };
  94. - (BOOL)prefersStatusBarHidden
  95. {
  96. return YES;
  97. }
  98. @end