Skip to content

Commit

Permalink
*fixed issues with changing resolution
Browse files Browse the repository at this point in the history
+added sample screenshot
  • Loading branch information
bahstrike committed Mar 16, 2022
1 parent 0f4a7fe commit 90de0c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions DyeAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,32 @@ public Size ExportDimensions
// for caching current bitmap (not pnt)
private string lastFilename = null;
private DateTime lastFileWrite = new DateTime();
private Size lastOutputSize = new Size(0, 0);
private Bitmap lastBitmap = null;


public void OpenFile(string file)
public void OpenFile(string file, bool autodetectResolution=true)
{
if (string.IsNullOrEmpty(file) || !File.Exists(file))
return;

try
{

PNTImage pnt = null;

switch (Path.GetExtension(file).ToLowerInvariant())
{
case ".pnt":
pnt = PNTImage.LoadPNT(palette, file);

// autoselect resolution
if (pnt.width >= 256)
resolution.SelectedIndex = 1;//256x256
else
resolution.SelectedIndex = 0;//128x128 (shrug)
if (autodetectResolution)
{
// autoselect resolution
if (pnt.width >= 256)
resolution.SelectedIndex = 1;//256x256
else
resolution.SelectedIndex = 0;//128x128 (shrug)
}
break;

case ".bmp":
Expand All @@ -186,10 +189,13 @@ public void OpenFile(string file)
if (!string.IsNullOrEmpty(lastFilename))
{
// check if different/modified.. if so then invalidate our existing entry
if (!string.Equals(file, lastFilename, StringComparison.InvariantCultureIgnoreCase) || !modifyTime.Equals(lastFileWrite))
if (!string.Equals(file, lastFilename, StringComparison.InvariantCultureIgnoreCase) ||
!modifyTime.Equals(lastFileWrite) ||
!ExportDimensions.Equals(lastOutputSize)/*hack to force reload if output dimensions change*/)
{
lastFilename = null;
lastFileWrite = new DateTime();
lastOutputSize = new Size(0, 0);
lastBitmap = null;
}
}
Expand Down Expand Up @@ -234,6 +240,7 @@ public void OpenFile(string file)

lastFilename = file;
lastFileWrite = modifyTime;
lastOutputSize = bmp.Size;
lastBitmap = bmp;
}

Expand All @@ -250,7 +257,9 @@ public void OpenFile(string file)
}

currentfile.Text = file;
resolution.Text = $"{pnt.width}x{pnt.height}";

if(autodetectResolution)
resolution.Text = $"{pnt.width}x{pnt.height}";

preview.Image = pnt.GenerateBitmap();

Expand All @@ -263,6 +272,10 @@ public void OpenFile(string file)
{
MessageBox.Show(e.Message);
}
finally
{

}

}

Expand Down Expand Up @@ -410,7 +423,7 @@ private void gamechoice_SelectedIndexChanged(object sender, EventArgs e)
public void Reprocess()
{
// reload current file
OpenFile(currentfile.Text);
OpenFile(currentfile.Text, false);
}


Expand Down
Binary file added images/dyeatlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 90de0c6

Please sign in to comment.