Add support for loading images for use in ImGui windows

This commit is contained in:
meli 2020-01-23 13:45:40 -08:00
parent c95b39b6e8
commit cc676a25f5
3 changed files with 43 additions and 1 deletions

View file

@ -109,6 +109,32 @@ namespace Dalamud.Interface
this.presentHook.Dispose();
}
public TextureWrap LoadImage(string filePath)
{
try
{
return this.scene?.LoadImage(filePath) ?? null;
}
catch (Exception ex)
{
Log.Error(ex, $"Failed to load image from {filePath}");
}
return null;
}
public TextureWrap LoadImage(byte[] imageData)
{
try
{
return this.scene?.LoadImage(imageData) ?? null;
}
catch (Exception ex)
{
Log.Error(ex, "Failed to load image from memory");
}
return null;
}
private IntPtr PresentDetour(IntPtr swapChain, uint syncInterval, uint presentFlags)
{
if (this.scene == null)

View file

@ -26,6 +26,22 @@ namespace Dalamud.Interface
this.interfaceManager.OnDraw -= OnDraw;
}
/// <summary>
/// Loads an image from the specified file.
/// </summary>
/// <param name="filePath">The full filepath to the image.</param>
/// <returns>A <see cref="TextureWrap"/> object wrapping the created image. Use <see cref="TextureWrap.ImGuiHandle"/> inside ImGui.Image()</returns>
public TextureWrap LoadImage(string filePath) =>
this.interfaceManager.LoadImage(filePath);
/// <summary>
/// Loads an image from a byte stream, such as a png downloaded into memory.
/// </summary>
/// <param name="imageData">A byte array containing the raw image data.</param>
/// <returns>A <see cref="TextureWrap"/> object wrapping the created image. Use <see cref="TextureWrap.ImGuiHandle"/> inside ImGui.Image()</returns>
public TextureWrap LoadImage(byte[] imageData) =>
this.interfaceManager.LoadImage(imageData);
private void OnDraw() {
ImGui.PushID(this.namespaceName);
OnBuildUi?.Invoke();

@ -1 +1 @@
Subproject commit 09dde468ea8a6a1729fc8dd334379d1514264742
Subproject commit 4b78854fcbf60775a7c34d73c83ad69115ce4587