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_cam.c -- windows specific camera view code
28 static HGLRC s_hglrcZ;
35 LONG WINAPI WZ_WndProc (
41 int fwKeys, xPos, yPos;
44 GetClientRect(hWnd, &rect);
50 QEW_StopGL( hWnd, s_hglrcZ, s_hdcZ );
55 QEW_SetupPixelFormat( s_hdcZ, false);
56 if ( ( s_hglrcZ = wglCreateContext( s_hdcZ ) ) == 0 )
57 Error( "wglCreateContext in WZ_WndProc failed" );
59 if (!wglMakeCurrent( s_hdcZ, s_hglrcZ ))
60 Error ("wglMakeCurrent in WZ_WndProc failed");
62 if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcZ ) )
63 Error( "wglShareLists in WZ_WndProc failed" );
70 BeginPaint(hWnd, &ps);
72 if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) )
73 Error ("wglMakeCurrent failed");
74 QE_CheckOpenGLForErrors();
91 if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
92 BringWindowToTop(hWnd);
94 SetFocus( g_qeglobals.d_hwndZ );
95 SetCapture( g_qeglobals.d_hwndZ );
96 fwKeys = wParam; // key flags
97 xPos = (short)LOWORD(lParam); // horizontal position of cursor
98 yPos = (short)HIWORD(lParam); // vertical position of cursor
99 yPos = (int)rect.bottom - 1 - yPos;
100 Z_MouseDown (xPos, yPos, fwKeys);
106 fwKeys = wParam; // key flags
107 xPos = (short)LOWORD(lParam); // horizontal position of cursor
108 yPos = (short)HIWORD(lParam); // vertical position of cursor
109 yPos = (int)rect.bottom - 1 - yPos;
110 Z_MouseUp (xPos, yPos, fwKeys);
111 if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
115 case WM_GETMINMAXINFO:
117 MINMAXINFO *pmmi = (LPMINMAXINFO) lParam;
119 pmmi->ptMinTrackSize.x = ZWIN_WIDTH;
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 Z_MouseMoved (xPos, yPos, fwKeys);
132 z.width = rect.right;
133 z.height = rect.bottom;
134 InvalidateRect( g_qeglobals.d_hwndZ, NULL, false);
137 case WM_NCCALCSIZE:// don't let windows copy pixels
138 DefWindowProc (hWnd, uMsg, wParam, lParam);
143 SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
147 /* call destroy window to cleanup and go away */
148 DestroyWindow (hWnd);
152 return DefWindowProc (hWnd, uMsg, wParam, lParam);
161 void WZ_Create (HINSTANCE hInstance)
165 /* Register the camera class */
166 memset (&wc, 0, sizeof(wc));
169 wc.lpfnWndProc = (WNDPROC)WZ_WndProc;
172 wc.hInstance = hInstance;
174 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
175 wc.hbrBackground = NULL;
176 wc.lpszMenuName = NULL;
177 wc.lpszClassName = Z_WINDOW_CLASS;
179 if (!RegisterClass (&wc) )
180 Error ("WCam_Register: failed");
182 g_qeglobals.d_hwndZ = CreateWindow (Z_WINDOW_CLASS ,
185 0,20,ZWIN_WIDTH,screen_height-38, // size
186 g_qeglobals.d_hwndMain, // parent
190 if (!g_qeglobals.d_hwndZ)
191 Error ("Couldn't create zwindow");
193 LoadWindowState(g_qeglobals.d_hwndZ, "zwindow");
194 ShowWindow (g_qeglobals.d_hwndZ, SW_SHOWDEFAULT);