ZWnd.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "qe3.h"
  23. #include "Radiant.h"
  24. #include "ZWnd.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CZWnd
  32. IMPLEMENT_DYNCREATE(CZWnd, CWnd);
  33. CZWnd::CZWnd()
  34. {
  35. m_pZClip = NULL;
  36. }
  37. CZWnd::~CZWnd()
  38. {
  39. }
  40. BEGIN_MESSAGE_MAP(CZWnd, CWnd)
  41. //{{AFX_MSG_MAP(CZWnd)
  42. ON_WM_CREATE()
  43. ON_WM_DESTROY()
  44. ON_WM_KEYDOWN()
  45. ON_WM_LBUTTONDOWN()
  46. ON_WM_MBUTTONDOWN()
  47. ON_WM_RBUTTONDOWN()
  48. ON_WM_PAINT()
  49. ON_WM_GETMINMAXINFO()
  50. ON_WM_MOUSEMOVE()
  51. ON_WM_SIZE()
  52. ON_WM_NCCALCSIZE()
  53. ON_WM_KILLFOCUS()
  54. ON_WM_SETFOCUS()
  55. ON_WM_CLOSE()
  56. ON_WM_LBUTTONUP()
  57. ON_WM_MBUTTONUP()
  58. ON_WM_RBUTTONUP()
  59. ON_WM_KEYUP()
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CZWnd message handlers
  64. int CZWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  65. {
  66. if (CWnd::OnCreate(lpCreateStruct) == -1)
  67. return -1;
  68. m_dcZ = ::GetDC(GetSafeHwnd());
  69. QEW_SetupPixelFormat(m_dcZ, false);
  70. m_pZClip = new CZClip();
  71. return 0;
  72. }
  73. void CZWnd::OnDestroy()
  74. {
  75. if (m_pZClip)
  76. {
  77. delete m_pZClip;
  78. m_pZClip = NULL;
  79. }
  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. if (!qwglMakeCurrent(dc.m_hDC, win32.hGLRC))
  116. {
  117. common->Printf("ERROR: wglMakeCurrent failed..\n ");
  118. common->Printf("Please restart " EDITOR_WINDOWTEXT " if the Z view is not working\n");
  119. }
  120. else
  121. {
  122. QE_CheckOpenGLForErrors();
  123. Z_Draw ();
  124. //qwglSwapBuffers(m_dcZ);
  125. qwglSwapBuffers(dc.m_hDC);
  126. TRACE("Z Paint\n");
  127. }
  128. }
  129. void CZWnd::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  130. {
  131. lpMMI->ptMinTrackSize.x = ZWIN_WIDTH;
  132. }
  133. void CZWnd::OnMouseMove(UINT nFlags, CPoint point)
  134. {
  135. CRect rctZ;
  136. GetClientRect(rctZ);
  137. float fz = z.origin[2] + ((rctZ.Height() - 1 - point.y) - (z.height/2)) / z.scale;
  138. fz = floor(fz / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  139. CString strStatus;
  140. strStatus.Format("Z:: %.1f", fz);
  141. g_pParentWnd->SetStatusText(1, strStatus);
  142. Z_MouseMoved (point.x, rctZ.Height() - 1 - point.y, nFlags);
  143. }
  144. void CZWnd::OnSize(UINT nType, int cx, int cy)
  145. {
  146. CWnd::OnSize(nType, cx, cy);
  147. CRect rctZ;
  148. GetClientRect(rctZ);
  149. z.width = rctZ.right;
  150. z.height = rctZ.bottom;
  151. if (z.width < 10)
  152. z.width = 10;
  153. if (z.height < 10)
  154. z.height = 10;
  155. Invalidate();
  156. }
  157. void CZWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  158. {
  159. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  160. }
  161. void CZWnd::OnKillFocus(CWnd* pNewWnd)
  162. {
  163. CWnd::OnKillFocus(pNewWnd);
  164. SendMessage(WM_NCACTIVATE, FALSE , 0 );
  165. }
  166. void CZWnd::OnSetFocus(CWnd* pOldWnd)
  167. {
  168. CWnd::OnSetFocus(pOldWnd);
  169. SendMessage(WM_NCACTIVATE, TRUE , 0 );
  170. }
  171. void CZWnd::OnClose()
  172. {
  173. CWnd::OnClose();
  174. }
  175. void CZWnd::OnLButtonUp(UINT nFlags, CPoint point)
  176. {
  177. CRect rctZ;
  178. GetClientRect(rctZ);
  179. Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  180. if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  181. ReleaseCapture ();
  182. }
  183. void CZWnd::OnMButtonUp(UINT nFlags, CPoint point)
  184. {
  185. CRect rctZ;
  186. GetClientRect(rctZ);
  187. Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  188. if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  189. ReleaseCapture ();
  190. }
  191. void CZWnd::OnRButtonUp(UINT nFlags, CPoint point)
  192. {
  193. CRect rctZ;
  194. GetClientRect(rctZ);
  195. Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  196. if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  197. ReleaseCapture ();
  198. }
  199. BOOL CZWnd::PreCreateWindow(CREATESTRUCT& cs)
  200. {
  201. WNDCLASS wc;
  202. HINSTANCE hInstance = AfxGetInstanceHandle();
  203. if (::GetClassInfo(hInstance, Z_WINDOW_CLASS, &wc) == FALSE)
  204. {
  205. // Register a new class
  206. memset (&wc, 0, sizeof(wc));
  207. wc.style = CS_NOCLOSE;// | CS_OWNDC;
  208. wc.lpszClassName = Z_WINDOW_CLASS;
  209. wc.hCursor = LoadCursor (NULL,IDC_ARROW);
  210. wc.lpfnWndProc = ::DefWindowProc;
  211. if (AfxRegisterClass(&wc) == FALSE)
  212. Error ("CZWnd RegisterClass: failed");
  213. }
  214. cs.lpszClass = Z_WINDOW_CLASS;
  215. cs.lpszName = "Z";
  216. if (cs.style != QE3_CHILDSTYLE)
  217. cs.style = QE3_SPLITTER_STYLE;
  218. return CWnd::PreCreateWindow(cs);
  219. }
  220. void CZWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  221. {
  222. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
  223. }