-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_z.c
174 lines (139 loc) · 4.06 KB
/
win_z.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// win_z.c -- windows specific z view code
#include "qe3.h"
static HDC s_hdcZ;
static HGLRC s_hglrcZ;
/*
============
WZ_WndProc
============
*/
LONG WINAPI WZ_WndProc (
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
int fwKeys, xPos, yPos;
RECT rect;
GetClientRect(hWnd, &rect);
switch (uMsg)
{
case WM_DESTROY:
QEW_StopGL( hWnd, s_hglrcZ, s_hdcZ );
return 0;
case WM_CREATE:
s_hdcZ = GetDC(hWnd);
QEW_SetupPixelFormat( s_hdcZ, false);
if ( ( s_hglrcZ = wglCreateContext( s_hdcZ ) ) == 0 )
Error( "wglCreateContext in WZ_WndProc failed" );
if (!wglMakeCurrent( s_hdcZ, s_hglrcZ ))
Error ("wglMakeCurrent in WZ_WndProc failed");
if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcZ ) )
Error( "wglShareLists in WZ_WndProc failed" );
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) )
Error ("wglMakeCurrent failed");
QE_CheckOpenGLForErrors();
Z_Draw ();
SwapBuffers(s_hdcZ);
EndPaint(hWnd, &ps);
}
return 0;
case WM_KEYDOWN:
QE_KeyDown (wParam);
return 0;
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONDOWN:
if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
BringWindowToTop(hWnd);
SetFocus( g_qeglobals.d_hwndZ );
SetCapture( g_qeglobals.d_hwndZ );
fwKeys = wParam; // key flags
xPos = (short)LOWORD(lParam); // horizontal position of cursor
yPos = (short)HIWORD(lParam); // vertical position of cursor
yPos = (int)rect.bottom - 1 - yPos;
Z_MouseDown (xPos, yPos, fwKeys);
return 0;
case WM_MBUTTONUP:
case WM_RBUTTONUP:
case WM_LBUTTONUP:
fwKeys = wParam; // key flags
xPos = (short)LOWORD(lParam); // horizontal position of cursor
yPos = (short)HIWORD(lParam); // vertical position of cursor
yPos = (int)rect.bottom - 1 - yPos;
Z_MouseUp (xPos, yPos, fwKeys);
if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
ReleaseCapture ();
return 0;
case WM_GETMINMAXINFO:
{
MINMAXINFO *pmmi = (LPMINMAXINFO) lParam;
pmmi->ptMinTrackSize.x = ZWIN_WIDTH;
return 0;
}
case WM_MOUSEMOVE:
fwKeys = wParam; // key flags
xPos = (short)LOWORD(lParam); // horizontal position of cursor
yPos = (short)HIWORD(lParam); // vertical position of cursor
yPos = (int)rect.bottom - 1 - yPos;
Z_MouseMoved (xPos, yPos, fwKeys);
return 0;
case WM_SIZE:
g_qeglobals.d_z.width = rect.right;
g_qeglobals.d_z.height = rect.bottom;
InvalidateRect( g_qeglobals.d_hwndZ, NULL, false);
return 0;
case WM_NCCALCSIZE:// don't let windows copy pixels
DefWindowProc (hWnd, uMsg, wParam, lParam);
return WVR_REDRAW;
case WM_KILLFOCUS:
case WM_SETFOCUS:
SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
return 0;
case WM_CLOSE:
/* call destroy window to cleanup and go away */
DestroyWindow (hWnd);
return 0;
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
/*
==============
WZ_Create
==============
*/
void WZ_Create (HINSTANCE hInstance)
{
WNDCLASS wc;
/* Register the z class */
memset (&wc, 0, sizeof(wc));
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)WZ_WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = Z_WINDOW_CLASS;
if (!RegisterClass (&wc) )
Error ("WZ_Register: failed");
g_qeglobals.d_hwndZ = CreateWindow (Z_WINDOW_CLASS ,
"Z",
QE3_STYLE,
0,20,ZWIN_WIDTH,screen_height-38, // size
g_qeglobals.d_hwndMain, // parent
0, // no menu
hInstance,
NULL);
if (!g_qeglobals.d_hwndZ)
Error ("Couldn't create Z Window");
LoadWindowState(g_qeglobals.d_hwndZ, "zwindow");
ShowWindow (g_qeglobals.d_hwndZ, SW_SHOWDEFAULT);
}