unreal3窗口锁定鼠标开关

GameViewportClient中有个变量控制是否显示硬件鼠标:

var transient bool bDisplayHardwareMouseCursor

也就是系统的光标,一般通过该类中的函数来操纵:

simulated event SetHardwareMouseCursorVisibility(bool bIsVisible)
{
    local Vector2D ViewportSize;
    
    //If we are going to be turning on the hardware cursor when it was not already on, we will move the cursor to the middle of the screen
    if (bIsVisible && !bDisplayHardwareMouseCursor)
    {
        GetViewportSize(ViewportSize);
        SetMouse(ViewportSize.X/2,ViewportSize.Y/2);
    }
    bDisplayHardwareMouseCursor = bIsVisible;

    ForceUpdateMouseCursor(TRUE);
}

 

其中ForceUpdateMouseCursor是native函数,调用到UGameViewportClient::ForceUpdateMouseCursor,

在Windows上的实现类为FWindowsViewport,其成员函数

void FWindowsViewport::UpdateMouseLock( UBOOL bEnforceMouseLockRequestedFlag )

在每个tick中被调用,会对该控制变量进行检测:

    RECT ClipRect;
    UBOOL bIsHardwareCursorVisible = (GEngine && GEngine->GameViewport && GEngine->GameViewport->bDisplayHardwareMouseCursor);
    UBOOL bIsAnyCursorVisible = bIsSystemCursorVisible || bIsHardwareCursorVisible;
    UBOOL bClipRectValid = (::GetClipCursor( &ClipRect ) != 0);
    UBOOL bHasFocus = HasFocus();
    UBOOL bShouldMouseLock = bEnforceMouseLockRequestedFlag ? bMouseLockRequested : bHasFocus && (IsFullscreen() || !bIsAnyCursorVisible || bMouseLockRequested);

最后在bShouldMouseLock为TRUE时,调用::ClipCursor锁定鼠标。

 

posted on 2016-03-28 18:05  冷欺花  阅读(612)  评论(0编辑  收藏  举报

导航