diff --git a/Ui/Viewer.cs b/Ui/Viewer.cs index ab3d837..76bb706 100644 --- a/Ui/Viewer.cs +++ b/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;