Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ZWnd.cpp

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 // ZWnd.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "Radiant.h"
00027 #include "ZWnd.h"
00028 #include "qe3.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00037 // CZWnd
00038 IMPLEMENT_DYNCREATE(CZWnd, CWnd);
00039 
00040 
00041 CZWnd::CZWnd()
00042 {
00043 }
00044 
00045 CZWnd::~CZWnd()
00046 {
00047 }
00048 
00049 
00050 BEGIN_MESSAGE_MAP(CZWnd, CWnd)
00051     //{{AFX_MSG_MAP(CZWnd)
00052     ON_WM_CREATE()
00053     ON_WM_DESTROY()
00054     ON_WM_KEYDOWN()
00055     ON_WM_LBUTTONDOWN()
00056     ON_WM_MBUTTONDOWN()
00057     ON_WM_RBUTTONDOWN()
00058     ON_WM_PAINT()
00059     ON_WM_GETMINMAXINFO()
00060     ON_WM_MOUSEMOVE()
00061     ON_WM_SIZE()
00062     ON_WM_NCCALCSIZE()
00063     ON_WM_KILLFOCUS()
00064     ON_WM_SETFOCUS()
00065     ON_WM_CLOSE()
00066     ON_WM_LBUTTONUP()
00067     ON_WM_MBUTTONUP()
00068     ON_WM_RBUTTONUP()
00069     ON_WM_KEYUP()
00070     //}}AFX_MSG_MAP
00071 END_MESSAGE_MAP()
00072 
00073 
00075 // CZWnd message handlers
00076 
00077 int CZWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00078 {
00079     if (CWnd::OnCreate(lpCreateStruct) == -1)
00080         return -1;
00081 
00082     g_qeglobals.d_hwndZ = GetSafeHwnd();
00083 
00084   m_dcZ = ::GetDC(GetSafeHwnd());
00085   QEW_SetupPixelFormat(m_dcZ, false);
00086     if ((m_hglrcZ = qwglCreateContext(m_dcZ )) == 0)
00087       Error("wglCreateContext in CZWnd::OnCreate failed");
00088 
00089     if (!qwglShareLists(g_qeglobals.d_hglrcBase, m_hglrcZ))
00090       Error( "wglShareLists in CZWnd::OnCreate failed");
00091 
00092   if (!qwglMakeCurrent(m_dcZ, m_hglrcZ))
00093       Error ("wglMakeCurrent in CZWnd::OnCreate failed");
00094 
00095     return 0;
00096 }
00097 
00098 void CZWnd::OnDestroy() 
00099 {
00100   QEW_StopGL(GetSafeHwnd(), m_hglrcZ, m_dcZ);
00101     CWnd::OnDestroy();
00102 }
00103 
00104 void CZWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
00105 {
00106   g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
00107 }
00108 
00109 void CZWnd::OnLButtonDown(UINT nFlags, CPoint point) 
00110 {
00111   SetFocus();
00112   SetCapture();
00113   CRect rctZ;
00114   GetClientRect(rctZ);
00115     Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
00116 }
00117 
00118 void CZWnd::OnMButtonDown(UINT nFlags, CPoint point) 
00119 {
00120   SetFocus();
00121   SetCapture();
00122   CRect rctZ;
00123   GetClientRect(rctZ);
00124     Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
00125 }
00126 
00127 void CZWnd::OnRButtonDown(UINT nFlags, CPoint point) 
00128 {
00129   SetFocus();
00130   SetCapture();
00131   CRect rctZ;
00132   GetClientRect(rctZ);
00133     Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
00134 }
00135 
00136 void CZWnd::OnPaint() 
00137 {
00138     CPaintDC dc(this); // device context for painting
00139   //if (!wglMakeCurrent(m_dcZ, m_hglrcZ))
00140   if (!qwglMakeCurrent(dc.m_hDC, m_hglrcZ))
00141   {
00142     Sys_Printf("ERROR: wglMakeCurrent failed..\n ");
00143     Sys_Printf("Please restart Q3Radiant if the Z view is not working\n");
00144   }
00145   else
00146   {
00147       QE_CheckOpenGLForErrors();
00148     Z_Draw ();
00149       //qwglSwapBuffers(m_dcZ);
00150       qwglSwapBuffers(dc.m_hDC);
00151     TRACE("Z Paint\n");
00152   }
00153 }
00154 
00155 void CZWnd::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
00156 {
00157     lpMMI->ptMinTrackSize.x = ZWIN_WIDTH;
00158 }
00159 
00160 void CZWnd::OnMouseMove(UINT nFlags, CPoint point) 
00161 {
00162   CRect rctZ;
00163   GetClientRect(rctZ);
00164   float fz = z.origin[2] + ((rctZ.Height() - 1 - point.y) - (z.height/2)) / z.scale;
00165     fz = floor(fz / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
00166   CString strStatus;
00167   strStatus.Format("Z:: %.1f", fz);
00168   g_pParentWnd->SetStatusText(1, strStatus);
00169   Z_MouseMoved (point.x, rctZ.Height() - 1 - point.y, nFlags);
00170 }
00171 
00172 void CZWnd::OnSize(UINT nType, int cx, int cy) 
00173 {
00174     CWnd::OnSize(nType, cx, cy);
00175   CRect rctZ;
00176   GetClientRect(rctZ);
00177   z.width = rctZ.right;
00178     z.height = rctZ.bottom;
00179   if (z.width < 10)
00180     z.width = 10;
00181   if (z.height < 10)
00182     z.height = 10;
00183   Invalidate();
00184 }
00185 
00186 void CZWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
00187 {
00188     CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
00189 }
00190 
00191 void CZWnd::OnKillFocus(CWnd* pNewWnd) 
00192 {
00193     CWnd::OnKillFocus(pNewWnd);
00194     SendMessage(WM_NCACTIVATE, FALSE , 0 );
00195 }
00196 
00197 void CZWnd::OnSetFocus(CWnd* pOldWnd) 
00198 {
00199     CWnd::OnSetFocus(pOldWnd);
00200     SendMessage(WM_NCACTIVATE, TRUE , 0 );
00201 }
00202 
00203 void CZWnd::OnClose() 
00204 {
00205     CWnd::OnClose();
00206 }
00207 
00208 void CZWnd::OnLButtonUp(UINT nFlags, CPoint point) 
00209 {
00210   CRect rctZ;
00211   GetClientRect(rctZ);
00212     Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
00213     if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
00214     ReleaseCapture ();
00215 }
00216 
00217 void CZWnd::OnMButtonUp(UINT nFlags, CPoint point) 
00218 {
00219   CRect rctZ;
00220   GetClientRect(rctZ);
00221     Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
00222     if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
00223     ReleaseCapture ();
00224 }
00225 
00226 void CZWnd::OnRButtonUp(UINT nFlags, CPoint point) 
00227 {
00228   CRect rctZ;
00229   GetClientRect(rctZ);
00230     Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
00231     if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
00232     ReleaseCapture ();
00233 }
00234 
00235 
00236 BOOL CZWnd::PreCreateWindow(CREATESTRUCT& cs) 
00237 {
00238   WNDCLASS wc;
00239   HINSTANCE hInstance = AfxGetInstanceHandle();
00240   if (::GetClassInfo(hInstance, Z_WINDOW_CLASS, &wc) == FALSE)
00241   {
00242     // Register a new class
00243     memset (&wc, 0, sizeof(wc));
00244     wc.style         = CS_NOCLOSE | CS_OWNDC;
00245     wc.lpszClassName = Z_WINDOW_CLASS;
00246     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
00247     wc.lpfnWndProc = ::DefWindowProc;
00248     if (AfxRegisterClass(&wc) == FALSE)
00249       Error ("CZWnd RegisterClass: failed");
00250   }
00251 
00252   cs.lpszClass = Z_WINDOW_CLASS;
00253   cs.lpszName = "Z";
00254   if (cs.style != QE3_CHILDSTYLE)
00255     cs.style = QE3_SPLITTER_STYLE;
00256 
00257     return CWnd::PreCreateWindow(cs);
00258 }
00259 
00260 
00261 void CZWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
00262 {
00263   g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
00264 }

Generated on Thu Aug 25 12:38:44 2005 for Quake III Arena by  doxygen 1.3.9.1