WIN_Z.CPP 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // win_cam.c -- windows specific camera view code
  19. #include "stdafx.h"
  20. #include "qe3.h"
  21. static HDC s_hdcZ;
  22. static HGLRC s_hglrcZ;
  23. /*
  24. ============
  25. WZ_WndProc
  26. ============
  27. */
  28. LONG WINAPI WZ_WndProc (
  29. HWND hWnd,
  30. UINT uMsg,
  31. WPARAM wParam,
  32. LPARAM lParam)
  33. {
  34. int fwKeys, xPos, yPos;
  35. RECT rect;
  36. GetClientRect(hWnd, &rect);
  37. switch (uMsg)
  38. {
  39. case WM_DESTROY:
  40. QEW_StopGL( hWnd, s_hglrcZ, s_hdcZ );
  41. return 0;
  42. case WM_CREATE:
  43. s_hdcZ = GetDC(hWnd);
  44. QEW_SetupPixelFormat( s_hdcZ, false);
  45. if ( ( s_hglrcZ = wglCreateContext( s_hdcZ ) ) == 0 )
  46. Error( "wglCreateContext in WZ_WndProc failed" );
  47. if (!wglMakeCurrent( s_hdcZ, s_hglrcZ ))
  48. Error ("wglMakeCurrent in WZ_WndProc failed");
  49. if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcZ ) )
  50. Error( "wglShareLists in WZ_WndProc failed" );
  51. return 0;
  52. case WM_PAINT:
  53. {
  54. PAINTSTRUCT ps;
  55. BeginPaint(hWnd, &ps);
  56. if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) )
  57. Error ("wglMakeCurrent failed");
  58. QE_CheckOpenGLForErrors();
  59. Z_Draw ();
  60. SwapBuffers(s_hdcZ);
  61. EndPaint(hWnd, &ps);
  62. }
  63. return 0;
  64. case WM_KEYDOWN:
  65. QE_KeyDown (wParam);
  66. return 0;
  67. case WM_MBUTTONDOWN:
  68. case WM_RBUTTONDOWN:
  69. case WM_LBUTTONDOWN:
  70. if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
  71. BringWindowToTop(hWnd);
  72. SetFocus( g_qeglobals.d_hwndZ );
  73. SetCapture( g_qeglobals.d_hwndZ );
  74. fwKeys = wParam; // key flags
  75. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  76. yPos = (short)HIWORD(lParam); // vertical position of cursor
  77. yPos = (int)rect.bottom - 1 - yPos;
  78. Z_MouseDown (xPos, yPos, fwKeys);
  79. return 0;
  80. case WM_MBUTTONUP:
  81. case WM_RBUTTONUP:
  82. case WM_LBUTTONUP:
  83. fwKeys = wParam; // key flags
  84. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  85. yPos = (short)HIWORD(lParam); // vertical position of cursor
  86. yPos = (int)rect.bottom - 1 - yPos;
  87. Z_MouseUp (xPos, yPos, fwKeys);
  88. if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  89. ReleaseCapture ();
  90. return 0;
  91. case WM_GETMINMAXINFO:
  92. {
  93. MINMAXINFO *pmmi = (LPMINMAXINFO) lParam;
  94. pmmi->ptMinTrackSize.x = ZWIN_WIDTH;
  95. return 0;
  96. }
  97. case WM_MOUSEMOVE:
  98. fwKeys = wParam; // key flags
  99. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  100. yPos = (short)HIWORD(lParam); // vertical position of cursor
  101. yPos = (int)rect.bottom - 1 - yPos;
  102. Z_MouseMoved (xPos, yPos, fwKeys);
  103. return 0;
  104. case WM_SIZE:
  105. z.width = rect.right;
  106. z.height = rect.bottom;
  107. InvalidateRect( g_qeglobals.d_hwndZ, NULL, false);
  108. return 0;
  109. case WM_NCCALCSIZE:// don't let windows copy pixels
  110. DefWindowProc (hWnd, uMsg, wParam, lParam);
  111. return WVR_REDRAW;
  112. case WM_KILLFOCUS:
  113. case WM_SETFOCUS:
  114. SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
  115. return 0;
  116. case WM_CLOSE:
  117. /* call destroy window to cleanup and go away */
  118. DestroyWindow (hWnd);
  119. return 0;
  120. }
  121. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  122. }
  123. /*
  124. ==============
  125. WZ_Create
  126. ==============
  127. */
  128. void WZ_Create (HINSTANCE hInstance)
  129. {
  130. WNDCLASS wc;
  131. memset (&wc, 0, sizeof(wc));
  132. wc.style = CS_NOCLOSE;
  133. wc.lpfnWndProc = (WNDPROC)WZ_WndProc;
  134. wc.cbClsExtra = 0;
  135. wc.cbWndExtra = 0;
  136. wc.hInstance = hInstance;
  137. wc.hIcon = 0;
  138. wc.hCursor = LoadCursor (NULL,IDC_ARROW);
  139. wc.hbrBackground = NULL;
  140. wc.lpszMenuName = NULL;
  141. wc.lpszClassName = Z_WINDOW_CLASS;
  142. if (!RegisterClass (&wc) )
  143. Error ("WCam_Register: failed");
  144. g_qeglobals.d_hwndZ = CreateWindow (Z_WINDOW_CLASS ,
  145. "Z",
  146. QE3_STYLE,
  147. 0,20,ZWIN_WIDTH,screen_height-38, // size
  148. g_qeglobals.d_hwndMain, // parent
  149. 0, // no menu
  150. hInstance,
  151. NULL);
  152. if (!g_qeglobals.d_hwndZ)
  153. Error ("Couldn't create zwindow");
  154. LoadWindowState(g_qeglobals.d_hwndZ, "zwindow");
  155. ShowWindow (g_qeglobals.d_hwndZ, SW_SHOWDEFAULT);
  156. }