2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools 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.
12 Quake 2 Tools 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.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
23 // win_xy.c -- windows specific xy view code
28 static HGLRC s_hglrcXY;
30 static unsigned s_stipple[32] =
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,
47 LONG WINAPI WXY_WndProc (
53 int fwKeys, xPos, yPos;
57 GetClientRect(hWnd, &rect);
63 s_hdcXY = GetDC(hWnd);
65 QEW_SetupPixelFormat(s_hdcXY, false);
67 if ( ( s_hglrcXY = wglCreateContext( s_hdcXY ) ) == 0 )
68 Error( "wglCreateContext in WXY_WndProc failed" );
70 if (!wglMakeCurrent( s_hdcXY, s_hglrcXY ))
71 Error ("wglMakeCurrent failed");
73 if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcXY ) )
74 Error( "wglShareLists in WXY_WndProc failed" );
76 glPolygonStipple ((char *)s_stipple);
77 glLineStipple (3, 0xaaaa);
82 QEW_StopGL( hWnd, s_hglrcXY, s_hdcXY );
89 BeginPaint(hWnd, &ps);
91 if (!wglMakeCurrent( s_hdcXY, s_hglrcXY ))
92 Error ("wglMakeCurrent failed");
94 QE_CheckOpenGLForErrors();
96 QE_CheckOpenGLForErrors();
105 return QE_KeyDown (wParam);
110 if ( GetTopWindow( g_qeglobals.d_hwndMain ) != hWnd)
111 BringWindowToTop(hWnd);
112 SetFocus( g_qeglobals.d_hwndXY );
113 SetCapture( g_qeglobals.d_hwndXY );
114 fwKeys = wParam; // key flags
115 xPos = (short)LOWORD(lParam); // horizontal position of cursor
116 yPos = (short)HIWORD(lParam); // vertical position of cursor
117 yPos = (int)rect.bottom - 1 - yPos;
118 XY_MouseDown (xPos, yPos, fwKeys);
124 fwKeys = wParam; // key flags
125 xPos = (short)LOWORD(lParam); // horizontal position of cursor
126 yPos = (short)HIWORD(lParam); // vertical position of cursor
127 yPos = (int)rect.bottom - 1 - yPos;
128 XY_MouseUp (xPos, yPos, fwKeys);
129 if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
134 fwKeys = wParam; // key flags
135 xPos = (short)LOWORD(lParam); // horizontal position of cursor
136 yPos = (short)HIWORD(lParam); // vertical position of cursor
137 yPos = (int)rect.bottom - 1 - yPos;
138 XY_MouseMoved (xPos, yPos, fwKeys);
142 g_qeglobals.d_xy.width = rect.right;
143 g_qeglobals.d_xy.height = rect.bottom;
144 InvalidateRect( g_qeglobals.d_hwndXY, NULL, false);
147 case WM_NCCALCSIZE:// don't let windows copy pixels
148 DefWindowProc (hWnd, uMsg, wParam, lParam);
153 SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
157 DestroyWindow (hWnd);
161 return DefWindowProc (hWnd, uMsg, wParam, lParam);
170 void WXY_Create (HINSTANCE hInstance)
174 /* Register the camera class */
175 memset (&wc, 0, sizeof(wc));
178 wc.lpfnWndProc = (WNDPROC)WXY_WndProc;
181 wc.hInstance = hInstance;
183 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
184 wc.hbrBackground = NULL; //(HBRUSH)(COLOR_WINDOW+1);
185 wc.lpszMenuName = NULL;
186 wc.lpszClassName = XY_WINDOW_CLASS;
188 if (!RegisterClass (&wc) )
189 Error ("RegisterClass: failed");
191 g_qeglobals.d_hwndXY = CreateWindow (XY_WINDOW_CLASS ,
195 (int)(screen_height*CWIN_SIZE)-20,
196 screen_width-ZWIN_WIDTH,
197 (int)(screen_height*(1.0-CWIN_SIZE)-38), // size
199 g_qeglobals.d_hwndMain, // parent
204 if (!g_qeglobals.d_hwndXY )
205 Error ("Couldn't create XY View");
207 LoadWindowState(g_qeglobals.d_hwndXY, "xywindow");
208 ShowWindow(g_qeglobals.d_hwndXY, SW_SHOWDEFAULT);
211 static void WXY_InitPixelFormat( PIXELFORMATDESCRIPTOR *pPFD )
213 memset( pPFD, 0, sizeof( *pPFD ) );
215 pPFD->nSize = sizeof( PIXELFORMATDESCRIPTOR );
217 pPFD->dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
218 pPFD->iPixelType = PFD_TYPE_RGBA;
219 pPFD->cColorBits = 24;
220 pPFD->cDepthBits = 32;
221 pPFD->iLayerType = PFD_MAIN_PLANE;
225 void WXY_Print( void )
232 ** initialize the PRINTDLG struct and execute it
234 memset( &pd, 0, sizeof( pd ) );
235 pd.lStructSize = sizeof( pd );
236 pd.hwndOwner = g_qeglobals.d_hwndXY;
237 pd.Flags = PD_RETURNDC;
239 if ( !PrintDlg( &pd ) || !pd.hDC )
241 MessageBox( g_qeglobals.d_hwndMain, "Could not PrintDlg()", "QE4 Print Error", MB_OK | MB_ICONERROR );
248 memset( &di, 0, sizeof( di ) );
249 di.cbSize = sizeof( di );
250 di.lpszDocName = "QE4";
251 if ( StartDoc( pd.hDC, &di ) <= 0 )
253 MessageBox( g_qeglobals.d_hwndMain, "Could not StartDoc()", "QE4 Print Error", MB_OK | MB_ICONERROR );
260 if ( StartPage( pd.hDC ) <= 0 )
262 MessageBox( g_qeglobals.d_hwndMain, "Could not StartPage()", "QE4 Print Error", MB_OK | MB_ICONERROR );
267 ** read pixels from the XY window
270 int bmwidth = 320, bmheight = 320;
275 GetWindowRect( g_qeglobals.d_hwndXY, &r );
277 bmwidth = r.right - r.left;
278 bmheight = r.bottom - r.top;
280 pwidth = GetDeviceCaps( pd.hDC, PHYSICALWIDTH ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETX );
281 pheight = GetDeviceCaps( pd.hDC, PHYSICALHEIGHT ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETY );
293 ** EndPage and EndDoc
295 if ( EndPage( pd.hDC ) <= 0 )
297 MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndPage()", MB_OK | MB_ICONERROR );
301 if ( EndDoc( pd.hDC ) <= 0 )
303 MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndDoc()", MB_OK | MB_ICONERROR );