platformInterface.cpp 4.5 KB

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