Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Private/SViewportToolBar.cpp
Dan Hertzka c042ddcb94 ---- Merging with SlateDev branch ----
Introduces the concept of "Active Ticking" to allow Slate to go to sleep when there is no need to update the UI.

While asleep, Slate will skip the Tick & Paint pass for that frame entirely.
- There are TWO ways to "wake" Slate and cause a Tick/Paint pass:
    1. Provide some sort of input (mouse movement, clicks, and key presses). Slate will always tick when the user is active.
        - Therefore, if the logic in a given widget's Tick is only relevant in response to user action, there is no need to register an active tick.
    2. Register an Active Tick. Currently this is an all-or-nothing situation, so if a single active tick needs to execute, all of Slate will be ticked.

- The purpose of an Active Tick is to allow a widget to "drive" Slate and guarantee a Tick/Paint pass in the absence of any user action.
    - Examples include animation, async operations that update periodically, progress updates, loading bars, etc.

- An empty active tick is registered for viewports when they are real-time, so game project widgets are unaffected by this change and should continue to work as before.

- An Active Tick is registered by creating an FWidgetActiveTickDelegate and passing it to SWidget::RegisterActiveTick()
    - There are THREE ways to unregister an active tick:
        1. Return EActiveTickReturnType::StopTicking from the active tick function
        2. Pass the FActiveTickHandle returned by RegisterActiveTick() to SWidget::UnregisterActiveTick()
        3. Destroy the widget responsible for the active tick

- Sleeping is currently disabled, can be enabled with Slate.AllowSlateToSleep cvar
- There is currently a little buffer time during which Slate continues to tick following any input. Long-term, this is planned to be removed.
    - The duration of the buffer can be adjusted using Slate.SleepBufferPostInput cvar (defaults to 1.0f)

- The FCurveSequence API has been updated to work with the active tick system
    - Playing a curve sequence now requires that you pass the widget being animated by the sequence
    - The active tick will automatically be registered on behalf of the widget and unregister when the sequence is complete
    - GetLerpLooping() has been removed. Instead, pass true as the second param to Play() to indicate that the animation will loop. This causes the active tick to be registered indefinitely until paused or jumped to the start/end.

[CL 2391669 by Dan Hertzka in Main branch]
2014-12-17 16:07:57 -05:00

99 lines
2.8 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "UnrealEd.h"
#include "SViewportToolBar.h"
#define LOCTEXT_NAMESPACE "ViewportToolBar"
namespace ToolBarConstants
{
/** The opacity when we are hovered */
const float HoveredOpacity = 1.0f;
/** The opacity when we are not hovered */
const float NonHoveredOpacity = .75f;
/** The amount of time to wait before fading out the toolbar after the mouse leaves it (to reduce poping when mouse moves in and out frequently */
const float TimeToFadeOut = 1.0f;
/** The amount of time spent actually fading in or out */
const float FadeTime = .15f;
}
void SViewportToolBar::Construct( const FArguments& InArgs )
{
bIsHovered = false;
FadeInSequence = FCurveSequence( 0.0f, ToolBarConstants::FadeTime );
FadeOutSequence = FCurveSequence( ToolBarConstants::TimeToFadeOut, ToolBarConstants::FadeTime );
FadeOutSequence.JumpToEnd();
}
TWeakPtr<SMenuAnchor> SViewportToolBar::GetOpenMenu() const
{
return OpenedMenu;
}
void SViewportToolBar::SetOpenMenu( TSharedPtr< SMenuAnchor >& NewMenu )
{
if( OpenedMenu.IsValid() && OpenedMenu.Pin() != NewMenu )
{
// Close any other open menus
OpenedMenu.Pin()->SetIsOpen( false );
}
OpenedMenu = NewMenu;
}
FLinearColor SViewportToolBar::OnGetColorAndOpacity() const
{
FLinearColor Color = FLinearColor::White;
if( OpenedMenu.IsValid() && OpenedMenu.Pin()->IsOpen() )
{
// Never fade out the toolbar if a menu is open
Color.A = ToolBarConstants::HoveredOpacity;
}
else if( FadeOutSequence.IsPlaying() || !bIsHovered )
{
Color.A = FMath::Lerp( ToolBarConstants::HoveredOpacity, ToolBarConstants::NonHoveredOpacity, FadeOutSequence.GetLerp() );
}
else
{
Color.A = FMath::Lerp( ToolBarConstants::NonHoveredOpacity, ToolBarConstants::HoveredOpacity, FadeInSequence.GetLerp() );
}
return Color;
}
void SViewportToolBar::OnMouseEnter( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent )
{
// The viewport could potentially be moved around inside the toolbar when the mouse is captured
// If that is the case we do not play the fade transition
if( !FSlateApplication::Get().IsUsingHighPrecisionMouseMovment() )
{
bIsHovered = true;
if( FadeOutSequence.IsPlaying() )
{
// Fade out is already playing so just force the fade in curve to the end so we don't have a "pop"
// effect from quickly resetting the alpha
FadeInSequence.JumpToEnd();
}
else
{
FadeInSequence.Play( this->AsShared() );
}
}
}
void SViewportToolBar::OnMouseLeave( const FPointerEvent& MouseEvent )
{
// The viewport could potentially be moved around inside the toolbar when the mouse is captured
// If that is the case we do not play the fade transition
if( !FSlateApplication::Get().IsUsingHighPrecisionMouseMovment() )
{
bIsHovered = false;
FadeOutSequence.Play( this->AsShared() );
}
}
#undef LOCTEXT_NAMESPACE