|
@@ -0,0 +1,140 @@
|
|
|
+#pragma once
|
|
|
+
|
|
|
+#include "EzAbilityTimelineScrubPanel.h"
|
|
|
+#include "Fonts/FontMeasure.h"
|
|
|
+
|
|
|
+SEzAbilityTimelineScrubPanel::SEzAbilityTimelineScrubPanel()
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void SEzAbilityTimelineScrubPanel::Construct(const FArguments& InArgs)
|
|
|
+{
|
|
|
+ m_Font = FSlateFontInfo(FPaths::EngineContentDir() / TEXT("Slate/Fonts/Roboto-Regular.ttf"), 8);
|
|
|
+ m_Brush = FAppStyle::GetBrush("WhiteBrush");
|
|
|
+}
|
|
|
+
|
|
|
+FVector2D SEzAbilityTimelineScrubPanel::ComputeDesiredSize(float scale) const
|
|
|
+{
|
|
|
+ return FVector2D(100.0f, 40.0f);
|
|
|
+}
|
|
|
+
|
|
|
+int32 SEzAbilityTimelineScrubPanel::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
|
|
|
+{
|
|
|
+ FVector2D TimeRange(0.0f, 1.0f);
|
|
|
+
|
|
|
+ const TSharedRef< FSlateFontMeasure > FontMeasureService = FSlateApplication::Get().GetRenderer()->GetFontMeasureService();
|
|
|
+
|
|
|
+ const float CurrentPosition = 1;
|
|
|
+ const float AbilityLength = 1;
|
|
|
+ const float TimeRatio = CurrentPosition / AbilityLength;
|
|
|
+
|
|
|
+ FNumberFormattingOptions WholeNumberFmt;
|
|
|
+ WholeNumberFmt.SetMaximumFractionalDigits(0);
|
|
|
+
|
|
|
+ FNumberFormattingOptions FmtOptions;
|
|
|
+ FmtOptions.SetMaximumFractionalDigits(2);
|
|
|
+ FmtOptions.SetMinimumFractionalDigits(1);
|
|
|
+
|
|
|
+ FText MinText = FText::AsNumber(TimeRange.X, &WholeNumberFmt);
|
|
|
+ FText MaxText = FText::AsNumber(TimeRange.Y, &WholeNumberFmt);
|
|
|
+ FVector2D MinSize = FontMeasureService->Measure(MinText, m_Font);
|
|
|
+ FVector2D MaxSize = FontMeasureService->Measure(MaxText, m_Font);
|
|
|
+
|
|
|
+ const FVector2D& WidgetSize = AllottedGeometry.GetLocalSize();
|
|
|
+
|
|
|
+
|
|
|
+ const float Padding = MaxSize.X * 0.5f + 4.0f;
|
|
|
+ const float ScrollbarWidth = 12.0f;
|
|
|
+ const float VertPadding = 4.0f;
|
|
|
+ FVector2D TextOffset(0.0f, VertPadding);
|
|
|
+
|
|
|
+
|
|
|
+ int32 CurrentLayer = LayerId;
|
|
|
+
|
|
|
+ FSlateDrawElement::MakeBox(OutDrawElements,
|
|
|
+ CurrentLayer++,
|
|
|
+ AllottedGeometry.ToPaintGeometry(),
|
|
|
+ m_Brush);
|
|
|
+
|
|
|
+ FSlateLayoutTransform Transform;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ TextOffset.X = WidgetSize.X - MaxSize.X * 0.5f - Padding - ScrollbarWidth;
|
|
|
+
|
|
|
+ Transform = FSlateLayoutTransform(TextOffset);
|
|
|
+
|
|
|
+ FSlateDrawElement::MakeText(OutDrawElements,
|
|
|
+ CurrentLayer++,
|
|
|
+ AllottedGeometry.ToPaintGeometry(Transform),
|
|
|
+ MaxText,
|
|
|
+ m_Font);
|
|
|
+
|
|
|
+
|
|
|
+ float MajorLineSize = WidgetSize.Y * 0.45f;
|
|
|
+ float MinorLineSize = WidgetSize.Y * 0.20f;
|
|
|
+
|
|
|
+ TArray<FVector2D> Line;
|
|
|
+ Line.SetNum(2);
|
|
|
+
|
|
|
+ float MajorFreq = 1;
|
|
|
+ float MinorFreq = 1;
|
|
|
+
|
|
|
+
|
|
|
+ float StepTime = 0.0f;
|
|
|
+ FText MajorLabel;
|
|
|
+
|
|
|
+ Line[0].Y = WidgetSize.Y - 1.0f - VertPadding;
|
|
|
+ Line[1].Y = WidgetSize.Y - MajorLineSize + VertPadding;
|
|
|
+
|
|
|
+
|
|
|
+ const float WidgetInteriorSize = WidgetSize.X - Padding * 2.0f - ScrollbarWidth;
|
|
|
+
|
|
|
+ for (; StepTime < TimeRange.Y; StepTime += MajorFreq)
|
|
|
+ {
|
|
|
+ Line[0].X = Padding + WidgetInteriorSize * (StepTime / TimeRange.Y);
|
|
|
+ Line[1].X = Line[0].X;
|
|
|
+
|
|
|
+ FSlateDrawElement::MakeLines(OutDrawElements,
|
|
|
+ CurrentLayer++,
|
|
|
+ AllottedGeometry.ToPaintGeometry(),
|
|
|
+ Line);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (StepTime = 0.0f; StepTime < TimeRange.Y; StepTime += MinorFreq)
|
|
|
+ {
|
|
|
+ Line[0].X = Padding + WidgetInteriorSize * (StepTime / TimeRange.Y);
|
|
|
+ Line[1].X = Line[0].X;
|
|
|
+
|
|
|
+ FSlateDrawElement::MakeLines(OutDrawElements,
|
|
|
+ CurrentLayer++,
|
|
|
+ AllottedGeometry.ToPaintGeometry(),
|
|
|
+ Line);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Line[0].X = WidgetSize.X - Padding - ScrollbarWidth;
|
|
|
+ Line[1].X = Line[0].X;
|
|
|
+
|
|
|
+ FSlateDrawElement::MakeLines(OutDrawElements,
|
|
|
+ CurrentLayer++,
|
|
|
+ AllottedGeometry.ToPaintGeometry(),
|
|
|
+ Line);
|
|
|
+
|
|
|
+
|
|
|
+ FVector2D MarkerSize(12.0f, 12.0f);
|
|
|
+ FVector2D MarkerOffset;
|
|
|
+
|
|
|
+
|
|
|
+ MarkerOffset.X = (Padding + WidgetInteriorSize * TimeRatio - MarkerSize.X * 0.5f);
|
|
|
+ MarkerOffset.Y = 4;
|
|
|
+
|
|
|
+ Transform = FSlateLayoutTransform(MarkerOffset);
|
|
|
+
|
|
|
+ FSlateDrawElement::MakeBox(OutDrawElements, CurrentLayer++, AllottedGeometry.ToPaintGeometry(MarkerSize, Transform), FAppStyle::GetBrush("WhiteBrush"));
|
|
|
+
|
|
|
+ return SCompoundWidget::OnPaint(Args, AllottedGeometry, MyClippingRect, OutDrawElements, CurrentLayer, InWidgetStyle, bParentEnabled);
|
|
|
+}
|