// in_next.m #import #import #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 ; isidemove += 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; }