startSDL.mm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "StdInc.h"
  11. #import "startSDL.h"
  12. #import "GameChatKeyboardHandler.h"
  13. #include "../Global.h"
  14. #include "CMT.h"
  15. #include "CServerHandler.h"
  16. #include "CFocusableHelper.h"
  17. #include <SDL_main.h>
  18. #include <SDL_events.h>
  19. #include <SDL_render.h>
  20. #include <SDL_system.h>
  21. #import <UIKit/UIKit.h>
  22. @interface SDLViewObserver : NSObject <UIGestureRecognizerDelegate>
  23. @property (nonatomic, strong) GameChatKeyboardHandler * gameChatHandler;
  24. @end
  25. @implementation SDLViewObserver
  26. @end
  27. int startSDL(int argc, char * argv[], BOOL startManually)
  28. {
  29. @autoreleasepool {
  30. auto observer = [SDLViewObserver new];
  31. observer.gameChatHandler = [GameChatKeyboardHandler new];
  32. id textFieldObserver = [NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidEndEditingNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
  33. removeFocusFromActiveInput();
  34. }];
  35. int result;
  36. if (startManually)
  37. {
  38. // copied from -[SDLUIKitDelegate postFinishLaunch]
  39. SDL_SetMainReady();
  40. SDL_iOSSetEventPump(SDL_TRUE);
  41. result = SDL_main(argc, argv);
  42. SDL_iOSSetEventPump(SDL_FALSE);
  43. }
  44. else
  45. result = SDL_UIKitRunApp(argc, argv, SDL_main);
  46. [NSNotificationCenter.defaultCenter removeObserver:textFieldObserver];
  47. return result;
  48. }
  49. }