sdlWindowMgr.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "windowManager/sdl/sdlWindowMgr.h"
  23. #include "platformSDL/sdlInputManager.h"
  24. #include "platform/platformVolume.h"
  25. #include "core/util/path.h"
  26. #include "gfx/gfxDevice.h"
  27. #include "core/util/journal/process.h"
  28. #include "core/strings/unicode.h"
  29. #include "gfx/bitmap/gBitmap.h"
  30. #include "SDL.h"
  31. // ------------------------------------------------------------------------
  32. void sdl_CloseSplashWindow(void* hinst);
  33. #ifdef TORQUE_SDL
  34. #ifdef TORQUE_SECURE_VFS
  35. PlatformWindowManagerSDL::DragAndDropFSInfo::DragAndDropFSInfo()
  36. {
  37. }
  38. PlatformWindowManagerSDL::DragAndDropFSInfo::DragAndDropFSInfo(String rootName, Torque::FS::FileSystemRef fileSystem) : mRootName(rootName), mDragAndDropFS(fileSystem)
  39. {
  40. if (!Torque::FS::Mount(rootName, fileSystem))
  41. {
  42. Con::errorf("Could not mount drag and drop FS!");
  43. }
  44. }
  45. PlatformWindowManagerSDL::DragAndDropFSInfo::~DragAndDropFSInfo()
  46. {
  47. // FIXME: Cleanup - we can't simply do this unmount due to the way the hash mapping works
  48. // Torque::FS::Unmount(mDragAndDropFS);
  49. }
  50. #endif
  51. PlatformWindowManager * CreatePlatformWindowManager()
  52. {
  53. return new PlatformWindowManagerSDL();
  54. }
  55. #endif
  56. // ------------------------------------------------------------------------
  57. PlatformWindowManagerSDL::PlatformWindowManagerSDL()
  58. {
  59. // Register in the process list.
  60. mOnProcessSignalSlot.setDelegate( this, &PlatformWindowManagerSDL::_process );
  61. Process::notify( mOnProcessSignalSlot, PROCESS_INPUT_ORDER );
  62. // Init our list of allocated windows.
  63. mWindowListHead = NULL;
  64. // By default, we have no parent window.
  65. mParentWindow = NULL;
  66. mCurtainWindow = NULL;
  67. mDisplayWindow = true;
  68. mOffscreenRender = false;
  69. mInputState = KeyboardInputState::NONE;
  70. }
  71. PlatformWindowManagerSDL::~PlatformWindowManagerSDL()
  72. {
  73. // Kill all our windows first.
  74. while(mWindowListHead)
  75. // The destructors update the list, so this works just fine.
  76. delete mWindowListHead;
  77. }
  78. RectI PlatformWindowManagerSDL::getPrimaryDesktopArea()
  79. {
  80. // Primary is monitor 0
  81. return getMonitorRect(0);
  82. }
  83. Point2I PlatformWindowManagerSDL::getDesktopResolution()
  84. {
  85. SDL_DisplayMode mode;
  86. SDL_GetDesktopDisplayMode(0, &mode);
  87. // Return Resolution
  88. return Point2I(mode.w, mode.h);
  89. }
  90. S32 PlatformWindowManagerSDL::getDesktopBitDepth()
  91. {
  92. // Return Bits per Pixel
  93. SDL_DisplayMode mode;
  94. SDL_GetDesktopDisplayMode(0, &mode);
  95. int bbp;
  96. unsigned int r,g,b,a;
  97. SDL_PixelFormatEnumToMasks(mode.format, &bbp, &r, &g, &b, &a);
  98. return bbp;
  99. }
  100. S32 PlatformWindowManagerSDL::findFirstMatchingMonitor(const char* name)
  101. {
  102. S32 count = SDL_GetNumVideoDisplays();
  103. for (U32 index = 0; index < count; ++index)
  104. {
  105. if (dStrstr(name, SDL_GetDisplayName(index)) == name)
  106. return index;
  107. }
  108. return 0;
  109. }
  110. U32 PlatformWindowManagerSDL::getMonitorCount()
  111. {
  112. S32 monitorCount = SDL_GetNumVideoDisplays();
  113. if (monitorCount < 0)
  114. {
  115. Con::errorf("SDL_GetNumVideoDisplays() failed: %s", SDL_GetError());
  116. monitorCount = 0;
  117. }
  118. return (U32)monitorCount;
  119. }
  120. const char* PlatformWindowManagerSDL::getMonitorName(U32 index)
  121. {
  122. const char* monitorName = SDL_GetDisplayName(index);
  123. if (monitorName == NULL)
  124. Con::errorf("SDL_GetDisplayName() failed: %s", SDL_GetError());
  125. return monitorName;
  126. }
  127. RectI PlatformWindowManagerSDL::getMonitorRect(U32 index)
  128. {
  129. SDL_Rect sdlRect;
  130. if (0 != SDL_GetDisplayBounds(index, &sdlRect))
  131. {
  132. Con::errorf("SDL_GetDisplayBounds() failed: %s", SDL_GetError());
  133. return RectI(0, 0, 0, 0);
  134. }
  135. return RectI(sdlRect.x, sdlRect.y, sdlRect.w, sdlRect.h);
  136. }
  137. RectI PlatformWindowManagerSDL::getMonitorUsableRect(U32 index)
  138. {
  139. SDL_Rect sdlRect;
  140. if (0 != SDL_GetDisplayUsableBounds(index, &sdlRect))
  141. {
  142. Con::errorf("SDL_GetDisplayUsableBounds() failed: %s", SDL_GetError());
  143. return RectI(0, 0, 0, 0);
  144. }
  145. return RectI(sdlRect.x, sdlRect.y, sdlRect.w, sdlRect.h);
  146. }
  147. U32 PlatformWindowManagerSDL::getMonitorModeCount(U32 monitorIndex)
  148. {
  149. S32 modeCount = SDL_GetNumDisplayModes(monitorIndex);
  150. if (modeCount < 0)
  151. {
  152. Con::errorf("SDL_GetNumDisplayModes(%d) failed: %s", monitorIndex, SDL_GetError());
  153. modeCount = 0;
  154. }
  155. return (U32)modeCount;
  156. }
  157. const String PlatformWindowManagerSDL::getMonitorMode(U32 monitorIndex, U32 modeIndex)
  158. {
  159. SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
  160. if (SDL_GetDisplayMode(monitorIndex, modeIndex, &mode) != 0)
  161. {
  162. Con::errorf("SDL_GetDisplayMode(%d, %d) failed: %s", monitorIndex, modeIndex, SDL_GetError());
  163. return String::EmptyString;
  164. }
  165. GFXVideoMode vm;
  166. vm.resolution.set(mode.w, mode.h);
  167. vm.refreshRate = mode.refresh_rate;
  168. vm.bitDepth = 32;
  169. vm.antialiasLevel = 0;
  170. vm.fullScreen = false;
  171. vm.wideScreen = false;
  172. return vm.toString();
  173. }
  174. const String PlatformWindowManagerSDL::getMonitorDesktopMode(U32 monitorIndex)
  175. {
  176. SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
  177. if (SDL_GetDesktopDisplayMode(monitorIndex, &mode) != 0)
  178. {
  179. Con::errorf("SDL_GetDesktopDisplayMode(%d) failed: %s", monitorIndex, SDL_GetError());
  180. return String::EmptyString;
  181. }
  182. GFXVideoMode vm;
  183. vm.resolution.set(mode.w, mode.h);
  184. vm.refreshRate = mode.refresh_rate;
  185. int bbp;
  186. unsigned int r, g, b, a;
  187. SDL_PixelFormatEnumToMasks(mode.format, &bbp, &r, &g, &b, &a);
  188. vm.bitDepth = bbp;
  189. vm.antialiasLevel = 0;
  190. vm.fullScreen = false;
  191. vm.wideScreen = ((mode.w / 16) * 9) == mode.h;
  192. return vm.toString();
  193. }
  194. void PlatformWindowManagerSDL::getMonitorRegions(Vector<RectI> &regions)
  195. {
  196. SDL_Rect sdlRect;
  197. S32 monitorCount = SDL_GetNumVideoDisplays();
  198. for (S32 index = 0; index < monitorCount; ++index)
  199. {
  200. if (0 == SDL_GetDisplayBounds(index, &sdlRect))
  201. regions.push_back(RectI(sdlRect.x, sdlRect.y, sdlRect.w, sdlRect.h));
  202. }
  203. }
  204. void PlatformWindowManagerSDL::getWindows(VectorPtr<PlatformWindow*> &windows)
  205. {
  206. PlatformWindowSDL *win = mWindowListHead;
  207. while(win)
  208. {
  209. windows.push_back(win);
  210. win = win->mNextWindow;
  211. }
  212. }
  213. PlatformWindow *PlatformWindowManagerSDL::createWindow(GFXDevice *device, const GFXVideoMode &mode)
  214. {
  215. // Do the allocation.
  216. PlatformWindowSDL *window = new PlatformWindowSDL();
  217. U32 windowFlags = /*SDL_WINDOW_SHOWN |*/ SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
  218. if(GFX->getAdapterType() == OpenGL)
  219. windowFlags |= SDL_WINDOW_OPENGL;
  220. window->mWindowHandle = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mode.resolution.x, mode.resolution.y, windowFlags );
  221. window->mWindowId = SDL_GetWindowID( window->mWindowHandle );
  222. window->mOwningManager = this;
  223. mWindowMap[ window->mWindowId ] = window;
  224. //Now, fetch our window icon, if any
  225. Torque::Path iconPath = Torque::Path(Con::getVariable( "$Core::windowIcon" ));
  226. if (iconPath.getExtension() == String("bmp"))
  227. {
  228. Con::errorf("Unable to use bmp format images for the window icon. Please use a different format.");
  229. }
  230. else
  231. {
  232. Resource<GBitmap> img = GBitmap::load(iconPath);
  233. if (img != NULL)
  234. {
  235. U32 pitch;
  236. U32 width = img->getWidth();
  237. bool hasAlpha = img->getHasTransparency();
  238. U32 depth;
  239. if (hasAlpha)
  240. {
  241. pitch = 4 * width;
  242. depth = 32;
  243. }
  244. else
  245. {
  246. pitch = 3 * width;
  247. depth = 24;
  248. }
  249. Uint32 rmask, gmask, bmask, amask;
  250. if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
  251. {
  252. S32 shift = hasAlpha ? 8 : 0;
  253. rmask = 0xff000000 >> shift;
  254. gmask = 0x00ff0000 >> shift;
  255. bmask = 0x0000ff00 >> shift;
  256. amask = 0x000000ff >> shift;
  257. }
  258. else
  259. {
  260. rmask = 0x000000ff;
  261. gmask = 0x0000ff00;
  262. bmask = 0x00ff0000;
  263. amask = hasAlpha ? 0xff000000 : 0;
  264. }
  265. SDL_Surface* iconSurface = SDL_CreateRGBSurfaceFrom(img->getAddress(0, 0), img->getWidth(), img->getHeight(), depth, pitch, rmask, gmask, bmask, amask);
  266. SDL_SetWindowIcon(window->mWindowHandle, iconSurface);
  267. SDL_FreeSurface(iconSurface);
  268. }
  269. }
  270. if(device)
  271. {
  272. window->mDevice = device;
  273. window->mTarget = device->allocWindowTarget(window);
  274. AssertISV(window->mTarget, "PlatformWindowManagerSDL::createWindow - failed to get a window target back from the device.");
  275. }
  276. else
  277. {
  278. Con::warnf("PlatformWindowManagerSDL::createWindow - created a window with no device!");
  279. }
  280. //Set it up for drag-n-drop events
  281. #ifdef TORQUE_TOOLS
  282. SDL_EventState(SDL_DROPBEGIN, SDL_ENABLE);
  283. SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
  284. SDL_EventState(SDL_DROPCOMPLETE, SDL_ENABLE);
  285. #endif
  286. linkWindow(window);
  287. SDL_SetWindowMinimumSize(window->mWindowHandle, Con::getIntVariable("$Video::minimumXResolution", 1024),
  288. Con::getIntVariable("$Video::minimumYResolution", 720));
  289. return window;
  290. }
  291. void PlatformWindowManagerSDL::setParentWindow(void* newParent)
  292. {
  293. }
  294. void* PlatformWindowManagerSDL::getParentWindow()
  295. {
  296. return NULL;
  297. }
  298. void PlatformWindowManagerSDL::_process()
  299. {
  300. SDL_Event evt;
  301. while( SDL_PollEvent(&evt) )
  302. {
  303. if (evt.type >= SDL_JOYAXISMOTION && evt.type <= SDL_CONTROLLERDEVICEREMAPPED)
  304. {
  305. SDLInputManager* mgr = static_cast<SDLInputManager*>(Input::getManager());
  306. if (mgr)
  307. mgr->processEvent(evt);
  308. continue;
  309. }
  310. switch(evt.type)
  311. {
  312. case SDL_QUIT:
  313. {
  314. PlatformWindowSDL *window = static_cast<PlatformWindowSDL*>( getFirstWindow() );
  315. if(window)
  316. window->appEvent.trigger( window->getWindowId(), WindowClose );
  317. break;
  318. }
  319. case SDL_KEYDOWN:
  320. case SDL_KEYUP:
  321. {
  322. PlatformWindowSDL *window = mWindowMap[evt.key.windowID];
  323. if(window)
  324. window->_processSDLEvent(evt);
  325. break;
  326. }
  327. case SDL_MOUSEWHEEL:
  328. {
  329. PlatformWindowSDL *window = mWindowMap[evt.wheel.windowID];
  330. if (window)
  331. window->_processSDLEvent(evt);
  332. break;
  333. }
  334. case SDL_MOUSEMOTION:
  335. {
  336. PlatformWindowSDL *window = mWindowMap[evt.motion.windowID];
  337. if(window)
  338. window->_processSDLEvent(evt);
  339. break;
  340. }
  341. case SDL_MOUSEBUTTONDOWN:
  342. case SDL_MOUSEBUTTONUP:
  343. {
  344. PlatformWindowSDL *window = mWindowMap[evt.button.windowID];
  345. if(window)
  346. window->_processSDLEvent(evt);
  347. break;
  348. }
  349. case SDL_TEXTINPUT:
  350. {
  351. PlatformWindowSDL *window = mWindowMap[evt.text.windowID];
  352. if(window)
  353. window->_processSDLEvent(evt);
  354. break;
  355. }
  356. case SDL_WINDOWEVENT:
  357. {
  358. PlatformWindowSDL *window = mWindowMap[evt.window.windowID];
  359. if(window)
  360. window->_processSDLEvent(evt);
  361. break;
  362. }
  363. case(SDL_DROPBEGIN):
  364. {
  365. if (!Con::isFunction("onDropBegin"))
  366. break;
  367. Con::executef("onDropBegin");
  368. }
  369. case (SDL_DROPFILE):
  370. {
  371. // In case if dropped file
  372. if (!Con::isFunction("onDropFile"))
  373. break;
  374. char* fileName = evt.drop.file;
  375. if (!Platform::isDirectory(fileName) && !Platform::isFile(fileName))
  376. break;
  377. #ifdef TORQUE_SECURE_VFS
  378. // Determine what the directory is so we can mount it
  379. Torque::Path targetDirectory = Torque::Path(fileName);
  380. // If we're dropping a file, strip off file information - otherwise if a directory mount it directly
  381. if (Platform::isFile(fileName))
  382. {
  383. targetDirectory.setExtension("");
  384. targetDirectory.setFileName("");
  385. }
  386. const String directoryName = targetDirectory.getDirectory(targetDirectory.getDirectoryCount() - 1);
  387. auto dropFSMount = mActiveDragAndDropFSByPath.find(targetDirectory);
  388. if (dropFSMount == mActiveDragAndDropFSByPath.end())
  389. {
  390. Torque::FS::FileSystemRef newMount = Platform::FS::createNativeFS(targetDirectory.getFullPath());
  391. // Search for an unused root in case we have duplicate names
  392. U32 rootCounter = 1;
  393. String chosenRootName = directoryName;
  394. auto search = mActiveDragAndDropByRoot.find(chosenRootName);
  395. while (search != mActiveDragAndDropByRoot.end())
  396. {
  397. char buffer[32];
  398. dSprintf(buffer, 32, "%u", rootCounter);
  399. chosenRootName = directoryName + buffer;
  400. search = mActiveDragAndDropByRoot.find(chosenRootName);
  401. }
  402. mActiveDragAndDropFSByPath[targetDirectory] = DragAndDropFSInfo(directoryName, newMount);
  403. mActiveDragAndDropFSByPath[chosenRootName] = mActiveDragAndDropFSByPath[targetDirectory];
  404. }
  405. DragAndDropFSInfo& filesystemInformation = mActiveDragAndDropFSByPath[targetDirectory];
  406. // Load source file information
  407. Torque::Path sourceFile = fileName;
  408. // Build a reference to the file in VFS
  409. Torque::Path targetFile;
  410. targetFile.setRoot(filesystemInformation.mRootName);
  411. targetFile.setPath("/");
  412. // Only copy file & extension information if we're dropping a file
  413. if (Platform::isFile(fileName))
  414. {
  415. targetFile.setFileName(sourceFile.getFileName());
  416. targetFile.setExtension(sourceFile.getExtension());
  417. }
  418. Con::executef("onDropFile", StringTable->insert(targetFile.getFullPath()));
  419. #else
  420. Con::executef("onDropFile", StringTable->insert(fileName));
  421. #endif
  422. SDL_free(fileName); // Free dropped_filedir memory
  423. break;
  424. }
  425. case(SDL_DROPCOMPLETE):
  426. {
  427. if (Con::isFunction("onDropEnd"))
  428. Con::executef("onDropEnd");
  429. break;
  430. }
  431. default:
  432. {
  433. #ifdef TORQUE_DEBUG
  434. Con::warnf("Unhandled SDL input event: 0x%04x", evt.type);
  435. #endif
  436. }
  437. }
  438. }
  439. // After the event loop is processed, we can now see if we have to notify
  440. // SDL that we want text based events. This fixes a bug where text based
  441. // events would be generated while key presses would still be happening.
  442. // See KeyboardInputState for further documentation.
  443. if (mInputState != KeyboardInputState::NONE)
  444. {
  445. // Update text mode toggling.
  446. if (mInputState == KeyboardInputState::TEXT_INPUT)
  447. SDL_StartTextInput();
  448. else
  449. SDL_StopTextInput();
  450. // Done until we need to update it again.
  451. mInputState = KeyboardInputState::NONE;
  452. }
  453. }
  454. PlatformWindow * PlatformWindowManagerSDL::getWindowById( WindowId id )
  455. {
  456. // Walk the list and find the matching id, if any.
  457. PlatformWindowSDL *win = mWindowListHead;
  458. while(win)
  459. {
  460. if(win->getWindowId() == id)
  461. return win;
  462. win = win->mNextWindow;
  463. }
  464. return NULL;
  465. }
  466. PlatformWindow * PlatformWindowManagerSDL::getFirstWindow()
  467. {
  468. return mWindowListHead != NULL ? mWindowListHead : NULL;
  469. }
  470. PlatformWindow* PlatformWindowManagerSDL::getFocusedWindow()
  471. {
  472. PlatformWindowSDL* window = mWindowListHead;
  473. while( window )
  474. {
  475. if( window->isFocused() )
  476. return window;
  477. window = window->mNextWindow;
  478. }
  479. return NULL;
  480. }
  481. void PlatformWindowManagerSDL::linkWindow( PlatformWindowSDL *w )
  482. {
  483. w->mNextWindow = mWindowListHead;
  484. mWindowListHead = w;
  485. }
  486. void PlatformWindowManagerSDL::unlinkWindow( PlatformWindowSDL *w )
  487. {
  488. PlatformWindowSDL **walk = &mWindowListHead;
  489. while(*walk)
  490. {
  491. if(*walk != w)
  492. {
  493. // Advance to next item in list.
  494. walk = &(*walk)->mNextWindow;
  495. continue;
  496. }
  497. // Got a match - unlink and return.
  498. *walk = (*walk)->mNextWindow;
  499. return;
  500. }
  501. }
  502. void PlatformWindowManagerSDL::_processCmdLineArgs( const S32 argc, const char **argv )
  503. {
  504. // TODO SDL
  505. }
  506. void PlatformWindowManagerSDL::lowerCurtain()
  507. {
  508. if(mCurtainWindow)
  509. return;
  510. // TODO SDL
  511. }
  512. void PlatformWindowManagerSDL::raiseCurtain()
  513. {
  514. if(!mCurtainWindow)
  515. return;
  516. // TODO SDL
  517. }
  518. void PlatformWindowManagerSDL::updateSDLTextInputState(KeyboardInputState state)
  519. {
  520. // Force update state. This will respond at the end of the event loop.
  521. mInputState = state;
  522. }
  523. void Platform::openFolder(const char* path )
  524. {
  525. AssertFatal(0, "Not Implemented");
  526. }
  527. void Platform::openFile(const char* path )
  528. {
  529. AssertFatal(0, "Not Implemented");
  530. }
  531. //------------------------------------------------------------------------------
  532. namespace GL
  533. {
  534. void gglPerformBinds();
  535. }
  536. void InitWindowingSystem()
  537. {
  538. }
  539. AFTER_MODULE_INIT(gfx)
  540. {
  541. #if !defined(TORQUE_DEDICATED)
  542. int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE);
  543. AssertFatal(res != -1, avar("SDL error:%s", SDL_GetError()));
  544. // By default, SDL enables text input. We disable it on initialization, and
  545. // we will enable it whenever the time is right.
  546. SDL_StopTextInput();
  547. #endif
  548. }