win_z.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1997-2006 Id Software, Inc.
  4. This file is part of Quake 2 Tools source code.
  5. Quake 2 Tools 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 2 Tools 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 Quake 2 Tools source code; 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 "qe3.h"
  20. static HDC s_hdcZ;
  21. static HGLRC s_hglrcZ;
  22. /*
  23. ============
  24. WZ_WndProc
  25. ============
  26. */
  27. LONG WINAPI WZ_WndProc (
  28. HWND hWnd,
  29. UINT uMsg,
  30. WPARAM wParam,
  31. LPARAM lParam)
  32. {
  33. int fwKeys, xPos, yPos;
  34. RECT rect;
  35. GetClientRect(hWnd, &rect);
  36. switch (uMsg)
  37. {
  38. case WM_DESTROY:
  39. QEW_StopGL( hWnd, s_hglrcZ, s_hdcZ );
  40. return 0;
  41. case WM_CREATE:
  42. s_hdcZ = GetDC(hWnd);
  43. QEW_SetupPixelFormat( s_hdcZ, false);
  44. if ( ( s_hglrcZ = wglCreateContext( s_hdcZ ) ) == 0 )
  45. Error( "wglCreateContext in WZ_WndProc failed" );
  46. if (!wglMakeCurrent( s_hdcZ, s_hglrcZ ))
  47. Error ("wglMakeCurrent in WZ_WndProc failed");
  48. if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcZ ) )
  49. Error( "wglShareLists in WZ_WndProc failed" );
  50. return 0;
  51. case WM_PAINT:
  52. {
  53. PAINTSTRUCT ps;
  54. BeginPaint(hWnd, &ps);
  55. if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) )
  56. Error ("wglMakeCurrent failed");
  57. QE_CheckOpenGLForErrors();
  58. Z_Draw ();
  59. SwapBuffers(s_hdcZ);
  60. EndPaint(hWnd, &ps);
  61. }
  62. return 0;
  63. case WM_KEYDOWN:
  64. QE_KeyDown (wParam);
  65. return 0;
  66. case WM_MBUTTONDOWN:
  67. case WM_RBUTTONDOWN:
  68. case WM_LBUTTONDOWN:
  69. if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
  70. BringWindowToTop(hWnd);
  71. SetFocus( g_qeglobals.d_hwndZ );
  72. SetCapture( g_qeglobals.d_hwndZ );
  73. fwKeys = wParam; // key flags
  74. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  75. yPos = (short)HIWORD(lParam); // vertical position of cursor
  76. yPos = (int)rect.bottom - 1 - yPos;
  77. Z_MouseDown (xPos, yPos, fwKeys);
  78. return 0;
  79. case WM_MBUTTONUP:
  80. case WM_RBUTTONUP:
  81. case WM_LBUTTONUP:
  82. fwKeys = wParam; // key flags
  83. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  84. yPos = (short)HIWORD(lParam); // vertical position of cursor
  85. yPos = (int)rect.bottom - 1 - yPos;
  86. Z_MouseUp (xPos, yPos, fwKeys);
  87. if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  88. ReleaseCapture ();
  89. return 0;
  90. case WM_GETMINMAXINFO:
  91. {
  92. MINMAXINFO *pmmi = (LPMINMAXINFO) lParam;
  93. pmmi->ptMinTrackSize.x = ZWIN_WIDTH;
  94. return 0;
  95. }
  96. case WM_MOUSEMOVE:
  97. fwKeys = wParam; // key flags
  98. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  99. yPos = (short)HIWORD(lParam); // vertical position of cursor
  100. yPos = (int)rect.bottom - 1 - yPos;
  101. Z_MouseMoved (xPos, yPos, fwKeys);
  102. return 0;
  103. case WM_SIZE:
  104. z.width = rect.right;
  105. z.height = rect.bottom;
  106. InvalidateRect( g_qeglobals.d_hwndZ, NULL, false);
  107. return 0;
  108. case WM_NCCALCSIZE:// don't let windows copy pixels
  109. DefWindowProc (hWnd, uMsg, wParam, lParam);
  110. return WVR_REDRAW;
  111. case WM_KILLFOCUS:
  112. case WM_SETFOCUS:
  113. SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
  114. return 0;
  115. case WM_CLOSE:
  116. /* call destroy window to cleanup and go away */
  117. DestroyWindow (hWnd);
  118. return 0;
  119. }
  120. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  121. }
  122. /*
  123. ==============
  124. WZ_Create
  125. ==============
  126. */
  127. void WZ_Create (HINSTANCE hInstance)
  128. {
  129. WNDCLASS wc;
  130. /* Register the camera class */
  131. memset (&wc, 0, sizeof(wc));
  132. wc.style = 0;
  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. }