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();
|
||||
}
|
||||
|
||||
public DrawStatus Draw() {
|
||||
if (!this._visible) {
|
||||
public DrawStatus Draw()
|
||||
{
|
||||
if (!this._visible)
|
||||
{
|
||||
return DrawStatus.Finished;
|
||||
}
|
||||
|
||||
|
@ -54,7 +56,8 @@ internal class Viewer : IDrawable {
|
|||
using var popId = new OnDispose(ImGui.PopID);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -63,7 +66,8 @@ internal class Viewer : IDrawable {
|
|||
|
||||
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.");
|
||||
|
||||
ImGui.PushFont(UiBuilder.MonoFont);
|
||||
|
@ -72,35 +76,46 @@ internal class Viewer : IDrawable {
|
|||
ImGui.TextUnformatted(this.Error.Message);
|
||||
}
|
||||
|
||||
if (this.Image != null) {
|
||||
var beforeImage = ImGui.GetCursorScreenPos();
|
||||
var avail = ImGui.GetContentRegionAvail();
|
||||
var imageSize = this.Image.Size;
|
||||
if (this.Image == null) {
|
||||
return DrawStatus.Continuing;
|
||||
}
|
||||
|
||||
var constrainedX = avail.X < imageSize.X;
|
||||
var constrainedY = avail.Y < imageSize.Y;
|
||||
var beforeImage = ImGui.GetCursorScreenPos();
|
||||
var avail = ImGui.GetContentRegionAvail();
|
||||
var imageSize = this.Image.Size;
|
||||
|
||||
var sizeToUse = imageSize;
|
||||
if (constrainedX || constrainedY) {
|
||||
// var dividend = imageSize / avail;
|
||||
// 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 constrainedX = avail.X < imageSize.X;
|
||||
var constrainedY = avail.Y < imageSize.Y;
|
||||
var ratio = 1f;
|
||||
|
||||
var dividend = avail / imageSize;
|
||||
// scale the image based on the more-constrained dimension
|
||||
var 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
|
||||
);
|
||||
}
|
||||
var sizeToUse = imageSize;
|
||||
if (constrainedX || constrainedY) {
|
||||
// var dividend = imageSize / avail;
|
||||
// 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
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Memory;
|
||||
using WebP.Net;
|
||||
using WebP.Net.Natives;
|
||||
using WebP.Net.Natives.Enums;
|
||||
using WebP.Net.Natives.Structs;
|
||||
|
@ -34,7 +32,7 @@ internal static class WebPHelper {
|
|||
decoderConfig.output.colorSpace = WebpCspMode.ModeRgba;
|
||||
decoderConfig.output.isExternalMemory = 1;
|
||||
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) {
|
||||
decoderConfig.output.u.Rgba.rgba = (nint) rgbaPtr;
|
||||
var code = Native.WebPDecode((nint) imagePtr, imageBytes.Length, ref decoderConfig);
|
||||
|
|
Loading…
Reference in New Issue