Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Binaries/*
Build/*
Intermediate/*

.vscode
7 changes: 6 additions & 1 deletion BUITween.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"Name": "BUITween",
"Type": "Runtime",
"LoadingPhase": "Default"
}
},
{
"Name": "BUITweenBP",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]
}
40 changes: 20 additions & 20 deletions Source/BUITween/Private/BUITweenInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ void FBUITweenInstance::Begin()
}

// Set all the props to the existng state
TranslationProp.OnBegin( pWidget->RenderTransform.Translation );
ScaleProp.OnBegin( pWidget->RenderTransform.Scale );
RotationProp.OnBegin( pWidget->RenderTransform.Angle );
TranslationProp.OnBegin( pWidget->GetRenderTransform().Translation );
ScaleProp.OnBegin( pWidget->GetRenderTransform().Scale );
RotationProp.OnBegin( pWidget->GetRenderTransform().Angle );
OpacityProp.OnBegin( pWidget->GetRenderOpacity() );

{
UUserWidget* UW = Cast<UUserWidget>( pWidget );
if ( UW )
{
ColorProp.OnBegin( UW->ColorAndOpacity );
ColorProp.OnBegin( UW->GetColorAndOpacity() );
}
UImage* UI = Cast<UImage>( pWidget );
if ( UI )
{
ColorProp.OnBegin( UI->ColorAndOpacity );
ColorProp.OnBegin( UI->GetColorAndOpacity() );
}
UBorder* Border = Cast<UBorder>( pWidget );
if ( Border )
{
ColorProp.OnBegin( Border->ContentColorAndOpacity );
ColorProp.OnBegin( Border->GetContentColorAndOpacity() );
}
}

Expand All @@ -61,32 +61,32 @@ void FBUITweenInstance::Begin()
if ( OverlaySlot )
{
PaddingProp.OnBegin( FVector4(
OverlaySlot->Padding.Left,
OverlaySlot->Padding.Top,
OverlaySlot->Padding.Bottom,
OverlaySlot->Padding.Right ) );
OverlaySlot->GetPadding().Left,
OverlaySlot->GetPadding().Top,
OverlaySlot->GetPadding().Bottom,
OverlaySlot->GetPadding().Right ) );
}
else if ( HorizontalBoxSlot )
{
PaddingProp.OnBegin( FVector4(
HorizontalBoxSlot->Padding.Left,
HorizontalBoxSlot->Padding.Top,
HorizontalBoxSlot->Padding.Bottom,
HorizontalBoxSlot->Padding.Right ) );
HorizontalBoxSlot->GetPadding().Left,
HorizontalBoxSlot->GetPadding().Top,
HorizontalBoxSlot->GetPadding().Bottom,
HorizontalBoxSlot->GetPadding().Right ) );
}
else if ( VerticalBoxSlot )
{
PaddingProp.OnBegin( FVector4(
VerticalBoxSlot->Padding.Left,
VerticalBoxSlot->Padding.Top,
VerticalBoxSlot->Padding.Bottom,
VerticalBoxSlot->Padding.Right ) );
VerticalBoxSlot->GetPadding().Left,
VerticalBoxSlot->GetPadding().Top,
VerticalBoxSlot->GetPadding().Bottom,
VerticalBoxSlot->GetPadding().Right ) );
}

USizeBox* SizeBox = Cast<USizeBox>( pWidget );
if ( SizeBox )
{
MaxDesiredHeightProp.OnBegin( SizeBox->MaxDesiredHeight );
MaxDesiredHeightProp.OnBegin( SizeBox->GetMaxDesiredHeight() );
}

// Apply the starting conditions, even if we delay
Expand Down Expand Up @@ -173,7 +173,7 @@ void FBUITweenInstance::Apply( float EasedAlpha )
}

bool bChangedRenderTransform = false;
FWidgetTransform CurrentTransform = Target->RenderTransform;
FWidgetTransform CurrentTransform = Target->GetRenderTransform();

if ( TranslationProp.IsSet() )
{
Expand Down
105 changes: 56 additions & 49 deletions Source/BUITween/Public/BUIEasing.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include "CoreMinimal.h"
#include "CoreUObject.h"

UENUM()
enum class EBUIEasingType
UENUM(BlueprintType)
enum class EBUIEasingType : uint8
{
Linear,
Smoothstep,
Expand Down Expand Up @@ -40,41 +39,40 @@ enum class EBUIEasingType
struct FBUIEasing
{
public:
#define TWO_PI (6.28318530717f)


static float Ease( EBUIEasingType Type, float time, float duration = 1.0f, float overshootOrAmplitude = 0.1f, float period = 1.0f )
{
switch ( Type )
{
case EBUIEasingType::Linear: return Linear( time, duration ); break;
case EBUIEasingType::Smoothstep: return Smoothstep( time, 0, duration); break;
case EBUIEasingType::InSine: return InSine( time, duration ); break;
case EBUIEasingType::OutSine: return OutSine( time, duration ); break;
case EBUIEasingType::InOutSine: return InOutSine( time, duration ); break;
case EBUIEasingType::InQuad: return InQuad( time, duration ); break;
case EBUIEasingType::OutQuad: return OutQuad( time, duration ); break;
case EBUIEasingType::InOutQuad: return InOutQuad( time, duration ); break;
case EBUIEasingType::InCubic: return InCubic( time, duration ); break;
case EBUIEasingType::OutCubic: return OutCubic( time, duration ); break;
case EBUIEasingType::InOutCubic: return InOutCubic( time, duration ); break;
case EBUIEasingType::InQuart: return InQuart( time, duration ); break;
case EBUIEasingType::OutQuart: return OutQuart( time, duration ); break;
case EBUIEasingType::InOutQuart: return InOutQuart( time, duration ); break;
case EBUIEasingType::InQuint: return InQuint( time, duration ); break;
case EBUIEasingType::OutQuint: return OutQuint( time, duration ); break;
case EBUIEasingType::InOutQuint: return InOutQuint( time, duration ); break;
case EBUIEasingType::InExpo: return InExpo( time, duration ); break;
case EBUIEasingType::OutExpo: return OutExpo( time, duration ); break;
case EBUIEasingType::InOutExpo: return InOutExpo( time, duration ); break;
case EBUIEasingType::InCirc: return InCirc( time, duration ); break;
case EBUIEasingType::OutCirc: return OutCirc( time, duration ); break;
case EBUIEasingType::InOutCirc: return InOutCirc( time, duration ); break;
case EBUIEasingType::InElastic: return InElastic( time, duration, overshootOrAmplitude, period ); break;
case EBUIEasingType::OutElastic: return OutElastic( time, duration, overshootOrAmplitude, period ); break;
case EBUIEasingType::InOutElastic: return InOutElastic( time, duration, overshootOrAmplitude, period ); break;
case EBUIEasingType::InBack: return InBack( time, duration, overshootOrAmplitude, period ); break;
case EBUIEasingType::OutBack: return OutBack( time, duration, overshootOrAmplitude, period ); break;
case EBUIEasingType::InOutBack: return InOutBack( time, duration, overshootOrAmplitude, period ); break;
case EBUIEasingType::Linear: return Linear( time, duration );
case EBUIEasingType::Smoothstep: return Smoothstep( time, 0, duration);
case EBUIEasingType::InSine: return InSine( time, duration );
case EBUIEasingType::OutSine: return OutSine( time, duration );
case EBUIEasingType::InOutSine: return InOutSine( time, duration );
case EBUIEasingType::InQuad: return InQuad( time, duration );
case EBUIEasingType::OutQuad: return OutQuad( time, duration );
case EBUIEasingType::InOutQuad: return InOutQuad( time, duration );
case EBUIEasingType::InCubic: return InCubic( time, duration );
case EBUIEasingType::OutCubic: return OutCubic( time, duration );
case EBUIEasingType::InOutCubic: return InOutCubic( time, duration );
case EBUIEasingType::InQuart: return InQuart( time, duration );
case EBUIEasingType::OutQuart: return OutQuart( time, duration );
case EBUIEasingType::InOutQuart: return InOutQuart( time, duration );
case EBUIEasingType::InQuint: return InQuint( time, duration );
case EBUIEasingType::OutQuint: return OutQuint( time, duration );
case EBUIEasingType::InOutQuint: return InOutQuint( time, duration );
case EBUIEasingType::InExpo: return InExpo( time, duration );
case EBUIEasingType::OutExpo: return OutExpo( time, duration );
case EBUIEasingType::InOutExpo: return InOutExpo( time, duration );
case EBUIEasingType::InCirc: return InCirc( time, duration );
case EBUIEasingType::OutCirc: return OutCirc( time, duration );
case EBUIEasingType::InOutCirc: return InOutCirc( time, duration );
case EBUIEasingType::InElastic: return InElastic( time, duration, overshootOrAmplitude, period );
case EBUIEasingType::OutElastic: return OutElastic( time, duration, overshootOrAmplitude, period );
case EBUIEasingType::InOutElastic: return InOutElastic( time, duration, overshootOrAmplitude, period );
case EBUIEasingType::InBack: return InBack( time, duration, overshootOrAmplitude, period );
case EBUIEasingType::OutBack: return OutBack( time, duration, overshootOrAmplitude, period );
case EBUIEasingType::InOutBack: return InOutBack( time, duration, overshootOrAmplitude, period );
}
return 0;
}
Expand Down Expand Up @@ -126,17 +124,17 @@ struct FBUIEasing
return -0.5f * ( time * ( time - 2 ) - 1 );
}

static float InCubic( float time, float duration = 1.0f )
{
time /= duration;
return time * time * time;
}
static float InCubic( float time, float duration = 1.0f )
{
time /= duration;
return time * time * time;
}

static float OutCubic( float time, float duration = 1.0f )
{
time = time / duration - 1;
return ( time * time * time + 1 );
}
static float OutCubic( float time, float duration = 1.0f )
{
time = time / duration - 1;
return ( time * time * time + 1 );
}

static float InOutCubic( float time, float duration = 1.0f )
{
Expand Down Expand Up @@ -269,18 +267,27 @@ struct FBUIEasing
{
float s;
if ( time == 0 ) return 0;
time /= duration * 0.5f;
if ( time == 2 ) return 1;
time /= duration;
if ( time == 1 ) return 1;
if ( period == 0 ) period = duration * ( 0.3f * 1.5f );
if ( overshootOrAmplitude < 1 ) {
overshootOrAmplitude = 1;
s = period / 4;
}
else s = period / TWO_PI * ( float ) FMath::Asin( 1 / overshootOrAmplitude );
time -= 1;

time *= 2; // Scale time to 0-2

if ( time < 1 )
{
time -= 1;
return -0.5f * ( overshootOrAmplitude * ( float ) FMath::Pow( 2, 10 * time ) * ( float ) FMath::Sin( ( time * duration - s ) * TWO_PI / period ) );
return overshootOrAmplitude * ( float ) FMath::Pow( 2, -10 * time ) * ( float ) FMath::Sin( ( time * duration - s ) * TWO_PI / period ) * 0.5f + 1;
}
else
{
time -= 1; // Adjust for the second half
return overshootOrAmplitude * ( float ) FMath::Pow( 2, -10 * time ) * ( float ) FMath::Sin( ( time * duration - s ) * TWO_PI / period ) * 0.5f + 1;
}
}

static float InBack( float time, float duration = 1.0f, float overshootOrAmplitude = 0.1f, float period = 1.0f )
Expand All @@ -307,4 +314,4 @@ struct FBUIEasing

};

#undef TWO_PI

Loading