Example #1
0
File: in_win.c Project: jite/jquake
void IN_ActivateMouse (void) 
{
	mouseactivatetoggle = true;

	if (mouseinitialized) 
	{
		#if DIRECTINPUT_VERSION	>= 0x0700
		if (dinput)
		{
			if (g_pMouse) 
			{
				if (!dinput_acquired) 
				{
					HRESULT		hr;

					// we may fail to reacquire if the window has been recreated
					hr = IDirectInputDevice_Acquire(g_pMouse);

					if (FAILED(hr)) 
					{
						if ( !IN_InitDInput() ) 
						{
							Com_Printf ("WARNING: can't reinitializing dinput mouse...\n");
							Com_Printf ("Falling back to Win32 mouse support...\n");
							Cvar_LatchedSetValue( &in_mouse, mt_normal );
							Cbuf_AddText ("in_restart\n");
						}
					}
					else
					{
						dinput_acquired = true;
					}
				}
			} 
			else 
			{
				return;
			}
		} else
		#endif // DIRECTINPUT_VERSION >= 0x700
		{
		#ifdef USINGRAWINPUT
			if (rawmicecount > 0)
			{
				if (IN_RawInput_Register()) {
					Com_Printf("Raw input: unable to register raw input, deinitializing\n");
					IN_RawInput_DeInit();
				}
			}
		#endif // USINGRAWINPUT

			if (mouseparmsvalid)
				restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);

			IN_CenterMouseToWindow();
			SetCapture (mainwindow);
			ClipCursor (&window_rect);
		}
		mouseactive = true;
	}
}
Example #2
0
/*
* IN_ActivateMouse
*
* Called when the window gains focus or changes in some way
*/
static void IN_ActivateMouse( void ) {
	int width, height;

	if( !mouseinitialized ) {
		return;
	}
	if( !in_mouse->integer ) {
		mouseactive = false;
		return;
	}
	if( mouseactive ) {
		return;
	}

	mouseactive = true;

	if( dinput_initialized ) {
		mstate_di = 0;
		if( g_pMouse ) {
			if( cl_hwnd ) {
				if( FAILED( IDirectInputDevice_SetCooperativeLevel( g_pMouse, cl_hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND ) ) ) {
					Com_DPrintf( "Couldn't set DI coop level\n" );
					return;
				}
			}
			if( !dinput_acquired ) {
				IDirectInputDevice_Acquire( g_pMouse );
				dinput_acquired = true;
			}
		}
		return;
	}

	if( rawinput_initialized ) {
		if( IN_RawInput_Register() ) {
			Com_Printf( "Raw input: unable to register raw input, deinitializing\n" );
			IN_RawInput_Shutdown();
		}
	}

	mouse_oldbuttonstate = 0;

	if( mouseparmsvalid ) {
		restore_spi = SystemParametersInfo( SPI_SETMOUSE, 0, newmouseparms, 0 );
	}

	width = GetSystemMetrics( SM_CXSCREEN );
	height = GetSystemMetrics( SM_CYSCREEN );

	GetWindowRect( cl_hwnd, &window_rect );
	if( window_rect.left < 0 ) {
		window_rect.left = 0;
	}
	if( window_rect.top < 0 ) {
		window_rect.top = 0;
	}
	if( window_rect.right >= width ) {
		window_rect.right = width - 1;
	}
	if( window_rect.bottom >= height - 1 ) {
		window_rect.bottom = height - 1;
	}

	window_center_x = ( window_rect.right + window_rect.left ) / 2;
	window_center_y = ( window_rect.top + window_rect.bottom ) / 2;

	SetCursorPos( window_center_x, window_center_y );

	SetCapture( cl_hwnd );
	ClipCursor( &window_rect );
	while( ShowCursor( FALSE ) >= 0 ) ;
}