WIN_XY.CPP (7641B)
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 // win_xy.c -- windows specific xy view code 23 24 #include "stdafx.h" 25 #include "qe3.h" 26 27 static HDC s_hdcXY; 28 static HGLRC s_hglrcXY; 29 30 static unsigned s_stipple[32] = 31 { 32 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 33 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 34 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 35 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 36 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 37 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 38 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 39 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555, 40 }; 41 42 /* 43 ============ 44 WXY_WndProc 45 ============ 46 */ 47 LONG WINAPI XYWndProc ( 48 HWND hWnd, 49 UINT uMsg, 50 WPARAM wParam, 51 LPARAM lParam) 52 { 53 int fwKeys, xPos, yPos; 54 RECT rect; 55 56 57 GetClientRect(hWnd, &rect); 58 59 switch (uMsg) 60 { 61 case WM_CREATE: 62 63 s_hdcXY = GetDC(hWnd); 64 QEW_SetupPixelFormat(s_hdcXY, false); 65 66 if ( ( s_hglrcXY = wglCreateContext( s_hdcXY ) ) == 0 ) 67 Error( "wglCreateContext in WXY_WndProc failed" ); 68 69 if (!wglMakeCurrent( s_hdcXY, s_hglrcXY )) 70 Error ("wglMakeCurrent failed"); 71 72 if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcXY ) ) 73 Error( "wglShareLists in WXY_WndProc failed" ); 74 75 glPolygonStipple ((unsigned char *)s_stipple); 76 glLineStipple (3, 0xaaaa); 77 78 return 0; 79 80 case WM_DESTROY: 81 QEW_StopGL( hWnd, s_hglrcXY, s_hdcXY ); 82 return 0; 83 84 case WM_PAINT: 85 { 86 PAINTSTRUCT ps; 87 88 BeginPaint(hWnd, &ps); 89 90 if (!wglMakeCurrent( s_hdcXY, s_hglrcXY )) 91 Error ("wglMakeCurrent failed"); 92 93 QE_CheckOpenGLForErrors(); 94 XY_Draw (); 95 QE_CheckOpenGLForErrors(); 96 97 SwapBuffers(s_hdcXY); 98 99 EndPaint(hWnd, &ps); 100 } 101 return 0; 102 103 case WM_KEYDOWN: 104 return QE_KeyDown (wParam); 105 106 case WM_MBUTTONDOWN: 107 case WM_RBUTTONDOWN: 108 case WM_LBUTTONDOWN: 109 if ( GetTopWindow( g_qeglobals.d_hwndMain ) != hWnd) 110 BringWindowToTop(hWnd); 111 SetFocus( g_qeglobals.d_hwndXY ); 112 SetCapture( g_qeglobals.d_hwndXY ); 113 fwKeys = wParam; // key flags 114 xPos = (short)LOWORD(lParam); // horizontal position of cursor 115 yPos = (short)HIWORD(lParam); // vertical position of cursor 116 yPos = (int)rect.bottom - 1 - yPos; 117 XY_MouseDown (xPos, yPos, fwKeys); 118 return 0; 119 120 case WM_MBUTTONUP: 121 case WM_RBUTTONUP: 122 case WM_LBUTTONUP: 123 fwKeys = wParam; // key flags 124 xPos = (short)LOWORD(lParam); // horizontal position of cursor 125 yPos = (short)HIWORD(lParam); // vertical position of cursor 126 yPos = (int)rect.bottom - 1 - yPos; 127 XY_MouseUp (xPos, yPos, fwKeys); 128 if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON))) 129 ReleaseCapture (); 130 return 0; 131 132 case WM_MOUSEMOVE: 133 if (::GetFocus() != hWnd) 134 ::SetFocus(hWnd); 135 fwKeys = wParam; // key flags 136 xPos = (short)LOWORD(lParam); // horizontal position of cursor 137 yPos = (short)HIWORD(lParam); // vertical position of cursor 138 yPos = (int)rect.bottom - 1 - yPos; 139 XY_MouseMoved (xPos, yPos, fwKeys); 140 return 0; 141 142 case WM_SIZE: 143 g_qeglobals.d_xy.width = rect.right; 144 g_qeglobals.d_xy.height = rect.bottom - 16; 145 InvalidateRect( g_qeglobals.d_hwndXY, NULL, false); 146 return 0; 147 148 case WM_NCCALCSIZE:// don't let windows copy pixels 149 DefWindowProc (hWnd, uMsg, wParam, lParam); 150 return WVR_REDRAW; 151 152 case WM_KILLFOCUS: 153 case WM_SETFOCUS: 154 SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 ); 155 return 0; 156 157 case WM_CLOSE: 158 DestroyWindow (hWnd); 159 return 0; 160 } 161 162 return DefWindowProc (hWnd, uMsg, wParam, lParam); 163 } 164 165 166 /* 167 ============== 168 WXY_Create 169 ============== 170 */ 171 void WXY_Create (HINSTANCE hInstance) 172 { 173 ASSERT(0); 174 #if 0 175 WNDCLASS wc; 176 177 /* Register the camera class */ 178 memset (&wc, 0, sizeof(wc)); 179 180 wc.style = CS_NOCLOSE; 181 wc.lpfnWndProc = (WNDPROC)WXY_WndProc; 182 wc.cbClsExtra = 0; 183 wc.cbWndExtra = 0; 184 wc.hInstance = hInstance; 185 wc.hIcon = 0; 186 wc.hCursor = LoadCursor (NULL,IDC_ARROW); 187 wc.hbrBackground = NULL; //(HBRUSH)(COLOR_WINDOW+1); 188 wc.lpszMenuName = NULL; 189 wc.lpszClassName = XY_WINDOW_CLASS; 190 191 if (!RegisterClass (&wc) ) 192 Error ("RegisterClass: failed"); 193 194 g_qeglobals.d_hwndXY = CreateWindow (XY_WINDOW_CLASS , 195 "XY View", 196 QE3_STYLE , 197 ZWIN_WIDTH, 198 (int)(screen_height*CWIN_SIZE)-20, 199 screen_width-ZWIN_WIDTH, 200 (int)(screen_height*(1.0-CWIN_SIZE)-38), // size 201 202 g_qeglobals.d_hwndMain, // parent 203 0, // no menu 204 hInstance, 205 NULL); 206 207 if (!g_qeglobals.d_hwndXY ) 208 Error ("Couldn't create XY View"); 209 210 LoadWindowState(g_qeglobals.d_hwndXY, "xywindow"); 211 ShowWindow(g_qeglobals.d_hwndXY, SW_SHOWDEFAULT); 212 #endif 213 } 214 215 static void WXY_InitPixelFormat( PIXELFORMATDESCRIPTOR *pPFD ) 216 { 217 memset( pPFD, 0, sizeof( *pPFD ) ); 218 219 pPFD->nSize = sizeof( PIXELFORMATDESCRIPTOR ); 220 pPFD->nVersion = 1; 221 pPFD->dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; 222 pPFD->iPixelType = PFD_TYPE_RGBA; 223 pPFD->cColorBits = 24; 224 pPFD->cDepthBits = 32; 225 pPFD->iLayerType = PFD_MAIN_PLANE; 226 227 } 228 229 void WXY_Print( void ) 230 { 231 DOCINFO di; 232 233 PRINTDLG pd; 234 235 /* 236 ** initialize the PRINTDLG struct and execute it 237 */ 238 memset( &pd, 0, sizeof( pd ) ); 239 pd.lStructSize = sizeof( pd ); 240 pd.hwndOwner = g_qeglobals.d_hwndXY; 241 pd.Flags = PD_RETURNDC; 242 pd.hInstance = 0; 243 if ( !PrintDlg( &pd ) || !pd.hDC ) 244 { 245 MessageBox( g_qeglobals.d_hwndMain, "Could not PrintDlg()", "QE4 Print Error", MB_OK | MB_ICONERROR ); 246 return; 247 } 248 249 /* 250 ** StartDoc 251 */ 252 memset( &di, 0, sizeof( di ) ); 253 di.cbSize = sizeof( di ); 254 di.lpszDocName = "QE4"; 255 if ( StartDoc( pd.hDC, &di ) <= 0 ) 256 { 257 MessageBox( g_qeglobals.d_hwndMain, "Could not StartDoc()", "QE4 Print Error", MB_OK | MB_ICONERROR ); 258 return; 259 } 260 261 /* 262 ** StartPage 263 */ 264 if ( StartPage( pd.hDC ) <= 0 ) 265 { 266 MessageBox( g_qeglobals.d_hwndMain, "Could not StartPage()", "QE4 Print Error", MB_OK | MB_ICONERROR ); 267 return; 268 } 269 270 /* 271 ** read pixels from the XY window 272 */ 273 { 274 int bmwidth = 320, bmheight = 320; 275 int pwidth, pheight; 276 277 RECT r; 278 279 GetWindowRect( g_qeglobals.d_hwndXY, &r ); 280 281 bmwidth = r.right - r.left; 282 bmheight = r.bottom - r.top; 283 284 pwidth = GetDeviceCaps( pd.hDC, PHYSICALWIDTH ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETX ); 285 pheight = GetDeviceCaps( pd.hDC, PHYSICALHEIGHT ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETY ); 286 287 StretchBlt( pd.hDC, 288 0, 0, 289 pwidth, pheight, 290 s_hdcXY, 291 0, 0, 292 bmwidth, bmheight, 293 SRCCOPY ); 294 } 295 296 /* 297 ** EndPage and EndDoc 298 */ 299 if ( EndPage( pd.hDC ) <= 0 ) 300 { 301 MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndPage()", MB_OK | MB_ICONERROR ); 302 return; 303 } 304 305 if ( EndDoc( pd.hDC ) <= 0 ) 306 { 307 MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndDoc()", MB_OK | MB_ICONERROR ); 308 return; 309 } 310 }