int32 SSection::OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const { int32 StartLayer = SCompoundWidget::OnPaint( Args, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled ); FGeometry SectionGeometry = AllottedGeometry.MakeChild( FVector2D( SequencerSectionConstants::SectionGripSize, 0 ), AllottedGeometry.GetDrawSize() - FVector2D( SequencerSectionConstants::SectionGripSize*2, 0.0f ) ); FSlateRect SectionClipRect = SectionGeometry.GetClippingRect().IntersectionWith( MyClippingRect ); // Ask the interface to draw the section int32 PostSectionLayer = SectionInterface->OnPaintSection( SectionGeometry, SectionClipRect, OutDrawElements, LayerId, bParentEnabled ); DrawSectionBorders(AllottedGeometry, MyClippingRect, OutDrawElements, PostSectionLayer ); PaintKeys( SectionGeometry, MyClippingRect, OutDrawElements, PostSectionLayer, InWidgetStyle ); // Section name with drop shadow FText SectionTitle = SectionInterface->GetSectionTitle(); if (!SectionTitle.IsEmpty()) { FSlateDrawElement::MakeText( OutDrawElements, PostSectionLayer+1, SectionGeometry.ToOffsetPaintGeometry(FVector2D(6, 6)), SectionTitle, FEditorStyle::GetFontStyle("NormalFont"), MyClippingRect, ESlateDrawEffect::None, FLinearColor::Black ); FSlateDrawElement::MakeText( OutDrawElements, PostSectionLayer+2, SectionGeometry.ToOffsetPaintGeometry(FVector2D(5, 5)), SectionTitle, FEditorStyle::GetFontStyle("NormalFont"), MyClippingRect, ESlateDrawEffect::None, FLinearColor::White ); } return LayerId; }
int32 SProfilerThreadView::OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const { // SCOPE_LOG_TIME_FUNC(); // Rendering info. const bool bEnabled = ShouldBeEnabled( bParentEnabled ); const ESlateDrawEffect::Type DrawEffects = bEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect; const FSlateBrush* BackgroundBrush = FEditorStyle::GetBrush( "Profiler.LineGraphArea" ); const FSlateBrush* WhiteBrush = FEditorStyle::GetBrush( "WhiteTexture" ); // Paint state for this call to OnPaint, valid only in this scope. PaintState = new((void*)PaintStateMemory) FSlateOnPaintState( AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, InWidgetStyle, DrawEffects ); // Draw background. FSlateDrawElement::MakeBox ( PaintState->OutDrawElements, PaintState->LayerId, PaintState->AllottedGeometry.ToPaintGeometry( FVector2D( 0, 0 ), PaintState->Size2D() ), BackgroundBrush, PaintState->AbsoluteClippingRect, PaintState->DrawEffects, BackgroundBrush->GetTint( InWidgetStyle ) * InWidgetStyle.GetColorAndOpacityTint() ); LayerId++; // Draw all cycle counters for each thread nodes. if( IsReady() ) { DrawFramesBackgroundAndTimelines(); DrawUIStackNodes(); DrawFrameMarkers(); } #if 0/*DEBUG_PROFILER_PERFORMANCE*/ LayerId++; // Draw debug information. float GraphDescPosY = PaintState->Size2D().Y - 4.0f * PaintState->SummaryFont8Height; // Debug text. FSlateDrawElement::MakeText ( OutDrawElements, LayerId, AllottedGeometry.ToOffsetPaintGeometry( FVector2D( 16.0f, GraphDescPosY ) ), FString::Printf( TEXT( "Pos X=%f,Y=%f R X=%f,Y=%f TR X=%f,Y=%f ZF X=%f" ), PositionXMS, PositionY, RangeXMS, RangeY, TotalRangeXMS, TotalRangeY, ZoomFactorX ), PaintState->SummaryFont8, MyClippingRect, DrawEffects, FLinearColor::White ); GraphDescPosY -= PaintState->SummaryFont8Height + 1.0f; FSlateDrawElement::MakeText ( OutDrawElements, LayerId, AllottedGeometry.ToOffsetPaintGeometry( FVector2D( 16.0f, GraphDescPosY ) ), FString::Printf( TEXT( "NumMSPerWin=%f H Fr=%i,TID=%i,PX=%f,PY=%f" ), NumMillisecondsPerWindow, HoveredFrameIndex, HoveredThreadID, HoveredPositionX, HoveredPositionY ), PaintState->SummaryFont8, MyClippingRect, DrawEffects, FLinearColor::White ); GraphDescPosY -= PaintState->SummaryFont8Height + 1.0f; FSlateDrawElement::MakeText ( OutDrawElements, LayerId, AllottedGeometry.ToOffsetPaintGeometry( FVector2D( 16.0f, GraphDescPosY ) ), FString::Printf( TEXT( "DistD=%.2f FI=%3i,%3i" ), DistanceDragged, FramesIndices.X, FramesIndices.Y ), PaintState->SummaryFont8, MyClippingRect, DrawEffects, FLinearColor::White ); GraphDescPosY -= PaintState->SummaryFont8Height + 1.0f; #endif // DEBUG_PROFILER_PERFORMANCE // Reset paint state. PaintState = nullptr; return SCompoundWidget::OnPaint( Args, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled && IsEnabled() ); }
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 FLinearColor ColorAndOpacitySRGB = InWidgetStyle.GetColorAndOpacityTint(); static const FLinearColor SelectedBarColor(FLinearColor::White); // Paint inside the border only. const FVector2D BorderPadding = FTaskGraphStyle::Get()->GetVector("TaskGraph.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; }
int32 SHistogram::OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const { static double TotalTime = 0.0f; static uint32 NumCalls = 0; const double StartTime = FPlatformTime::Seconds(); const TSharedRef< FSlateFontMeasure > FontMeasureService = FSlateApplication::Get().GetRenderer()->GetFontMeasureService(); // Rendering info. const bool bEnabled = ShouldBeEnabled( bParentEnabled ); ESlateDrawEffect::Type DrawEffects = bEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect; const FSlateBrush* TimelineAreaBrush = FEditorStyle::GetBrush("Profiler.LineGraphArea"); const FSlateBrush* WhiteBrush = FEditorStyle::GetBrush("WhiteTexture"); const FSlateBrush* FillImage = FEditorStyle::GetBrush("TaskGraph.Mono"); // Draw background. FSlateDrawElement::MakeBox ( OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry( FVector2D(0,0), FVector2D(AllottedGeometry.Size.X,AllottedGeometry.Size.Y) ), TimelineAreaBrush, MyClippingRect, DrawEffects, TimelineAreaBrush->GetTint( InWidgetStyle ) * InWidgetStyle.GetColorAndOpacityTint() ); LayerId++; const float LabelBuffer = 25.0f; // draw the grid lines uint32 CountX = (uint32)((AllottedGeometry.Size.X-LabelBuffer*2.0f) / Description.GetBinCount()); float StartX = LabelBuffer; static const FLinearColor GridColor = FLinearColor(0.0f,0.0f,0.0f, 0.25f); static const FLinearColor GridTextColor = FLinearColor(1.0f,1.0f,1.0f, 0.25f); static const FLinearColor BorderColor = FLinearColor(0.0f,0.0f,0.0f,1.0f); FSlateFontInfo SummaryFont(FPaths::EngineContentDir() / TEXT("Slate/Fonts/Roboto-Regular.ttf"), 8 ); const float MaxFontCharHeight = FontMeasureService->Measure( TEXT("!"), SummaryFont ).Y; TArray<FVector2D> LinePoints; // draw the histogram box LinePoints.Add( FVector2D(StartX-1, LabelBuffer-1) ); LinePoints.Add( FVector2D(StartX + Description.GetBinCount()*CountX+1, LabelBuffer-1) ); LinePoints.Add( FVector2D(StartX + Description.GetBinCount()*CountX+1, AllottedGeometry.Size.Y - LabelBuffer+1) ); LinePoints.Add( FVector2D(StartX-1, AllottedGeometry.Size.Y - LabelBuffer+1) ); LinePoints.Add( FVector2D(StartX-1, LabelBuffer-1) ); FSlateDrawElement::MakeLines ( OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), LinePoints, MyClippingRect, DrawEffects, BorderColor ); LinePoints.Empty(); LayerId++; // draw the vertical lines for (int32 Index = 0; Index < Description.GetBinCount(); ++Index) { float MarkerPosX = StartX + Index * CountX; LinePoints.Add( FVector2D(MarkerPosX, LabelBuffer-1) ); LinePoints.Add( FVector2D(MarkerPosX, AllottedGeometry.Size.Y - LabelBuffer+1) ); FSlateDrawElement::MakeLines ( OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), LinePoints, MyClippingRect, DrawEffects, GridColor ); LinePoints.Empty(); // Bottom - X-Axes numbers, starting from MinValue const FString XLabel = FString::Printf(TEXT("%.0f"), Description.MinValue + Index*Description.Interval); float FontCharWidth = FontMeasureService->Measure(XLabel, SummaryFont).X; FSlateDrawElement::MakeText ( OutDrawElements, LayerId, AllottedGeometry.ToOffsetPaintGeometry( FVector2D(MarkerPosX-FontCharWidth/2.0f,AllottedGeometry.Size.Y-LabelBuffer/2.0f-MaxFontCharHeight/2.0f) ), XLabel, SummaryFont, MyClippingRect, DrawEffects, FLinearColor::White ); } LayerId++; // draw the horizontal lines float CountY = (AllottedGeometry.Size.Y-LabelBuffer*2.0f) / 4; float StartY = LabelBuffer; for (int32 Index = 0; Index < 5; ++Index) { float MarkerPosY = StartY + Index * CountY; LinePoints.Add( FVector2D(StartX, MarkerPosY) ); LinePoints.Add( FVector2D(StartX + Description.GetBinCount()*CountX, MarkerPosY) ); FSlateDrawElement::MakeLines ( OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), LinePoints, MyClippingRect, DrawEffects, GridColor ); LinePoints.Empty(); // Bottom - Y-Axes numbers, starting from 0 const FString YLabel = FString::Printf(TEXT("%i"), Description.Normalize ? 25 * (4-Index) : Description.GetTotalCount() / 4 * Index); float FontCharWidth = FontMeasureService->Measure(YLabel, SummaryFont).X; FSlateDrawElement::MakeText ( OutDrawElements, LayerId, AllottedGeometry.ToOffsetPaintGeometry( FVector2D(LabelBuffer/2.0f-FontCharWidth/2.0f,MarkerPosY-MaxFontCharHeight/2.0f) ), YLabel, SummaryFont, MyClippingRect, DrawEffects, FLinearColor::White ); } LayerId++; for (int32 Index = 0; Index < Description.GetBinCount(); ++Index) { float MarkerPosX = StartX + Index * CountX; float SizeY = (float)Description.GetCount(Index) / (float)Description.GetTotalCount() * (AllottedGeometry.Size.Y - LabelBuffer*2.0f); FSlateDrawElement::MakeBox( OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry( FVector2D(MarkerPosX, AllottedGeometry.Size.Y - SizeY- LabelBuffer), FVector2D(CountX, SizeY) ), FillImage, MyClippingRect, DrawEffects, FLinearColor::Green ); } return SCompoundWidget::OnPaint( Args, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled && IsEnabled() ); }