ZWnd.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. // ZWnd.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "Radiant.h"
  22. #include "ZWnd.h"
  23. #include "qe3.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CZWnd
  31. IMPLEMENT_DYNCREATE(CZWnd, CWnd);
  32. CZWnd::CZWnd()
  33. {
  34. }
  35. CZWnd::~CZWnd()
  36. {
  37. }
  38. BEGIN_MESSAGE_MAP(CZWnd, CWnd)
  39. //{{AFX_MSG_MAP(CZWnd)
  40. ON_WM_CREATE()
  41. ON_WM_DESTROY()
  42. ON_WM_KEYDOWN()
  43. ON_WM_LBUTTONDOWN()
  44. ON_WM_MBUTTONDOWN()
  45. ON_WM_RBUTTONDOWN()
  46. ON_WM_PAINT()
  47. ON_WM_GETMINMAXINFO()
  48. ON_WM_MOUSEMOVE()
  49. ON_WM_SIZE()
  50. ON_WM_NCCALCSIZE()
  51. ON_WM_KILLFOCUS()
  52. ON_WM_SETFOCUS()
  53. ON_WM_CLOSE()
  54. ON_WM_LBUTTONUP()
  55. ON_WM_MBUTTONUP()
  56. ON_WM_RBUTTONUP()
  57. ON_WM_KEYUP()
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CZWnd message handlers
  62. int CZWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  63. {
  64. if (CWnd::OnCreate(lpCreateStruct) == -1)
  65. return -1;
  66. g_qeglobals.d_hwndZ = GetSafeHwnd();
  67. m_dcZ = ::GetDC(GetSafeHwnd());
  68. QEW_SetupPixelFormat(m_dcZ, false);
  69. if ((m_hglrcZ = qwglCreateContext(m_dcZ )) == 0)
  70. Error("wglCreateContext in CZWnd::OnCreate failed");
  71. if (!qwglShareLists(g_qeglobals.d_hglrcBase, m_hglrcZ))
  72. Error( "wglShareLists in CZWnd::OnCreate failed");
  73. if (!qwglMakeCurrent(m_dcZ, m_hglrcZ))
  74. Error ("wglMakeCurrent in CZWnd::OnCreate failed");
  75. return 0;
  76. }
  77. void CZWnd::OnDestroy()
  78. {
  79. QEW_StopGL(GetSafeHwnd(), m_hglrcZ, m_dcZ);
  80. CWnd::OnDestroy();
  81. }
  82. void CZWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  83. {
  84. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
  85. }
  86. void CZWnd::OnLButtonDown(UINT nFlags, CPoint point)
  87. {
  88. SetFocus();
  89. SetCapture();
  90. CRect rctZ;
  91. GetClientRect(rctZ);
  92. Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  93. }
  94. void CZWnd::OnMButtonDown(UINT nFlags, CPoint point)
  95. {
  96. SetFocus();
  97. SetCapture();
  98. CRect rctZ;
  99. GetClientRect(rctZ);
  100. Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  101. }
  102. void CZWnd::OnRButtonDown(UINT nFlags, CPoint point)
  103. {
  104. SetFocus();
  105. SetCapture();
  106. CRect rctZ;
  107. GetClientRect(rctZ);
  108. Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  109. }
  110. void CZWnd::OnPaint()
  111. {
  112. CPaintDC dc(this); // device context for painting
  113. //if (!wglMakeCurrent(m_dcZ, m_hglrcZ))
  114. if (!qwglMakeCurrent(dc.m_hDC, m_hglrcZ))
  115. {
  116. Sys_Printf("ERROR: wglMakeCurrent failed..\n ");
  117. Sys_Printf("Please restart Q3Radiant if the Z view is not working\n");
  118. }
  119. else
  120. {
  121. QE_CheckOpenGLForErrors();
  122. Z_Draw ();
  123. //qwglSwapBuffers(m_dcZ);
  124. qwglSwapBuffers(dc.m_hDC);
  125. TRACE("Z Paint\n");
  126. }
  127. }
  128. void CZWnd::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  129. {
  130. lpMMI->ptMinTrackSize.x = ZWIN_WIDTH;
  131. }
  132. void CZWnd::OnMouseMove(UINT nFlags, CPoint point)
  133. {
  134. CRect rctZ;
  135. GetClientRect(rctZ);
  136. float fz = z.origin[2] + ((rctZ.Height() - 1 - point.y) - (z.height/2)) / z.scale;
  137. fz = floor(fz / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  138. CString strStatus;
  139. strStatus.Format("Z:: %.1f", fz);
  140. g_pParentWnd->SetStatusText(1, strStatus);
  141. Z_MouseMoved (point.x, rctZ.Height() - 1 - point.y, nFlags);
  142. }
  143. void CZWnd::OnSize(UINT nType, int cx, int cy)
  144. {
  145. CWnd::OnSize(nType, cx, cy);
  146. CRect rctZ;
  147. GetClientRect(rctZ);
  148. z.width = rctZ.right;
  149. z.height = rctZ.bottom;
  150. if (z.width < 10)
  151. z.width = 10;
  152. if (z.height < 10)
  153. z.height = 10;
  154. Invalidate();
  155. }
  156. void CZWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  157. {
  158. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  159. }
  160. void CZWnd::OnKillFocus(CWnd* pNewWnd)
  161. {
  162. CWnd::OnKillFocus(pNewWnd);
  163. SendMessage(WM_NCACTIVATE, FALSE , 0 );
  164. }
  165. void CZWnd::OnSetFocus(CWnd* pOldWnd)
  166. {
  167. CWnd::OnSetFocus(pOldWnd);
  168. SendMessage(WM_NCACTIVATE, TRUE , 0 );
  169. }
  170. void CZWnd::OnClose()
  171. {
  172. CWnd::OnClose();
  173. }
  174. void CZWnd::OnLButtonUp(UINT nFlags, CPoint point)
  175. {
  176. CRect rctZ;
  177. GetClientRect(rctZ);
  178. Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  179. if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  180. ReleaseCapture ();
  181. }
  182. void CZWnd::OnMButtonUp(UINT nFlags, CPoint point)
  183. {
  184. CRect rctZ;
  185. GetClientRect(rctZ);
  186. Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  187. if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  188. ReleaseCapture ();
  189. }
  190. void CZWnd::OnRButtonUp(UINT nFlags, CPoint point)
  191. {
  192. CRect rctZ;
  193. GetClientRect(rctZ);
  194. Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  195. if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  196. ReleaseCapture ();
  197. }
  198. BOOL CZWnd::PreCreateWindow(CREATESTRUCT& cs)
  199. {
  200. WNDCLASS wc;
  201. HINSTANCE hInstance = AfxGetInstanceHandle();
  202. if (::GetClassInfo(hInstance, Z_WINDOW_CLASS, &wc) == FALSE)
  203. {
  204. // Register a new class
  205. memset (&wc, 0, sizeof(wc));
  206. wc.style = CS_NOCLOSE | CS_OWNDC;
  207. wc.lpszClassName = Z_WINDOW_CLASS;
  208. wc.hCursor = LoadCursor (NULL,IDC_ARROW);
  209. wc.lpfnWndProc = ::DefWindowProc;
  210. if (AfxRegisterClass(&wc) == FALSE)
  211. Error ("CZWnd RegisterClass: failed");
  212. }
  213. cs.lpszClass = Z_WINDOW_CLASS;
  214. cs.lpszName = "Z";
  215. if (cs.style != QE3_CHILDSTYLE)
  216. cs.style = QE3_SPLITTER_STYLE;
  217. return CWnd::PreCreateWindow(cs);
  218. }
  219. void CZWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  220. {
  221. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
  222. }