platformInterface.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "platform/platform.h"
  23. #include "windowManager/platformWindowMgr.h"
  24. #include "gfx/gfxInit.h"
  25. #include "gfx/gfxDevice.h"
  26. #include "core/util/journal/process.h"
  27. #include "core/util/autoPtr.h"
  28. // This file converts from the windowmanager system to the old platform and
  29. // event interfaces. So it's a bit hackish but hopefully will not be necessary
  30. // for very long. Because of the heavy use of globals in the old platform
  31. // layer, this layer also has a fair number of globals.
  32. // WindowManager
  33. //
  34. // PlatformWindowManager::get() wrapped in Macro WindowManager
  35. static AutoPtr< PlatformWindowManager > smWindowManager;
  36. PlatformWindowManager *PlatformWindowManager::get()
  37. {
  38. if( smWindowManager.isNull() )
  39. smWindowManager = CreatePlatformWindowManager();
  40. return smWindowManager.ptr();
  41. }
  42. void PlatformWindowManager::processCmdLineArgs( const S32 argc, const char **argv )
  43. {
  44. // Only call the get() routine if we have arguments on the command line
  45. if(argc > 0)
  46. {
  47. PlatformWindowManager::get()->_processCmdLineArgs(argc, argv);
  48. }
  49. }
  50. GFXDevice *gDevice = NULL;
  51. PlatformWindow *gWindow = NULL;
  52. // Conversion from window manager input conventions to Torque standard.
  53. static struct ModifierBitMap {
  54. U32 grendelMask,torqueMask;
  55. } _ModifierBitMap[] = {
  56. { IM_LSHIFT, SI_LSHIFT },
  57. { IM_RSHIFT, SI_RSHIFT },
  58. { IM_LALT, SI_LALT },
  59. { IM_RALT, SI_RALT },
  60. { IM_LCTRL, SI_LCTRL },
  61. { IM_RCTRL, SI_RCTRL },
  62. { IM_LOPT, SI_MAC_LOPT },
  63. { IM_ROPT, SI_MAC_ROPT },
  64. };
  65. static S32 _ModifierBitMapCount = sizeof(_ModifierBitMap) / sizeof(ModifierBitMap);
  66. InputModifiers convertModifierBits(const U32 in)
  67. {
  68. U32 out=0;
  69. for(S32 i=0; i<_ModifierBitMapCount; i++)
  70. if(in & _ModifierBitMap[i].grendelMask)
  71. out |= _ModifierBitMap[i].torqueMask;
  72. return (InputModifiers)out;
  73. }
  74. //------------------------------------------------------------------------------
  75. void Platform::setWindowSize(U32 newWidth, U32 newHeight, bool fullScreen )
  76. {
  77. AssertISV(gWindow, "Platform::setWindowSize - no window present!");
  78. // Grab the curent video settings and diddle them with the new values.
  79. GFXVideoMode vm = gWindow->getVideoMode();
  80. vm.resolution.set(newWidth, newHeight);
  81. vm.fullScreen = fullScreen;
  82. gWindow->setVideoMode(vm);
  83. }
  84. void Platform::setWindowLocked(bool locked)
  85. {
  86. PlatformWindow* window = WindowManager->getFirstWindow();
  87. if( window )
  88. window->setMouseLocked( locked );
  89. }
  90. void Platform::minimizeWindow()
  91. {
  92. // requires PlatformWindow API extension...
  93. if(gWindow)
  94. gWindow->minimize();
  95. }
  96. void Platform::closeWindow()
  97. {
  98. // Shutdown all our stuff.
  99. //SAFE_DELETE(gDevice); // <-- device is already cleaned up elsewhere by now...
  100. SAFE_DELETE(gWindow);
  101. }
  102. //------------------------------------------------------------------------------
  103. #ifdef TORQUE_OS_WIN
  104. // Hack so we can get the HWND of the global window more easily - replacement
  105. // for the HWND that was in the platstate.
  106. #include "windowManager/win32/win32Window.h"
  107. HWND getWin32WindowHandle()
  108. {
  109. PlatformWindow* window = WindowManager->getFocusedWindow();
  110. if( !window )
  111. {
  112. window = WindowManager->getFirstWindow();
  113. if( !window )
  114. return NULL;
  115. }
  116. return (HWND)window->getSystemWindow( PlatformWindow::WindowSystem_Windows );
  117. }
  118. #endif