2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "Framework/Text/SlateWidgetRun.h"
|
|
|
|
|
#include "Layout/ArrangedChildren.h"
|
|
|
|
|
#include "Framework/Text/DefaultLayoutBlock.h"
|
2014-07-23 08:23:21 -04:00
|
|
|
|
|
|
|
|
#if WITH_FANCY_TEXT
|
|
|
|
|
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "Framework/Text/RunUtils.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-08-27 18:29:57 -04:00
|
|
|
TSharedRef< FSlateWidgetRun > FSlateWidgetRun::Create(const TSharedRef<class FTextLayout>& TextLayout, const FRunInfo& InRunInfo, const TSharedRef< const FString >& InText, const FWidgetRunInfo& InWidgetInfo)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-08-27 18:29:57 -04:00
|
|
|
return MakeShareable(new FSlateWidgetRun(TextLayout, InRunInfo, InText, InWidgetInfo));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 18:29:57 -04:00
|
|
|
TSharedRef< FSlateWidgetRun > FSlateWidgetRun::Create(const TSharedRef<class FTextLayout>& TextLayout, const FRunInfo& InRunInfo, const TSharedRef< const FString >& InText, const FWidgetRunInfo& InWidgetInfo, const FTextRange& InRange)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-08-27 18:29:57 -04:00
|
|
|
return MakeShareable(new FSlateWidgetRun(TextLayout, InRunInfo, InText, InWidgetInfo, InRange));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FTextRange FSlateWidgetRun::GetTextRange() const
|
|
|
|
|
{
|
|
|
|
|
return Range;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 11:14:37 -04:00
|
|
|
void FSlateWidgetRun::SetTextRange( const FTextRange& Value )
|
|
|
|
|
{
|
|
|
|
|
Range = Value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
int16 FSlateWidgetRun::GetBaseLine( float Scale ) const
|
|
|
|
|
{
|
2022-03-02 21:14:02 -05:00
|
|
|
return Info.Baseline.Get(0) * Scale;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16 FSlateWidgetRun::GetMaxHeight( float Scale ) const
|
|
|
|
|
{
|
|
|
|
|
return Info.Size.Get( Info.Widget->GetDesiredSize() ).Y * Scale;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 16:14:13 -05:00
|
|
|
FVector2D FSlateWidgetRun::Measure( int32 StartIndex, int32 EndIndex, float Scale, const FRunTextContext& TextContext ) const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-09-18 08:09:29 -04:00
|
|
|
if ( EndIndex - StartIndex == 0 )
|
|
|
|
|
{
|
|
|
|
|
return FVector2D( 0, GetMaxHeight( Scale ) );
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
return Info.Size.Get( Info.Widget->GetDesiredSize() ) * Scale;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 16:14:13 -05:00
|
|
|
int8 FSlateWidgetRun::GetKerning( int32 CurrentIndex, float Scale, const FRunTextContext& TextContext ) const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 16:14:13 -05:00
|
|
|
TSharedRef< ILayoutBlock > FSlateWidgetRun::CreateBlock( int32 StartIndex, int32 EndIndex, FVector2D Size, const FLayoutBlockTextContext& TextContext, const TSharedPtr< IRunRenderer >& Renderer )
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2015-11-04 16:14:13 -05:00
|
|
|
return FDefaultLayoutBlock::Create( SharedThis( this ), FTextRange( StartIndex, EndIndex ), Size, TextContext, Renderer );
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-20 13:19:19 -04:00
|
|
|
int32 FSlateWidgetRun::OnPaint(const FPaintArgs& PaintArgs, const FTextArgs& TextArgs, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-09-04 15:41:07 -04:00
|
|
|
// The block size and offset values are pre-scaled, so we need to account for that when converting the block offsets into paint geometry
|
|
|
|
|
const float InverseScale = Inverse(AllottedGeometry.Scale);
|
|
|
|
|
|
2014-08-27 18:29:57 -04:00
|
|
|
const FVector2D DesiredWidgetSize = Info.Widget->GetDesiredSize();
|
|
|
|
|
if (DesiredWidgetSize != WidgetSize)
|
|
|
|
|
{
|
|
|
|
|
WidgetSize = DesiredWidgetSize;
|
|
|
|
|
|
|
|
|
|
const TSharedPtr<FTextLayout> TextLayoutPtr = TextLayout.Pin();
|
|
|
|
|
if (TextLayoutPtr.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TextLayoutPtr->DirtyRunLayout(SharedThis(this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-20 13:19:19 -04:00
|
|
|
const FGeometry WidgetGeometry = AllottedGeometry.MakeChild(TransformVector(InverseScale, TextArgs.Block->GetSize()), FSlateLayoutTransform(TransformPoint(InverseScale, TextArgs.Block->GetLocationOffset())));
|
|
|
|
|
return Info.Widget->Paint(PaintArgs, WidgetGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-07-28 06:53:40 -04:00
|
|
|
const TArray< TSharedRef<SWidget> >& FSlateWidgetRun::GetChildren()
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-28 06:53:40 -04:00
|
|
|
return Children;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FSlateWidgetRun::ArrangeChildren( const TSharedRef< ILayoutBlock >& Block, const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren ) const
|
|
|
|
|
{
|
2014-09-04 15:41:07 -04:00
|
|
|
// The block size and offset values are pre-scaled, so we need to account for that when converting the block offsets into paint geometry
|
|
|
|
|
const float InverseScale = Inverse(AllottedGeometry.Scale);
|
|
|
|
|
|
|
|
|
|
ArrangedChildren.AddWidget(
|
|
|
|
|
AllottedGeometry.MakeChild(Info.Widget, TransformVector(InverseScale, Block->GetSize()), FSlateLayoutTransform(TransformPoint(InverseScale, Block->GetLocationOffset())))
|
|
|
|
|
);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-07-21 06:48:45 -04:00
|
|
|
int32 FSlateWidgetRun::GetTextIndexAt( const TSharedRef< ILayoutBlock >& Block, const FVector2D& Location, float Scale, ETextHitPoint* const OutHitPoint ) const
|
2014-06-09 11:14:37 -04:00
|
|
|
{
|
2014-09-18 08:09:29 -04:00
|
|
|
// A widget should always contain a single character (a breaking space)
|
|
|
|
|
check(Range.Len() == 1);
|
|
|
|
|
|
|
|
|
|
const FVector2D& BlockOffset = Block->GetLocationOffset();
|
|
|
|
|
const FVector2D& BlockSize = Block->GetSize();
|
|
|
|
|
|
|
|
|
|
const float Left = BlockOffset.X;
|
|
|
|
|
const float Top = BlockOffset.Y;
|
|
|
|
|
const float Right = BlockOffset.X + BlockSize.X;
|
|
|
|
|
const float Bottom = BlockOffset.Y + BlockSize.Y;
|
|
|
|
|
|
|
|
|
|
const bool ContainsPoint = Location.X >= Left && Location.X < Right && Location.Y >= Top && Location.Y < Bottom;
|
|
|
|
|
|
|
|
|
|
if ( !ContainsPoint )
|
|
|
|
|
{
|
|
|
|
|
return INDEX_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FVector2D ScaledWidgetSize = Info.Widget->GetDesiredSize() * Scale;
|
|
|
|
|
const int32 Index = (Location.X <= (Left + (ScaledWidgetSize.X * 0.5f))) ? Range.BeginIndex : Range.EndIndex;
|
|
|
|
|
|
|
|
|
|
if (OutHitPoint)
|
|
|
|
|
{
|
|
|
|
|
const FTextRange BlockRange = Block->GetTextRange();
|
2016-01-22 08:13:18 -05:00
|
|
|
const FLayoutBlockTextContext BlockTextContext = Block->GetTextContext();
|
|
|
|
|
|
|
|
|
|
// The block for a widget will always detect a LTR reading direction, so use the base direction (of the line) for the image hit-point detection
|
|
|
|
|
*OutHitPoint = RunUtils::CalculateTextHitPoint(Index, BlockRange, BlockTextContext.BaseDirection);
|
2014-09-18 08:09:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Index;
|
2014-06-09 11:14:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FVector2D FSlateWidgetRun::GetLocationAt( const TSharedRef< ILayoutBlock >& Block, int32 Offset, float Scale ) const
|
|
|
|
|
{
|
|
|
|
|
return Block->GetLocationOffset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FSlateWidgetRun::Move(const TSharedRef<FString>& NewText, const FTextRange& NewRange)
|
|
|
|
|
{
|
|
|
|
|
Text = NewText;
|
|
|
|
|
Range = NewRange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSharedRef<IRun> FSlateWidgetRun::Clone() const
|
|
|
|
|
{
|
2014-08-27 18:29:57 -04:00
|
|
|
return FSlateWidgetRun::Create(TextLayout.Pin().ToSharedRef(), RunInfo, Text, Info, Range);
|
2014-06-09 11:14:37 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-07 06:46:11 -04:00
|
|
|
void FSlateWidgetRun::AppendTextTo(FString& AppendToText) const
|
2014-06-09 11:14:37 -04:00
|
|
|
{
|
2014-09-18 08:09:29 -04:00
|
|
|
AppendToText.Append(**Text + Range.BeginIndex, Range.Len());
|
2014-06-09 11:14:37 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-07 06:46:11 -04:00
|
|
|
void FSlateWidgetRun::AppendTextTo(FString& AppendToText, const FTextRange& PartialRange) const
|
2014-06-09 11:14:37 -04:00
|
|
|
{
|
|
|
|
|
check(Range.BeginIndex <= PartialRange.BeginIndex);
|
|
|
|
|
check(Range.EndIndex >= PartialRange.EndIndex);
|
2014-09-18 08:09:29 -04:00
|
|
|
|
|
|
|
|
AppendToText.Append(**Text + PartialRange.BeginIndex, PartialRange.Len());
|
2014-06-09 11:14:37 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-07 06:46:11 -04:00
|
|
|
const FRunInfo& FSlateWidgetRun::GetRunInfo() const
|
|
|
|
|
{
|
|
|
|
|
return RunInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 08:09:29 -04:00
|
|
|
ERunAttributes FSlateWidgetRun::GetRunAttributes() const
|
|
|
|
|
{
|
|
|
|
|
return ERunAttributes::None;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 15:23:52 -04:00
|
|
|
FSlateWidgetRun::FSlateWidgetRun(const TSharedRef<class FTextLayout>& InTextLayout, const FRunInfo& InRunInfo, const TSharedRef< const FString >& InText, const FWidgetRunInfo& InWidgetInfo)
|
|
|
|
|
: TextLayout(InTextLayout)
|
2014-08-27 18:29:57 -04:00
|
|
|
, RunInfo( InRunInfo )
|
2014-08-07 06:46:11 -04:00
|
|
|
, Text( InText )
|
2014-03-14 14:13:41 -04:00
|
|
|
, Range( 0, Text->Len() )
|
|
|
|
|
, Info( InWidgetInfo )
|
|
|
|
|
, Children()
|
2014-08-27 18:29:57 -04:00
|
|
|
, WidgetSize()
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
Info.Widget->SlatePrepass();
|
2014-08-27 18:29:57 -04:00
|
|
|
WidgetSize = Info.Widget->GetDesiredSize();
|
|
|
|
|
Children.Add(Info.Widget);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2015-04-09 15:23:52 -04:00
|
|
|
FSlateWidgetRun::FSlateWidgetRun(const TSharedRef<class FTextLayout>& InTextLayout, const FRunInfo& InRunInfo, const TSharedRef< const FString >& InText, const FWidgetRunInfo& InWidgetInfo, const FTextRange& InRange)
|
|
|
|
|
: TextLayout(InTextLayout)
|
2014-08-27 18:29:57 -04:00
|
|
|
, RunInfo(InRunInfo)
|
2014-08-07 06:46:11 -04:00
|
|
|
, Text( InText )
|
2014-03-14 14:13:41 -04:00
|
|
|
, Range( InRange )
|
|
|
|
|
, Info( InWidgetInfo )
|
|
|
|
|
, Children()
|
2014-08-27 18:29:57 -04:00
|
|
|
, WidgetSize()
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
Info.Widget->SlatePrepass();
|
2014-08-27 18:29:57 -04:00
|
|
|
WidgetSize = Info.Widget->GetDesiredSize();
|
2014-03-14 14:13:41 -04:00
|
|
|
Children.Add( Info.Widget );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FSlateWidgetRun::FSlateWidgetRun( const FSlateWidgetRun& Run )
|
2014-08-27 18:29:57 -04:00
|
|
|
: TextLayout(Run.TextLayout)
|
|
|
|
|
, RunInfo(Run.RunInfo)
|
2014-08-07 06:46:11 -04:00
|
|
|
, Text( Run.Text )
|
2014-03-14 14:13:41 -04:00
|
|
|
, Range( Run.Range )
|
|
|
|
|
, Info( Run.Info )
|
2014-07-28 06:53:40 -04:00
|
|
|
, Children()
|
2014-08-27 18:29:57 -04:00
|
|
|
, WidgetSize(Run.WidgetSize)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 08:23:21 -04:00
|
|
|
|
|
|
|
|
#endif //WITH_FANCY_TEXT
|