/* ============ VID_CheckChanges This function gets called once just before drawing each frame, and it's sole purpose in life is to check to see if any of the video mode parameters have changed, and if they have to update the rendering DLL and/or video mode to match. ============ */ void VID_CheckChanges (void) { if ( vid_restart ) { cl.force_refdef = true; // can't use a paused refdef S_StopAllSounds(); /* ** refresh has changed */ vid_fullscreen->modified = true; cl.refresh_prepped = false; cls.disable_screen = true; VID_Shutdown(); Com_Printf( "--------- [Loading Renderer] ---------\n" ); vid_active = true; if ( R_Init( 0, 0 ) == -1 ) { R_Shutdown(); Com_Error (ERR_FATAL, "Couldn't initialize renderer!"); } Com_Printf( "------------------------------------\n"); vid_restart = false; cls.disable_screen = false; IN_Activate(false); IN_Activate(true); } }
void AppActivate(BOOL fActive, BOOL minimize) { Minimized = minimize; Key_ClearStates(); // we don't want to act like we're active if we're minimized if (fActive && !Minimized) ActiveApp = true; else ActiveApp = false; // minimize/restore mouse-capture on demand if (!ActiveApp) { IN_Activate (false); CDAudio_Activate (false); S_Activate (false); if ( win_noalttab->value ) { WIN_EnableAltTab(); } } else { IN_Activate (true); CDAudio_Activate (true); S_Activate (true); if ( win_noalttab->value ) { WIN_DisableAltTab(); } } }
void IN_Frame (void) { if (!mouse_avail) return; if ( !cl.refresh_prepped || cls.key_dest == key_console || cls.key_dest == key_menu) IN_Activate(false); else IN_Activate(true); }
/* ====================== Host_Map_f handle a map <servername> command from the console. Active clients are kicked off. ====================== */ void Host_Map_f (void) { int i; char name[MAX_QPATH], *p; if (Cmd_Argc() < 2) //no map name given { if (cls.state == ca_dedicated) { if (sv.active) Con_Printf ("Current map: %s\n", sv.name); else Con_Printf ("Server not active\n"); } else if (cls.state == ca_connected) { Con_Printf ("Current map: %s ( %s )\n", cl.levelname, cl.mapname); } else { Con_Printf ("map <levelname>: start a new server\n"); } return; } if (cmd_source != src_command) return; cls.demonum = -1; // stop demo loop in case this fails CL_Disconnect (); Host_ShutdownServer(false); if (cls.state != ca_dedicated) IN_Activate(); key_dest = key_game; // remove console or menu SCR_BeginLoadingPlaque (); svs.serverflags = 0; // haven't completed an episode yet q_strlcpy (name, Cmd_Argv(1), sizeof(name)); // remove (any) trailing ".bsp" from mapname -- S.A. p = strstr(name, ".bsp"); if (p && p[4] == '\0') *p = '\0'; SV_SpawnServer (name); if (!sv.active) return; if (cls.state != ca_dedicated) { memset (cls.spawnparms, 0, MAX_MAPSTRING); for (i = 2; i < Cmd_Argc(); i++) { q_strlcat (cls.spawnparms, Cmd_Argv(i), MAX_MAPSTRING); q_strlcat (cls.spawnparms, " ", MAX_MAPSTRING); } Cmd_ExecuteString ("connect local", src_command); } }
/* ================== Host_Changelevel_f Goes to a new map, taking all clients along ================== */ void Host_Changelevel_f (void) { char level[MAX_QPATH]; if (Cmd_Argc() != 2) { Con_Printf ("changelevel <levelname> : continue game on a new level\n"); return; } if (!sv.active || cls.demoplayback) { Con_Printf ("Only the server may changelevel\n"); return; } //johnfitz -- check for client having map before anything else q_snprintf (level, sizeof(level), "maps/%s.bsp", Cmd_Argv(1)); if (!COM_FileExists(level, NULL)) Host_Error ("cannot find map %s", level); //johnfitz if (cls.state != ca_dedicated) IN_Activate(); // -- S.A. key_dest = key_game; // remove console or menu SV_SaveSpawnparms (); q_strlcpy (level, Cmd_Argv(1), sizeof(level)); SV_SpawnServer (level); // also issue an error if spawn failed -- O.S. if (!sv.active) Host_Error ("cannot run map %s", level); }
// new proc by S.A., called by alt-return key binding. void VID_Toggle (void) { static qboolean vid_toggle_works = true; S_ClearBuffer (); if (!vid_toggle_works) goto vrestart; if (SDL_WM_ToggleFullScreen(draw_context) == 1) { Sbar_Changed (); // Sbar seems to need refreshing modestate = draw_context->flags & SDL_FULLSCREEN ? MS_FULLSCREEN : MS_WINDOWED; VID_SyncCvars(); // update mouse grab if (key_dest == key_console || key_dest == key_menu) { if (modestate == MS_WINDOWED) IN_Deactivate(true); else if (modestate == MS_FULLSCREEN) IN_Activate(); } } else { vid_toggle_works = false; Con_DPrintf ("SDL_WM_ToggleFullScreen failed, attempting VID_Restart\n"); vrestart: Cvar_SetQuick (&vid_fullscreen, draw_context-> flags & SDL_FULLSCREEN ? "0" : "1"); Cbuf_AddText ("vid_restart\n"); } }
void IN_Init (void) { textmode = Key_TextEntry(); if (textmode) SDL_StartTextInput(); else SDL_StopTextInput(); if (safemode || COM_CheckParm("-nomouse")) { no_mouse = true; /* discard all mouse events when input is deactivated */ IN_BeginIgnoringMouseEvents(); } Cvar_RegisterVariable(&in_debugkeys); Cvar_RegisterVariable(&joy_sensitivity_yaw); Cvar_RegisterVariable(&joy_sensitivity_pitch); Cvar_RegisterVariable(&joy_deadzone); Cvar_RegisterVariable(&joy_deadzone_trigger); Cvar_RegisterVariable(&joy_invert); Cvar_RegisterVariable(&joy_exponent); Cvar_RegisterVariable(&joy_swapmovelook); Cvar_RegisterVariable(&joy_enable); IN_Activate(); IN_StartupJoystick(); }
/* * IN_Frame * * Called every frame, even if not generating commands */ void IN_Frame( void ) { extern cvar_t *vid_fullscreen; if( !mouseinitialized ) { return; } if( vid_fullscreen ) { if( !vid_fullscreen->integer || cl_parent_hwnd ) { extern cvar_t *in_grabinconsole; // if we have a parent window (say, a browser plugin window) and // the window is not focused, deactivate the input if( cl_parent_hwnd && !AppFocused ) { if( in_appactive ) { IN_Activate( false ); } } else if( in_grabinconsole->integer || cls.key_dest != key_console ) { if( !in_appactive && ActiveApp ) { IN_Activate( true ); } } else { if( in_appactive ) { IN_Activate( false ); } } } else { if( !ActiveApp && in_appactive ) { IN_Activate( false ); } else if( ActiveApp && !in_appactive ) { IN_Activate( true ); } } } if( !in_mouse || !in_appactive ) { IN_DeactivateMouse(); return; } IN_ActivateMouse(); }
void IN_Shutdown (void) { if (!mouse_avail) return; IN_Activate(false); mouse_avail = false; Cmd_RemoveCommand ("+mlook"); Cmd_RemoveCommand ("-mlook"); Cmd_RemoveCommand ("force_centerview"); }
static void AppActivate( bool fActive, bool minimize ) { Minimized = minimize; common->DPrintf( "AppActivate: %i\n", fActive ); Key_ClearStates(); // FIXME!!! // we don't want to act like we're active if we're minimized ActiveApp = fActive && !Minimized; // minimize/restore mouse-capture on demand IN_Activate( ActiveApp ); CDAudio_Activate( ActiveApp ); SNDDMA_Activate(); }
void IN_Frame( void ) { if( !input_inited ) return; if( !mapped || ( ( x11display.features.wmStateFullscreen || !Cvar_Value( "vid_fullscreen" ) ) && ( !focus || ( ( cls.key_dest == key_console ) && !in_grabinconsole->integer ) ) ) ) { if( input_active ) IN_Activate( qfalse ); } else { if( !input_active ) IN_Activate( qtrue ); } HandleEvents(); if( input_active && in_dgamouse->modified ) { uninstall_grabs(); install_grabs(); } }
/* =================== Key_SetDest =================== */ void Key_SetDest(keydest_t dest) { int diff; // if not connected, console or menu should be up if (cls.state < ca_active && !(dest & (KEY_MENU | KEY_CONSOLE))) { dest |= KEY_CONSOLE; } diff = cls.key_dest ^ dest; cls.key_dest = dest; // activate or deactivate mouse if (diff & (KEY_CONSOLE | KEY_MENU)) { IN_Activate(); CL_CheckForPause(); } }
/* ============ IN_Init ============ */ void IN_Init( void ) { qboolean ret = qfalse; #if USE_LIRC Lirc_Init(); #endif in_enable = Cvar_Get( "in_enable", "1", 0 ); in_enable->changed = in_param_changed; if( !in_enable->integer ) { Com_Printf( "Mouse input disabled.\n" ); return; } #if USE_DINPUT in_direct = Cvar_Get( "in_direct", "1", 0 ); if( in_direct->integer ) { DI_FillAPI( &input.api ); ret = input.api.Init(); if( !ret ) { Cvar_Set( "in_direct", "0" ); } } #endif if( !ret ) { VID_FillInputAPI( &input.api ); ret = input.api.Init(); if( !ret ) { Cvar_Set( "in_enable", "0" ); return; } } #if USE_DINPUT in_direct->changed = in_param_changed; #endif in_smart_grab = Cvar_Get( "in_smart_grab", "0", 0 ); in_smart_grab->changed = in_smart_grab_changed; input.initialized = qtrue; IN_Activate(); }
void IN_Init (void) { // mouse variables m_filter = Cvar_Get ("m_filter", "0", 0); in_mouse = Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE); // on-screen keyboard variables in_osk = Cvar_Get ("in_osk", "0", CVAR_ARCHIVE); // Wii Remote look mode variables in_wlook = Cvar_Get ("in_wlook", "0", CVAR_ARCHIVE); // Wii Remote variables in_wmote = Cvar_Get ("in_wmote", "1", CVAR_ARCHIVE); in_wmotemovscale = Cvar_Get ("in_wmotemovscale", "3", CVAR_ARCHIVE); in_wmotevangscale = Cvar_Get ("in_wmotevangscale", "3", CVAR_ARCHIVE); in_wmotemovmin = Cvar_Get ("in_wmotemovmin", "4", CVAR_ARCHIVE); // Gamecube controller variables in_gcpad = Cvar_Get ("in_gcpad", "1", CVAR_ARCHIVE); in_gcpadmovscale = Cvar_Get ("in_gcpadmovscale", "3", CVAR_ARCHIVE); in_gcpadmovmin = Cvar_Get ("in_gcpadmovmin", "0", CVAR_ARCHIVE); // Classic controller variables in_clsct = Cvar_Get ("in_clsct", "1", CVAR_ARCHIVE); in_clsctmovscale = Cvar_Get ("in_clsctmovscale", "9", CVAR_ARCHIVE); in_clsctvangscale = Cvar_Get ("in_clsctvangscale", "9", CVAR_ARCHIVE); in_clsctmovmin = Cvar_Get ("in_clsctmovmin", "0", CVAR_ARCHIVE); // joystick variables in_joystick = Cvar_Get ("in_joystick", "0", CVAR_ARCHIVE); Cmd_AddCommand ("+mlook", IN_MLookDown); Cmd_AddCommand ("-mlook", IN_MLookUp); IN_StartupMouse (); IN_StartupWmote (); IN_StartupGCPad (); IN_StartupClsCt (); IN_Activate(true); }
void IN_Frame( void ) { qboolean m_active = qfalse; if( !input_inited ) return; HandleEvents(); if( focus ) { if( !Cvar_Value( "vid_fullscreen" ) && ( ( cls.key_dest == key_console ) && !in_grabinconsole->integer ) ) { m_active = qfalse; } else { m_active = qtrue; } } IN_Activate( m_active ); }
/* =================== VID_Restart -- johnfitz -- change video modes on the fly =================== */ static void VID_Restart (void) { int width, height, bpp; qboolean fullscreen; if (vid_locked || !vid_changed) return; if (r_oculusrift.value) { // phoboslab R_ReleaseHMDRenderer(); } width = (int)vid_width.value; height = (int)vid_height.value; bpp = (int)vid_bpp.value; fullscreen = vid_fullscreen.value ? true : false; // // validate new mode // if (!VID_ValidMode (width, height, bpp, fullscreen)) { Con_Printf ("%dx%dx%d %s is not a valid mode\n", width, height, bpp, fullscreen? "fullscreen" : "windowed"); return; } // // set new mode // VID_SetMode (width, height, bpp, fullscreen); GL_Init (); TexMgr_ReloadImages (); GL_SetupState (); //warpimages needs to be recalculated TexMgr_RecalcWarpImageSize (); //conwidth and conheight need to be recalculated vid.conwidth = (scr_conwidth.value > 0) ? (int)scr_conwidth.value : (scr_conscale.value > 0) ? (int)(vid.width/scr_conscale.value) : vid.width; vid.conwidth = CLAMP (320, vid.conwidth, vid.width); vid.conwidth &= 0xFFFFFFF8; vid.conheight = vid.conwidth * vid.height / vid.width; // // keep cvars in line with actual mode // VID_SyncCvars(); // // update mouse grab // if (key_dest == key_console || key_dest == key_menu) { if (modestate == MS_WINDOWED) IN_Deactivate(true); else if (modestate == MS_FULLSCREEN) IN_Activate(); } if (r_oculusrift.value) { // phoboslab R_InitHMDRenderer(); } }
/* ================ VID_MenuKey ================ */ static void VID_MenuKey (int key) { switch (key) { case K_ESCAPE: VID_SyncCvars (); //sync cvars before leaving menu. FIXME: there are other ways to leave menu S_LocalSound ("misc/menu1.wav"); M_Menu_Options_f (); break; case K_UPARROW: S_LocalSound ("misc/menu1.wav"); video_options_cursor--; if (video_options_cursor < 0) video_options_cursor = VIDEO_OPTIONS_ITEMS-1; break; case K_DOWNARROW: S_LocalSound ("misc/menu1.wav"); video_options_cursor++; if (video_options_cursor >= VIDEO_OPTIONS_ITEMS) video_options_cursor = 0; break; case K_LEFTARROW: S_LocalSound ("misc/menu3.wav"); switch (video_options_cursor) { case VID_OPT_MODE: VID_Menu_ChooseNextMode (1); break; case VID_OPT_BPP: VID_Menu_ChooseNextBpp (1); break; case VID_OPT_FULLSCREEN: Cbuf_AddText ("toggle vid_fullscreen\n"); break; case VID_OPT_VSYNC: Cbuf_AddText ("toggle vid_vsync\n"); // kristian break; default: break; } break; case K_RIGHTARROW: S_LocalSound ("misc/menu3.wav"); switch (video_options_cursor) { case VID_OPT_MODE: VID_Menu_ChooseNextMode (-1); break; case VID_OPT_BPP: VID_Menu_ChooseNextBpp (-1); break; case VID_OPT_FULLSCREEN: Cbuf_AddText ("toggle vid_fullscreen\n"); break; case VID_OPT_VSYNC: Cbuf_AddText ("toggle vid_vsync\n"); break; default: break; } break; case K_ENTER: m_entersound = true; switch (video_options_cursor) { case VID_OPT_MODE: VID_Menu_ChooseNextMode (1); break; case VID_OPT_BPP: VID_Menu_ChooseNextBpp (1); break; case VID_OPT_FULLSCREEN: Cbuf_AddText ("toggle vid_fullscreen\n"); break; case VID_OPT_VSYNC: Cbuf_AddText ("toggle vid_vsync\n"); break; case VID_OPT_TEST: Cbuf_AddText ("vid_test\n"); break; case VID_OPT_APPLY: Cbuf_AddText ("vid_restart\n"); key_dest = key_game; m_state = m_none; IN_Activate(); break; default: break; } break; default: break; } }
static void in_smart_grab_changed( cvar_t *self ) { IN_Activate(); }
// main window procedure static LRESULT WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch ( uMsg ) { case WM_CREATE: GMainWindow = hWnd; if ( r_fullscreen->integer ) { WIN_DisableAltTab(); } else { WIN_EnableAltTab(); } break; case WM_DESTROY: // let sound and input know about this? GMainWindow = NULL; if ( r_fullscreen->integer ) { WIN_EnableAltTab(); } break; case WM_CLOSE: Cbuf_ExecuteText( EXEC_APPEND, "quit" ); break; case WM_ACTIVATE: AppActivate( LOWORD( wParam ) != WA_INACTIVE, !!HIWORD( wParam ) ); break; case WM_MOVE: if ( !r_fullscreen->integer ) { int xPos = ( short )LOWORD( lParam ); // horizontal position int yPos = ( short )HIWORD( lParam ); // vertical position RECT r; r.left = 0; r.top = 0; r.right = 1; r.bottom = 1; int style = GetWindowLong( hWnd, GWL_STYLE ); AdjustWindowRect( &r, style, FALSE ); Cvar_SetValue( "vid_xpos", xPos + r.left ); Cvar_SetValue( "vid_ypos", yPos + r.top ); vid_xpos->modified = false; vid_ypos->modified = false; if ( ActiveApp ) { IN_Activate( true ); } } break; case WM_SYSCOMMAND: if ( wParam == SC_SCREENSAVE ) { return 0; } break; case WM_SYSKEYDOWN: if ( wParam == 13 ) { if ( r_fullscreen ) { Cvar_SetValue( "r_fullscreen", !r_fullscreen->integer ); Cbuf_AddText( "vid_restart\n" ); } return 0; } // fall through break; case MM_MCINOTIFY: if ( CDAudio_MessageHandler( hWnd, uMsg, wParam, lParam ) == 0 ) { return 0; } break; } if ( IN_HandleInputMessage( uMsg, wParam, lParam ) ) { return 0; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
/* ==================== MainWndProc main window procedure ==================== */ LONG WINAPI MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LONG lRet = 0; if ( uMsg == MSH_MOUSEWHEEL ) { if ( ( ( int ) wParam ) > 0 ) { Key_Event( K_MWHEELUP, true, sys_msg_time ); Key_Event( K_MWHEELUP, false, sys_msg_time ); } else { Key_Event( K_MWHEELDOWN, true, sys_msg_time ); Key_Event( K_MWHEELDOWN, false, sys_msg_time ); } return DefWindowProc (hWnd, uMsg, wParam, lParam); } switch (uMsg) { case WM_MOUSEWHEEL: /* ** this chunk of code theoretically only works under NT4 and Win98 ** since this message doesn't exist under Win95 */ if ( ( short ) HIWORD( wParam ) > 0 ) { Key_Event( K_MWHEELUP, true, sys_msg_time ); Key_Event( K_MWHEELUP, false, sys_msg_time ); } else { Key_Event( K_MWHEELDOWN, true, sys_msg_time ); Key_Event( K_MWHEELDOWN, false, sys_msg_time ); } break; case WM_HOTKEY: return 0; case WM_CREATE: cl_hwnd = hWnd; MSH_MOUSEWHEEL = RegisterWindowMessage("MSWHEEL_ROLLMSG"); return DefWindowProc (hWnd, uMsg, wParam, lParam); case WM_PAINT: SCR_DirtyScreen (); // force entire screen to update next frame return DefWindowProc (hWnd, uMsg, wParam, lParam); case WM_DESTROY: // let sound and input know about this? cl_hwnd = NULL; return DefWindowProc (hWnd, uMsg, wParam, lParam); case WM_ACTIVATE: { int fActive, fMinimized; // KJB: Watch this for problems in fullscreen modes with Alt-tabbing. fActive = LOWORD(wParam); fMinimized = (BOOL) HIWORD(wParam); AppActivate( fActive != WA_INACTIVE, fMinimized); if ( reflib_active ) GLimp_AppActivate( !( fActive == WA_INACTIVE ) ); } return DefWindowProc (hWnd, uMsg, wParam, lParam); case WM_MOVE: { int xPos, yPos; RECT r; int style; if (!vid_fullscreen->value) { xPos = (short) LOWORD(lParam); // horizontal position yPos = (short) HIWORD(lParam); // vertical position r.left = 0; r.top = 0; r.right = 1; r.bottom = 1; style = GetWindowLong( hWnd, GWL_STYLE ); AdjustWindowRect( &r, style, FALSE ); Cvar_SetValue( "vid_xpos", xPos + r.left); Cvar_SetValue( "vid_ypos", yPos + r.top); vid_xpos->modified = false; vid_ypos->modified = false; if (ActiveApp) IN_Activate (true); } } return DefWindowProc (hWnd, uMsg, wParam, lParam); // this is complicated because Win32 seems to pack multiple mouse events into // one update sometimes, so we always check all states and look for events case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: #ifdef ENABLE_MOUSE4_MOUSE5 // mattx86: mouse4_mouse5 case WM_XBUTTONDOWN: case WM_XBUTTONUP: #endif case WM_MOUSEMOVE: { int temp; temp = 0; if (wParam & MK_LBUTTON) temp |= 1; if (wParam & MK_RBUTTON) temp |= 2; if (wParam & MK_MBUTTON) temp |= 4; #ifdef ENABLE_MOUSE4_MOUSE5 // mattx86: mouse4_mouse5 if (wParam & MK_XBUTTON1) temp |= 8; if (wParam & MK_XBUTTON2) temp |= 16; #endif IN_MouseEvent (temp); } break; case WM_SYSCOMMAND: if ( wParam == SC_SCREENSAVE ) return 0; return DefWindowProc (hWnd, uMsg, wParam, lParam); case WM_SYSKEYDOWN: if ( wParam == 13 ) { if ( vid_fullscreen ) { Cvar_SetValue( "vid_fullscreen", !vid_fullscreen->value ); } return 0; } // fall through case WM_KEYDOWN: Key_Event( MapKey( lParam ), true, sys_msg_time); break; case WM_SYSKEYUP: case WM_KEYUP: Key_Event( MapKey( lParam ), false, sys_msg_time); break; case MM_MCINOTIFY: { LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam); } break; default: // pass all unhandled messages to DefWindowProc return DefWindowProc (hWnd, uMsg, wParam, lParam); } /* return 0 if handled message, 1 if not */ return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
/* ================== CL_DeltaFrame A valid frame has been parsed. ================== */ void CL_DeltaFrame(void) { centity_t *ent; entity_state_t *state; int i, j; int framenum; // getting a valid frame message ends the connection process if (cls.state == ca_precached) set_active_state(); // set server time framenum = cl.frame.number - cl.serverdelta; cl.servertime = framenum * CL_FRAMETIME; #if USE_FPS cl.keyservertime = (framenum / cl.framediv) * BASE_FRAMETIME; #endif // rebuild the list of solid entities for this frame cl.numSolidEntities = 0; // initialize position of the player's own entity from playerstate. // this is needed in situations when player entity is invisible, but // server sends an effect referencing it's origin (such as MZ_LOGIN, etc) ent = &cl_entities[cl.frame.clientNum + 1]; Com_PlayerToEntityState(&cl.frame.ps, &ent->current); for (i = 0; i < cl.frame.numEntities; i++) { j = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK; state = &cl.entityStates[j]; // set current and prev entity_update(state); // fire events entity_event(state->number); } if (cls.demo.recording && !cls.demo.paused && !cls.demo.seeking && CL_FRAMESYNC) { CL_EmitDemoFrame(); } if (cls.demo.playback) { // this delta has nothing to do with local viewangles, // clear it to avoid interfering with demo freelook hack VectorClear(cl.frame.ps.pmove.delta_angles); } if (cl.oldframe.ps.pmove.pm_type != cl.frame.ps.pmove.pm_type) { IN_Activate(); } player_update(&cl.oldframe, &cl.frame, 1); #if USE_FPS if (CL_FRAMESYNC) player_update(&cl.oldkeyframe, &cl.keyframe, cl.framediv); #endif CL_CheckPredictionError(); SCR_SetCrosshairColor(); }
LONG WINAPI MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LONG lRet = 0; static qboolean newwindow = true; static qboolean minimized = false; if (uMsg == MSH_MOUSEWHEEL) { if (((int)wParam) > 0) { Key_Event(K_MWHEELUP, true, sys_msg_time); Key_Event(K_MWHEELUP, false, sys_msg_time); } else { Key_Event(K_MWHEELDOWN, true, sys_msg_time); Key_Event(K_MWHEELDOWN, false, sys_msg_time); } return DefWindowProc(hWnd, uMsg, wParam, lParam); } //Com_Printf("%x\n", uMsg); switch (uMsg) { case WM_MOUSEWHEEL: /* ** this chunk of code theoretically only works under NT4 and Win98 ** since this message doesn't exist under Win95 */ if ((short)HIWORD(wParam) > 0) { Key_Event(K_MWHEELUP, true, sys_msg_time); Key_Event(K_MWHEELUP, false, sys_msg_time); } else { Key_Event(K_MWHEELDOWN, true, sys_msg_time); Key_Event(K_MWHEELDOWN, false, sys_msg_time); } break; case WM_HOTKEY: return 0; case WM_CREATE: cl_hwnd = hWnd; newwindow = true; MSH_MOUSEWHEEL = RegisterWindowMessage("MSWHEEL_ROLLMSG"); return DefWindowProc (hWnd, uMsg, wParam, lParam); case WM_PAINT: SCR_DirtyScreen(); // force entire screen to update next frame return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_DESTROY: // let sound and input know about this? cl_hwnd = NULL; return DefWindowProc(hWnd, uMsg, wParam, lParam); /* case WM_KILLFOCUS: // jit - make sure mouse is deactivated if another window takes focus AppActivate(false, minimized, newwindow); if (reflib_active) re.AppActivate(false); return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_NCACTIVATE: AppActivate(wParam, minimized, newwindow); if (reflib_active) re.AppActivate(wParam); return DefWindowProc(hWnd, uMsg, wParam, lParam); */ /*case WM_ACTIVATEAPP: AppActivate(wParam, minimized, newwindow); if (reflib_active) re.AppActivate(wParam); return DefWindowProc(hWnd, uMsg, wParam, lParam);*/ /* jit - disabled this because we run CheckActive() every frame because we aren't getting appropriate events when the game loses focus/foreground, sometimes. case WM_ACTIVATE: { int fActive; qboolean active; HWND foregroundWindow = GetForegroundWindow(); // KJB: Watch this for problems in fullscreen modes with Alt-tabbing. fActive = LOWORD(wParam); minimized = (BOOL)HIWORD(wParam); active = (fActive != WA_INACTIVE); //if (foregroundWindow != hWnd) // active = false; Com_Printf("\nForeground: %d hWnd: %d\n\n", foregroundWindow, hWnd); AppActivate(active, minimized, newwindow); if (reflib_active) re.AppActivate(active); newwindow = false; return DefWindowProc(hWnd, uMsg, wParam, lParam); } /* case WM_WINDOWPOSCHANGED: // jit - handle another case of losing app focus { LPWINDOWPOS windowpos = (LPWINDOWPOS)lParam; if (windowpos->flags & 0x800) // SWP_STATECHANGED { HWND foregroundWindow = GetForegroundWindow(); qboolean active = (foregroundWindow == hWnd); AppActivate(active, minimized, newwindow); if (reflib_active) re.AppActivate(active); } Com_Printf("\nWindowposchanged flags %x\n", windowpos->flags); return DefWindowProc(hWnd, uMsg, wParam, lParam); } */ case WM_MOVE: { int xPos, yPos; RECT r; int style; if (!vid_fullscreen->value) { xPos = (short)LOWORD(lParam); // horizontal position yPos = (short)HIWORD(lParam); // vertical position r.left = 0; r.top = 0; r.right = 1; r.bottom = 1; style = GetWindowLong(hWnd, GWL_STYLE); AdjustWindowRect(&r, style, FALSE); Cvar_SetValue("vid_xpos", xPos + r.left); Cvar_SetValue("vid_ypos", yPos + r.top); vid_xpos->modified = false; vid_ypos->modified = false; } // jitmouse - force mouse to recenter properly if (ActiveApp) IN_Activate(true); } return DefWindowProc(hWnd, uMsg, wParam, lParam); // this is complicated because Win32 seems to pack multiple mouse events into // one update sometimes, so we always check all states and look for events case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MOUSEMOVE: case WM_XBUTTONDOWN: // jitmouse case WM_XBUTTONUP: // jitmouse { int temp = 0; if (wParam & MK_LBUTTON) temp |= 1; if (wParam & MK_RBUTTON) temp |= 2; if (wParam & MK_MBUTTON) temp |= 4; // === jitmouse if (wParam & MK_XBUTTON1) temp |= 8; if (wParam & MK_XBUTTON2) temp |= 16; // === IN_MouseEvent(temp); // ++ ARTHUR [9/04/03] - Mouse movement emulates keystroke Key_Event(K_MOUSEMOVE, true, sys_msg_time); // -- ARTHUR } break; case WM_INPUT: // jitmouse if (m_rawinput->value && !(cls.key_dest == key_console || g_windowed && M_MenuActive())) // Don't accumulate in-game mouse input when at the console or menu { UINT dwSize = 40; static BYTE lpb[40]; RAWINPUT *raw; GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)); raw = (RAWINPUT*)lpb; if (raw->header.dwType == RIM_TYPEMOUSE) { extern int g_raw_mouse_x, g_raw_mouse_y; g_raw_mouse_x += raw->data.mouse.lLastX; g_raw_mouse_y += raw->data.mouse.lLastY; } } break; case WM_SYSCOMMAND: if (wParam == SC_SCREENSAVE) return 0; return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_SYSKEYDOWN: if (wParam == 13) // alt-enter toggles fullscreen { if (!win_noaltenter || !win_noaltenter->value) // jitkeyboard { if (vid_fullscreen) Cvar_SetValue("vid_fullscreen", !vid_fullscreen->value); return 0; } } // fall through case WM_KEYDOWN: Key_Event(Sys_MapKeyModified(wParam, lParam), true, sys_msg_time); break; case WM_SYSKEYUP: case WM_KEYUP: Key_Event(Sys_MapKeyModified(wParam, lParam), false, sys_msg_time); break; case WM_SIZE: if (lParam) // This is 0 when minimized? { M_RefreshMenu(); // jitmenu re.DrawResizeWindow(LOWORD(lParam), HIWORD(lParam)); VID_NewWindow(LOWORD(lParam), HIWORD(lParam)); } if (wParam == SIZE_MINIMIZED) // jit minimized = true; else minimized = false; break; case WM_CLOSE: case WM_QUIT: Com_Quit(); break; case WM_APPCOMMAND: #ifdef OGG_SUPPORT if(ogg_started) switch(GET_APPCOMMAND_LPARAM(lParam)) { case APPCOMMAND_MEDIA_PLAY_PAUSE: Cbuf_AddText("ogg_playpause\n"); return 1; case APPCOMMAND_MEDIA_NEXTTRACK: Cbuf_AddText("ogg_play >\n"); return 1; case APPCOMMAND_MEDIA_PREVIOUSTRACK: Cbuf_AddText("ogg_play <\n"); return 1; case APPCOMMAND_MEDIA_STOP: Cbuf_AddText("ogg_stop\n"); return 1; } break; #endif case MM_MCINOTIFY: { LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); lRet = CDAudio_MessageHandler(hWnd, uMsg, wParam, lParam); } break; default: // pass all unhandled messages to DefWindowProc return DefWindowProc(hWnd, uMsg, wParam, lParam); } //CheckActive(hWnd); // return 0 if handled message, 1 if not return DefWindowProc(hWnd, uMsg, wParam, lParam); }
/* =================== Key_Event Called by the system between frames for both key up and key down events Should NOT be called during an interrupt! =================== */ void Key_Event(unsigned key, qboolean down, unsigned time) { char *kb; char cmd[MAX_STRING_CHARS]; if (key >= 256) { Com_Error(ERR_FATAL, "%s: bad key", __func__); } Com_DDDPrintf("%u: %c%s\n", time, down ? '+' : '-', Key_KeynumToString(key)); // hack for menu key binding if (key_wait_cb && down && !key_wait_cb(key_wait_arg, key)) { return; } // update key down and auto-repeat status if (down) { if (keydown[key] < 255) keydown[key]++; } else { keydown[key] = 0; } // console key is hardcoded, so the user can never unbind it if (!Key_IsDown(K_SHIFT) && (key == '`' || key == '~')) { if (keydown[key] == 1) { Con_ToggleConsole_f(); } return; } // Alt+Enter is hardcoded for all systems if (Key_IsDown(K_ALT) && key == K_ENTER) { if (keydown[key] == 1) { VID_ToggleFullscreen(); } return; } // menu key is hardcoded, so the user can never unbind it if (key == K_ESCAPE) { if (!down) { return; } if (cls.key_dest == KEY_GAME && cl.frame.ps.stats[STAT_LAYOUTS] && cls.demo.playback == qfalse) { if (keydown[key] == 2) { // force main menu if escape is held UI_OpenMenu(UIMENU_GAME); } else if (keydown[key] == 1) { // put away help computer / inventory CL_ClientCommand("putaway"); } return; } // ignore autorepeats if (keydown[key] > 1) { return; } if (cls.key_dest & KEY_CONSOLE) { if (cls.state < ca_active && !(cls.key_dest & KEY_MENU)) { UI_OpenMenu(UIMENU_MAIN); } else { Con_Close(qtrue); } } else if (cls.key_dest & KEY_MENU) { UI_Keydown(key); } else if (cls.key_dest & KEY_MESSAGE) { Key_Message(key); } else if (cls.state == ca_active) { UI_OpenMenu(UIMENU_GAME); } else { UI_OpenMenu(UIMENU_MAIN); } return; } // track if any key is down for BUTTON_ANY if (down) { if (keydown[key] == 1) anykeydown++; } else { anykeydown--; if (anykeydown < 0) anykeydown = 0; } // hack for demo freelook in windowed mode if (cls.key_dest == KEY_GAME && cls.demo.playback && key == K_SHIFT && keydown[key] <= 1) { IN_Activate(); } // // if not a consolekey, send to the interpreter no matter what mode is // if ((cls.key_dest == KEY_GAME) || ((cls.key_dest & KEY_CONSOLE) && !Q_IsBitSet(consolekeys, key)) || ((cls.key_dest & KEY_MENU) && (key >= K_F1 && key <= K_F12)) || (!down && Q_IsBitSet(buttondown, key))) { // // Key up events only generate commands if the game key binding is a button // command (leading + sign). These will occur even in console mode, to keep the // character from continuing an action started before a console switch. Button // commands include the kenum as a parameter, so multiple downs can be matched // with ups. // if (!down) { kb = keybindings[key]; if (kb && kb[0] == '+') { Q_snprintf(cmd, sizeof(cmd), "-%s %i %i\n", kb + 1, key, time); Cbuf_AddText(&cmd_buffer, cmd); } Q_ClearBit(buttondown, key); return; } // ignore autorepeats if (keydown[key] > 1) { return; } // generate button up command when released Q_SetBit(buttondown, key); kb = keybindings[key]; if (kb) { if (kb[0] == '+') { // button commands add keynum and time as a parm Q_snprintf(cmd, sizeof(cmd), "%s %i %i\n", kb, key, time); Cbuf_AddText(&cmd_buffer, cmd); } else { Cbuf_AddText(&cmd_buffer, kb); Cbuf_AddText(&cmd_buffer, "\n"); } } return; } if (cls.key_dest == KEY_GAME) return; if (!down) return; // other subsystems only care about key down events if (cls.key_dest & KEY_CONSOLE) { Key_Console(key); } else if (cls.key_dest & KEY_MENU) { UI_Keydown(key); } else if (cls.key_dest & KEY_MESSAGE) { Key_Message(key); } if (Key_IsDown(K_CTRL) || Key_IsDown(K_ALT)) { return; } switch (key) { case K_KP_SLASH: key = '/'; break; case K_KP_MULTIPLY: key = '*'; break; case K_KP_MINUS: key = '-'; break; case K_KP_PLUS: key = '+'; break; case K_KP_HOME: key = '7'; break; case K_KP_UPARROW: key = '8'; break; case K_KP_PGUP: key = '9'; break; case K_KP_LEFTARROW: key = '4'; break; case K_KP_5: key = '5'; break; case K_KP_RIGHTARROW: key = '6'; break; case K_KP_END: key = '1'; break; case K_KP_DOWNARROW: key = '2'; break; case K_KP_PGDN: key = '3'; break; case K_KP_INS: key = '0'; break; case K_KP_DEL: key = '.'; break; } // if key is printable, generate char events if (key < 32 || key >= 127) { return; } if (Key_IsDown(K_SHIFT)) { key = keyshift[key]; } if (cls.key_dest & KEY_CONSOLE) { Char_Console(key); } else if (cls.key_dest & KEY_MENU) { UI_CharEvent(key); } else if (cls.key_dest & KEY_MESSAGE) { Char_Message(key); } }