60 lines
1.8 KiB
C++

#include "PwnStyle.h"
#include "Brushes/SlateImageBrush.h"
#include "Misc/Paths.h"
#include "Styling/SlateStyle.h"
#include "Styling/SlateStyleRegistry.h"
TSharedPtr<FSlateStyleSet> FPwnStyle::StyleInstance = nullptr;
const FVector2D Icon16x16(16.0f, 16.0f);
const FVector2D Icon20x20(20.0f, 20.0f);
const FVector2D Icon40x40(40.0f, 40.0f);
const FVector2D Icon64x64(64.0f, 64.0f);
void FPwnStyle::Initialize() {
if (!StyleInstance.IsValid()) {
StyleInstance = Create();
FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance);
}
}
void FPwnStyle::Shutdown() {
FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
ensure(StyleInstance.IsUnique());
StyleInstance.Reset();
}
FName FPwnStyle::GetStyleSetName() {
static FName StyleSetName(TEXT("PwnStyle"));
return StyleSetName;
}
#define IMAGE_BRUSH(RelativePath, ...) FSlateImageBrush(StyleRef->GetContentRootDir() / RelativePath + TEXT(".png"), __VA_ARGS__ )
#define SET_CPP_CLASS_ICON(ClassName, IconName) Style.Set("ClassIcon.##ClassName##", new IMAGE_BRUSH(IconName, Icon20x20));
#define SET_BLUEPRINT_CLASS_ICON(ClassName, IconName) Style.Set("ClassIcon.BP_##ClassName##_C", new IMAGE_BRUSH(IconName, Icon20x20));
TSharedRef<FSlateStyleSet> FPwnStyle::Create() {
TSharedRef<FSlateStyleSet> StyleRef = MakeShareable(new FSlateStyleSet(GetStyleSetName()));
StyleRef->SetContentRoot(FPaths::ProjectContentDir() / TEXT("Editor/EditorResources"));
StyleRef->SetCoreContentRoot(FPaths::ProjectContentDir() / TEXT("Editor/EditorResources"));
FSlateStyleSet& Style = StyleRef.Get();
SET_CPP_CLASS_ICON(PwnTrigger, "Trigger");
SET_BLUEPRINT_CLASS_ICON(CameraModule, "CameraModule");
SET_BLUEPRINT_CLASS_ICON(CameraTransitionModule, "CameraTransitionModule");
return StyleRef;
}
#undef IMAGE_BRUSH
#undef BOX_BRUSH
#undef BORDER_BRUSH
const ISlateStyle& FPwnStyle::Get() {
return *StyleInstance;
}