Files
UnrealEngineUWP/Engine/Source/Developer/SlateReflector/Private/SlateReflectorModule.cpp
Jamie Dale 1b119af458 Added the ability to take, save, and load widget snapshots via the widget reflector (Epic Friday)
Major changes:
 - The widget reflector UI now uses tabs. The hierarchy and stats views have been moved to tabs, and new tabs have been added to support picking widgets from a snapshot.
 - The widget reflector node trees are no longer using UObject types. The idea here was to make the serialization easier, but it didn't work and I ended up using JSON instead.
 - When you take or load a widget snapshot, you're now shown the screenshot of the window associated with that snapshot, and are able to pick widgets from it as you would do with a live tree.

API changes:
 - The tab spawners for the widget reflector and atlas visualizers are now registered automatically when the SlateReflector module is loaded. These are now the only way to create these windows.
 - The tabbed layout within the widget reflector has made it impossible to create the widget reflector unless spawned via a tab manager. To this end, the following functions have been removed from ISlateReflectorModule:
  - GetWidgetReflector
  - GetAtlasVisualizer
  - GetTextureAtlasVisualizer
  - GetFontAtlasVisualizer
 - These functions used to be used to create a raw widget reflector or atlas viewer widget.
  - If you were doing this because you were placing it into your own window, you can take advantage of the fact that the widget reflector tab spawner is always available, and use the global tab manager to create your window and place a spawned widget reflector tab inside it - SummonPerfTestSuite in SPerfSuite.cpp provides an example of this.
  - If you were doing this in the handler of your own widget reflector tab spawner, you can either just use the standard widget reflector tab spawner instead (you need to load the SlateReflector module once, and then "WidgetReflector" will be available to spawn via the global tab manager), or you can just use the DisplayWidgetReflector function of ISlateReflectorModule (which will internally do the same thing).

[CL 2661609 by Jamie Dale in Main branch]
2015-08-19 16:30:27 -04:00

214 lines
5.7 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "SlateReflectorPrivatePCH.h"
#include "ISlateReflectorModule.h"
#include "SDockTab.h"
#include "ModuleManager.h"
#include "SAtlasVisualizer.h"
#define LOCTEXT_NAMESPACE "FSlateReflectorModule"
/**
* Implements the SlateReflector module.
*/
class FSlateReflectorModule
: public ISlateReflectorModule
{
public:
// ISlateReflectorModule interface
TSharedRef<SWidget> GetWidgetReflector(const TSharedRef<SDockTab>& InParentTab)
{
TSharedPtr<SWidgetReflector> WidgetReflector = WidgetReflectorPtr.Pin();
if (!WidgetReflector.IsValid())
{
WidgetReflector = SNew(SWidgetReflector)
.ParentTab(InParentTab);
WidgetReflectorPtr = WidgetReflector;
FSlateApplication::Get().SetWidgetReflector(WidgetReflector.ToSharedRef());
}
return WidgetReflector.ToSharedRef();
}
TSharedRef<SWidget> GetAtlasVisualizer( ISlateAtlasProvider* InAtlasProvider )
{
return SNew(SAtlasVisualizer)
.AtlasProvider(InAtlasProvider);
}
TSharedRef<SWidget> GetTextureAtlasVisualizer()
{
ISlateAtlasProvider* const AtlasProvider = FSlateApplication::Get().GetRenderer()->GetTextureAtlasProvider();
if( AtlasProvider )
{
return GetAtlasVisualizer( AtlasProvider );
}
else
{
return SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("NoTextureAtlasProvider", "There is no texture atlas provider available for the current renderer."))
];
}
}
TSharedRef<SWidget> GetFontAtlasVisualizer()
{
ISlateAtlasProvider* const AtlasProvider = FSlateApplication::Get().GetRenderer()->GetFontAtlasProvider();
if( AtlasProvider )
{
return GetAtlasVisualizer( AtlasProvider );
}
else
{
return SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("NoFontAtlasProvider", "There is no font atlas provider available for the current renderer."))
];
}
}
virtual void DisplayWidgetReflector() override
{
check(bHasRegisteredTabSpawners);
FGlobalTabmanager::Get()->InvokeTab(FTabId("WidgetReflector"));
}
virtual void DisplayTextureAtlasVisualizer() override
{
check(bHasRegisteredTabSpawners);
FGlobalTabmanager::Get()->InvokeTab(FTabId("TextureAtlasVisualizer"));
}
virtual void DisplayFontAtlasVisualizer() override
{
check(bHasRegisteredTabSpawners);
FGlobalTabmanager::Get()->InvokeTab(FTabId("FontAtlasVisualizer"));
}
virtual void RegisterTabSpawner( const TSharedPtr<FWorkspaceItem>& WorkspaceGroup ) override
{
if (bHasRegisteredTabSpawners)
{
UnregisterTabSpawner();
}
bHasRegisteredTabSpawners = true;
{
FTabSpawnerEntry& SpawnerEntry = FGlobalTabmanager::Get()->RegisterNomadTabSpawner("WidgetReflector", FOnSpawnTab::CreateRaw(this, &FSlateReflectorModule::MakeWidgetReflectorTab) )
.SetDisplayName(LOCTEXT("WidgetReflectorTitle", "Widget Reflector"))
.SetTooltipText(LOCTEXT("WidgetReflectorTooltipText", "Open the Widget Reflector tab."))
.SetIcon(FSlateIcon(FCoreStyle::Get().GetStyleSetName(), "WidgetReflector.TabIcon"));
if (WorkspaceGroup.IsValid())
{
SpawnerEntry.SetGroup(WorkspaceGroup.ToSharedRef());
}
}
{
FTabSpawnerEntry& SpawnerEntry = FGlobalTabmanager::Get()->RegisterNomadTabSpawner("TextureAtlasVisualizer", FOnSpawnTab::CreateRaw(this, &FSlateReflectorModule::MakeTextureAtlasVisualizerTab) )
.SetDisplayName(LOCTEXT("TextureAtlasVisualizerTitle", "Texture Atlas Visualizer"))
.SetTooltipText(LOCTEXT("TextureAtlasVisualizerTooltipText", "Open the Texture Atlas Visualizer tab."))
.SetMenuType(ETabSpawnerMenuType::Hidden);
if (WorkspaceGroup.IsValid())
{
SpawnerEntry.SetGroup(WorkspaceGroup.ToSharedRef());
}
}
{
FTabSpawnerEntry& SpawnerEntry = FGlobalTabmanager::Get()->RegisterNomadTabSpawner("FontAtlasVisualizer", FOnSpawnTab::CreateRaw(this, &FSlateReflectorModule::MakeFontAtlasVisualizerTab) )
.SetDisplayName(LOCTEXT("FontAtlasVisualizerTitle", "Font Atlas Visualizer"))
.SetTooltipText(LOCTEXT("FontAtlasVisualizerTooltipText", "Open the Font Atlas Visualizer tab."))
.SetMenuType(ETabSpawnerMenuType::Hidden);
if (WorkspaceGroup.IsValid())
{
SpawnerEntry.SetGroup(WorkspaceGroup.ToSharedRef());
}
}
}
virtual void UnregisterTabSpawner() override
{
bHasRegisteredTabSpawners = false;
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner("WidgetReflector");
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner("TextureAtlasVisualizer");
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner("FontAtlasVisualizer");
}
public:
// IModuleInterface interface
virtual void StartupModule() override
{
bHasRegisteredTabSpawners = false;
RegisterTabSpawner(nullptr);
}
virtual void ShutdownModule() override
{
UnregisterTabSpawner();
}
private:
TSharedRef<SDockTab> MakeWidgetReflectorTab( const FSpawnTabArgs& )
{
TSharedRef<SDockTab> WidgetReflectorTab = SNew(SDockTab)
.TabRole(ETabRole::NomadTab);
WidgetReflectorTab->SetContent(GetWidgetReflector(WidgetReflectorTab));
return WidgetReflectorTab;
}
TSharedRef<SDockTab> MakeTextureAtlasVisualizerTab( const FSpawnTabArgs& )
{
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
GetTextureAtlasVisualizer()
];
}
TSharedRef<SDockTab> MakeFontAtlasVisualizerTab( const FSpawnTabArgs& )
{
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
GetFontAtlasVisualizer()
];
}
private:
/** True if the tab spawners have been registered for this module */
bool bHasRegisteredTabSpawners;
/** Holds the widget reflector singleton. */
TWeakPtr<SWidgetReflector> WidgetReflectorPtr;
};
IMPLEMENT_MODULE(FSlateReflectorModule, SlateReflector);
#undef LOCTEXT_NAMESPACE