Skip to content

Commit

Permalink
Fix showing large images;
Browse files Browse the repository at this point in the history
Update to 1.3.8;
  • Loading branch information
onepiecefreak3 committed Feb 8, 2025
1 parent 26ee31f commit 90bdf86
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ImGui.Forms/Controls/Base/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Update(Rectangle contentRect)

// Draw border
if (ShowBorder)
ImGuiNET.ImGui.GetWindowDrawList().AddRect(contentRect.Position, contentRect.Position + contentRect.Size, ImGuiNET.ImGui.GetColorU32(ImGuiCol.Border), 0);
ImGuiNET.ImGui.GetWindowDrawList().AddRect(contentRect.Position, contentRect.Position + contentRect.Size, ImGuiNET.ImGui.GetColorU32(ImGuiCol.Border));

ApplyStyles();
UpdateInternal(contentRect);
Expand Down
8 changes: 6 additions & 2 deletions ImGui.Forms/Controls/ZoomablePictureBox.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Numerics;
using ImGui.Forms.Controls.Base;
using ImGui.Forms.Extensions;
using ImGui.Forms.Models;
using ImGui.Forms.Resources;
using ImGui.Forms.Support;
using ImGuiNET;

namespace ImGui.Forms.Controls
Expand Down Expand Up @@ -31,6 +31,8 @@ public ThemedImageResource Image

public Size Size { get; set; } = Size.Parent;

public bool ShowImageBorder { get; set; }

#endregion

#region Events
Expand All @@ -56,7 +58,7 @@ protected override void UpdateInternal(Veldrid.Rectangle contentRect)
{
if (Image == null || (nint)_baseImg == nint.Zero)
return;

ImGuiNET.ImGui.Dummy(contentRect.Size);

var componentCenterPosition = contentRect.Position + contentRect.Size / 2;
Expand Down Expand Up @@ -104,6 +106,8 @@ protected override void UpdateInternal(Veldrid.Rectangle contentRect)
var absoluteContentEndPosition = absoluteContentPosition + scaledContentSize;

ImGuiNET.ImGui.GetWindowDrawList().AddImage((nint)_baseImg, absoluteContentPosition, absoluteContentEndPosition);
if (ShowImageBorder)
ImGuiNET.ImGui.GetWindowDrawList().AddRect(absoluteContentPosition, absoluteContentEndPosition, Style.GetColor(ImGuiCol.Border).ToUInt32());
}

private void OnMouseScrolled()
Expand Down
6 changes: 3 additions & 3 deletions ImGui.Forms/Factories/ImageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ private nint LoadImageInternal(Image<Rgba32> image)

private unsafe void CopyImageData(Texture texture, Image<Rgba32> image)
{
if (!image.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> data))
return;
var copiedImage = new Rgba32[image.Width * image.Height];
image.CopyPixelDataTo(copiedImage);

int size = image.Width * image.Height * 4;

fixed (Rgba32* imgData = data.Span)
fixed (Rgba32* imgData = copiedImage)
_gd.UpdateTexture(texture, (nint)imgData, (uint)size, 0, 0, 0, (uint)image.Width, (uint)image.Height, 1, 0, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion ImGui.Forms/ImGui.Forms.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Imgui.Forms</id>
<version>1.3.7</version>
<version>1.3.8</version>
<description>A WinForms-inspired object-oriented framework around Dear ImGui (https://github.com/ocornut/imgui)</description>

<authors>onepiecefreak</authors>
Expand Down

0 comments on commit 90bdf86

Please sign in to comment.