// Copyright Epic Games, Inc. All Rights Reserved. #include "AronaStyle.h" #include "Styling/SlateStyleRegistry.h" #include "Framework/Application/SlateApplication.h" #include "Misc/AronaConfig.h" TSharedPtr< FAronaStyle > FAronaStyle::StyleInstance = NULL; void FAronaStyle::Initialize() { if (!StyleInstance.IsValid()) { StyleInstance = Create(); StyleInstance->LoadConfig(); FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance); } } void FAronaStyle::Shutdown() { FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance); ensure(StyleInstance.IsUnique()); StyleInstance.Reset(); } const FButtonStyle* FAronaStyle::GetButtonStyle(const FName& PropertyName, const ANSICHAR* Specifier) { return &StyleInstance->GetWidgetStyle(PropertyName, Specifier, nullptr); } const FSlateBrush* FAronaStyle::GetSlateBrush(const FName& PropertyName, const ANSICHAR* Specifier) { return StyleInstance->GetBrush(PropertyName, Specifier, nullptr); } FSlateFontInfo FAronaStyle::GetFontInfo(const FName& PropertyName, const ANSICHAR* Specifier) { return StyleInstance->GetFontStyle(PropertyName, Specifier); } #define IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush( Style->RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ ) #define BOX_BRUSH( RelativePath, ... ) FSlateBoxBrush( Style->RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ ) #define BORDER_BRUSH( RelativePath, ... ) FSlateBorderBrush( Style->RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ ) #define TTF_FONT( RelativePath, ... ) FSlateFontInfo( Style->RootToContentDir( RelativePath, TEXT(".ttf") ), __VA_ARGS__ ) #define OTF_FONT( RelativePath, ... ) FSlateFontInfo( Style->RootToContentDir( RelativePath, TEXT(".otf") ), __VA_ARGS__ ) #define MakeImageBrush(Name, Path, Size) \ FSlateImageBrush Name = IMAGE_BRUSH(TEXT(Path), Size); \ Name.Tiling = ESlateBrushTileType::NoTile; \ Name.ImageSize = Size; \ Name.DrawAs = ESlateBrushDrawType::Image; \ Name.ImageType = ESlateBrushImageType::FullColor; \ void FAronaStyle::LoadConfig() { TSharedRef Style = StyleInstance.ToSharedRef(); AddButtonStyle(CloseButtonStyleName); AddFontInfo(DefaultFontName); AddFloatValue(VolumeMeterBarSpace); AddImageBrush(PianoRollBackground); AddImageBrush(VolumeMeterBar); AddImageBrush(WhiteBrush); AddImageBrush(BlackKey); AddImageBrush(WhiteKey); } void FAronaStyle::AddImageBrush(FName Key) { TOptional ImageFileName = GetConfigValue(Key); if (!ImageFileName) return; TOptional ImageSize = GetConfigValue(FName(Key.ToString() + "Size")); const FString ImageFilePathName = StyleInstance->RootToContentDir(ImageFileName.GetValue(), TEXT(".png")); StyleInstance->Set(Key, new FSlateImageBrush(ImageFilePathName, ImageSize.Get(FVector2f(16)))); } void FAronaStyle::AddFloatValue(FName Key) { TOptional Value = GetConfigValue(Key); if (!Value) return; StyleInstance->Set(Key, Value.GetValue()); } void FAronaStyle::AddFontInfo(FName Key) { const TOptional FontName = GetConfigValue(Key); if (!FontName) return; const TOptional FontSize = GetConfigValue(FName(Key.ToString() + "Size")); StyleInstance->Set(Key, FSlateFontInfo(StyleInstance->RootToContentDir(FontName.GetValue(), TEXT(".ttf")), FontSize.Get(12))); } void FAronaStyle::AddButtonStyle(FName Key) { const FString ButtonNormalName = Key.ToString() + "Normal"; const FString ButtonHoveredName = Key.ToString() + "Hovered"; const FString ButtonPressedName = Key.ToString() + "Pressed"; const TOptional ButtonNormal = GetConfigValue(FName(ButtonNormalName)); const TOptional ButtonHovered = GetConfigValue(FName(ButtonHoveredName)); const TOptional ButtonPressed = GetConfigValue(FName(ButtonPressedName)); const TOptional Size = GetConfigValue(FName(Key.ToString() + "Size")); FButtonStyle ButtonStyle; const FSlateImageBrush ButtonNormalBrush = FSlateImageBrush(StyleInstance->RootToContentDir(ButtonNormal.Get(""), TEXT(".png")), Size.Get(FVector2f(16))); const FSlateImageBrush ButtonHoveredBrush = FSlateImageBrush(StyleInstance->RootToContentDir(ButtonHovered.Get(""), TEXT(".png")), Size.Get(FVector2f(16))); const FSlateImageBrush ButtonPressedBrush = FSlateImageBrush(StyleInstance->RootToContentDir(ButtonPressed.Get(""), TEXT(".png")), Size.Get(FVector2f(16))); ButtonStyle.SetNormal(ButtonNormalBrush).SetHovered(ButtonHoveredBrush).SetPressed(ButtonPressedBrush); StyleInstance->Set(CloseButtonStyleName, ButtonStyle); } TSharedRef< FAronaStyle > FAronaStyle::Create() { TSharedRef Style = MakeShareable(new FAronaStyle("AronaStyle")); FString SkinName; FAronaConfig::GetValue("Skin", "Skin", SkinName); Style->SkinDir = FPaths::ProjectContentDir() / TEXT("Skin") / SkinName; Style->Config.Read(Style->SkinDir / TEXT("Skin.ini")); Style->SetContentRoot(Style->SkinDir); return Style; } #undef IMAGE_BRUSH #undef BOX_BRUSH #undef BORDER_BRUSH #undef TTF_FONT #undef OTF_FONT void FAronaStyle::ReloadTextures() { if (FSlateApplication::IsInitialized()) { FSlateApplication::Get().GetRenderer()->ReloadTextureResources(); } } const ISlateStyle& FAronaStyle::Get() { return *StyleInstance; } const FName& FAronaStyle::GetStyleSetName() const { static FName Name(TEXT("AronaModuleStyle")); return Name; }