platformWin32.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef _PLATFORMWIN32_H_
  23. #define _PLATFORMWIN32_H_
  24. // Sanity check for UNICODE
  25. #ifdef TORQUE_UNICODE
  26. # ifndef UNICODE
  27. # error "ERROR: You must have UNICODE defined in your preprocessor settings (ie, /DUNICODE) if you have TORQUE_UNICODE enabled in torqueConfig.h!"
  28. # endif
  29. #endif
  30. #include <windows.h>
  31. #ifndef _PLATFORM_H_
  32. #include "platform/platform.h"
  33. #endif
  34. #ifndef _MRECT_H_
  35. #include "math/mRect.h"
  36. #endif
  37. #if defined(TORQUE_COMPILER_CODEWARRIOR)
  38. # include <ansi_prefix.win32.h>
  39. # include <stdio.h>
  40. # include <string.h>
  41. #else
  42. # include <stdio.h>
  43. # include <string.h>
  44. #endif
  45. #ifdef _MSC_VER
  46. #pragma warning(disable: 4996) // turn off "deprecation" warnings
  47. #endif
  48. #define NOMINMAX
  49. // Hack to get a correct HWND instead of using global state.
  50. extern HWND getWin32WindowHandle();
  51. struct Win32PlatState
  52. {
  53. FILE *log_fp;
  54. HINSTANCE hinstOpenGL;
  55. HINSTANCE hinstGLU;
  56. HINSTANCE hinstOpenAL;
  57. HWND appWindow;
  58. HDC appDC;
  59. HINSTANCE appInstance;
  60. HGLRC hGLRC;
  61. DWORD processId;
  62. bool renderThreadBlocked;
  63. S32 nMessagesPerFrame; ///< The max number of messages to dispatch per frame
  64. HMENU appMenu; ///< The menu bar for the window
  65. #ifdef UNICODE
  66. //HIMC imeHandle;
  67. #endif
  68. S32 desktopBitsPixel;
  69. S32 desktopWidth;
  70. S32 desktopHeight;
  71. S32 desktopClientWidth;
  72. S32 desktopClientHeight;
  73. U32 currentTime;
  74. // minimum time per frame
  75. U32 sleepTicks;
  76. // are we in the background?
  77. bool backgrounded;
  78. Win32PlatState();
  79. };
  80. extern Win32PlatState winState;
  81. extern void setModifierKeys( S32 modKeys );
  82. //-------------------------------------- Helper Functions
  83. template< typename T >
  84. inline void forwardslashT( T *str )
  85. {
  86. while(*str)
  87. {
  88. if(*str == '\\')
  89. *str = '/';
  90. str++;
  91. }
  92. }
  93. inline void forwardslash( char* str )
  94. {
  95. forwardslashT< char >( str );
  96. }
  97. inline void forwardslash( WCHAR* str )
  98. {
  99. forwardslashT< WCHAR >( str );
  100. }
  101. template< typename T >
  102. inline void backslashT( T *str )
  103. {
  104. while(*str)
  105. {
  106. if(*str == '/')
  107. *str = '\\';
  108. str++;
  109. }
  110. }
  111. inline void backslash( char* str )
  112. {
  113. backslashT< char >( str );
  114. }
  115. inline void backslash( WCHAR* str )
  116. {
  117. backslashT< WCHAR >( str );
  118. }
  119. #endif //_PLATFORMWIN32_H_