Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Add EditorIcons container for faster editor icons caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mafiesto4 committed Sep 1, 2018
1 parent 9f3d6f4 commit 8da6893
Show file tree
Hide file tree
Showing 45 changed files with 272 additions and 175 deletions.
8 changes: 8 additions & 0 deletions FlaxEditor/API/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ internal static bool IsDevInstance()
/// </summary>
public readonly EditorUndo Undo;

/// <summary>
/// The icons container.
/// </summary>
public readonly EditorIcons Icons;

/// <summary>
/// Gets the main transform gizmo used by the <see cref="SceneEditorWindow"/>.
/// </summary>
Expand Down Expand Up @@ -180,6 +185,9 @@ internal Editor()

Internal_GetProjectInfo(out _projectInfo);

Icons = new EditorIcons();
Icons.GetIcons();

// Create common editor modules
RegisterModule(Options = new OptionsModule(this));
RegisterModule(ProjectCache = new ProjectCacheModule(this));
Expand Down
2 changes: 1 addition & 1 deletion FlaxEditor/Content/Items/ContentFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public bool ContainsChild(string path)
public override bool Exists => System.IO.Directory.Exists(Path);

/// <inheritdoc />
public override string DefaultThumbnailName => "Folder64";
public override Sprite DefaultThumbnail => Editor.Instance.Icons.Folder64;

/// <inheritdoc />
internal override void UpdatePath(string value)
Expand Down
6 changes: 3 additions & 3 deletions FlaxEditor/Content/Items/ContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ public string NamePath
/// Gets the default name of the content item thumbnail.
/// Returns null if not used.
/// </summary>
public virtual string DefaultThumbnailName => null;
public virtual Sprite DefaultThumbnail => Sprite.Invalid;

/// <summary>
/// Gets a value indicating whether this item has default thumbnail.
/// </summary>
public bool HasDefaultThumbnail => DefaultThumbnailName != null;
public bool HasDefaultThumbnail => DefaultThumbnail.IsValid;

/// <summary>
/// Gets or sets the item thumbnail. Warning, thumbnail may not be available if item has no references (<see cref="ReferencesCount"/>).
Expand Down Expand Up @@ -352,7 +352,7 @@ public void DrawThumbnail(ref Rectangle rectangle)
const float thumbnailInShadowSize = 50.0f;
var shadowRect = rectangle.MakeExpanded((DefaultThumbnailSize - thumbnailInShadowSize) * rectangle.Width / DefaultThumbnailSize * 1.3f);
if (!_shadowIcon.IsValid)
_shadowIcon = Editor.Instance.UI.GetIcon("AssetShadow");
_shadowIcon = Editor.Instance.Icons.AssetShadow;
Render2D.DrawSprite(_shadowIcon, shadowRect);
}

Expand Down
4 changes: 3 additions & 1 deletion FlaxEditor/Content/Items/FileItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2012-2018 Wojciech Figat. All rights reserved.

using FlaxEngine;

namespace FlaxEditor.Content
{
/// <summary>
Expand All @@ -21,6 +23,6 @@ public FileItem(string path)
public override ContentItemType ItemType => ContentItemType.Other;

/// <inheritdoc />
public override string DefaultThumbnailName => "Document64";
public override Sprite DefaultThumbnail => Editor.Instance.Icons.Document64;
}
}
2 changes: 1 addition & 1 deletion FlaxEditor/Content/Items/JsonAssetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public JsonAssetItem(string path, Guid id, string typeName)
public override ContentDomain ItemDomain => ContentDomain.Document;

/// <inheritdoc />
public override string DefaultThumbnailName => "Document64";
public override Sprite DefaultThumbnail => Editor.Instance.Icons.Document64;

/// <inheritdoc />
protected override bool DrawShadow => false;
Expand Down
4 changes: 3 additions & 1 deletion FlaxEditor/Content/Items/NewItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2012-2018 Wojciech Figat. All rights reserved.

using FlaxEngine;

namespace FlaxEditor.Content
{
/// <summary>
Expand Down Expand Up @@ -35,7 +37,7 @@ public NewItem(string path, ContentProxy proxy, object arg)
public override ContentItemType ItemType => ContentItemType.Other;

/// <inheritdoc />
public override string DefaultThumbnailName => "Document64";
public override Sprite DefaultThumbnail => Editor.Instance.Icons.Document64;

/// <inheritdoc />
protected override bool DrawShadow => true;
Expand Down
2 changes: 1 addition & 1 deletion FlaxEditor/Content/Items/PrefabItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public PrefabItem(string path, Guid id)
public override ContentItemType ItemType => ContentItemType.Asset;

/// <inheritdoc />
public override string DefaultThumbnailName => null;
public override Sprite DefaultThumbnail => Sprite.Invalid;
}
}
2 changes: 1 addition & 1 deletion FlaxEditor/Content/Items/SceneItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public SceneItem(string path, Guid id)
public override ContentItemType ItemType => ContentItemType.Scene;

/// <inheritdoc />
public override string DefaultThumbnailName => "Scene64";
public override Sprite DefaultThumbnail => Editor.Instance.Icons.Scene64;
}
}
3 changes: 2 additions & 1 deletion FlaxEditor/Content/Items/ScriptItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Text;
using FlaxEditor.Scripting;
using FlaxEngine;

namespace FlaxEditor.Content
{
Expand Down Expand Up @@ -77,7 +78,7 @@ public static string CreateScriptName(string path)
public override ContentItemType ItemType => ContentItemType.Script;

/// <inheritdoc />
public override string DefaultThumbnailName => "Script64";
public override Sprite DefaultThumbnail => Editor.Instance.Icons.Script64;

/// <inheritdoc />
public override ScriptItem FindScriptWitScriptName(string scriptName)
Expand Down
6 changes: 3 additions & 3 deletions FlaxEditor/Content/Thumbnails/ThumbnailsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public void RequestPreview(ContentItem item)
throw new ArgumentNullException();

// Check if use default icon
var defaultThumbnail = item.DefaultThumbnailName;
if (!string.IsNullOrEmpty(defaultThumbnail))
var defaultThumbnail = item.DefaultThumbnail;
if (defaultThumbnail.IsValid)
{
item.Thumbnail = Editor.Instance.UI.GetIcon(defaultThumbnail);
item.Thumbnail = defaultThumbnail;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion FlaxEditor/Content/Tree/ContentTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ContentTreeNode(ContentTreeNode parent, string path)
/// <param name="type">The folder type.</param>
/// <param name="path">The folder path.</param>
protected ContentTreeNode(ContentFolderType type, string path)
: base(false, Editor.Instance.UI.FolderClosed12, Editor.Instance.UI.FolderOpened12)
: base(false, Editor.Instance.Icons.FolderClosed12, Editor.Instance.Icons.FolderOpened12)
{
_folder = new ContentFolder(type, path, this);
Text = _folder.ShortName;
Expand Down
2 changes: 1 addition & 1 deletion FlaxEditor/CustomEditors/Dedicated/ScriptsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public override void Initialize(LayoutElementsContainer layout)
IsScrollable = false,
Color = new Color(0.7f),
Margin = new Margin(1),
Brush = new SpriteBrush(Editor.Instance.UI.DragBar12),
Brush = new SpriteBrush(Editor.Instance.Icons.DragBar12),
Tag = script,
Parent = group.Panel
};
Expand Down
122 changes: 122 additions & 0 deletions FlaxEditor/EditorIcons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright (c) 2012-2018 Wojciech Figat. All rights reserved.

using System.Reflection;
using FlaxEngine;

#pragma warning disable 1591

namespace FlaxEditor
{
/// <summary>
/// The editor icons atlas. Cached internally to improve performance.
/// </summary>
/// <remarks>
/// Postfix number informs about the sprite resolution (in pixels).
/// </remarks>
public sealed class EditorIcons
{
public Sprite FolderClosed12;
public Sprite FolderOpened12;
public Sprite DragBar12;
public Sprite ArrowDown12;
public Sprite ArrowRight12;
public Sprite Search12;
public Sprite Settings12;
public Sprite Cross12;
public Sprite CheckBoxIntermediate12;
public Sprite CheckBoxTick12;
public Sprite StatusBarSizeGrip12;

public Sprite ArrowRightBorder16;
public Sprite World16;
public Sprite ScaleStep16;
public Sprite RotateStep16;
public Sprite Grid16;
public Sprite Translate16;
public Sprite Rotate16;
public Sprite Scale16;
public Sprite Link16;
public Sprite Docs16;

public Sprite Save32;
public Sprite Undo32;
public Sprite Redo32;
public Sprite Translate32;
public Sprite Rotate32;
public Sprite Scale32;
public Sprite Play32;
public Sprite Pause32;
public Sprite Step32;
public Sprite Stop32;
public Sprite PageScale32;
public Sprite Bone32;
public Sprite Docs32;
public Sprite Import32;
public Sprite AddDoc32;
public Sprite RemoveDoc32;
public Sprite Find32;
public Sprite Reload32;
public Sprite ArrowLeft32;
public Sprite ArrowRight32;
public Sprite ArrowUp32;
public Sprite Error32;
public Sprite Warning32;
public Sprite Info32;
public Sprite UV32;
public Sprite Image32;
public Sprite Link32;

public Sprite Add48;
public Sprite Paint48;
public Sprite Foliage48;
public Sprite Mountain48;

public Sprite Plugin64;
public Sprite Document64;
public Sprite Script64;
public Sprite Folder64;
public Sprite Scene64;

public Sprite Logo128;

public Sprite VisjectBoxOpen;
public Sprite VisjectBoxClose;
public Sprite VisjectArrowOpen;
public Sprite VisjectArrowClose;

public Sprite AssetShadow;
public Sprite ColorWheel;
public Sprite Windows;
public Sprite XboxOne;
public Sprite WindowsStore;

internal void GetIcons()
{
// Load asset
var iconsAtlas = FlaxEngine.Content.LoadInternal<SpriteAtlas>(EditorAssets.IconsAtlas);
if (iconsAtlas == null)
{
Editor.LogError("Cannot load editor icons atlas.");
return;
}
if (iconsAtlas.WaitForLoaded())
{
Editor.LogError("Failed to load editor icons atlas.");
return;
}

// Find icons
var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
for (int i = 0; i < fields.Length; i++)
{
var field = fields[i];
var sprite = iconsAtlas.GetSprite(field.Name);
if (!sprite.IsValid)
{
Editor.LogWarning(string.Format("Failed to load sprite icon \'{0}\'.", field.Name));
}
field.SetValue(this, sprite);
}
}
}
}
1 change: 1 addition & 0 deletions FlaxEditor/FlaxEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
<Compile Include="CustomEditors\Values\ValueContainer.cs" />
<Compile Include="CustomEditorWindow.cs" />
<Compile Include="EditorAssets.cs" />
<Compile Include="EditorIcons.cs" />
<Compile Include="GUI\ComboBox.cs" />
<Compile Include="GUI\ContextMenu\ContextMenu.cs" />
<Compile Include="GUI\ContextMenu\ContextMenuBase.cs" />
Expand Down
2 changes: 1 addition & 1 deletion FlaxEditor/GUI/Dialogs/ColorSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ColorSelector()
public ColorSelector(float wheelSize = 64)
: base(0, 0, wheelSize, wheelSize)
{
_colorWheelSprite = Editor.Instance.UI.GetIcon("ColorWheel");
_colorWheelSprite = Editor.Instance.Icons.ColorWheel;
_wheelRect = new Rectangle(0, 0, wheelSize, wheelSize);
}

Expand Down
14 changes: 11 additions & 3 deletions FlaxEditor/GUI/Dialogs/Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ public abstract class Dialog : ContainerControl
{
private string _title;

/// <summary>
/// Flag used to block the calling thread if it used ShowDialog option.
/// </summary>
protected long _isWaitingForDialog;

/// <summary>
/// The parent window.
/// </summary>
protected FlaxEngine.Window _window;

/// <summary>
/// The dialog result.
/// </summary>
protected DialogResult _result;

/// <summary>
/// Gets the dialog result.
/// </summary>
/// <value>
/// The result.
/// </value>
public DialogResult Result => _result;

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions FlaxEditor/GUI/PlatformSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public PlatformType Selected
/// </summary>
public PlatformSelector()
{
var ui = Editor.Instance.UI;
var icons = Editor.Instance.Icons;
var platforms = new[]
{
new PlatformData(PlatformType.Windows, ui.GetIcon("Windows")),
new PlatformData(PlatformType.XboxOne, ui.GetIcon("XboxOne")),
new PlatformData(PlatformType.WindowsStore, ui.GetIcon("WindowsStore")),
new PlatformData(PlatformType.Windows, icons.Windows),
new PlatformData(PlatformType.XboxOne, icons.XboxOne),
new PlatformData(PlatformType.WindowsStore, icons.WindowsStore),
};

const float IconSize = 48.0f;
Expand Down
Loading

0 comments on commit 8da6893

Please sign in to comment.