From 6c20a69392bcfa63d2382e4127e40ef24b74cd2f Mon Sep 17 00:00:00 2001 From: Albert Tony Date: Mon, 16 May 2022 16:20:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix=EF=BC=9A=E5=8D=87=E7=BA=A7=E5=B9=B6?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=88=B0UE5.0=E3=80=82=E5=B7=B2=E7=9F=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98:=201.=20UE5=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E4=B8=AD=E9=A6=96=E6=AC=A1=E8=BF=90=E8=A1=8C=EF=BC=8C=E8=BD=BD?= =?UTF-8?q?=E5=85=A5=E5=9B=BE=E7=89=87=E8=B5=84=E6=BA=90=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=8832X32=EF=BC=89.=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=89=93=E5=BC=80=E9=A1=B9=E7=9B=AE=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=80=89=E6=8B=A9=E6=B6=89=E5=8F=8A=E5=88=B0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=B5=84=E6=BA=90=E9=87=8D=E6=96=B0=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E3=80=82=202.=20=E6=89=93=E5=8C=85=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E5=80=99=EF=BC=8C=E5=87=BA=E7=8E=B0slate=E8=B7=A8=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=8A=A5=E9=94=99=EF=BC=8C=E9=9C=80=E8=A6=81=E8=B7=9F?= =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E7=9A=84=E6=8E=92=E6=9F=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/FairyGUI/FairyGUI.Build.cs | 3 ++ Source/FairyGUI/Private/FairyApplication.cpp | 5 +- Source/FairyGUI/Private/UI/GComponent.cpp | 2 +- Source/FairyGUI/Private/UI/GList.cpp | 8 ++-- .../Private/Widgets/BitmapFontRun.cpp | 8 ++-- Source/FairyGUI/Private/Widgets/LoaderRun.cpp | 7 +-- .../Private/Widgets/Mesh/PolygonMesh.cpp | 6 +-- .../Private/Widgets/Mesh/VertexHelper.cpp | 6 +-- Source/FairyGUI/Private/Widgets/NGraphics.cpp | 4 +- Source/FairyGUI/Private/Widgets/NTexture.cpp | 4 +- .../FairyGUI/Private/Widgets/SContainer.cpp | 35 ++++++++++---- .../Private/Widgets/SDisplayObject.cpp | 15 ++++-- Source/FairyGUI/Public/UI/GObjectPool.h | 5 ++ Source/FairyGUI/Public/UI/PackageItem.h | 5 ++ Source/FairyGUI/Public/Widgets/BitmapFont.h | 5 ++ .../FairyGUI/Public/Widgets/BitmapFontRun.h | 4 +- Source/FairyGUI/Public/Widgets/LoaderRun.h | 7 ++- Source/FairyGUI/Public/Widgets/NGraphics.h | 5 ++ Source/FairyGUI/Public/Widgets/SContainer.h | 47 +++++++++++++++++-- .../FairyGUI/Public/Widgets/SDisplayObject.h | 6 +-- Source/FairyGUI/Public/Widgets/SMovieClip.h | 5 ++ Source/FairyGUI/Public/Widgets/STextInput.h | 2 +- 22 files changed, 147 insertions(+), 47 deletions(-) diff --git a/Source/FairyGUI/FairyGUI.Build.cs b/Source/FairyGUI/FairyGUI.Build.cs index 236e5c8..069d460 100644 --- a/Source/FairyGUI/FairyGUI.Build.cs +++ b/Source/FairyGUI/FairyGUI.Build.cs @@ -56,3 +56,6 @@ public FairyGUI(ReadOnlyTargetRules Target) : base(Target) ); } } + + + diff --git a/Source/FairyGUI/Private/FairyApplication.cpp b/Source/FairyGUI/Private/FairyApplication.cpp index c292b23..5b1f49b 100644 --- a/Source/FairyGUI/Private/FairyApplication.cpp +++ b/Source/FairyGUI/Private/FairyApplication.cpp @@ -224,7 +224,10 @@ void UFairyApplication::PlaySound(const FString& URL, float VolumnScale) if (SoundItem.IsValid()) { SoundItem->Load(); - FSlateApplication::Get().PlaySound(*SoundItem->Sound); + if (SoundItem->Sound.IsValid()) + { + FSlateApplication::Get().PlaySound(*SoundItem->Sound); + } } } diff --git a/Source/FairyGUI/Private/UI/GComponent.cpp b/Source/FairyGUI/Private/UI/GComponent.cpp index 0597a5c..da3bce4 100644 --- a/Source/FairyGUI/Private/UI/GComponent.cpp +++ b/Source/FairyGUI/Private/UI/GComponent.cpp @@ -20,7 +20,7 @@ UGComponent::UGComponent() : { DisplayObject = RootContainer = SNew(SContainer).GObject(this); DisplayObject->SetOpaque(false); - + Container = SNew(SContainer); Container->SetOpaque(false); RootContainer->AddChild(Container.ToSharedRef()); diff --git a/Source/FairyGUI/Private/UI/GList.cpp b/Source/FairyGUI/Private/UI/GList.cpp index f82b98c..38bf9be 100644 --- a/Source/FairyGUI/Private/UI/GList.cpp +++ b/Source/FairyGUI/Private/UI/GList.cpp @@ -832,7 +832,7 @@ void UGList::ScrollToView(int32 Index, bool bAnimation, bool bSetFirst) verifyf(Index >= 0 && Index < VirtualItems.Num(), TEXT("Invalid child index")); if (bLoop) - Index = FMath::FloorToFloat(FirstIndex / NumItems) * NumItems + Index; + Index = FMath::FloorToFloat(static_cast(FirstIndex) / NumItems) * NumItems + Index; FBox2D rect; FItemInfo& ii = VirtualItems[Index]; @@ -1072,19 +1072,19 @@ FVector2D UGList::GetSnappingPosition(const FVector2D& InPoint) FVector2D ret = InPoint; if (Layout == EListLayoutType::SingleColumn || Layout == EListLayoutType::FlowHorizontal) { - int32 index = GetIndexOnPos1(ret.Y, false); + int32 index = GetIndexOnPos1(reinterpret_cast(ret.Y), false); if (index < VirtualItems.Num() && InPoint.Y - ret.Y > VirtualItems[index].Size.Y / 2 && index < RealNumItems) ret.Y += VirtualItems[index].Size.Y + LineGap; } else if (Layout == EListLayoutType::SingleRow || Layout == EListLayoutType::FlowVertical) { - int32 index = GetIndexOnPos2(ret.X, false); + int32 index = GetIndexOnPos2(reinterpret_cast(ret.X), false); if (index < VirtualItems.Num() && InPoint.X - ret.X > VirtualItems[index].Size.X / 2 && index < RealNumItems) ret.X += VirtualItems[index].Size.X + ColumnGap; } else { - int32 index = GetIndexOnPos3(ret.X, false); + int32 index = GetIndexOnPos3(reinterpret_cast(ret.X), false); if (index < VirtualItems.Num() && InPoint.X - ret.X > VirtualItems[index].Size.X / 2 && index < RealNumItems) ret.X += VirtualItems[index].Size.X + ColumnGap; } diff --git a/Source/FairyGUI/Private/Widgets/BitmapFontRun.cpp b/Source/FairyGUI/Private/Widgets/BitmapFontRun.cpp index 93280dc..ad5086b 100644 --- a/Source/FairyGUI/Private/Widgets/BitmapFontRun.cpp +++ b/Source/FairyGUI/Private/Widgets/BitmapFontRun.cpp @@ -79,24 +79,24 @@ FVector2D FBitmapFontRun::GetLocationAt(const TSharedRef< ILayoutBlock >& Block, return Block->GetLocationOffset(); } -int32 FBitmapFontRun::OnPaint(const FPaintArgs& Args, const FTextLayout::FLineView& Line, const TSharedRef< ILayoutBlock >& Block, const FTextBlockStyle& DefaultStyle, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const +int32 FBitmapFontRun::OnPaint(const FPaintArgs& PaintArgs, const FTextArgs& TextArgs, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const { if (Glyph == nullptr) return LayerId; // 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); - + FLinearColor FinalColorAndOpacity; if (Font->bCanTint) - FinalColorAndOpacity = InWidgetStyle.GetColorAndOpacityTint() * DefaultStyle.ColorAndOpacity.GetSpecifiedColor(); + FinalColorAndOpacity = InWidgetStyle.GetColorAndOpacityTint() * TextArgs.DefaultStyle.ColorAndOpacity.GetSpecifiedColor(); else FinalColorAndOpacity = InWidgetStyle.GetColorAndOpacityTint(); const ESlateDrawEffect DrawEffects = bParentEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect; FSlateDrawElement::MakeBox( OutDrawElements, ++LayerId, - AllottedGeometry.ToPaintGeometry(Glyph->Size, FSlateLayoutTransform(TransformPoint(InverseScale, Block->GetLocationOffset()) + Glyph->Offset)), + AllottedGeometry.ToPaintGeometry(Glyph->Size, FSlateLayoutTransform(TransformPoint(InverseScale, TextArgs.Block->GetLocationOffset()) + Glyph->Offset)), &Brush, DrawEffects, FinalColorAndOpacity diff --git a/Source/FairyGUI/Private/Widgets/LoaderRun.cpp b/Source/FairyGUI/Private/Widgets/LoaderRun.cpp index a9d9169..1151c3a 100644 --- a/Source/FairyGUI/Private/Widgets/LoaderRun.cpp +++ b/Source/FairyGUI/Private/Widgets/LoaderRun.cpp @@ -102,11 +102,12 @@ FVector2D FLoaderRun::GetLocationAt(const TSharedRef< ILayoutBlock >& Block, int return Block->GetLocationOffset(); } -int32 FLoaderRun::OnPaint(const FPaintArgs& Args, const FTextLayout::FLineView& Line, const TSharedRef< ILayoutBlock >& Block, const FTextBlockStyle& DefaultStyle, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const +int32 FLoaderRun::OnPaint(const FPaintArgs& PaintArgs, const FTextArgs& TextArgs, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const { + const float InverseScale = Inverse(AllottedGeometry.Scale); - const FGeometry WidgetGeometry = AllottedGeometry.MakeChild(TransformVector(InverseScale, Block->GetSize()), FSlateLayoutTransform(TransformPoint(InverseScale, Block->GetLocationOffset()))); - return Children[0]->Paint(Args, WidgetGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled); + const FGeometry WidgetGeometry = AllottedGeometry.MakeChild(TransformVector(InverseScale, TextArgs.Block->GetSize()), FSlateLayoutTransform(TransformPoint(InverseScale, TextArgs.Block->GetLocationOffset()))); + return Children[0]->Paint(PaintArgs, WidgetGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled); } TSharedRef< ILayoutBlock > FLoaderRun::CreateBlock(int32 BeginIndex, int32 EndIndex, FVector2D Size, const FLayoutBlockTextContext& TextContext, const TSharedPtr< IRunRenderer >& Renderer) diff --git a/Source/FairyGUI/Private/Widgets/Mesh/PolygonMesh.cpp b/Source/FairyGUI/Private/Widgets/Mesh/PolygonMesh.cpp index 9754f4f..c3e6a09 100644 --- a/Source/FairyGUI/Private/Widgets/Mesh/PolygonMesh.cpp +++ b/Source/FairyGUI/Private/Widgets/Mesh/PolygonMesh.cpp @@ -103,12 +103,12 @@ void FPolygonMesh::DrawOutline(FVertexHelper& Helper) int32 start = k - numVertices; for (int32 i = 0; i < numVertices; i++) { - const FVector2D& p0 = Helper.Vertices[start + i].Position; + const FVector2D& p0 = FVector2D(Helper.Vertices[start + i].Position); FVector2D p1; if (i < numVertices - 1) - p1 = Helper.Vertices[start + i + 1].Position; + p1 = FVector2D(Helper.Vertices[start + i + 1].Position); else - p1 = Helper.Vertices[start].Position; + p1 = FVector2D(Helper.Vertices[start].Position); FVector2D widthVector(p1.Y - p0.Y, p0.X - p1.X); widthVector.Normalize(); diff --git a/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp b/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp index 75013eb..a8c6aac 100644 --- a/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp +++ b/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp @@ -30,7 +30,7 @@ void FVertexHelper::AddVertex(const FVector2D& Position, const FColor& Color) void FVertexHelper::AddVertex(const FVector2D& Position, const FColor& Color, const FVector2D& TexCoords) { FSlateVertex Vertex; - Vertex.Position = Position; + Vertex.Position = FVector2f(Position); Vertex.Color = Color; Vertex.TexCoords[0] = TexCoords.X; Vertex.TexCoords[1] = TexCoords.Y; @@ -117,8 +117,8 @@ const FVector2D& FVertexHelper::GetPosition(int32 Index) { if (Index < 0) Index = Vertices.Num() + Index; - - return Vertices[Index].Position; + + return FVector2D(Vertices[Index].Position); } FVector2D FVertexHelper::GetUVAtPosition(const FVector2D& Position, bool bUsePercent) diff --git a/Source/FairyGUI/Private/Widgets/NGraphics.cpp b/Source/FairyGUI/Private/Widgets/NGraphics.cpp index 2ab101d..c8f4842 100644 --- a/Source/FairyGUI/Private/Widgets/NGraphics.cpp +++ b/Source/FairyGUI/Private/Widgets/NGraphics.cpp @@ -91,7 +91,7 @@ void FNGraphics::Paint(const FGeometry& AllottedGeometry, int32 VerticeLength = Vertices.Num(); for (int32 i = 0; i < VerticeLength; i++) { - Vertices[i].Position = AllottedGeometry.LocalToAbsolute(PositionsBackup[i]); + Vertices[i].Position =FVector2f(AllottedGeometry.LocalToAbsolute(PositionsBackup[i])); } FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, ResourceHandle, Vertices, Triangles, nullptr, 0, 0, DrawEffects); @@ -157,7 +157,7 @@ void FNGraphics::UpdateMeshNow() AlphaBackup[i] = Vertex.Color.A; Vertex.Color.A = (uint8)FMath::Clamp(FMath::TruncToInt(Vertex.Color.A * UsingAlpha), 0, 255), - PositionsBackup[i] = Vertex.Position; + PositionsBackup[i] = FVector2D(Vertex.Position); } Vertices += Helper.Vertices; diff --git a/Source/FairyGUI/Private/Widgets/NTexture.cpp b/Source/FairyGUI/Private/Widgets/NTexture.cpp index 6d6e89c..c04bcc2 100644 --- a/Source/FairyGUI/Private/Widgets/NTexture.cpp +++ b/Source/FairyGUI/Private/Widgets/NTexture.cpp @@ -8,10 +8,10 @@ UNTexture* UNTexture::GetWhiteTexture() if (WhiteTexture == nullptr) { UTexture2D* NativeTexture = UTexture2D::CreateTransient(2, 2); - uint8* MipData = (uint8*)NativeTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE); + uint8* MipData = (uint8*)NativeTexture->GetPlatformData()->Mips[0].BulkData.Lock(LOCK_READ_WRITE); for (int32 i = 0; i < 16; i++) *(MipData + i) = 255; - NativeTexture->PlatformData->Mips[0].BulkData.Unlock(); + NativeTexture->GetPlatformData()->Mips[0].BulkData.Unlock(); #if WITH_EDITORONLY_DATA NativeTexture->CompressionNone = true; NativeTexture->MipGenSettings = TMGS_NoMipmaps; diff --git a/Source/FairyGUI/Private/Widgets/SContainer.cpp b/Source/FairyGUI/Private/Widgets/SContainer.cpp index 88422e0..f39f7dd 100644 --- a/Source/FairyGUI/Private/Widgets/SContainer.cpp +++ b/Source/FairyGUI/Private/Widgets/SContainer.cpp @@ -1,10 +1,26 @@ #include "Widgets/SContainer.h" #include "FairyApplication.h" +#include "UI/GComponent.h" #include "UI/GObject.h" -SContainer::SContainer() : - Children(this) +SContainer::FSlot::FSlot(const TSharedRef& InWidget) + : TSlotBase(InWidget) +{ +} + +SContainer::FSlot::FSlot(const FChildren& InParent) +{ + +} + +void SContainer::FSlot::Construct(const FChildren& SlotOwner, FSlotArguments&& InArg) +{ + TSlotBase::Construct(SlotOwner, MoveTemp(InArg)); +} + +SContainer::SContainer() + :Children(this) { bCanSupportFocus = false; } @@ -12,6 +28,7 @@ SContainer::SContainer() : void SContainer::Construct(const SContainer::FArguments& InArgs) { SDisplayObject::Construct(SDisplayObject::FArguments().GObject(InArgs._GObject)); + Children.AddSlots(MoveTemp(const_cast&>(InArgs._Slots))); } void SContainer::AddChild(const TSharedRef& SlotWidget) @@ -29,14 +46,12 @@ void SContainer::AddChildAt(const TSharedRef& SlotWidget, int32 Index) else { verifyf(!SlotWidget->GetParentWidget().IsValid(), TEXT("Cant add a child has parent")); - - FSlotBase& NewSlot = *new FSlotBase(); - if (Index == Count) - Children.Add(&NewSlot); - else - Children.Insert(&NewSlot, Index); - NewSlot.AttachWidget(SlotWidget); - + + if (Index == Count) + AddSlot(SlotWidget); + else + InsertSlot(SlotWidget,Index); + UGObject* OnStageObj = SDisplayObject::GetWidgetGObjectIfOnStage(AsShared()); if (OnStageObj != nullptr) { diff --git a/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp b/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp index 4152a3b..617d11d 100644 --- a/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp +++ b/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp @@ -4,7 +4,6 @@ #include "UI/GObject.h" bool SDisplayObject::bMindVisibleOnly = false; -FNoChildren SDisplayObject::NoChildrenInstance; FName SDisplayObject::SDisplayObjectTag("SDisplayObjectTag"); SDisplayObject::SDisplayObject() : @@ -29,7 +28,11 @@ const FVector2D& SDisplayObject::GetPosition() const if (!GetRenderTransform().IsSet()) return FVector2D::ZeroVector; else + { return GetRenderTransform()->GetTranslation(); + } + + } void SDisplayObject::SetPosition(const FVector2D& InPosition) @@ -108,13 +111,14 @@ void SDisplayObject::SetInteractable(bool bInInteractable) void SDisplayObject::UpdateVisibilityFlags() { + bool HitTestFlag = bInteractable && bTouchable; if (!bVisible) SetVisibility(EVisibility::Collapsed); else if (!HitTestFlag) SetVisibility(EVisibility::HitTestInvisible); else if (GObject.IsValid() && GObject->GetHitArea() != nullptr) - Visibility.BindRaw(this, &SDisplayObject::GetVisibilityFlags); + SetVisibility(TAttribute(this, &SDisplayObject::GetVisibilityFlags)); else if (!bOpaque) SetVisibility(EVisibility::SelfHitTestInvisible); else @@ -157,7 +161,7 @@ FVector2D SDisplayObject::ComputeDesiredSize(float) const FChildren* SDisplayObject::GetChildren() { - return &NoChildrenInstance; + return &FNoChildren::NoChildrenInstance; } void SDisplayObject::OnArrangeChildren(const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren) const @@ -228,6 +232,11 @@ FReply SDisplayObject::OnMouseWheel(const FGeometry& MyGeometry, const FPointerE return FReply::Unhandled(); } +void SDisplayObject::SetVisibility(TAttribute InVisibility) +{ + SWidget::SetVisibility(InVisibility); +} + bool SDisplayObject::IsWidgetOnStage(const TSharedPtr& InWidget) { TSharedPtr Ptr = InWidget; diff --git a/Source/FairyGUI/Public/UI/GObjectPool.h b/Source/FairyGUI/Public/UI/GObjectPool.h index 9399d59..0ea26dd 100644 --- a/Source/FairyGUI/Public/UI/GObjectPool.h +++ b/Source/FairyGUI/Public/UI/GObjectPool.h @@ -13,6 +13,11 @@ class FGObjectPool : public FGCObject virtual void AddReferencedObjects(FReferenceCollector& Collector) override; + virtual FString GetReferencerName() const override + { + return TEXT("FGObjectPool"); + }; + private: TMap> Pool; }; \ No newline at end of file diff --git a/Source/FairyGUI/Public/UI/PackageItem.h b/Source/FairyGUI/Public/UI/PackageItem.h index 33525c5..f637780 100644 --- a/Source/FairyGUI/Public/UI/PackageItem.h +++ b/Source/FairyGUI/Public/UI/PackageItem.h @@ -26,6 +26,11 @@ class FAIRYGUI_API FPackageItem : public FGCObject, public TSharedFromThis CreateBlock(int32 StartIndex, int32 EndIndex, FVector2D Size, const FLayoutBlockTextContext& TextContext, const TSharedPtr< IRunRenderer >& Renderer) override; - virtual int32 OnPaint(const FPaintArgs& Args, const FTextLayout::FLineView& Line, const TSharedRef< ILayoutBlock >& Block, const FTextBlockStyle& DefaultStyle, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; - + virtual int32 OnPaint(const FPaintArgs& PaintArgs, const FTextArgs& TextArgs, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; + virtual const TArray< TSharedRef >& GetChildren() override; virtual void ArrangeChildren(const TSharedRef< ILayoutBlock >& Block, const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren) const override; diff --git a/Source/FairyGUI/Public/Widgets/LoaderRun.h b/Source/FairyGUI/Public/Widgets/LoaderRun.h index 58967e8..edd6967 100644 --- a/Source/FairyGUI/Public/Widgets/LoaderRun.h +++ b/Source/FairyGUI/Public/Widgets/LoaderRun.h @@ -30,7 +30,7 @@ class FAIRYGUI_API FLoaderRun : public ISlateRun, public TSharedFromThis< FLoade virtual TSharedRef< ILayoutBlock > CreateBlock(int32 StartIndex, int32 EndIndex, FVector2D Size, const FLayoutBlockTextContext& TextContext, const TSharedPtr< IRunRenderer >& Renderer) override; - virtual int32 OnPaint(const FPaintArgs& Args, const FTextLayout::FLineView& Line, const TSharedRef< ILayoutBlock >& Block, const FTextBlockStyle& DefaultStyle, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; + virtual int32 OnPaint(const FPaintArgs& PaintArgs, const FTextArgs& TextArgs, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; virtual const TArray< TSharedRef >& GetChildren() override; @@ -55,6 +55,11 @@ class FAIRYGUI_API FLoaderRun : public ISlateRun, public TSharedFromThis< FLoade virtual void AddReferencedObjects(FReferenceCollector& Collector) override; + virtual FString GetReferencerName() const override + { + return TEXT("FLoaderRun"); + }; + protected: FLoaderRun(UFairyApplication* App, const FHTMLElement& HTMLElement, const TSharedRef< const FString >& InText, const FTextRange& InRange); diff --git a/Source/FairyGUI/Public/Widgets/NGraphics.h b/Source/FairyGUI/Public/Widgets/NGraphics.h index f6adfcd..3d9477c 100644 --- a/Source/FairyGUI/Public/Widgets/NGraphics.h +++ b/Source/FairyGUI/Public/Widgets/NGraphics.h @@ -35,6 +35,11 @@ class FAIRYGUI_API FNGraphics : public FGCObject virtual void AddReferencedObjects(FReferenceCollector& Collector) override; + virtual FString GetReferencerName() const override + { + return TEXT("FNGraphics"); + }; + private: void UpdateMeshNow(); diff --git a/Source/FairyGUI/Public/Widgets/SContainer.h b/Source/FairyGUI/Public/Widgets/SContainer.h index 7ff7e0e..2dca8c4 100644 --- a/Source/FairyGUI/Public/Widgets/SContainer.h +++ b/Source/FairyGUI/Public/Widgets/SContainer.h @@ -5,10 +5,49 @@ class FAIRYGUI_API SContainer : public SDisplayObject { public: - SLATE_BEGIN_ARGS(SContainer) : - _GObject(nullptr) - {} + + class FSlot : public TSlotBase + { + public: + SLATE_SLOT_BEGIN_ARGS(FSlot, TSlotBase) + SLATE_SLOT_END_ARGS() + + FSlot(const TSharedRef& InWidget); + + FSlot(const FChildren& InParent); + + FSlot() + { + } + + void Construct(const FChildren& SlotOwner, FSlotArguments&& InArg); + + }; + + static FSlot::FSlotArguments Slot(const TSharedRef& InWidget) + { + return FSlot::FSlotArguments(MakeUnique(InWidget)); + } + + using SContainerSlotArguments = TPanelChildren::FScopedWidgetSlotArguments; + + SContainerSlotArguments AddSlot(const TSharedRef& InWidget) + { + return InsertSlot(InWidget,INDEX_NONE); + } + + SContainerSlotArguments InsertSlot(const TSharedRef& InWidget,int32 Index = INDEX_NONE) + { + return SContainerSlotArguments{MakeUnique(InWidget), this->Children, Index}; + } + + SLATE_BEGIN_ARGS(SContainer) + : _GObject(nullptr) + { + _Visibility = EVisibility::SelfHitTestInvisible; + } SLATE_ARGUMENT(UGObject*, GObject) + SLATE_SLOT_ARGUMENT( SContainer::FSlot, Slots ) SLATE_END_ARGS() SContainer(); @@ -30,5 +69,5 @@ class FAIRYGUI_API SContainer : public SDisplayObject virtual FChildren* GetChildren() override; protected: - TPanelChildren Children; + TPanelChildren Children; }; \ No newline at end of file diff --git a/Source/FairyGUI/Public/Widgets/SDisplayObject.h b/Source/FairyGUI/Public/Widgets/SDisplayObject.h index 67b2fa0..a70d3e9 100644 --- a/Source/FairyGUI/Public/Widgets/SDisplayObject.h +++ b/Source/FairyGUI/Public/Widgets/SDisplayObject.h @@ -13,6 +13,7 @@ class FAIRYGUI_API SDisplayObject : public SWidget _GObject(nullptr), _Tag(SDisplayObject::SDisplayObjectTag) { + _Visibility = EVisibility::SelfHitTestInvisible; } SLATE_ARGUMENT(UGObject*, GObject) SLATE_ARGUMENT(FName, Tag) @@ -53,6 +54,8 @@ class FAIRYGUI_API SDisplayObject : public SWidget virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override; virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; + virtual void SetVisibility( TAttribute InVisibility ) override final; + TWeakObjectPtr GObject; static bool IsWidgetOnStage(const TSharedPtr& InWidget); @@ -77,7 +80,4 @@ class FAIRYGUI_API SDisplayObject : public SWidget FVector2D Size; static bool bMindVisibleOnly; - -private: - static FNoChildren NoChildrenInstance; }; \ No newline at end of file diff --git a/Source/FairyGUI/Public/Widgets/SMovieClip.h b/Source/FairyGUI/Public/Widgets/SMovieClip.h index 37e0c12..740ad92 100644 --- a/Source/FairyGUI/Public/Widgets/SMovieClip.h +++ b/Source/FairyGUI/Public/Widgets/SMovieClip.h @@ -17,6 +17,11 @@ struct FAIRYGUI_API FMovieClipData : public FGCObject FMovieClipData(); virtual void AddReferencedObjects(FReferenceCollector& Collector) override; + + virtual FString GetReferencerName() const override + { + return TEXT("FMovieClip"); + }; }; class FAIRYGUI_API SMovieClip : public SFImage diff --git a/Source/FairyGUI/Public/Widgets/STextInput.h b/Source/FairyGUI/Public/Widgets/STextInput.h index f116da3..f4fb807 100644 --- a/Source/FairyGUI/Public/Widgets/STextInput.h +++ b/Source/FairyGUI/Public/Widgets/STextInput.h @@ -28,5 +28,5 @@ class FAIRYGUI_API STextInput : public SDisplayObject TSharedRef Widget; protected: - FSimpleSlot ChildSlot; + FSingleWidgetChildrenWithSlot ChildSlot; }; \ No newline at end of file From 02f265b3bcab716df90d9137cc880da09b1da0fe Mon Sep 17 00:00:00 2001 From: Albert Tony Date: Mon, 16 May 2022 19:14:30 +0800 Subject: [PATCH 2/3] fix:returning address of local variable or temporary --- Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp | 2 +- Source/FairyGUI/Private/Widgets/SDisplayObject.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp b/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp index a8c6aac..163e8fa 100644 --- a/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp +++ b/Source/FairyGUI/Private/Widgets/Mesh/VertexHelper.cpp @@ -118,7 +118,7 @@ const FVector2D& FVertexHelper::GetPosition(int32 Index) if (Index < 0) Index = Vertices.Num() + Index; - return FVector2D(Vertices[Index].Position); + return *new FVector2D(Vertices[Index].Position); } FVector2D FVertexHelper::GetUVAtPosition(const FVector2D& Position, bool bUsePercent) diff --git a/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp b/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp index 617d11d..67515fc 100644 --- a/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp +++ b/Source/FairyGUI/Private/Widgets/SDisplayObject.cpp @@ -29,10 +29,11 @@ const FVector2D& SDisplayObject::GetPosition() const return FVector2D::ZeroVector; else { - return GetRenderTransform()->GetTranslation(); + FVector2D& fv = *new FVector2D() ; + fv = GetRenderTransform()->GetTranslation(); + return fv; } - - + } void SDisplayObject::SetPosition(const FVector2D& InPosition) From 6a736ceea9df809b546eaa1e559e7add7d8892ba Mon Sep 17 00:00:00 2001 From: Albert Tony Date: Sat, 29 Jul 2023 15:43:38 +0800 Subject: [PATCH 3/3] fix: upgrade plugin to unreal engine 5.2 & :bug: AsyncLoadThread enable result in game launch crash --- Source/FairyGUI/Private/UI/GComponent.cpp | 6 +++++- Source/FairyGUI/Public/Event/EventContext.h | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/FairyGUI/Private/UI/GComponent.cpp b/Source/FairyGUI/Private/UI/GComponent.cpp index da3bce4..adf3e5e 100644 --- a/Source/FairyGUI/Private/UI/GComponent.cpp +++ b/Source/FairyGUI/Private/UI/GComponent.cpp @@ -23,7 +23,11 @@ UGComponent::UGComponent() : Container = SNew(SContainer); Container->SetOpaque(false); - RootContainer->AddChild(Container.ToSharedRef()); + + if (IsInGameThread()) + { + RootContainer->AddChild(Container.ToSharedRef()); + } } UGComponent::~UGComponent() diff --git a/Source/FairyGUI/Public/Event/EventContext.h b/Source/FairyGUI/Public/Event/EventContext.h index efeb7a6..4021aa1 100644 --- a/Source/FairyGUI/Public/Event/EventContext.h +++ b/Source/FairyGUI/Public/Event/EventContext.h @@ -37,7 +37,8 @@ class FAIRYGUI_API UEventContext : public UObject UFUNCTION(BlueprintCallable, Category = "FairyGUI") const FVector2D& GetPointerPosition() const { - return PointerEvent->GetScreenSpacePosition(); + achedPointerPosition = PointerEvent->GetScreenSpacePosition(); + return CachedPointerPosition; } UFUNCTION(BlueprintCallable, Category = "FairyGUI") @@ -135,6 +136,7 @@ class FAIRYGUI_API UEventContext : public UObject bool bDefaultPrevented; bool bIsMouseCaptor; FPointerEvent* PointerEvent; + mutable FVector2D CachedPointerPosition; FKeyEvent* KeyEvent; int32 ClickCount; FNVariant Data;