Files
UnrealEngineUWP/Engine/Source/Editor/LevelEditor/Private/DlgDeltaTransform.cpp

271 lines
7.1 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "DlgDeltaTransform.h"
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 "InputCoreTypes.h"
#include "Input/Reply.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/SCompoundWidget.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/SWindow.h"
#include "Framework/Application/SlateApplication.h"
#include "Widgets/Layout/SBorder.h"
#include "Widgets/Layout/SUniformGridPanel.h"
#include "Widgets/Input/SButton.h"
#include "Styling/AppStyle.h"
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 "Editor/UnrealEdEngine.h"
#include "Editor.h"
#include "UnrealEdGlobals.h"
#include "Widgets/Input/SVectorInputBox.h"
#define LOCTEXT_NAMESPACE "DeltaTransform"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// SDlgDeltaTransform
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class SDlgDeltaTransform : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS( SDlgDeltaTransform )
{}
/** Window in which this widget resides */
SLATE_ATTRIBUTE(TSharedPtr<SWindow>, ParentWindow)
SLATE_END_ARGS()
/** Used to construct widgets */
void Construct( const FArguments& InArgs )
{
// Set this widget as focused, to allow users to hit ESC to cancel.
ParentWindow = InArgs._ParentWindow.Get();
ParentWindow->SetWidgetToFocusOnActivate(SharedThis(this));
DeltaTransform.Set(FVector::ZeroVector);
ChildSlot
[
SNew(SBorder)
.BorderImage( FAppStyle::GetBrush( "ToolPanel.GroupBorder" ) )
[
SNew(SVerticalBox)
// Add user input block
+SVerticalBox::Slot()
.AutoHeight()
.Padding(2)
[
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(3)
[
SNew( SHorizontalBox )
+ SHorizontalBox::Slot()
.FillWidth(1)
.VAlign( VAlign_Center )
[
SNew( SVectorInputBox )
.X( this, &SDlgDeltaTransform::GetDeltaX )
.Y( this, &SDlgDeltaTransform::GetDeltaY )
.Z( this, &SDlgDeltaTransform::GetDeltaZ )
.bColorAxisLabels( true )
.AllowSpin( false )
.OnXCommitted( this, &SDlgDeltaTransform::OnSetDelta, 0 )
.OnYCommitted( this, &SDlgDeltaTransform::OnSetDelta, 1 )
.OnZCommitted( this, &SDlgDeltaTransform::OnSetDelta, 2 )
]
]
]
// Add Ok, Ok to all and Cancel buttons.
+SVerticalBox::Slot()
.AutoHeight()
.Padding(5)
.HAlign(HAlign_Right)
[
SNew(SUniformGridPanel)
.SlotPadding(FAppStyle::GetMargin("StandardDialog.SlotPadding"))
.MinDesiredSlotWidth(FAppStyle::GetFloat("StandardDialog.MinDesiredSlotWidth"))
.MinDesiredSlotHeight(FAppStyle::GetFloat("StandardDialog.MinDesiredSlotHeight"))
+SUniformGridPanel::Slot(0,0)
[
SNew(SButton)
.HAlign(HAlign_Center)
.ContentPadding(FAppStyle::GetMargin("StandardDialog.ContentPadding"))
.Text( NSLOCTEXT("ModalDialogs", "SDlgDeltaTransform_OK", "OK") )
.OnClicked( this, &SDlgDeltaTransform::OnButtonClick, FDlgDeltaTransform::OK )
]
+SUniformGridPanel::Slot(1,0)
[
SNew(SButton)
.HAlign(HAlign_Center)
.ContentPadding(FAppStyle::GetMargin("StandardDialog.ContentPadding"))
.Text( NSLOCTEXT("ModalDialogs", "SDlgDeltaTransform_Cancel", "Cancel") )
.OnClicked( this, &SDlgDeltaTransform::OnButtonClick, FDlgDeltaTransform::Cancel )
]
]
]
];
}
SDlgDeltaTransform()
: bUserResponse(FDlgDeltaTransform::Cancel)
{
}
/**
* Returns the EResult of the button which the user pressed, if the user
* canceled the action using ESC it will return as if canceled.
*/
FDlgDeltaTransform::EResult GetUserResponse() const
{
return bUserResponse;
}
/** Override the base method to allow for keyboard focus */
virtual bool SupportsKeyboardFocus() const
{
return true;
}
/** Used to intercept Escape key presses, then interprets them as cancel */
virtual FReply OnKeyDown( const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent )
{
// Pressing escape returns as if the user canceled
if ( InKeyEvent.GetKey() == EKeys::Escape )
{
return OnButtonClick(FDlgDeltaTransform::Cancel);
}
return FReply::Unhandled();
}
private:
/** A vector where it may optionally be unset */
struct FOptionalVector
{
/**
* Sets the value from an FVector
*/
void Set( const FVector& InVec )
{
X = InVec.X;
Y = InVec.Y;
Z = InVec.Z;
}
/**
* Sets the value from an FRotator
*/
void Set( const FRotator& InRot )
{
X = InRot.Roll;
Y = InRot.Pitch;
Z = InRot.Yaw;
}
/** @return Whether or not the value is set */
bool IsSet() const
{
// The vector is set if all values are set
return X.IsSet() && Y.IsSet() && Z.IsSet();
}
TOptional<float> X;
TOptional<float> Y;
TOptional<float> Z;
};
/**
* Handles when a button is pressed, should be bound with appropriate EResult Key
*
* @param ButtonID - The return type of the button which has been pressed.
*/
FReply OnButtonClick(FDlgDeltaTransform::EResult ButtonID)
{
ParentWindow->RequestDestroyWindow();
bUserResponse = ButtonID;
if (ButtonID == FDlgDeltaTransform::OK)
{
GUnrealEd->Exec( GEditor->GetEditorWorldContext().World(),
*FString::Printf(TEXT("ELEMENT DELTAMOVE X=%.5f Y=%.5f Z=%.5f"),
DeltaTransform.X.GetValue(), DeltaTransform.Y.GetValue(), DeltaTransform.Z.GetValue()) );
}
return FReply::Handled();
}
TOptional<float> GetDeltaX() const
{
return DeltaTransform.X;
}
TOptional<float> GetDeltaY() const
{
return DeltaTransform.Y;
}
TOptional<float> GetDeltaZ() const
{
return DeltaTransform.Z;
}
void OnSetDelta( float NewValue, ETextCommit::Type CommitInfo, int32 Axis )
{
switch (Axis)
{
case 0:
DeltaTransform.X = NewValue;
break;
case 1:
DeltaTransform.Y = NewValue;
break;
case 2:
DeltaTransform.Z = NewValue;
break;
default:
break;
}
}
FOptionalVector DeltaTransform;
/** Used to cache the users response to the warning */
FDlgDeltaTransform::EResult bUserResponse;
/** Pointer to the window which holds this Widget, required for modal control */
TSharedPtr<SWindow> ParentWindow;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// FDlgDeltaTransform
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FDlgDeltaTransform::FDlgDeltaTransform()
{
if (FSlateApplication::IsInitialized())
{
DeltaTransformWindow = SNew(SWindow)
.Title(LOCTEXT("DeltaTransformDlgTitle", "Delta Transform"))
.SupportsMinimize(false) .SupportsMaximize(false)
.SizingRule( ESizingRule::Autosized );
DeltaTransformWidget = SNew(SDlgDeltaTransform)
.ParentWindow(DeltaTransformWindow);
DeltaTransformWindow->SetContent( DeltaTransformWidget.ToSharedRef() );
}
}
FDlgDeltaTransform::EResult FDlgDeltaTransform::ShowModal()
{
GEditor->EditorAddModalWindow(DeltaTransformWindow.ToSharedRef());
return (EResult)DeltaTransformWidget->GetUserResponse();
}
#undef LOCTEXT_NAMESPACE