forked from id-Software/Quake-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin_next.m
More file actions
332 lines (259 loc) · 6.49 KB
/
in_next.m
File metadata and controls
332 lines (259 loc) · 6.49 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// in_next.m
#import <AppKit/AppKit.h>
#import <drivers/event_status_driver.h>
#include "../client/client.h"
float mousex, mousey;
float mouse_center_x = 160;
float mouse_center_y = 100;
void PSsetmouse (float x, float y);
void PSshowcursor (void);
void PShidecursor (void);
void PScurrentmouse (int win, float *x, float *y);
extern NSView *vid_view_i;
extern NSWindow *vid_window_i;
qboolean mlooking;
qboolean mouseinitialized;
int mouse_buttons;
int mouse_oldbuttonstate;
int mouseactive;
int mousereset;
int mx_accum, my_accum;
int window_center_x, window_center_y;
int old_mouse_x, old_mouse_y;
cvar_t in_mouse = {"in_mouse", "0", CVAR_ARCHIVE};
cvar_t m_filter = {"m_filter", "0", CVAR_ARCHIVE};
cvar_t freelook = {"in_freelook", "0", CVAR_ARCHIVE};
/*
===========
IN_ActivateMouse
Called when the window gains focus or changes in some way
===========
*/
void IN_ActivateMouse (void)
{
NSRect r;
if (!mouseinitialized)
return;
if (!in_mouse.value)
return;
r = [vid_window_i frame];
window_center_x = r.size.width / 2;
window_center_y = r.size.height / 2;
if (!mouseactive)
PShidecursor ();
mouseactive = true;
mousereset = true;
}
/*
===========
IN_DeactivateMouse
Called when the window loses focus
===========
*/
void IN_DeactivateMouse (void)
{
if (!mouseinitialized)
return;
if (mouseactive)
PSshowcursor ();
mouseactive = false;
}
/*
===========
IN_StartupMouse
===========
*/
void IN_StartupMouse (void)
{
if ( COM_CheckParm ("-nomouse") )
return;
mouseinitialized = true;
mouse_buttons = 3;
IN_ActivateMouse ();
}
/*
===========
IN_MouseEvent
===========
*/
void IN_MouseEvent (int mstate)
{
int i;
if (!mouseactive)
return;
// perform button actions
for (i=0 ; i<mouse_buttons ; i++)
{
if ( (mstate & (1<<i)) &&
!(mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, true);
}
if ( !(mstate & (1<<i)) &&
(mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, false);
}
}
mouse_oldbuttonstate = mstate;
}
/*
===========
IN_Accumulate
===========
*/
void IN_Accumulate (void)
{
int dx, dy;
static int old_x, old_y;
if (!mouseinitialized)
return;
if (in_mouse.modified)
{
in_mouse.modified = false;
IN_DeactivateMouse ();
IN_ActivateMouse ();
}
if (!mouseactive)
return;
// [vid_view_i lockFocus];
if (mousereset)
{ // we haven't centered cursor yet
mousereset = false;
}
else
{
NSPoint p;
PScurrentmouse ([vid_window_i windowNumber], &mousex, &mousey);
p.x = mousex;
p.y = mousey;
p = [vid_view_i convertPoint:p fromView: nil];
mousex = p.x;
mousey = p.y;
dx = mousex - old_x;
dy = old_y - mousey;
if (!dx && !dy)
return;
mx_accum += dx;
my_accum += dy;
}
// force the mouse to the center, so there's room to move
PSsetmouse (window_center_x, window_center_y);
PScurrentmouse ([vid_window_i windowNumber], &mousex, &mousey);
// PSsetmouse (window_center_x, window_center_y);
old_x = window_center_x;
old_y = window_center_y;
// [vid_view_i unlockFocus];
}
/*
===========
IN_MouseMove
===========
*/
void IN_MouseMove (usercmd_t *cmd)
{
int mx, my;
int mouse_x, mouse_y;
IN_Accumulate ();
mx = mx_accum;
my = my_accum;
mx_accum = 0;
my_accum = 0;
if (m_filter.value)
{
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
}
else
{
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
if (!mx && !my)
return;
if (!mouseactive)
return;
mouse_x *= sensitivity.value;
mouse_y *= sensitivity.value;
// add mouse X/Y movement to cmd
if ( (in_strafe.state & 1) || (lookstrafe.value && mlooking ))
cmd->sidemove += m_side.value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw.value * mouse_x;
if ( (mlooking || freelook.value) && !(in_strafe.state & 1))
{
cl.viewangles[PITCH] += m_pitch.value * mouse_y;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
}
else
{
cmd->forwardmove -= m_forward.value * mouse_y;
}
}
void IN_ShowMouse (void)
{
PSshowcursor ();
}
void IN_HideMouse (void)
{
PShidecursor ();
}
NXEventHandle eventhandle;
NXMouseScaling oldscaling, newscaling;
NXMouseButton oldbutton;
/*
=============
IN_Init
=============
*/
void IN_Init (void)
{
Cvar_RegisterVariable (&in_mouse);
Cvar_RegisterVariable (&m_filter);
Cvar_RegisterVariable (&freelook);
Cmd_AddCommand ("showmouse", IN_ShowMouse);
Cmd_AddCommand ("hidemouse", IN_HideMouse);
IN_StartupMouse ();
// open the event status driver
eventhandle = NXOpenEventStatus();
NXGetMouseScaling (eventhandle, &oldscaling);
NXSetMouseScaling (eventhandle, &newscaling);
oldbutton = NXMouseButtonEnabled (eventhandle);
NXEnableMouseButton (eventhandle, 2);
}
/*
=============
IN_Shutdown
=============
*/
void IN_Shutdown (void)
{
IN_DeactivateMouse ();
// put mouse scaling back the way it was
NXSetMouseScaling (eventhandle, &oldscaling);
NXEnableMouseButton (eventhandle, oldbutton);
NXCloseEventStatus (eventhandle);
}
void IN_Move (usercmd_t *cmd)
{
IN_MouseMove (cmd);
}
void IN_Commands (void)
{
}
/*
=========================================================================
VIEW CENTERING
=========================================================================
*/
void V_StopPitchDrift (void)
{
cl.laststop = cl.time;
cl.nodrift = true;
cl.pitchvel = 0;
}