doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ZWnd.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "qe3.h"
33 #include "Radiant.h"
34 #include "ZWnd.h"
35 
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #undef THIS_FILE
39 static char THIS_FILE[] = __FILE__;
40 #endif
41 
43 // CZWnd
45 
46 
48 {
49  m_pZClip = NULL;
50 }
51 
53 {
54 }
55 
56 
57 BEGIN_MESSAGE_MAP(CZWnd, CWnd)
58  //{{AFX_MSG_MAP(CZWnd)
59  ON_WM_CREATE()
60  ON_WM_DESTROY()
61  ON_WM_KEYDOWN()
62  ON_WM_LBUTTONDOWN()
63  ON_WM_MBUTTONDOWN()
64  ON_WM_RBUTTONDOWN()
65  ON_WM_PAINT()
66  ON_WM_GETMINMAXINFO()
67  ON_WM_MOUSEMOVE()
68  ON_WM_SIZE()
69  ON_WM_NCCALCSIZE()
70  ON_WM_KILLFOCUS()
71  ON_WM_SETFOCUS()
72  ON_WM_CLOSE()
73  ON_WM_LBUTTONUP()
74  ON_WM_MBUTTONUP()
75  ON_WM_RBUTTONUP()
76  ON_WM_KEYUP()
77  //}}AFX_MSG_MAP
78 END_MESSAGE_MAP()
79 
80 
82 // CZWnd message handlers
83 
84 int CZWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
85 {
86  if (CWnd::OnCreate(lpCreateStruct) == -1)
87  return -1;
88 
89  m_dcZ = ::GetDC(GetSafeHwnd());
90  QEW_SetupPixelFormat(m_dcZ, false);
91 
92  m_pZClip = new CZClip();
93 
94  return 0;
95 }
96 
98 {
99  if (m_pZClip)
100  {
101  delete m_pZClip;
102  m_pZClip = NULL;
103  }
104 
105  CWnd::OnDestroy();
106 }
107 
108 void CZWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
109 {
110  g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
111 }
112 
113 void CZWnd::OnLButtonDown(UINT nFlags, CPoint point)
114 {
115  SetFocus();
116  SetCapture();
117  CRect rctZ;
118  GetClientRect(rctZ);
119  Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
120 }
121 
122 void CZWnd::OnMButtonDown(UINT nFlags, CPoint point)
123 {
124  SetFocus();
125  SetCapture();
126  CRect rctZ;
127  GetClientRect(rctZ);
128  Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
129 }
130 
131 void CZWnd::OnRButtonDown(UINT nFlags, CPoint point)
132 {
133  SetFocus();
134  SetCapture();
135  CRect rctZ;
136  GetClientRect(rctZ);
137  Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
138 }
139 
141 {
142  CPaintDC dc(this); // device context for painting
143  //if (!wglMakeCurrent(m_dcZ, m_hglrcZ))
144  //if (!qwglMakeCurrent(dc.m_hDC, m_hglrcZ))
145  if (!qwglMakeCurrent(dc.m_hDC, win32.hGLRC))
146  {
147  common->Printf("ERROR: wglMakeCurrent failed..\n ");
148  common->Printf("Please restart " EDITOR_WINDOWTEXT " if the Z view is not working\n");
149  }
150  else
151  {
152  QE_CheckOpenGLForErrors();
153 
154  Z_Draw ();
155  //qwglSwapBuffers(m_dcZ);
156  qwglSwapBuffers(dc.m_hDC);
157  TRACE("Z Paint\n");
158  }
159 }
160 
161 void CZWnd::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
162 {
163  lpMMI->ptMinTrackSize.x = ZWIN_WIDTH;
164 }
165 
166 void CZWnd::OnMouseMove(UINT nFlags, CPoint point)
167 {
168  CRect rctZ;
169  GetClientRect(rctZ);
170  float fz = z.origin[2] + ((rctZ.Height() - 1 - point.y) - (z.height/2)) / z.scale;
171  fz = floor(fz / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
172  CString strStatus;
173  strStatus.Format("Z:: %.1f", fz);
174  g_pParentWnd->SetStatusText(1, strStatus);
175  Z_MouseMoved (point.x, rctZ.Height() - 1 - point.y, nFlags);
176 }
177 
178 void CZWnd::OnSize(UINT nType, int cx, int cy)
179 {
180  CWnd::OnSize(nType, cx, cy);
181  CRect rctZ;
182  GetClientRect(rctZ);
183  z.width = rctZ.right;
184  z.height = rctZ.bottom;
185  if (z.width < 10)
186  z.width = 10;
187  if (z.height < 10)
188  z.height = 10;
189  Invalidate();
190 }
191 
192 void CZWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
193 {
194  CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
195 }
196 
197 void CZWnd::OnKillFocus(CWnd* pNewWnd)
198 {
199  CWnd::OnKillFocus(pNewWnd);
200  SendMessage(WM_NCACTIVATE, FALSE , 0 );
201 }
202 
203 void CZWnd::OnSetFocus(CWnd* pOldWnd)
204 {
205  CWnd::OnSetFocus(pOldWnd);
206  SendMessage(WM_NCACTIVATE, TRUE , 0 );
207 }
208 
210 {
211  CWnd::OnClose();
212 }
213 
214 void CZWnd::OnLButtonUp(UINT nFlags, CPoint point)
215 {
216  CRect rctZ;
217  GetClientRect(rctZ);
218  Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
219  if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
220  ReleaseCapture ();
221 }
222 
223 void CZWnd::OnMButtonUp(UINT nFlags, CPoint point)
224 {
225  CRect rctZ;
226  GetClientRect(rctZ);
227  Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
228  if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
229  ReleaseCapture ();
230 }
231 
232 void CZWnd::OnRButtonUp(UINT nFlags, CPoint point)
233 {
234  CRect rctZ;
235  GetClientRect(rctZ);
236  Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
237  if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
238  ReleaseCapture ();
239 }
240 
241 
242 BOOL CZWnd::PreCreateWindow(CREATESTRUCT& cs)
243 {
244  WNDCLASS wc;
245  HINSTANCE hInstance = AfxGetInstanceHandle();
246  if (::GetClassInfo(hInstance, Z_WINDOW_CLASS, &wc) == FALSE)
247  {
248  // Register a new class
249  memset (&wc, 0, sizeof(wc));
250  wc.style = CS_NOCLOSE;// | CS_OWNDC;
251  wc.lpszClassName = Z_WINDOW_CLASS;
252  wc.hCursor = LoadCursor (NULL,IDC_ARROW);
253  wc.lpfnWndProc = ::DefWindowProc;
254  if (AfxRegisterClass(&wc) == FALSE)
255  Error ("CZWnd RegisterClass: failed");
256  }
257 
258  cs.lpszClass = Z_WINDOW_CLASS;
259  cs.lpszName = "Z";
260  if (cs.style != QE3_CHILDSTYLE)
261  cs.style = QE3_SPLITTER_STYLE;
262 
263  return CWnd::PreCreateWindow(cs);
264 }
265 
266 
267 void CZWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
268 {
269  g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
270 }
CMainFrame * g_pParentWnd
Definition: MainFrm.cpp:73
void SetStatusText(int nPane, const char *pText)
Definition: MainFrm.cpp:3922
afx_msg void OnDestroy()
Definition: ZWnd.cpp:97
afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
Definition: ZWnd.cpp:113
Definition: ZWnd.h:42
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
HGLRC hGLRC
Definition: win_local.h:122
afx_msg void OnSetFocus(CWnd *pOldWnd)
Definition: ZWnd.cpp:203
afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR *lpncsp)
Definition: ZWnd.cpp:192
virtual ~CZWnd()
Definition: ZWnd.cpp:52
#define BOOL
Definition: mprintf.c:71
CZWnd()
Definition: ZWnd.cpp:47
void Error(const char *pFormat,...)
Definition: cmdlib.cpp:45
IMPLEMENT_DYNCREATE(CZWnd, CWnd)
afx_msg void OnClose()
Definition: ZWnd.cpp:209
afx_msg void OnMButtonDown(UINT nFlags, CPoint point)
Definition: ZWnd.cpp:122
idCommon * common
Definition: Common.cpp:206
#define NULL
Definition: Lib.h:88
#define FAR
Definition: jmorecfg.h:205
void HandleKey(UINT nChar, UINT nRepCnt, UINT nFlags, bool bDown=true)
Definition: MainFrm.h:70
afx_msg void OnRButtonUp(UINT nFlags, CPoint point)
Definition: ZWnd.cpp:232
virtual void Printf(const char *fmt,...) id_attribute((format(printf
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
Definition: ZWnd.cpp:166
virtual BOOL PreCreateWindow(CREATESTRUCT &cs)
Definition: ZWnd.cpp:242
afx_msg void OnMButtonUp(UINT nFlags, CPoint point)
Definition: ZWnd.cpp:223
Definition: ZClip.h:39
afx_msg void OnSize(UINT nType, int cx, int cy)
Definition: ZWnd.cpp:178
afx_msg void OnLButtonUp(UINT nFlags, CPoint point)
Definition: ZWnd.cpp:214
afx_msg void OnRButtonDown(UINT nFlags, CPoint point)
Definition: ZWnd.cpp:131
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
Definition: ZWnd.cpp:108
#define FALSE
Definition: mprintf.c:70
afx_msg void OnPaint()
Definition: ZWnd.cpp:140
#define TRUE
Definition: mprintf.c:69
#define EDITOR_WINDOWTEXT
Definition: Licensee.h:93
Win32Vars_t win32
Definition: win_main.cpp:65
afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
Definition: ZWnd.cpp:267
GLdouble GLdouble z
Definition: glext.h:3067
afx_msg void OnKillFocus(CWnd *pNewWnd)
Definition: ZWnd.cpp:197
CZClip * m_pZClip
Definition: ZWnd.h:66
afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR *lpMMI)
Definition: ZWnd.cpp:161