UE5 菜单栏最小化功能实现代码剖析记录
  3cAxQ5E22S4z 2023年11月02日 65 0

背景

菜单栏点击最小化事件,产生了哪些操作,如何自己实现最小化功能,直接上代码


窗口最小化代码

Engine\Source\Runtime\Slate\Public\Framework\Application\SWindowTitleBar.h

	FReply MinimizeButton_OnClicked( )
	{
		TSharedPtr<SWindow> OwnerWindow = OwnerWindowPtr.Pin();

		if (OwnerWindow.IsValid())
		{
			TSharedPtr<FGenericWindow> NativeWindow = OwnerWindow->GetNativeWindow();

			if (NativeWindow.IsValid())
			{
				NativeWindow->Minimize();
			}
		}

		return FReply::Handled();
	}

最小化窗口以后,做了这个操作return FReply::Handled();

	/**
	 * An event should return a FReply::Handled() to let the system know that an event was handled.
	 */
	static FReply Handled( )
	{
		return FReply(true);
	}


	/**
	 * Hidden default constructor.
	 */
	FReply( bool bIsHandled )
		: TReplyBase<FReply>(bIsHandled)
		, RequestedMousePos()
		, EventHandler(nullptr)
		, MouseCaptor(nullptr)
		, FocusRecipient(nullptr)
		, MouseLockWidget(nullptr)
		, DetectDragForWidget(nullptr)
		, NavigationDestination(nullptr)
		, DragDropContent(nullptr)
		, FocusChangeReason(EFocusCause::SetDirectly)
		, NavigationType(EUINavigation::Invalid)
		, NavigationGenesis(ENavigationGenesis::User)
		, NavigationSource(ENavigationSource::FocusedWidget)
		, bReleaseMouseCapture(false)
		, bSetUserFocus(false)
		, bReleaseUserFocus(false)
		, bAllUsers(false)
		, bShouldReleaseMouseLock(false)
		, bUseHighPrecisionMouse(false)
		, bPreventThrottling(false)
		, bEndDragDrop(false)
	{ }


	//If the user hasn't requested a new mouse captor and the button still has mouse capture,
	//then the default behavior of the button is to release mouse capture.
	if ( Reply.GetMouseCaptor().IsValid() == false && HasMouseCapture() )
	{
		Reply.ReleaseMouseCapture();
	}


	/** 
	 * An event should return a FReply::Handled().ReleaseMouse() to ask the system to release mouse capture
	 * NOTE: Deactivates high precision mouse movement if activated.
	 */
	FReply& ReleaseMouseCapture()
	{
		this->MouseCaptor.Reset();
		this->bReleaseMouseCapture = true;
		this->bUseHighPrecisionMouse = false;
		return Me();
	}


bool FSlateApplication::ProcessMouseButtonUpEvent( const FPointerEvent& MouseEvent )
{
	SCOPE_CYCLE_COUNTER(STAT_ProcessMouseButtonUp);

#if WITH_SLATE_DEBUGGING
	FSlateDebugging::FScopeProcessInputEvent Scope(ESlateDebuggingInputEvent::MouseButtonUp, MouseEvent);
#endif

	// If in responsive mode throttle, leave it on mouse up.  Release this before dispatching the event to prevent being stuck in this mode
	// until the next click if a modal dialog is opened.
	if (MouseButtonDownResponsivnessThrottle.IsValid())
	{
		FSlateThrottleManager::Get().LeaveResponsiveMode(MouseButtonDownResponsivnessThrottle);
	}

	SetLastUserInteractionTime(this->GetCurrentTime());
	LastUserInteractionTimeForThrottling = LastUserInteractionTime;

	const bool bIsCursorUser = MouseEvent.GetUserIndex() == CursorUserIndex;
	if (bIsCursorUser)
	{
		PressedMouseButtons.Remove(MouseEvent.GetEffectingButton());
	}

	// Input preprocessors get the first chance at the input
	if (InputPreProcessors.HandleMouseButtonUpEvent(*this, MouseEvent))
	{
		return true;
	}

	// An empty widget path is passed in.  As an optimization, one will be generated only if a captured mouse event isn't routed
	FWidgetPath EmptyPath;
	const bool bHandled = RoutePointerUpEvent( EmptyPath, MouseEvent ).IsEventHandled();

	if ( bIsCursorUser && PressedMouseButtons.Num() == 0 )
	{
		PlatformApplication->SetCapture( nullptr );
	}

	return bHandled;
}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论