ExtContentBrowserStyle.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #include "ExtContentBrowserStyle.h"
  3. #include "Styling/SlateStyleRegistry.h"
  4. #include "Framework/Application/SlateApplication.h"
  5. #include "Slate/SlateGameResources.h"
  6. #include "Interfaces/IPluginManager.h"
  7. #include "DocumentationStyle.h"
  8. TSharedPtr< FSlateStyleSet > FExtContentBrowserStyle::StyleInstance = NULL;
  9. FLinearColor FExtContentBrowserStyle::CustomContentBrowserBorderBackgroundColor(.05f, 0.05f, 0.05f, 1.0f);
  10. FLinearColor FExtContentBrowserStyle::CustomToolbarBackgroundColor(0.0f, 0.0f, 0.0f, .2f);
  11. FLinearColor FExtContentBrowserStyle::CustomSourceViewBackgroundColor(0.0f, 0.0f, 0.0f, .1f);
  12. FLinearColor FExtContentBrowserStyle::CustomAssetViewBackgroundColor(0.0f, 0.0f, 0.0f, .1f);
  13. void FExtContentBrowserStyle::Initialize()
  14. {
  15. if (!StyleInstance.IsValid())
  16. {
  17. StyleInstance = Create();
  18. FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance);
  19. }
  20. }
  21. void FExtContentBrowserStyle::Shutdown()
  22. {
  23. FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
  24. ensure(StyleInstance.IsUnique());
  25. StyleInstance.Reset();
  26. }
  27. FName FExtContentBrowserStyle::GetStyleSetName()
  28. {
  29. static FName StyleSetName(TEXT("UAssetBrowserStyle"));
  30. return StyleSetName;
  31. }
  32. FSlateFontInfo FExtContentBrowserStyle::GetFontStyle(FName PropertyName, const ANSICHAR* Specifier /*= NULL*/)
  33. {
  34. return Get().GetFontStyle(PropertyName, Specifier);
  35. }
  36. #define IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush( StyleSet->RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ )
  37. #define BOX_BRUSH( RelativePath, ... ) FSlateBoxBrush( StyleSet->RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ )
  38. #define BORDER_BRUSH( RelativePath, ... ) FSlateBorderBrush( StyleSet->RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ )
  39. #define TTF_FONT( RelativePath, ... ) FSlateFontInfo( StyleSet->RootToContentDir( RelativePath, TEXT(".ttf") ), __VA_ARGS__ )
  40. #define OTF_FONT( RelativePath, ... ) FSlateFontInfo( StyleSet->RootToContentDir( RelativePath, TEXT(".otf") ), __VA_ARGS__ )
  41. #define DEFAULT_FONT(...) FCoreStyle::GetDefaultFontStyle(__VA_ARGS__)
  42. const FVector2D Icon12x12(12.0f, 12.0f);
  43. const FVector2D Icon16x16(16.0f, 16.0f);
  44. const FVector2D Icon20x20(20.0f, 20.0f);
  45. const FVector2D Icon24x24(24.0f, 24.0f);
  46. const FVector2D Icon40x40(40.0f, 40.0f);
  47. TSharedRef< FSlateStyleSet > FExtContentBrowserStyle::Create()
  48. {
  49. TSharedRef< FSlateStyleSet > StyleSet = MakeShareable(new FSlateStyleSet("UAssetBrowserStyle"));
  50. StyleSet->SetContentRoot(IPluginManager::Get().FindPlugin("UAssetBrowser")->GetBaseDir() / TEXT("Resources"));
  51. // Icons
  52. {
  53. StyleSet->Set("UAssetBrowser.Icon16x", new IMAGE_BRUSH(TEXT("Icons/UAssetBrowserIcon24"), Icon16x16));
  54. StyleSet->Set("UAssetBrowser.Icon24x", new IMAGE_BRUSH(TEXT("Icons/UAssetBrowserIcon24"), Icon24x24));
  55. StyleSet->Set("UAssetBrowser.OpenUAssetBrowser", new IMAGE_BRUSH(TEXT("Icons/UAssetBrowserIcon64"), Icon40x40));
  56. StyleSet->Set("UAssetBrowser.OpenUAssetBrowser.Small", new IMAGE_BRUSH(TEXT("Icons/UAssetBrowserIcon24"), Icon16x16));
  57. }
  58. // Images
  59. {
  60. StyleSet->Set("UAssetBrowser.Help", new IMAGE_BRUSH(TEXT("Images/Documentation16"), Icon16x16));
  61. StyleSet->Set("UAssetBrowser.Rotation16px", new IMAGE_BRUSH(TEXT("Images/Loading"), Icon16x16));
  62. StyleSet->Set("UAssetBrowser.ShowSourcesView", new IMAGE_BRUSH(TEXT("Images/AssetTreeToggleExpanded16"), Icon16x16));
  63. StyleSet->Set("UAssetBrowser.HideSourcesView", new IMAGE_BRUSH(TEXT("Images/AssetTreeToggleCollapsed16"), Icon16x16));
  64. StyleSet->Set("UAssetBrowser.ShowDependencyViewer", new IMAGE_BRUSH(TEXT("Images/DependencyViewerExpanded16"), Icon16x16));
  65. StyleSet->Set("UAssetBrowser.HideDependencyViewer", new IMAGE_BRUSH(TEXT("Images/DependencyViewer16"), Icon16x16));
  66. StyleSet->Set("UAssetBrowser.ValidationUknown", new IMAGE_BRUSH(TEXT("Images/ValidationUknown"), Icon16x16));
  67. StyleSet->Set("UAssetBrowser.ValidationValid", new IMAGE_BRUSH(TEXT("Images/ValidationValid"), Icon16x16));
  68. StyleSet->Set("UAssetBrowser.ValidationInValid", new IMAGE_BRUSH(TEXT("Images/ValidationInValid"), Icon16x16));
  69. StyleSet->Set("UAssetBrowser.ValidationIssue", new IMAGE_BRUSH(TEXT("Images/ValidationIssue"), Icon16x16));
  70. // Folder Icons
  71. StyleSet->Set("UAssetBrowser.AssetTreeFolderDeveloper", new IMAGE_BRUSH("Images/FolderClosed", FVector2D(18, 16)));
  72. StyleSet->Set("UAssetBrowser.AssetTreeFolderOpenCode", new IMAGE_BRUSH("Images/FolderOpen_Code", FVector2D(18, 16)));
  73. StyleSet->Set("UAssetBrowser.AssetTreeFolderClosedCode", new IMAGE_BRUSH("Images/FolderClosed_Code", FVector2D(18, 16)));
  74. StyleSet->Set("UAssetBrowser.AssetTreeFolderClosed", new IMAGE_BRUSH("Images/FolderClosed", FVector2D(18, 16)));
  75. StyleSet->Set("UAssetBrowser.AssetTreeFolderOpen", new IMAGE_BRUSH("Images/FolderOpen", FVector2D(18, 16)));
  76. StyleSet->Set("UAssetBrowser.AssetTreeFolderClosedPlugin", new IMAGE_BRUSH("Images/FolderClosed_Plugin", FVector2D(18, 16)));
  77. StyleSet->Set("UAssetBrowser.AssetTreeFolderOpenPlugin", new IMAGE_BRUSH("Images/FolderOpen_Plugin", FVector2D(18, 16)));
  78. StyleSet->Set("UAssetBrowser.AssetTreeFolderClosedProject", new IMAGE_BRUSH("Images/FolderClosed_Project", FVector2D(18, 16)));
  79. StyleSet->Set("UAssetBrowser.AssetTreeFolderOpenProject", new IMAGE_BRUSH("Images/FolderOpen_Project", FVector2D(18, 16)));
  80. StyleSet->Set("UAssetBrowser.AssetTreeFolderClosedVaultCache", new IMAGE_BRUSH("Images/FolderClosed_VaultCache", FVector2D(18, 16)));
  81. StyleSet->Set("UAssetBrowser.AssetTreeFolderOpenVaultCache", new IMAGE_BRUSH("Images/FolderOpen_VaultCache", FVector2D(18, 16)));
  82. }
  83. // Font
  84. {
  85. StyleSet->Set("UAssetBrowser.SourceTreeRootItemFont", DEFAULT_FONT("Regular", 12));
  86. StyleSet->Set("UAssetBrowser.SourceTreeRootItemFont.LoadingFont", DEFAULT_FONT("Regular", 9));
  87. StyleSet->Set("UAssetBrowser.SourceTreeItemFont", DEFAULT_FONT("Regular", 10));
  88. }
  89. // TextStyle
  90. {
  91. FTextBlockStyle NormalText = FTextBlockStyle()
  92. .SetFont(DEFAULT_FONT("Regular", FCoreStyle::RegularTextSize))
  93. .SetColorAndOpacity(FSlateColor::UseForeground())
  94. .SetShadowOffset(FVector2D::ZeroVector)
  95. .SetShadowColorAndOpacity(FLinearColor::Black);
  96. StyleSet->Set("UAssetBrowser.TopBar.Font", FTextBlockStyle(NormalText)
  97. .SetFont(DEFAULT_FONT("Bold", 11))
  98. .SetColorAndOpacity(FLinearColor(1.0f, 1.0f, 1.0f))
  99. .SetHighlightColor(FLinearColor(1.0f, 1.0f, 1.0f))
  100. .SetShadowOffset(FVector2D(1, 1))
  101. .SetShadowColorAndOpacity(FLinearColor(0, 0, 0, 0.9f)));
  102. StyleSet->Set("UAssetBrowser.TopBar.DebugFont", FTextBlockStyle(NormalText)
  103. .SetFont(DEFAULT_FONT("Regular", 10))
  104. .SetColorAndOpacity(FLinearColor(.7f, .7f, .7f))
  105. .SetHighlightColor(FLinearColor(1.0f, 1.0f, 1.0f))
  106. .SetShadowOffset(FVector2D(1, 1))
  107. .SetShadowColorAndOpacity(FLinearColor(0, 0, 0, 0.9f)));
  108. StyleSet->Set("UAssetBrowser.ChangeLogHeaderText", FTextBlockStyle(NormalText)
  109. .SetFont(DEFAULT_FONT("Regular", 10))
  110. .SetColorAndOpacity(FLinearColor(1.0f, 1.0f, 1.0f))
  111. .SetHighlightColor(FLinearColor(1.0f, 1.0f, 1.0f))
  112. .SetShadowOffset(FVector2D(1, 1))
  113. .SetShadowColorAndOpacity(FLinearColor(0, 0, 0, 0.9f)));
  114. StyleSet->Set("UAssetBrowser.SourceTreeRootItem.Loading", FTextBlockStyle(NormalText)
  115. .SetFont(DEFAULT_FONT("Regular", 8))
  116. .SetColorAndOpacity(FLinearColor(0.6f, 0.6f, 0.6f)));
  117. StyleSet->Set("UAssetBrowser.AssetThumbnail.EngineOverlay", FTextBlockStyle(NormalText)
  118. .SetFont(DEFAULT_FONT("Regular", 9))
  119. .SetColorAndOpacity(FLinearColor(1.0, 1.0, 1.0, 0.9))
  120. .SetShadowColorAndOpacity(FLinearColor(0, 0, 0, 0.8))
  121. .SetShadowOffset(FVector2D(1.0f, 1.0f)));
  122. }
  123. // Colors
  124. {
  125. StyleSet->Set("ErrorReporting.HardReferenceColor", FLinearColor(0.35f, 0, 0));
  126. StyleSet->Set("ErrorReporting.HardReferenceColor.Darker", FLinearColor(0.35f * 0.6f, 0, 0));
  127. StyleSet->Set("ErrorReporting.SoftReferenceColor", FLinearColor(0.828f, 0.364f, 0.003f));
  128. StyleSet->Set("ErrorReporting.SoftReferenceColor.Darker", FLinearColor(0.828f * 0.6f, 0.364f * 0.6f, 0.003f));
  129. }
  130. return StyleSet;
  131. }
  132. void FExtContentBrowserStyle::ReloadTextures()
  133. {
  134. if (FSlateApplication::IsInitialized())
  135. {
  136. FSlateApplication::Get().GetRenderer()->ReloadTextureResources();
  137. }
  138. }
  139. FDocumentationStyle FExtContentBrowserStyle::GetChangLogDocumentationStyle()
  140. {
  141. FDocumentationStyle DocumentationStyle;
  142. {
  143. DocumentationStyle
  144. .ContentStyle(TEXT("ChangeLog.Content.Text"))
  145. .BoldContentStyle(TEXT("ChangeLog.Content.TextBold"))
  146. .NumberedContentStyle(TEXT("ChangeLog.Content.Text"))
  147. .Header1Style(TEXT("ChangeLog.Content.HeaderText1"))
  148. .Header2Style(TEXT("ChangeLog.Content.HeaderText2"))
  149. .HyperlinkStyle(TEXT("Tutorials.Content.Hyperlink"))
  150. .HyperlinkTextStyle(TEXT("Tutorials.Content.HyperlinkText"))
  151. .SeparatorStyle(TEXT("Tutorials.Separator"));
  152. }
  153. return DocumentationStyle;
  154. }
  155. const ISlateStyle& FExtContentBrowserStyle::Get()
  156. {
  157. return *StyleInstance;
  158. }
  159. using namespace UAssetBrowserDOC;
  160. TSharedPtr< FSlateStyleSet > FExtDocumentationStyle::StyleSet = nullptr;
  161. void FExtDocumentationStyle::Initialize()
  162. {
  163. // Only register once
  164. if (StyleSet.IsValid())
  165. {
  166. return;
  167. }
  168. StyleSet = MakeShareable(new FSlateStyleSet(DocumentationStyleSetName));
  169. StyleSet->SetCoreContentRoot(FPaths::EngineContentDir() / TEXT("Slate"));
  170. StyleSet->SetContentRoot(FPaths::EngineContentDir() / TEXT("Editor/Slate"));
  171. const FTextBlockStyle& NormalText = FAppStyle::Get().GetWidgetStyle<FTextBlockStyle>("NormalText");
  172. // Documentation
  173. {
  174. // Documentation tooltip defaults
  175. const FSlateColor HyperlinkColor(FLinearColor(0.1f, 0.1f, 0.5f));
  176. {
  177. const FTextBlockStyle DocumentationTooltipText = FTextBlockStyle(NormalText)
  178. .SetFont(DEFAULT_FONT("Regular", 9))
  179. .SetColorAndOpacity(FLinearColor::Black);
  180. StyleSet->Set("Documentation.SDocumentationTooltip", FTextBlockStyle(DocumentationTooltipText));
  181. const FTextBlockStyle DocumentationTooltipTextSubdued = FTextBlockStyle(NormalText)
  182. .SetFont(DEFAULT_FONT("Regular", 8))
  183. .SetColorAndOpacity(FLinearColor(0.1f, 0.1f, 0.1f));
  184. StyleSet->Set("Documentation.SDocumentationTooltipSubdued", FTextBlockStyle(DocumentationTooltipTextSubdued));
  185. const FTextBlockStyle DocumentationTooltipHyperlinkText = FTextBlockStyle(NormalText)
  186. .SetFont(DEFAULT_FONT("Regular", 8))
  187. .SetColorAndOpacity(HyperlinkColor);
  188. StyleSet->Set("Documentation.SDocumentationTooltipHyperlinkText", FTextBlockStyle(DocumentationTooltipHyperlinkText));
  189. const FButtonStyle DocumentationTooltipHyperlinkButton = FButtonStyle()
  190. .SetNormal(BORDER_BRUSH("Old/HyperlinkDotted", FMargin(0, 0, 0, 3 / 16.0f), HyperlinkColor))
  191. .SetPressed(FSlateNoResource())
  192. .SetHovered(BORDER_BRUSH("Old/HyperlinkUnderline", FMargin(0, 0, 0, 3 / 16.0f), HyperlinkColor));
  193. StyleSet->Set("Documentation.SDocumentationTooltipHyperlinkButton", FButtonStyle(DocumentationTooltipHyperlinkButton));
  194. }
  195. // Documentation defaults
  196. const FTextBlockStyle DocumentationText = FTextBlockStyle(NormalText)
  197. .SetColorAndOpacity(FLinearColor::Black)
  198. .SetFont(DEFAULT_FONT("Regular", 11));
  199. const FTextBlockStyle DocumentationHyperlinkText = FTextBlockStyle(DocumentationText)
  200. .SetColorAndOpacity(HyperlinkColor);
  201. const FTextBlockStyle DocumentationHeaderText = FTextBlockStyle(NormalText)
  202. .SetColorAndOpacity(FLinearColor::Black)
  203. .SetFont(DEFAULT_FONT("Black", 32));
  204. const FButtonStyle DocumentationHyperlinkButton = FButtonStyle()
  205. .SetNormal(BORDER_BRUSH("Old/HyperlinkDotted", FMargin(0, 0, 0, 3 / 16.0f), HyperlinkColor))
  206. .SetPressed(FSlateNoResource())
  207. .SetHovered(BORDER_BRUSH("Old/HyperlinkUnderline", FMargin(0, 0, 0, 3 / 16.0f), HyperlinkColor));
  208. StyleSet->Set("Documentation.Content", FTextBlockStyle(DocumentationText));
  209. const FHyperlinkStyle DocumentationHyperlink = FHyperlinkStyle()
  210. .SetUnderlineStyle(DocumentationHyperlinkButton)
  211. .SetTextStyle(DocumentationText)
  212. .SetPadding(FMargin(0.0f));
  213. StyleSet->Set("Documentation.Hyperlink", DocumentationHyperlink);
  214. StyleSet->Set("Documentation.Hyperlink.Button", FButtonStyle(DocumentationHyperlinkButton));
  215. StyleSet->Set("Documentation.Hyperlink.Text", FTextBlockStyle(DocumentationHyperlinkText));
  216. StyleSet->Set("Documentation.NumberedContent", FTextBlockStyle(DocumentationText));
  217. StyleSet->Set("Documentation.BoldContent", FTextBlockStyle(DocumentationText)
  218. .SetTypefaceFontName(TEXT("Bold")));
  219. StyleSet->Set("Documentation.Header1", FTextBlockStyle(DocumentationHeaderText)
  220. .SetFontSize(32));
  221. StyleSet->Set("Documentation.Header2", FTextBlockStyle(DocumentationHeaderText)
  222. .SetFontSize(24));
  223. StyleSet->Set("Documentation.Separator", new BOX_BRUSH("Common/Separator", 1 / 4.0f, FLinearColor(1, 1, 1, 0.5f)));
  224. }
  225. {
  226. //StyleSet->Set("Documentation.ToolTip.Background", new BOX_BRUSH("Tutorials/TutorialContentBackground", FMargin(4 / 16.0f)));
  227. }
  228. // Tutorial
  229. {
  230. const FTextBlockStyle RichTextNormal = FTextBlockStyle()
  231. .SetFont(DEFAULT_FONT("Regular", 11))
  232. .SetColorAndOpacity(FSlateColor::UseForeground())
  233. .SetShadowOffset(FVector2D::ZeroVector)
  234. .SetShadowColorAndOpacity(FLinearColor::Black)
  235. .SetHighlightColor(FLinearColor(0.02f, 0.3f, 0.0f))
  236. .SetHighlightShape(BOX_BRUSH("Common/TextBlockHighlightShape", FMargin(3.f / 8.f)));
  237. StyleSet->Set("Tutorials.Content.Text", RichTextNormal);
  238. StyleSet->Set("Tutorials.Content.TextBold", FTextBlockStyle(RichTextNormal)
  239. .SetFont(DEFAULT_FONT("Bold", 11)));
  240. StyleSet->Set("Tutorials.Content.HeaderText1", FTextBlockStyle(RichTextNormal)
  241. .SetFontSize(20));
  242. StyleSet->Set("Tutorials.Content.HeaderText2", FTextBlockStyle(RichTextNormal)
  243. .SetFontSize(16));
  244. const FButtonStyle RichTextHyperlinkButton = FButtonStyle()
  245. .SetNormal(BORDER_BRUSH("Old/HyperlinkDotted", FMargin(0, 0, 0, 3 / 16.0f), FLinearColor::Blue))
  246. .SetPressed(FSlateNoResource())
  247. .SetHovered(BORDER_BRUSH("Old/HyperlinkUnderline", FMargin(0, 0, 0, 3 / 16.0f), FLinearColor::Blue));
  248. const FTextBlockStyle RichTextHyperlinkText = FTextBlockStyle(RichTextNormal)
  249. .SetColorAndOpacity(FLinearColor::Blue);
  250. StyleSet->Set("Tutorials.Content.HyperlinkText", RichTextHyperlinkText);
  251. const FHyperlinkStyle RichTextHyperlink = FHyperlinkStyle()
  252. .SetUnderlineStyle(RichTextHyperlinkButton)
  253. .SetTextStyle(RichTextHyperlinkText)
  254. .SetPadding(FMargin(0.0f));
  255. StyleSet->Set("Tutorials.Content.Hyperlink", RichTextHyperlink);
  256. StyleSet->Set("Tutorials.Content.ExternalLink", new IMAGE_BRUSH("Tutorials/ExternalLink", Icon16x16, FLinearColor::Blue));
  257. StyleSet->Set("Tutorials.Separator", new BOX_BRUSH("Common/Separator", 1 / 4.0f, FLinearColor::Black));
  258. }
  259. // ChangLog
  260. {
  261. const FTextBlockStyle RichTextNormal = FTextBlockStyle()
  262. .SetFont(DEFAULT_FONT("Regular", 10))
  263. .SetColorAndOpacity(FSlateColor::UseForeground())
  264. .SetShadowOffset(FVector2D::ZeroVector)
  265. .SetShadowColorAndOpacity(FLinearColor::Black)
  266. .SetHighlightColor(FLinearColor(0.02f, 0.3f, 0.0f))
  267. .SetHighlightShape(BOX_BRUSH("Common/TextBlockHighlightShape", FMargin(3.f / 8.f)));
  268. const FLinearColor ColorChangeLogText(0.8f, 0.8f, 0.8f, 0.7f);
  269. StyleSet->Set("ChangeLog.Content.Text", FTextBlockStyle(RichTextNormal)
  270. .SetColorAndOpacity(ColorChangeLogText));
  271. StyleSet->Set("ChangeLog.Content.TextBold", FTextBlockStyle(RichTextNormal)
  272. .SetFont(DEFAULT_FONT("Bold", 10)));
  273. StyleSet->Set("ChangeLog.Content.HeaderText1", FTextBlockStyle(RichTextNormal)
  274. .SetFont(DEFAULT_FONT("Bold", 10)));
  275. StyleSet->Set("ChangeLog.Content.HeaderText2", FTextBlockStyle(RichTextNormal)
  276. .SetFont(DEFAULT_FONT("Bold", 11)));
  277. }
  278. FSlateStyleRegistry::RegisterSlateStyle(*StyleSet.Get());
  279. };
  280. void FExtDocumentationStyle::Shutdown()
  281. {
  282. if (StyleSet.IsValid())
  283. {
  284. FSlateStyleRegistry::UnRegisterSlateStyle(*StyleSet.Get());
  285. ensure(StyleSet.IsUnique());
  286. StyleSet.Reset();
  287. }
  288. }
  289. #undef IMAGE_BRUSH
  290. #undef BOX_BRUSH
  291. #undef BORDER_BRUSH
  292. #undef TTF_FONT
  293. #undef OTF_FONT