Skip to content

Commit

Permalink
Added drag-n-drop support for Convert and Scale tabs, improved previewer
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Jul 28, 2020
1 parent 240ab44 commit 719894e
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 40 deletions.
Binary file modified .vs/MagickUtils/v16/.suo
Binary file not shown.
84 changes: 84 additions & 0 deletions ConvertTabHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MagickUtils
{
using IF = Program.ImageFormat;

class ConvertTabHelper
{
public static void ConvertFileList (string[] files, ComboBox qualityCombox, ComboBox qualityMaxCombox, IF selectedFormat, CheckBox delSrcCbox)
{
int qMin = int.Parse(qualityCombox.Text.Trim());
int qMax = qMin;
if(!string.IsNullOrWhiteSpace(qualityMaxCombox.Text.Trim()))
qMax = int.Parse(qualityMaxCombox.Text.Trim());

foreach(string file in files)
{
Program.Print("Convert Dragndrop: " + file);
if(!IOUtils.IsPathDirectory(file))
{
if(selectedFormat == IF.JPG)
ConvertUtils.ConvertToJpegRandomQuality(file, qMin, qMax, delSrcCbox.Checked);

if(selectedFormat == IF.PNG)
ConvertUtils.ConvertToPng(file, qMin, delSrcCbox.Checked);

if(selectedFormat == IF.DDS)
{
if(FormatOptions.ddsUseCrunch) ConvertUtilsUI.ConvertDirToDdsCrunch(qMin, qMax, delSrcCbox.Checked);
else ConvertUtils.ConvertToDds(file, delSrcCbox.Checked);
}

if(selectedFormat == IF.TGA)
ConvertUtils.ConvertToTga(file, delSrcCbox.Checked);

if(selectedFormat == IF.WEBP)
ConvertUtils.ConvertToWebp(file, qMin, delSrcCbox.Checked);

if(selectedFormat == IF.J2K)
ConvertUtils.ConvertToJpeg2000(file, qMin, delSrcCbox.Checked);

if(selectedFormat == IF.FLIF)
FlifInterface.EncodeImage(file, qMin, delSrcCbox.Checked);
}
}
}

public static void ConvertUsingPath (ComboBox qualityCombox, ComboBox qualityMaxCombox, IF selectedFormat, CheckBox delSrcCbox)
{
int qMin = int.Parse(qualityCombox.Text.Trim());
int qMax = qMin;
if(!string.IsNullOrWhiteSpace(qualityMaxCombox.Text.Trim()))
qMax = int.Parse(qualityMaxCombox.Text.Trim());

if(selectedFormat == IF.JPG)
ConvertUtilsUI.ConvertDirToJpeg(qMin, qMax, delSrcCbox.Checked);

if(selectedFormat == IF.PNG)
ConvertUtilsUI.ConvertDirToPng(qMin, delSrcCbox.Checked);

if(selectedFormat == IF.DDS)
{
if(FormatOptions.ddsUseCrunch) ConvertUtilsUI.ConvertDirToDdsCrunch(qMin, qMax, delSrcCbox.Checked);
else ConvertUtilsUI.ConvertDirToDds(delSrcCbox.Checked);
}

if(selectedFormat == IF.TGA)
ConvertUtilsUI.ConvertDirToTga(delSrcCbox.Checked);

if(selectedFormat == IF.WEBP)
ConvertUtilsUI.ConvertDirToWebp(qMin, delSrcCbox.Checked);

if(selectedFormat == IF.J2K)
ConvertUtilsUI.ConvertDirToJpeg2000(qMin, delSrcCbox.Checked);

if(selectedFormat == IF.FLIF)
ConvertUtilsUI.ConvertDirToFlif(qMin, delSrcCbox.Checked);
}
}
}
34 changes: 34 additions & 0 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 24 additions & 35 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,7 @@ void InitCombox (ComboBox cbox, int index)

private void convertStartBtn_Click (object sender, EventArgs e)
{
int qMin = int.Parse(qualityCombox.Text.Trim());
int qMax = qMin;
if(!string.IsNullOrWhiteSpace(qualityMaxCombox.Text.Trim()))
qMax = int.Parse(qualityMaxCombox.Text.Trim());

if(selectedFormat == Program.ImageFormat.JPG)
ConvertUtilsUI.ConvertDirToJpeg(qMin, qMax, delSrcCbox.Checked);

if(selectedFormat == Program.ImageFormat.PNG)
ConvertUtilsUI.ConvertDirToPng(qMin, delSrcCbox.Checked);

if(selectedFormat == Program.ImageFormat.DDS)
{
if(FormatOptions.ddsUseCrunch) ConvertUtilsUI.ConvertDirToDdsCrunch(qMin, qMax, delSrcCbox.Checked);
else ConvertUtilsUI.ConvertDirToDds(delSrcCbox.Checked);
}

if(selectedFormat == Program.ImageFormat.TGA)
ConvertUtilsUI.ConvertDirToTga(delSrcCbox.Checked);

if(selectedFormat == Program.ImageFormat.WEBP)
ConvertUtilsUI.ConvertDirToWebp(qMin, delSrcCbox.Checked);

if(selectedFormat == Program.ImageFormat.J2K)
ConvertUtilsUI.ConvertDirToJpeg2000(qMin, delSrcCbox.Checked);

if(selectedFormat == Program.ImageFormat.FLIF)
ConvertUtilsUI.ConvertDirToFlif(qMin, delSrcCbox.Checked);
ConvertTabHelper.ConvertUsingPath(qualityCombox, qualityMaxCombox, selectedFormat, delSrcCbox);
}

private void pathTextbox_TextChanged (object sender, EventArgs e)
Expand Down Expand Up @@ -157,12 +130,7 @@ private void extTbox_TextChanged (object sender, EventArgs e)

private void DoScaleBtn_Click (object sender, EventArgs e)
{
int sMin = int.Parse(minScaleCombox.Text);
int sMax = sMin;
if(!string.IsNullOrWhiteSpace(maxScaleCombox.Text.Trim()))
sMax = int.Parse(maxScaleCombox.Text);
int filterMode = filterModeCombox.SelectedIndex;
ScaleUtilsUI.ScaleDir(sMin, sMax, filterMode);
ScaleTabHelper.ScaleUsingPath(minScaleCombox, maxScaleCombox, filterModeCombox);
}

private void autoLevelBtn_Click (object sender, EventArgs e)
Expand Down Expand Up @@ -268,7 +236,6 @@ private void noOverwriteCbox_CheckedChanged (object sender, EventArgs e)

private void MainForm_DragEnter (object sender, DragEventArgs e)
{
Console.WriteLine("DragEnter!");
e.Effect = DragDropEffects.Copy;
}

Expand Down Expand Up @@ -360,5 +327,27 @@ private void noisePreviewBtn_Click (object sender, EventArgs e)
EffectsUtils.AddNoise(tempImgPath, GetNoiseTypeList(), int.Parse(attenuateCombox.Text.Trim()), monoChrCbox.Checked);
PreviewImage(tempImgPath);
}

private void tabPage1_DragEnter (object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}

private void tabPage1_DragDrop (object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
ConvertTabHelper.ConvertFileList(files, qualityCombox, qualityMaxCombox, selectedFormat, delSrcCbox);
}

private void tabPage2_DragEnter (object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}

private void tabPage2_DragDrop (object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
ScaleTabHelper.ScaleFileList(files, minScaleCombox, maxScaleCombox, filterModeCombox);
}
}
}
10 changes: 7 additions & 3 deletions ImagePreviewPopup.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions ImagePreviewPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,20 @@ private void ImagePreviewPopup_Load (object sender, EventArgs e)
WindowState = FormWindowState.Maximized;
previewPicbox.ImageLocation = Program.previewImgPath;
}

private void previewPicbox_Click (object sender, EventArgs e)
{
if(previewPicbox.SizeMode == PictureBoxSizeMode.CenterImage)
{
previewPicbox.SizeMode = PictureBoxSizeMode.Zoom;
return;
}

if(previewPicbox.SizeMode == PictureBoxSizeMode.Zoom)
{
previewPicbox.SizeMode = PictureBoxSizeMode.CenterImage;
return;
}
}
}
}
2 changes: 2 additions & 0 deletions MagickUtils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<ItemGroup>
<Compile Include="AdjustUtils.cs" />
<Compile Include="AdjustUtilsUI.cs" />
<Compile Include="ConvertTabHelper.cs" />
<Compile Include="ConvertUtils.cs" />
<Compile Include="ConvertUtilsUI.cs" />
<Compile Include="CrunchInterface.cs" />
Expand Down Expand Up @@ -109,6 +110,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ScaleTabHelper.cs" />
<Compile Include="ScaleUtils.cs" />
<Compile Include="ScaleUtilsUI.cs" />
</ItemGroup>
Expand Down
36 changes: 36 additions & 0 deletions ScaleTabHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MagickUtils
{
class ScaleTabHelper
{
public static void ScaleUsingPath (ComboBox minScaleCombox, ComboBox maxScaleCombox, ComboBox filterModeCombox)
{
int sMin = int.Parse(minScaleCombox.Text);
int sMax = sMin;
if(!string.IsNullOrWhiteSpace(maxScaleCombox.Text.Trim()))
sMax = int.Parse(maxScaleCombox.Text);
int filterMode = filterModeCombox.SelectedIndex;
ScaleUtilsUI.ScaleDir(sMin, sMax, filterMode);
}

public static void ScaleFileList (string[] files, ComboBox minScaleCombox, ComboBox maxScaleCombox, ComboBox filterModeCombox)
{
int sMin = int.Parse(minScaleCombox.Text);
int sMax = sMin;
if(!string.IsNullOrWhiteSpace(maxScaleCombox.Text.Trim()))
sMax = int.Parse(maxScaleCombox.Text);
int filterMode = filterModeCombox.SelectedIndex;

foreach(string file in files)
{
ScaleUtils.Scale(file, sMin, sMax, filterMode);
}
}
}
}
2 changes: 1 addition & 1 deletion ScaleUtils.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.IO;
using ImageMagick;
using FT = ImageMagick.FilterType;

namespace MagickUtils
{
using SM = ScaleUtils.ScaleMode;
using FT = ImageMagick.FilterType;

class ScaleUtils
{
Expand Down
Binary file modified bin/Debug/MagickUtils.exe
Binary file not shown.
Binary file modified bin/Debug/MagickUtils.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/MagickUtils.csproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
72d791692f1ddb3a3c0435f36a6c41aa32ffe65a
bdc25d94445612a77604be9b2c17d54738aec9cc
Binary file modified obj/Debug/MagickUtils.csproj.GenerateResource.cache
Binary file not shown.
Binary file modified obj/Debug/MagickUtils.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/MagickUtils.exe
Binary file not shown.
Binary file modified obj/Debug/MagickUtils.pdb
Binary file not shown.

0 comments on commit 719894e

Please sign in to comment.