Compare commits
3 Commits
44e4675d2f
...
c0604b2959
Author | SHA1 | Date |
---|---|---|
Anna | c0604b2959 | |
Anna | 0e763b9c0e | |
Anna | a7bc19b380 |
73
Ui/Viewer.cs
73
Ui/Viewer.cs
|
@ -45,8 +45,10 @@ internal class Viewer : IDrawable {
|
||||||
this.Image?.Dispose();
|
this.Image?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawStatus Draw() {
|
public DrawStatus Draw()
|
||||||
if (!this._visible) {
|
{
|
||||||
|
if (!this._visible)
|
||||||
|
{
|
||||||
return DrawStatus.Finished;
|
return DrawStatus.Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +56,8 @@ internal class Viewer : IDrawable {
|
||||||
using var popId = new OnDispose(ImGui.PopID);
|
using var popId = new OnDispose(ImGui.PopID);
|
||||||
|
|
||||||
using var end = new OnDispose(ImGui.End);
|
using var end = new OnDispose(ImGui.End);
|
||||||
if (!ImGui.Begin($"View {Path.GetFileName(this.ImagePath)}", ref this._visible, ImGuiWindowFlags.NoSavedSettings)) {
|
if (!ImGui.Begin($"View {Path.GetFileName(this.ImagePath)}", ref this._visible, ImGuiWindowFlags.NoSavedSettings))
|
||||||
|
{
|
||||||
return DrawStatus.Continuing;
|
return DrawStatus.Continuing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +66,8 @@ internal class Viewer : IDrawable {
|
||||||
|
|
||||||
ImGui.SetWindowSize(viewportSize * new Vector2(0.20f), ImGuiCond.Appearing);
|
ImGui.SetWindowSize(viewportSize * new Vector2(0.20f), ImGuiCond.Appearing);
|
||||||
|
|
||||||
if (this.Error != null) {
|
if (this.Error != null)
|
||||||
|
{
|
||||||
ImGuiHelpers.CenteredText("An error ocurred loading the image.");
|
ImGuiHelpers.CenteredText("An error ocurred loading the image.");
|
||||||
|
|
||||||
ImGui.PushFont(UiBuilder.MonoFont);
|
ImGui.PushFont(UiBuilder.MonoFont);
|
||||||
|
@ -72,35 +76,46 @@ internal class Viewer : IDrawable {
|
||||||
ImGui.TextUnformatted(this.Error.Message);
|
ImGui.TextUnformatted(this.Error.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.Image != null) {
|
if (this.Image == null) {
|
||||||
var beforeImage = ImGui.GetCursorScreenPos();
|
return DrawStatus.Continuing;
|
||||||
var avail = ImGui.GetContentRegionAvail();
|
}
|
||||||
var imageSize = this.Image.Size;
|
|
||||||
|
|
||||||
var constrainedX = avail.X < imageSize.X;
|
var beforeImage = ImGui.GetCursorScreenPos();
|
||||||
var constrainedY = avail.Y < imageSize.Y;
|
var avail = ImGui.GetContentRegionAvail();
|
||||||
|
var imageSize = this.Image.Size;
|
||||||
|
|
||||||
var sizeToUse = imageSize;
|
var constrainedX = avail.X < imageSize.X;
|
||||||
if (constrainedX || constrainedY) {
|
var constrainedY = avail.Y < imageSize.Y;
|
||||||
// var dividend = imageSize / avail;
|
var ratio = 1f;
|
||||||
// var inv = Vector2.One / dividend;
|
|
||||||
// scale the image based on the more-constrained dimension
|
|
||||||
// var ratio = dividend.X > dividend.Y
|
|
||||||
// ? inv.X // X is more constrained
|
|
||||||
// : inv.Y; // Y is more constrained
|
|
||||||
|
|
||||||
var dividend = avail / imageSize;
|
var sizeToUse = imageSize;
|
||||||
// scale the image based on the more-constrained dimension
|
if (constrainedX || constrainedY) {
|
||||||
var ratio = dividend.Y > dividend.X
|
// var dividend = imageSize / avail;
|
||||||
? dividend.X // X is more constrained
|
// var inv = Vector2.One / dividend;
|
||||||
: dividend.Y; // Y is more constrained
|
// scale the image based on the more-constrained dimension
|
||||||
sizeToUse = new Vector2(
|
// var ratio = dividend.X > dividend.Y
|
||||||
imageSize.X * ratio,
|
// ? inv.X // X is more constrained
|
||||||
imageSize.Y * ratio
|
// : inv.Y; // Y is more constrained
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui.Image(this.Image.ImGuiHandle, sizeToUse);
|
var dividend = avail / imageSize;
|
||||||
|
// scale the image based on the more-constrained dimension
|
||||||
|
ratio = dividend.Y > dividend.X
|
||||||
|
? dividend.X // X is more constrained
|
||||||
|
: dividend.Y; // Y is more constrained
|
||||||
|
sizeToUse = new Vector2(
|
||||||
|
imageSize.X * ratio,
|
||||||
|
imageSize.Y * ratio
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.Image(this.Image.ImGuiHandle, sizeToUse);
|
||||||
|
|
||||||
|
if (this.DotPosition is { } pos) {
|
||||||
|
var scaledPos = pos * ratio;
|
||||||
|
var posCoord = beforeImage + scaledPos;
|
||||||
|
|
||||||
|
ImGui.GetWindowDrawList().AddCircleFilled(posCoord, 6 * ImGuiHelpers.GlobalScale, 0x000000FF);
|
||||||
|
ImGui.GetWindowDrawList().AddCircleFilled(posCoord, 4 * ImGuiHelpers.GlobalScale, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DrawStatus.Continuing;
|
return DrawStatus.Continuing;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using Dalamud.Interface.Internal;
|
using Dalamud.Interface.Internal;
|
||||||
using Dalamud.Memory;
|
|
||||||
using WebP.Net;
|
|
||||||
using WebP.Net.Natives;
|
using WebP.Net.Natives;
|
||||||
using WebP.Net.Natives.Enums;
|
using WebP.Net.Natives.Enums;
|
||||||
using WebP.Net.Natives.Structs;
|
using WebP.Net.Natives.Structs;
|
||||||
|
@ -34,7 +32,7 @@ internal static class WebPHelper {
|
||||||
decoderConfig.output.colorSpace = WebpCspMode.ModeRgba;
|
decoderConfig.output.colorSpace = WebpCspMode.ModeRgba;
|
||||||
decoderConfig.output.isExternalMemory = 1;
|
decoderConfig.output.isExternalMemory = 1;
|
||||||
decoderConfig.output.u.Rgba.size = (nuint) rgba.Length;
|
decoderConfig.output.u.Rgba.size = (nuint) rgba.Length;
|
||||||
decoderConfig.output.u.Rgba.stride = height * 4;
|
decoderConfig.output.u.Rgba.stride = width * 4;
|
||||||
fixed (byte* rgbaPtr = rgba) {
|
fixed (byte* rgbaPtr = rgba) {
|
||||||
decoderConfig.output.u.Rgba.rgba = (nint) rgbaPtr;
|
decoderConfig.output.u.Rgba.rgba = (nint) rgbaPtr;
|
||||||
var code = Native.WebPDecode((nint) imagePtr, imageBytes.Length, ref decoderConfig);
|
var code = Native.WebPDecode((nint) imagePtr, imageBytes.Length, ref decoderConfig);
|
||||||
|
|
Loading…
Reference in New Issue