Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
6.6 KiB

  1. //========== Copyright � 2007, Valve Corporation, All rights reserved. ========
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "pch_tier0.h"
  7. #include "tier0/platwindow.h"
  8. #if defined( PLATFORM_WINDOWS )
  9. #if !defined( PLATFORM_X360 )
  10. #include <windows.h>
  11. #else
  12. #include "xbox/xbox_win32stubs.h"
  13. #endif
  14. #endif
  15. #ifdef PLATFORM_WINDOWS
  16. //-----------------------------------------------------------------------------
  17. // Window creation
  18. //-----------------------------------------------------------------------------
  19. PlatWindow_t Plat_CreateWindow( void *hInstance, const char *pTitle, int nWidth, int nHeight, int nFlags )
  20. {
  21. WNDCLASSEX wc;
  22. memset( &wc, 0, sizeof( wc ) );
  23. wc.cbSize = sizeof( wc );
  24. wc.style = CS_OWNDC | CS_DBLCLKS;
  25. wc.lpfnWndProc = DefWindowProc;
  26. wc.hInstance = (HINSTANCE)hInstance;
  27. wc.lpszClassName = "Valve001";
  28. wc.hIcon = NULL; //LoadIcon( s_HInstance, MAKEINTRESOURCE( IDI_LAUNCHER ) );
  29. wc.hIconSm = wc.hIcon;
  30. RegisterClassEx( &wc );
  31. // Note, it's hidden
  32. DWORD style = WS_POPUP | WS_CLIPSIBLINGS;
  33. style &= ~WS_MAXIMIZEBOX;
  34. if ( ( nFlags & WINDOW_CREATE_FULLSCREEN ) == 0 )
  35. {
  36. // Give it a frame
  37. style |= WS_OVERLAPPEDWINDOW;
  38. if ( nFlags & WINDOW_CREATE_RESIZING )
  39. {
  40. style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
  41. }
  42. else
  43. {
  44. style &= ~WS_THICKFRAME;
  45. }
  46. }
  47. RECT windowRect;
  48. windowRect.top = 0;
  49. windowRect.left = 0;
  50. windowRect.right = nWidth;
  51. windowRect.bottom = nHeight;
  52. // Compute rect needed for that size client area based on window style
  53. AdjustWindowRectEx( &windowRect, style, FALSE, 0 );
  54. // Create the window
  55. void *hWnd = CreateWindow( wc.lpszClassName, pTitle, style, 0, 0,
  56. windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,
  57. NULL, NULL, (HINSTANCE)hInstance, NULL );
  58. return (PlatWindow_t)hWnd;
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Window title
  62. //-----------------------------------------------------------------------------
  63. void Plat_SetWindowTitle( PlatWindow_t hWindow, const char *pTitle )
  64. {
  65. #ifdef PLATFORM_WINDOWS_PC
  66. SetWindowText( (HWND)hWindow, pTitle );
  67. #endif
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Window movement
  71. //-----------------------------------------------------------------------------
  72. void Plat_SetWindowPos( PlatWindow_t hWindow, int x, int y )
  73. {
  74. SetWindowPos( (HWND)hWindow, NULL, x, y, 0, 0,
  75. SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME );
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Gets the desktop resolution
  79. //-----------------------------------------------------------------------------
  80. void Plat_GetDesktopResolution( int *pWidth, int *pHeight )
  81. {
  82. *pWidth = GetSystemMetrics( SM_CXSCREEN );
  83. *pHeight = GetSystemMetrics( SM_CYSCREEN );
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Gets a window size
  87. //-----------------------------------------------------------------------------
  88. void Plat_GetWindowClientSize( PlatWindow_t hWindow, int *pWidth, int *pHeight )
  89. {
  90. RECT rect;
  91. GetClientRect( (HWND)hWindow, &rect );
  92. *pWidth = rect.right - rect.left;
  93. *pHeight = rect.bottom - rect.top;
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Is the window minimized?
  97. //-----------------------------------------------------------------------------
  98. bool Plat_IsWindowMinimized( PlatWindow_t hWindow )
  99. {
  100. return IsIconic( (HWND)hWindow ) != 0;
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Gets the shell window in a console app
  104. //-----------------------------------------------------------------------------
  105. PlatWindow_t Plat_GetShellWindow( )
  106. {
  107. #ifdef PLATFORM_WINDOWS_PC
  108. return (PlatWindow_t)GetShellWindow();
  109. #else
  110. return PLAT_WINDOW_INVALID;
  111. #endif
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Convert window -> Screen coordinates
  115. //-----------------------------------------------------------------------------
  116. void Plat_WindowToScreenCoords( PlatWindow_t hWnd, int &x, int &y )
  117. {
  118. POINT pt;
  119. pt.x = x; pt.y = y;
  120. ClientToScreen( (HWND)hWnd, &pt );
  121. x = pt.x; y = pt.y;
  122. }
  123. void Plat_ScreenToWindowCoords( PlatWindow_t hWnd, int &x, int &y )
  124. {
  125. POINT pt;
  126. pt.x = x; pt.y = y;
  127. ScreenToClient( (HWND)hWnd, &pt );
  128. x = pt.x; y = pt.y;
  129. }
  130. #else
  131. //-----------------------------------------------------------------------------
  132. // Window creation
  133. //-----------------------------------------------------------------------------
  134. PlatWindow_t Plat_CreateWindow( void *hInstance, const char *pTitle, int nWidth, int nHeight, int nFlags )
  135. {
  136. return PLAT_WINDOW_INVALID;
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Window title
  140. //-----------------------------------------------------------------------------
  141. void Plat_SetWindowTitle( PlatWindow_t hWindow, const char *pTitle )
  142. {
  143. }
  144. //-----------------------------------------------------------------------------
  145. // Window movement
  146. //-----------------------------------------------------------------------------
  147. void Plat_SetWindowPos( PlatWindow_t hWindow, int x, int y )
  148. {
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Gets the desktop resolution
  152. //-----------------------------------------------------------------------------
  153. void Plat_GetDesktopResolution( int *pWidth, int *pHeight )
  154. {
  155. *pWidth = 0;
  156. *pHeight = 0;
  157. }
  158. //-----------------------------------------------------------------------------
  159. // Gets a window size
  160. //-----------------------------------------------------------------------------
  161. void Plat_GetWindowClientSize( PlatWindow_t hWindow, int *pWidth, int *pHeight )
  162. {
  163. *pWidth = 0;
  164. *pHeight = 0;
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Is the window minimized?
  168. //-----------------------------------------------------------------------------
  169. bool Plat_IsWindowMinimized( PlatWindow_t hWindow )
  170. {
  171. return false;
  172. }
  173. //-----------------------------------------------------------------------------
  174. // Gets the shell window in a console app
  175. //-----------------------------------------------------------------------------
  176. PlatWindow_t Plat_GetShellWindow( )
  177. {
  178. return PLAT_WINDOW_INVALID;
  179. }
  180. //-----------------------------------------------------------------------------
  181. // Convert window -> Screen coordinates
  182. //-----------------------------------------------------------------------------
  183. void Plat_WindowToScreenCoords( PlatWindow_t hWnd, int &x, int &y )
  184. {
  185. }
  186. void Plat_ScreenToWindowCoords( PlatWindow_t hWnd, int &x, int &y )
  187. {
  188. }
  189. #endif