startSDL.mm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * startSDL.mm, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #import "startSDL.h"
  11. #import "GameChatKeyboardHandler.h"
  12. #include "../Global.h"
  13. #include "CMT.h"
  14. #include "CServerHandler.h"
  15. #include "CFocusableHelper.h"
  16. #include <SDL_main.h>
  17. #include <SDL_events.h>
  18. #include <SDL_render.h>
  19. #include <SDL_system.h>
  20. #import <UIKit/UIKit.h>
  21. @interface SDLViewObserver : NSObject <UIGestureRecognizerDelegate>
  22. @property (nonatomic, strong) GameChatKeyboardHandler * gameChatHandler;
  23. @end
  24. @implementation SDLViewObserver
  25. @end
  26. int startSDL(int argc, char * argv[], BOOL startManually)
  27. {
  28. @autoreleasepool {
  29. auto observer = [SDLViewObserver new];
  30. observer.gameChatHandler = [GameChatKeyboardHandler new];
  31. id textFieldObserver = [NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidEndEditingNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
  32. removeFocusFromActiveInput();
  33. }];
  34. int result;
  35. if (startManually)
  36. {
  37. // copied from -[SDLUIKitDelegate postFinishLaunch]
  38. SDL_SetMainReady();
  39. SDL_iOSSetEventPump(SDL_TRUE);
  40. result = SDL_main(argc, argv);
  41. SDL_iOSSetEventPump(SDL_FALSE);
  42. }
  43. else
  44. result = SDL_UIKitRunApp(argc, argv, SDL_main);
  45. [NSNotificationCenter.defaultCenter removeObserver:textFieldObserver];
  46. return result;
  47. }
  48. }