Torque3D Documentation / _generateds / platformInterface.cpp

platformInterface.cpp

Engine/source/windowManager/platformInterface.cpp

More...

Classes:

Detailed Description

Public Variables

struct ModifierBitMap _ModifierBitMap []
S32 _ModifierBitMapCount 
GFXDevice * gDevice 
PlatformWindow * gWindow 
AutoPtr< PlatformWindowManager > smWindowManager 

Public Functions

convertModifierBits(const U32 in)

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "windowManager/platformWindowMgr.h"
 26#include "gfx/gfxInit.h"
 27#include "gfx/gfxDevice.h"
 28#include "core/util/journal/process.h"
 29#include "core/util/autoPtr.h"
 30
 31// This file converts from the windowmanager system to the old platform and
 32// event interfaces. So it's a bit hackish but hopefully will not be necessary
 33// for very long. Because of the heavy use of globals in the old platform
 34// layer, this layer also has a fair number of globals.
 35
 36
 37// WindowManager
 38//
 39// PlatformWindowManager::get() wrapped in Macro WindowManager
 40static AutoPtr< PlatformWindowManager> smWindowManager;
 41PlatformWindowManager *PlatformWindowManager::get() 
 42{
 43   if( smWindowManager.isNull() )
 44      smWindowManager = CreatePlatformWindowManager();
 45   return smWindowManager.ptr();
 46}
 47
 48void PlatformWindowManager::processCmdLineArgs( const S32 argc, const char **argv )
 49{
 50   // Only call the get() routine if we have arguments on the command line
 51   if(argc > 0)
 52   {
 53      PlatformWindowManager::get()->_processCmdLineArgs(argc, argv);
 54   }
 55}
 56
 57
 58GFXDevice *gDevice          = NULL;
 59PlatformWindow *gWindow     = NULL;
 60
 61// Conversion from window manager input conventions to Torque standard.
 62static struct ModifierBitMap {
 63   U32 grendelMask,torqueMask;
 64} _ModifierBitMap[] = {
 65   { IM_LSHIFT, SI_LSHIFT   },
 66   { IM_RSHIFT, SI_RSHIFT   },
 67   { IM_LALT,   SI_LALT     },
 68   { IM_RALT,   SI_RALT     },
 69   { IM_LCTRL,  SI_LCTRL    },
 70   { IM_RCTRL,  SI_RCTRL    },
 71   { IM_LOPT,   SI_MAC_LOPT },
 72   { IM_ROPT,   SI_MAC_ROPT },
 73};
 74static S32 _ModifierBitMapCount = sizeof(_ModifierBitMap) / sizeof(ModifierBitMap);
 75
 76InputModifiers convertModifierBits(const U32 in)
 77{
 78   U32 out=0;
 79
 80   for(S32 i=0; i<_ModifierBitMapCount; i++)
 81      if(in & _ModifierBitMap[i].grendelMask)
 82         out |= _ModifierBitMap[i].torqueMask;
 83
 84   return (InputModifiers)out;
 85}
 86
 87//------------------------------------------------------------------------------
 88
 89void Platform::setWindowSize(U32 newWidth, U32 newHeight, bool fullScreen )
 90{
 91   AssertISV(gWindow, "Platform::setWindowSize - no window present!");
 92
 93   // Grab the curent video settings and diddle them with the new values.
 94   GFXVideoMode vm = gWindow->getVideoMode();
 95   vm.resolution.set(newWidth, newHeight);
 96   vm.fullScreen = fullScreen;
 97   gWindow->setVideoMode(vm);
 98}
 99
100void Platform::setWindowLocked(bool locked)
101{
102   PlatformWindow* window = WindowManager->getFirstWindow();
103   if( window )
104      window->setMouseLocked( locked );
105}
106
107void Platform::minimizeWindow()
108{
109   // requires PlatformWindow API extension...
110   if(gWindow)
111      gWindow->minimize();
112}
113
114void Platform::closeWindow()
115{
116   // Shutdown all our stuff.
117   //SAFE_DELETE(gDevice); // <-- device is already cleaned up elsewhere by now...
118   SAFE_DELETE(gWindow);
119}
120
121//------------------------------------------------------------------------------
122
123
124
125#ifdef TORQUE_OS_WIN
126// Hack so we can get the HWND of the global window more easily - replacement
127// for the HWND that was in the platstate.
128#include "windowManager/win32/win32Window.h"
129
130HWND getWin32WindowHandle()
131{
132   PlatformWindow* window = WindowManager->getFocusedWindow();
133   if( !window )
134   {
135      window = WindowManager->getFirstWindow();
136      if( !window )
137         return NULL;
138   }
139
140   return (HWND)window->getSystemWindow( PlatformWindow::WindowSystem_Windows );
141}
142
143#endif
144