Advertisement
Guest User

RichTextBox.cpp

a guest
Jan 20th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2. /* Replace this with your project.h */
  3. #include "MyProject.h"
  4. #include "RichTextBox.h"
  5. #include "Runtime/UMG/Public/Components/RichTextBlockDecorator.h"
  6.  
  7.  
  8. #define LOCTEXT_NAMESPACE "UMG"
  9.  
  10. URichTextBox::URichTextBox(const FObjectInitializer& ObjectInitializer)
  11.     : Super(ObjectInitializer)
  12. {
  13.     static ConstructorHelpers::FObjectFinder<UFont> RobotoFontObj(TEXT("/Engine/EngineFonts/Roboto"));
  14.     Font = FSlateFontInfo(RobotoFontObj.Object, 12, FName("Regular"));
  15.     ColorAndOpacity = FLinearColor::White;
  16.     LineHeightPercentage = 1;
  17.     ShadowOffset = FVector2D(1.0f, 1.0f);
  18.     ShadowColorAndOpacity = FLinearColor::Transparent;
  19.  
  20.  
  21.     Decorators.Add(ObjectInitializer.CreateOptionalDefaultSubobject<URichTextBlockDecorator>(this, FName("DefaultDecorator")));
  22. }
  23.  
  24. void URichTextBox::ReleaseSlateResources(bool bReleaseChildren)
  25. {
  26.     Super::ReleaseSlateResources(bReleaseChildren);
  27.  
  28.     MyRichTextBlock.Reset();
  29. }
  30.  
  31. void URichTextBox::SetText(FText InText)
  32. {
  33.     Text = InText;
  34.     if (MyRichTextBlock.IsValid())
  35.     {
  36.         MyRichTextBlock->SetText(Text);
  37.     }
  38. }
  39.  
  40. FText URichTextBox::GetText()
  41. {
  42.     return Text;
  43. }
  44.  
  45. TSharedRef<SWidget> URichTextBox::RebuildWidget()
  46. {
  47.     //+ OnHyperlinkClicked = FSlateHyperlinkRun::FOnClick::CreateStatic(&RichTextHelper::OnBrowserLinkClicked, AsShared());
  48.     //+ FHyperlinkDecorator::Create(TEXT("browser"), OnHyperlinkClicked))
  49.     //+MakeShareable(new FDefaultRichTextDecorator(Font, Color));
  50.  
  51.     DefaultStyle.SetFont(Font);
  52.     DefaultStyle.SetColorAndOpacity(ColorAndOpacity);
  53.     DefaultStyle.SetShadowColorAndOpacity(ShadowColorAndOpacity);
  54.     DefaultStyle.SetShadowOffset(ShadowOffset);
  55.  
  56.     TArray< TSharedRef< class ITextDecorator > > CreatedDecorators;
  57.  
  58.     for (URichTextBlockDecorator* Decorator : Decorators)
  59.     {
  60.         if (Decorator)
  61.         {
  62.             CreatedDecorators.Add(Decorator->CreateDecorator(Font, ColorAndOpacity));
  63.         }
  64.     }
  65.  
  66.     MyRichTextBlock =
  67.         SNew(SRichTextBlock)
  68.         .Justification(Justification)
  69.         .AutoWrapText(AutoWrapText)
  70.         .WrapTextAt(WrapTextAt)
  71.         .Margin(Margin)
  72.         .LineHeightPercentage(LineHeightPercentage)
  73.         .TextStyle(&DefaultStyle)
  74.         .Decorators(CreatedDecorators);
  75.  
  76.     return MyRichTextBlock.ToSharedRef();
  77. }
  78.  
  79. void URichTextBox::SynchronizeProperties()
  80. {
  81.     Super::SynchronizeProperties();
  82.  
  83.     UE_LOG(LogWindows, Log, TEXT("Synchronizing Properties"));
  84.  
  85.     TAttribute<FText> TextBinding = OPTIONAL_BINDING(FText, Text);
  86.  
  87.     DefaultStyle.SetFont(Font);
  88.     DefaultStyle.SetColorAndOpacity(ColorAndOpacity);
  89.     DefaultStyle.SetShadowColorAndOpacity(ShadowColorAndOpacity);
  90.     DefaultStyle.SetShadowOffset(ShadowOffset);
  91.  
  92.     MyRichTextBlock->SetText(TextBinding);
  93.  
  94. }
  95.  
  96. #if WITH_EDITOR
  97.  
  98. // const FSlateBrush* URichTextBox::GetEditorIcon()
  99. // {
  100. //  return FUMGStyle::Get().GetBrush("Widget.RichTextBlock");
  101. // }
  102.  
  103. const FText URichTextBox::GetPaletteCategory()
  104. {
  105.     return LOCTEXT("Common", "Common");
  106. }
  107.  
  108. #endif
  109.  
  110. /////////////////////////////////////////////////////
  111.  
  112. #undef LOCTEXT_NAMESPACE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement