ShareX/ShareX.MediaLib/Forms/ImageCombinerForm.cs

242 lines
7.4 KiB
C#
Raw Normal View History

2015-10-01 01:44:19 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2023-01-10 09:31:02 +13:00
Copyright (c) 2007-2023 ShareX Team
2015-10-01 01:44:19 +13:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
2020-08-31 23:24:46 +12:00
using ShareX.MediaLib.Properties;
2015-10-01 01:44:19 +13:00
using System;
using System.Collections.Generic;
using System.Drawing;
2021-06-15 00:18:09 +12:00
using System.Linq;
2015-10-01 01:44:19 +13:00
using System.Windows.Forms;
2017-07-10 09:50:10 +12:00
namespace ShareX.MediaLib
2015-10-01 01:44:19 +13:00
{
public partial class ImageCombinerForm : Form
2015-10-01 01:44:19 +13:00
{
2020-03-24 08:33:26 +13:00
public event Action<Bitmap> ProcessRequested;
2015-10-01 02:35:45 +13:00
2015-10-01 01:44:19 +13:00
public ImageCombinerOptions Options { get; private set; }
public ImageCombinerForm(ImageCombinerOptions options)
{
Options = options;
2015-10-01 01:44:19 +13:00
InitializeComponent();
2019-06-25 06:36:16 +12:00
ShareXResources.ApplyTheme(this);
if (Options.Orientation == Orientation.Horizontal)
{
rbOrientationHorizontal.Checked = true;
}
else
{
rbOrientationVertical.Checked = true;
}
UpdateAlignmentComboBox();
nudSpace.SetValue(Options.Space);
nudWrapAfter.SetValue(Options.WrapAfter);
cbAutoFillBackground.Checked = Options.AutoFillBackground;
2015-10-01 01:44:19 +13:00
}
2022-10-09 23:52:38 +13:00
public ImageCombinerForm(ImageCombinerOptions options, IEnumerable<string> imageFiles) : this(options)
{
if (imageFiles != null)
{
foreach (string image in imageFiles)
{
lvImages.Items.Add(image);
}
lblImageCount.Text = lvImages.Items.Count.ToString();
}
}
private void UpdateOrientation()
{
if (rbOrientationHorizontal.Checked)
{
Options.Orientation = Orientation.Horizontal;
}
else
{
Options.Orientation = Orientation.Vertical;
}
}
private void UpdateAlignmentComboBox()
{
cbAlignment.Items.Clear();
if (Options.Orientation == Orientation.Horizontal)
{
2020-08-31 23:24:46 +12:00
cbAlignment.Items.Add(Resources.AlignmentTop);
cbAlignment.Items.Add(Resources.AlignmentHorizontalCenter);
cbAlignment.Items.Add(Resources.AlignmentBottom);
}
else
{
2020-08-31 23:24:46 +12:00
cbAlignment.Items.Add(Resources.AlignmentLeft);
cbAlignment.Items.Add(Resources.AlignmentVerticalCenter);
cbAlignment.Items.Add(Resources.AlignmentRight);
}
cbAlignment.SelectedIndex = (int)Options.Alignment;
}
2015-10-01 01:44:19 +13:00
private void btnAdd_Click(object sender, EventArgs e)
{
2015-10-01 02:35:45 +13:00
string[] images = ImageHelpers.OpenImageFileDialog(true);
if (images != null)
{
foreach (string image in images)
{
lvImages.Items.Add(image);
}
2022-10-09 23:52:38 +13:00
lblImageCount.Text = lvImages.Items.Count.ToString();
2015-10-01 02:35:45 +13:00
}
2015-10-01 01:44:19 +13:00
}
private void btnRemove_Click(object sender, EventArgs e)
{
2015-10-01 02:35:45 +13:00
if (lvImages.SelectedItems.Count > 0)
{
foreach (ListViewItem lvi in lvImages.SelectedItems)
{
lvImages.Items.Remove(lvi);
}
2022-10-09 23:52:38 +13:00
lblImageCount.Text = lvImages.Items.Count.ToString();
2015-10-01 02:35:45 +13:00
}
2015-10-01 01:44:19 +13:00
}
private void btnMoveUp_Click(object sender, EventArgs e)
{
2015-10-01 02:35:45 +13:00
if (lvImages.SelectedItems.Count > 0)
{
lvImages.SelectedItems[0].MoveUp();
}
2015-10-01 01:44:19 +13:00
}
private void btnMoveDown_Click(object sender, EventArgs e)
{
2015-10-01 02:35:45 +13:00
if (lvImages.SelectedItems.Count > 0)
{
lvImages.SelectedItems[0].MoveDown();
}
}
private void rbOrientationHorizontal_CheckedChanged(object sender, EventArgs e)
{
UpdateOrientation();
UpdateAlignmentComboBox();
}
private void rbOrientationVertical_CheckedChanged(object sender, EventArgs e)
2015-10-01 02:35:45 +13:00
{
UpdateOrientation();
UpdateAlignmentComboBox();
}
private void cbAlignment_SelectedIndexChanged(object sender, EventArgs e)
{
Options.Alignment = (ImageCombinerAlignment)cbAlignment.SelectedIndex;
2015-10-01 02:35:45 +13:00
}
private void nudSpace_ValueChanged(object sender, EventArgs e)
{
Options.Space = (int)nudSpace.Value;
2015-10-01 01:44:19 +13:00
}
private void nudWrapAfter_ValueChanged(object sender, EventArgs e)
{
Options.WrapAfter = (int)nudWrapAfter.Value;
}
private void cbAutoFillBackground_CheckedChanged(object sender, EventArgs e)
{
Options.AutoFillBackground = cbAutoFillBackground.Checked;
}
2015-10-01 01:44:19 +13:00
private void btnCombine_Click(object sender, EventArgs e)
{
2015-10-01 02:35:45 +13:00
if (lvImages.Items.Count > 0)
{
try
{
2021-06-15 00:18:09 +12:00
List<string> imageFiles = lvImages.Items.Cast<ListViewItem>().Select(x => x.Text).ToList();
if (imageFiles.Count > 1)
{
Bitmap output = ImageHelpers.CombineImages(imageFiles, Options.Orientation, Options.Alignment, Options.Space, Options.WrapAfter,
Options.AutoFillBackground);
2021-06-15 00:18:09 +12:00
if (output != null)
{
2021-06-15 00:18:09 +12:00
OnProcessRequested(output);
}
}
2015-10-01 02:35:45 +13:00
}
catch (Exception ex)
{
DebugHelper.WriteException(ex);
2017-04-22 08:42:52 +12:00
ex.ShowError();
2015-10-01 02:35:45 +13:00
}
}
}
2020-03-24 08:33:26 +13:00
protected void OnProcessRequested(Bitmap bmp)
2015-10-01 02:35:45 +13:00
{
2021-06-10 10:14:01 +12:00
ProcessRequested?.Invoke(bmp);
2015-10-01 01:44:19 +13:00
}
private void ImageCombinerForm_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void ImageCombinerForm_DragDrop(object sender, DragEventArgs e)
{
2021-06-10 10:14:01 +12:00
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && e.Data.GetData(DataFormats.FileDrop, false) is string[] files)
{
2021-06-10 10:14:01 +12:00
foreach (string file in files)
{
2021-06-10 10:14:01 +12:00
lvImages.Items.Add(file);
}
2022-10-09 23:52:38 +13:00
lblImageCount.Text = lvImages.Items.Count.ToString();
}
}
2015-10-01 01:44:19 +13:00
}
}