Skip to content

Commit b0e4fed

Browse files
committed
Fixed issues
1 parent 7ae2b6c commit b0e4fed

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

Unity Mask Map Generator/Form1.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Coroutines;
2+
using System.Diagnostics;
13
using System.Drawing.Imaging;
24
using System.Runtime.CompilerServices;
35
using Unity_Mask_Map_Generator.DataClasses;
@@ -259,17 +261,19 @@ private void pictureBox3_DragDrop(object sender, DragEventArgs e)
259261
private async void generateMaskMap()
260262
{
261263
CheckForIllegalCrossThreadCalls = false;
262-
int width = metallic?.Width ?? ao?.Width ?? smoothness?.Width ?? detail?.Width ?? 256;
263-
int height = metallic?.Height ?? ao?.Height ?? smoothness?.Height ?? detail?.Height ?? 256;
264+
int width = Math.Max(Math.Max(metallic?.Width ?? 0, ao?.Width ?? 0), Math.Max(smoothness?.Width ?? 0, detail?.Width ?? 0));
265+
int height = Math.Max(Math.Max(metallic?.Height ?? 0, ao?.Height ?? 0), Math.Max(smoothness?.Height ?? 0, detail?.Height ?? 0));
264266
save.Visible = false;
265267
imgSize.Visible = false;
266268
maskMap?.Dispose();
267269
maskMap = null;
268270
resultPictureBox.Image = null;
269271
maskMap = new Bitmap(width, height);
270272
progressBar1.Visible = true;
271-
272-
await Task.Run(() =>
273+
EnableOrDisableCheckBoxes(false);
274+
Stopwatch stopwatch = new Stopwatch();
275+
stopwatch.Start();
276+
await GlobalScope.Launch(() =>
273277
{
274278
generate.Enabled = false;
275279
generate.Text = "Generating...";
@@ -293,18 +297,36 @@ await Task.Run(() =>
293297
progressLabel.Text = progress + "%";
294298
progressBar1.Value = progress;
295299
}
296-
imgSize.Text = "Image Size: " + width + "x" + height;
300+
stopwatch.Stop();
301+
imgSize.Text = $"Image Size: {width} x {height} ({stopwatch.ElapsedMilliseconds / 1000f}s)";
297302
imgSize.Visible = true;
298303
progressBar1.Visible = false;
299304
progressLabel.Visible = false;
300305
save.Visible = true;
301306
helpText2.Visible = false;
302307
generate.Text = "Generate";
308+
EnableOrDisableCheckBoxes(true);
303309
generate.Enabled = true;
304310
});
305311
resultPictureBox.Image = maskMap;
306312
}
307313

314+
private void EnableOrDisableCheckBoxes(bool state)
315+
{
316+
checkBox1.Enabled = state;
317+
checkBox2.Enabled = state;
318+
checkBox3.Enabled = state;
319+
checkBox4.Enabled = state;
320+
filePick1.Enabled = state;
321+
filePick2.Enabled = state;
322+
filePick3.Enabled = state;
323+
filePick4.Enabled = state;
324+
filePathText1.Enabled = state;
325+
filePathText2.Enabled = state;
326+
filePathText3.Enabled = state;
327+
filePathText4.Enabled = state;
328+
}
329+
308330
private void saveGeneratedImage()
309331
{
310332
using (SaveFileDialog saveFileDialog = new SaveFileDialog())

0 commit comments

Comments
 (0)