Last active
October 26, 2023 10:39
-
-
Save johnfredcee/cc077687b9c9172f9d75b7c22761eff6 to your computer and use it in GitHub Desktop.
UMG Polyline Editor WIdget Body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) John Connors 2023 | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions : | |
// | |
// The above copyright notice and this permission notice shall be included in all copies | |
// or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED “AS IS”, | |
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
#include "PolylineEditorWidget.h" | |
#define LOCTEXT_NAMESPACE "PolylineEditor" | |
UPolylineEditorWidget::UPolylineEditorWidget(const FObjectInitializer& ObjectInitializer) | |
: Super(ObjectInitializer) | |
{ | |
XRange = 1.0f; | |
YRange = 1.0f; | |
LineThickness = 2.0f; | |
bClosedLine = false; | |
bMirror = false; | |
} | |
void UPolylineEditorWidget::ReleaseSlateResources(bool bReleaseChildren) | |
{ | |
PolylineEditor.Reset(); | |
} | |
TSharedRef<SWidget> UPolylineEditorWidget::RebuildWidget() | |
{ | |
// clang-format: off | |
PolylineEditor = SNew(SPolylineEditor) | |
.Points(Points) | |
.Brush(&Brush) | |
.LineThickness(LineThickness) | |
.LineScale(FVector2f(XRange, YRange)) | |
.bClosedLine(bClosedLine) | |
.bMirror(bMirror) | |
.OnPointAdded(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandlePointAdded)) | |
.OnPointRemoved(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandlePointRemoved)) | |
.OnPointMoved(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandlePointMoved)); | |
// clang-format : on | |
return PolylineEditor.ToSharedRef(); | |
} | |
void UPolylineEditorWidget::SynchronizeProperties() | |
{ | |
PolylineEditor->SetBrush(&Brush); | |
PolylineEditor->SetLineThickness(LineThickness); | |
PolylineEditor->SetLineScale(FVector2f{ XRange, YRange }); | |
PolylineEditor->SetPoints(Points); | |
PolylineEditor->SetClosedLine(bClosedLine); | |
PolylineEditor->SetMirrored(bMirror); | |
Super::SynchronizeProperties(); | |
} | |
void UPolylineEditorWidget::HandlePointAdded() | |
{ | |
Points = PolylineEditor->GetPoints(); | |
PointsModified.Broadcast(); | |
} | |
void UPolylineEditorWidget::HandlePointRemoved() | |
{ | |
Points = PolylineEditor->GetPoints(); | |
PointsModified.Broadcast(); | |
} | |
void UPolylineEditorWidget::HandlePointMoved() | |
{ | |
Points = PolylineEditor->GetPoints(); | |
PointsModified.Broadcast(); | |
} | |
void UPolylineEditorWidget::ComputeAllPoints(TArray<FVector2f>& AllPoints) | |
{ | |
constexpr bool bIncludeAllMirrorPoints = true; | |
return PolylineEditor->ComputeAllPoints(AllPoints, bIncludeAllMirrorPoints); | |
} | |
#if WITH_EDITOR | |
const FText UPolylineEditorWidget::GetPaletteCategory() | |
{ | |
return LOCTEXT("Geometry", "Geometry"); | |
} | |
#endif | |
#undef LOCTEXT_NAMESPACE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment