Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

ZWnd.cpp (6279B)


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