234 lines
7.2 KiB
C
234 lines
7.2 KiB
C
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||
|
|
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "CoreMinimal.h"
|
||
|
|
#include "Input/CursorReply.h"
|
||
|
|
#include "Input/Reply.h"
|
||
|
|
#include "Layout/Geometry.h"
|
||
|
|
#include "Rendering/RenderingCommon.h"
|
||
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
||
|
|
#include "Widgets/SCompoundWidget.h"
|
||
|
|
|
||
|
|
// Insights
|
||
|
|
#include "Insights/Common/FixedCircularBuffer.h"
|
||
|
|
#include "Insights/ViewModels/FrameTrackHelper.h"
|
||
|
|
#include "Insights/ViewModels/FrameTrackViewport.h"
|
||
|
|
|
||
|
|
class SScrollBar;
|
||
|
|
|
||
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
|
||
|
|
struct FFrameTrackSampleRef
|
||
|
|
{
|
||
|
|
TSharedPtr<FFrameTrackSeries> Series;
|
||
|
|
TSharedPtr<FFrameTrackSample> Sample;
|
||
|
|
|
||
|
|
FFrameTrackSampleRef()
|
||
|
|
: Series(), Sample()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
FFrameTrackSampleRef(TSharedPtr<FFrameTrackSeries> InSeries, TSharedPtr<FFrameTrackSample> InSample)
|
||
|
|
: Series(InSeries), Sample(InSample)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
FFrameTrackSampleRef(const FFrameTrackSampleRef& Other)
|
||
|
|
: Series(Other.Series), Sample(Other.Sample)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
FFrameTrackSampleRef& operator=(const FFrameTrackSampleRef& Other)
|
||
|
|
{
|
||
|
|
Series = Other.Series;
|
||
|
|
Sample = Other.Sample;
|
||
|
|
return *this;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Reset()
|
||
|
|
{
|
||
|
|
Series.Reset();
|
||
|
|
Sample.Reset();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool IsValid() const
|
||
|
|
{
|
||
|
|
return Series.IsValid() && Sample.IsValid();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Equals(const FFrameTrackSampleRef& Other) const
|
||
|
|
{
|
||
|
|
return Series == Other.Series && ((Sample == Other.Sample) || (Sample.IsValid() && Other.Sample.IsValid() && Sample->Equals(*Other.Sample)));
|
||
|
|
}
|
||
|
|
|
||
|
|
static bool AreEquals(const FFrameTrackSampleRef& A, const FFrameTrackSampleRef& B)
|
||
|
|
{
|
||
|
|
return A.Equals(B);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
/**
|
||
|
|
* Widget used to present frames data in a bar track.
|
||
|
|
*/
|
||
|
|
class SFrameTrack: public SCompoundWidget
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
/** Number of pixels. */
|
||
|
|
static constexpr float MOUSE_SNAP_DISTANCE = 2.0f;
|
||
|
|
|
||
|
|
enum class ECursorType
|
||
|
|
{
|
||
|
|
Default,
|
||
|
|
Arrow,
|
||
|
|
Hand,
|
||
|
|
};
|
||
|
|
|
||
|
|
public:
|
||
|
|
/** Default constructor. */
|
||
|
|
SFrameTrack();
|
||
|
|
|
||
|
|
/** Virtual destructor. */
|
||
|
|
virtual ~SFrameTrack();
|
||
|
|
|
||
|
|
/** Resets internal widget's data to the default one. */
|
||
|
|
void Reset();
|
||
|
|
|
||
|
|
SLATE_BEGIN_ARGS(SFrameTrack)
|
||
|
|
{
|
||
|
|
_Clipping = EWidgetClipping::ClipToBounds;
|
||
|
|
}
|
||
|
|
SLATE_END_ARGS()
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Construct this widget
|
||
|
|
* @param InArgs The declaration data for this widget
|
||
|
|
*/
|
||
|
|
void Construct(const FArguments& InArgs);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Ticks this widget. Override in derived classes, but always call the parent implementation.
|
||
|
|
* @param AllottedGeometry The space allotted for this widget
|
||
|
|
* @param InCurrentTime Current absolute real time
|
||
|
|
* @param InDeltaTime Real time passed since last tick
|
||
|
|
*/
|
||
|
|
virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
|
||
|
|
|
||
|
|
virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
|
||
|
|
|
||
|
|
virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||
|
|
virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||
|
|
virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||
|
|
virtual void OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||
|
|
virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
|
||
|
|
virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||
|
|
virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||
|
|
|
||
|
|
virtual FCursorReply OnCursorQuery(const FGeometry& MyGeometry, const FPointerEvent& CursorEvent) const override;
|
||
|
|
|
||
|
|
protected:
|
||
|
|
TSharedRef<FFrameTrackSeries> FindOrAddSeries(int32 FrameType);
|
||
|
|
TSharedPtr<FFrameTrackSeries> FindSeries(int32 FrameType) const;
|
||
|
|
void UpdateState();
|
||
|
|
|
||
|
|
void DrawHorizontalAxisGrid(FDrawContext& DrawContext, const FSlateBrush* Brush, const FSlateFontInfo& Font) const;
|
||
|
|
void DrawVerticalAxisGrid(FDrawContext& DrawContext, const FSlateBrush* Brush, const FSlateFontInfo& Font) const;
|
||
|
|
|
||
|
|
FFrameTrackSampleRef GetSampleAtMousePosition(float X, float Y);
|
||
|
|
void SelectFrameAtMousePosition(float X, float Y);
|
||
|
|
|
||
|
|
void ShowContextMenu(const FPointerEvent& MouseEvent);
|
||
|
|
|
||
|
|
void ContextMenu_ShowGameFrames_Execute();
|
||
|
|
bool ContextMenu_ShowGameFrames_CanExecute();
|
||
|
|
bool ContextMenu_ShowGameFrames_IsChecked();
|
||
|
|
|
||
|
|
void ContextMenu_ShowRenderingFrames_Execute();
|
||
|
|
bool ContextMenu_ShowRenderingFrames_CanExecute();
|
||
|
|
bool ContextMenu_ShowRenderingFrames_IsChecked();
|
||
|
|
|
||
|
|
void ContextMenu_AutoZoom_Execute();
|
||
|
|
bool ContextMenu_AutoZoom_CanExecute();
|
||
|
|
bool ContextMenu_AutoZoom_IsChecked();
|
||
|
|
void AutoZoom();
|
||
|
|
|
||
|
|
/** Binds our UI commands to delegates. */
|
||
|
|
void BindCommands();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Called when the user scrolls the horizontal scrollbar.
|
||
|
|
* @param ScrollOffset Scroll offset as a fraction between 0 and 1.
|
||
|
|
*/
|
||
|
|
void HorizontalScrollBar_OnUserScrolled(float ScrollOffset);
|
||
|
|
void UpdateHorizontalScrollBar();
|
||
|
|
|
||
|
|
void ZoomHorizontally(const float Delta, const float X);
|
||
|
|
|
||
|
|
protected:
|
||
|
|
/** The track's viewport. Encapsulates info about position and scale. */
|
||
|
|
FFrameTrackViewport Viewport;
|
||
|
|
bool bIsViewportDirty;
|
||
|
|
|
||
|
|
/** Cached info for all frame series. */
|
||
|
|
TMap<int32, TSharedPtr<FFrameTrackSeries>> SeriesMap;
|
||
|
|
TArray<int32> SeriesOrder;
|
||
|
|
|
||
|
|
bool bIsStateDirty;
|
||
|
|
|
||
|
|
bool bShowGameFrames;
|
||
|
|
bool bShowRenderingFrames;
|
||
|
|
bool bIsAutoZoomEnabled;
|
||
|
|
float AutoZoomViewportPos;
|
||
|
|
float AutoZoomViewportScale;
|
||
|
|
float AutoZoomViewportSize;
|
||
|
|
|
||
|
|
uint64 AnalysisSyncNextTimestamp;
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////
|
||
|
|
|
||
|
|
TSharedPtr<SScrollBar> HorizontalScrollBar;
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////
|
||
|
|
// Panning and Zooming behaviors
|
||
|
|
|
||
|
|
/** The current mouse position. */
|
||
|
|
FVector2D MousePosition;
|
||
|
|
|
||
|
|
/** Mouse position during the call on mouse button down. */
|
||
|
|
FVector2D MousePositionOnButtonDown;
|
||
|
|
float ViewportPosXOnButtonDown;
|
||
|
|
|
||
|
|
/** Mouse position during the call on mouse button up. */
|
||
|
|
FVector2D MousePositionOnButtonUp;
|
||
|
|
|
||
|
|
bool bIsLMB_Pressed;
|
||
|
|
bool bIsRMB_Pressed;
|
||
|
|
|
||
|
|
/** True, if the user is currently interactively scrolling the view (ex.: by holding the left mouse button and dragging). */
|
||
|
|
bool bIsScrolling;
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////
|
||
|
|
// Selection
|
||
|
|
|
||
|
|
FFrameTrackSampleRef HoveredSample;
|
||
|
|
|
||
|
|
float TooltipDesiredOpacity;
|
||
|
|
mutable float TooltipOpacity;
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////
|
||
|
|
// Misc
|
||
|
|
|
||
|
|
FGeometry ThisGeometry;
|
||
|
|
|
||
|
|
/** Cursor type. */
|
||
|
|
ECursorType CursorType;
|
||
|
|
|
||
|
|
// Debug stats
|
||
|
|
int32 NumUpdatedFrames;
|
||
|
|
TFixedCircularBuffer<uint64, 32> UpdateDurationHistory;
|
||
|
|
mutable TFixedCircularBuffer<uint64, 32> DrawDurationHistory;
|
||
|
|
mutable TFixedCircularBuffer<uint64, 32> OnPaintDurationHistory;
|
||
|
|
mutable uint64 LastOnPaintTime;
|
||
|
|
};
|