Files
UnrealEngineUWP/Engine/Source/Developer/TaskGraph/Private/STimeline.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

184 lines
5.4 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "SlateBasics.h"
#include "EditorStyle.h"
#include "TaskGraphInterfaces.h"
#include "VisualizerEvents.h"
#include "STimeline.h"
void STimeline::Construct( const FArguments& InArgs )
{
MinValue = InArgs._MinValue;
MaxValue = InArgs._MaxValue;
FixedLabelSpacing = InArgs._FixedLabelSpacing;
BackgroundImage = FEditorStyle::GetBrush("TaskGraph.Background");
Zoom = 1.0f;
Offset = 0.0f;
}
int32 STimeline::OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const
{
// Used to track the layer ID we will return.
int32 RetLayerId = LayerId;
const TSharedRef< FSlateFontMeasure > FontMeasureService = FSlateApplication::Get().GetRenderer()->GetFontMeasureService();
bool bEnabled = ShouldBeEnabled( bParentEnabled );
const ESlateDrawEffect::Type DrawEffects = bEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect;
const FColor ColorAndOpacitySRGB = InWidgetStyle.GetColorAndOpacityTint();
const FColor SelectedBarColor( 255, 255, 255, 255 );
// Paint inside the border only.
const FVector2D BorderPadding = FEditorStyle::GetVector("ProgressBar.BorderPadding");
const FSlateRect ForegroundClippingRect = AllottedGeometry.GetClippingRect().InsetBy(FMargin(BorderPadding.X, BorderPadding.Y)).IntersectionWith(MyClippingRect);
const float OffsetX = DrawingOffsetX; // BorderPadding.X
const float Width = DrawingGeometry.Size.X; // AllottedGeometry.Size.X - - 2.0f * BorderPadding.X
FSlateFontInfo MyFont( FPaths::EngineContentDir() / TEXT("Slate/Fonts/Roboto-Regular.ttf"), 10 );
//FSlateDrawElement::MakeBox(
// OutDrawElements,
// RetLayerId++,
// AllottedGeometry.ToPaintGeometry(),
// BackgroundImage,
// MyClippingRect,
// DrawEffects,
// ColorAndOpacitySRGB
//);
// Create line points
const float RoundedMax = FMath::CeilToInt( MaxValue );
const float RoundedMin = FMath::FloorToInt( MinValue );
const float TimeScale = MaxValue - MinValue;
const int32 NumValues = FMath::FloorToInt( AllottedGeometry.Size.X * Zoom / FixedLabelSpacing );
TArray< FVector2D > LinePoints;
LinePoints.AddUninitialized( 2 );
{
LinePoints[0] = FVector2D( OffsetX, BorderPadding.Y + 1.0f );
LinePoints[1] = FVector2D( OffsetX + Width, BorderPadding.Y + 1.0f );
// Draw lines
FSlateDrawElement::MakeLines(
OutDrawElements,
RetLayerId++,
AllottedGeometry.ToPaintGeometry(),
LinePoints,
MyClippingRect,
ESlateDrawEffect::None,
FLinearColor::White
);
}
const FVector2D TextDrawSize = FontMeasureService->Measure(TEXT("0.00"), MyFont);
const float LineHeight = AllottedGeometry.Size.Y - BorderPadding.Y - TextDrawSize.Y - 2.0f;
for( int32 LineIndex = 0; LineIndex <= NumValues; LineIndex++ )
{
const float NormalizedX = (float)LineIndex / NumValues;
const float LineX = Offset + NormalizedX * Zoom;
if( LineX < 0.0f || LineX > 1.0f )
{
continue;
}
const float LineXPos = OffsetX + Width * LineX;
LinePoints[0] = FVector2D( LineXPos, BorderPadding.Y );
LinePoints[1] = FVector2D( LineXPos, LineHeight );
// Draw lines
FSlateDrawElement::MakeLines(
OutDrawElements,
RetLayerId++,
AllottedGeometry.ToPaintGeometry(),
LinePoints,
MyClippingRect,
ESlateDrawEffect::None,
FLinearColor::White
);
FString ValueText( FString::Printf( TEXT("%.2f"), MinValue + NormalizedX * TimeScale ) );
FVector2D DrawSize = FontMeasureService->Measure(ValueText, MyFont);
FVector2D TextPos( LineXPos - DrawSize.X * 0.5f, LineHeight );
if( TextPos.X < 0.0f )
{
TextPos.X = 0.0f;
}
else if( (TextPos.X + DrawSize.X) > AllottedGeometry.Size.X )
{
TextPos.X = OffsetX + Width - DrawSize.X;
}
FSlateDrawElement::MakeText(
OutDrawElements,
RetLayerId,
AllottedGeometry.ToOffsetPaintGeometry( TextPos ),
ValueText,
MyFont,
MyClippingRect,
ESlateDrawEffect::None,
FLinearColor::White
);
}
// Always draw lines at the start and at the end of the timeline
{
LinePoints[0] = FVector2D( OffsetX, BorderPadding.Y );
LinePoints[1] = FVector2D( OffsetX, LineHeight );
// Draw lines
FSlateDrawElement::MakeLines(
OutDrawElements,
RetLayerId++,
AllottedGeometry.ToPaintGeometry(),
LinePoints,
MyClippingRect,
ESlateDrawEffect::None,
FLinearColor::White
);
}
{
LinePoints[0] = FVector2D( OffsetX + Width, BorderPadding.Y );
LinePoints[1] = FVector2D( OffsetX + Width, LineHeight );
// Draw lines
FSlateDrawElement::MakeLines(
OutDrawElements,
RetLayerId++,
AllottedGeometry.ToPaintGeometry(),
LinePoints,
MyClippingRect,
ESlateDrawEffect::None,
FLinearColor::White
);
}
return RetLayerId - 1;
}
void STimeline::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
{
DrawingOffsetX = DrawingGeometry.AbsolutePosition.X - AllottedGeometry.AbsolutePosition.X;
}
FReply STimeline::OnMouseButtonDown( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent )
{
return SCompoundWidget::OnMouseButtonDown( MyGeometry, MouseEvent );
}
FReply STimeline::OnMouseMove( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent )
{
return SCompoundWidget::OnMouseMove( MyGeometry, MouseEvent );
}
FVector2D STimeline::ComputeDesiredSize() const
{
return FVector2D(500.0f, 50.0f);
}