]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake2/extra/qe4/win_z.c
a7233c8cf33d22cbf03a3689e9ac5dac8bb640e5
[xonotic/netradiant.git] / tools / quake2 / extra / qe4 / win_z.c
1 /*
2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
4
5 This file is part of Quake 2 Tools source code.
6
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.
11
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.
16
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 ===========================================================================
21 */
22
23 // win_cam.c -- windows specific camera view code
24
25 #include "qe3.h"
26
27 static HDC   s_hdcZ;
28 static HGLRC s_hglrcZ;
29
30 /*
31 ============
32 WZ_WndProc
33 ============
34 */
35 LONG WINAPI WZ_WndProc (
36     HWND    hWnd,
37     UINT    uMsg,
38     WPARAM  wParam,
39     LPARAM  lParam)
40 {
41         int             fwKeys, xPos, yPos;
42     RECT        rect;
43
44     GetClientRect(hWnd, &rect);
45
46     switch (uMsg)
47     {
48
49         case WM_DESTROY:
50                 QEW_StopGL( hWnd, s_hglrcZ, s_hdcZ );
51                 return 0;
52
53         case WM_CREATE:
54         s_hdcZ = GetDC(hWnd);
55             QEW_SetupPixelFormat( s_hdcZ, false);
56                 if ( ( s_hglrcZ = wglCreateContext( s_hdcZ ) ) == 0 )
57                         Error( "wglCreateContext in WZ_WndProc failed" );
58
59         if (!wglMakeCurrent( s_hdcZ, s_hglrcZ ))
60                         Error ("wglMakeCurrent in WZ_WndProc failed");
61
62                 if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcZ ) )
63                         Error( "wglShareLists in WZ_WndProc failed" );
64                 return 0;
65
66         case WM_PAINT:
67         {
68                     PAINTSTRUCT ps;
69
70                     BeginPaint(hWnd, &ps);
71
72             if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) )
73                                 Error ("wglMakeCurrent failed");
74                         QE_CheckOpenGLForErrors();
75
76                         Z_Draw ();
77                     SwapBuffers(s_hdcZ);
78
79                         EndPaint(hWnd, &ps);
80         }
81                 return 0;
82
83
84         case WM_KEYDOWN:
85                 QE_KeyDown (wParam);
86                 return 0;
87
88         case WM_MBUTTONDOWN:
89         case WM_RBUTTONDOWN:
90         case WM_LBUTTONDOWN:
91                 if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
92                         BringWindowToTop(hWnd);
93
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);
101                 return 0;
102
103         case WM_MBUTTONUP:
104         case WM_RBUTTONUP:
105         case WM_LBUTTONUP:
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)))
112                         ReleaseCapture ();
113                 return 0;
114
115         case WM_GETMINMAXINFO:
116         {
117                 MINMAXINFO *pmmi = (LPMINMAXINFO) lParam;
118
119                 pmmi->ptMinTrackSize.x = ZWIN_WIDTH;
120                 return 0;
121         }
122
123         case WM_MOUSEMOVE:
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);
129                 return 0;
130
131     case WM_SIZE:
132                 z.width = rect.right;
133                 z.height = rect.bottom;
134                 InvalidateRect( g_qeglobals.d_hwndZ, NULL, false);
135                 return 0;
136
137         case WM_NCCALCSIZE:// don't let windows copy pixels
138                 DefWindowProc (hWnd, uMsg, wParam, lParam);
139                 return WVR_REDRAW;
140
141         case WM_KILLFOCUS:
142         case WM_SETFOCUS:
143                 SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
144                 return 0;
145
146         case WM_CLOSE:
147         /* call destroy window to cleanup and go away */
148         DestroyWindow (hWnd);
149                 return 0;
150     }
151
152         return DefWindowProc (hWnd, uMsg, wParam, lParam);
153 }
154
155
156 /*
157 ==============
158 WZ_Create
159 ==============
160 */
161 void WZ_Create (HINSTANCE hInstance)
162 {
163     WNDCLASS   wc;
164
165     /* Register the camera class */
166         memset (&wc, 0, sizeof(wc));
167
168     wc.style         = 0;
169     wc.lpfnWndProc   = (WNDPROC)WZ_WndProc;
170     wc.cbClsExtra    = 0;
171     wc.cbWndExtra    = 0;
172     wc.hInstance     = hInstance;
173     wc.hIcon         = 0;
174     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
175     wc.hbrBackground = NULL;
176     wc.lpszMenuName  = NULL;
177     wc.lpszClassName = Z_WINDOW_CLASS;
178
179     if (!RegisterClass (&wc) )
180         Error ("WCam_Register: failed");
181
182         g_qeglobals.d_hwndZ = CreateWindow (Z_WINDOW_CLASS ,
183                 "Z",
184                 QE3_STYLE,
185                 0,20,ZWIN_WIDTH,screen_height-38,       // size
186                 g_qeglobals.d_hwndMain, // parent
187                 0,              // no menu
188                 hInstance,
189                 NULL);
190         if (!g_qeglobals.d_hwndZ)
191                 Error ("Couldn't create zwindow");
192
193         LoadWindowState(g_qeglobals.d_hwndZ, "zwindow");
194     ShowWindow (g_qeglobals.d_hwndZ, SW_SHOWDEFAULT);
195 }