From 2ed966fe05088b0a39c4a694a07f952631a5537c Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 7 Nov 2019 10:45:18 +0300 Subject: [PATCH] Added "Copy Discord emoji syntax" button to image splitter tool --- .../Forms/ImageSplitterForm.Designer.cs | 10 ++++ ShareX.MediaLib/Forms/ImageSplitterForm.cs | 35 +++++++++++++- ShareX.MediaLib/Forms/ImageSplitterForm.resx | 46 ++++++++++++++----- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/ShareX.MediaLib/Forms/ImageSplitterForm.Designer.cs b/ShareX.MediaLib/Forms/ImageSplitterForm.Designer.cs index 5f5e5c9c5..f72d1c69f 100644 --- a/ShareX.MediaLib/Forms/ImageSplitterForm.Designer.cs +++ b/ShareX.MediaLib/Forms/ImageSplitterForm.Designer.cs @@ -40,6 +40,7 @@ private void InitializeComponent() this.btnImageFilePathBrowse = new System.Windows.Forms.Button(); this.btnOutputFolderBrowse = new System.Windows.Forms.Button(); this.btnSplitImage = new System.Windows.Forms.Button(); + this.btnCopyDiscordEmoji = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.nudRowCount)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudColumnCount)).BeginInit(); this.SuspendLayout(); @@ -125,11 +126,19 @@ private void InitializeComponent() this.btnSplitImage.UseVisualStyleBackColor = true; this.btnSplitImage.Click += new System.EventHandler(this.BtnSplitImage_Click); // + // btnCopyDiscordEmoji + // + resources.ApplyResources(this.btnCopyDiscordEmoji, "btnCopyDiscordEmoji"); + this.btnCopyDiscordEmoji.Name = "btnCopyDiscordEmoji"; + this.btnCopyDiscordEmoji.UseVisualStyleBackColor = true; + this.btnCopyDiscordEmoji.Click += new System.EventHandler(this.btnCopyDiscordEmoji_Click); + // // ImageSplitterForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Window; + this.Controls.Add(this.btnCopyDiscordEmoji); this.Controls.Add(this.btnSplitImage); this.Controls.Add(this.btnOutputFolderBrowse); this.Controls.Add(this.btnImageFilePathBrowse); @@ -164,5 +173,6 @@ private void InitializeComponent() private System.Windows.Forms.Button btnImageFilePathBrowse; private System.Windows.Forms.Button btnOutputFolderBrowse; private System.Windows.Forms.Button btnSplitImage; + private System.Windows.Forms.Button btnCopyDiscordEmoji; } } \ No newline at end of file diff --git a/ShareX.MediaLib/Forms/ImageSplitterForm.cs b/ShareX.MediaLib/Forms/ImageSplitterForm.cs index c109b1baa..64249271f 100644 --- a/ShareX.MediaLib/Forms/ImageSplitterForm.cs +++ b/ShareX.MediaLib/Forms/ImageSplitterForm.cs @@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License using System.Drawing; using System.Drawing.Imaging; using System.IO; +using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -102,10 +103,12 @@ private List SplitImage(string filePath, int rowCount, int columnCount, { List images = ImageHelpers.SplitImage(img, rowCount, columnCount); + string originalFileName = Path.GetFileNameWithoutExtension(filePath); + for (int i = 0; i < images.Count; i++) { - string filename = Path.GetFileNameWithoutExtension(filePath) + (i + 1) + ".png"; - string outputPath = Path.Combine(outputFolder, filename); + string fileName = originalFileName + (i + 1) + ".png"; + string outputPath = Path.Combine(outputFolder, fileName); images[i].Save(outputPath, ImageFormat.Png); filePaths.Add(outputPath); } @@ -121,5 +124,33 @@ private async Task> SplitImageAsync(string filePath, int rowCount, return SplitImage(filePath, rowCount, columnCount, outputFolder); }); } + + private void btnCopyDiscordEmoji_Click(object sender, EventArgs e) + { + string filePath = txtImageFilePath.Text; + string fileName = Path.GetFileNameWithoutExtension(filePath); + int rowCount = (int)nudRowCount.Value; + int columnCount = (int)nudColumnCount.Value; + + StringBuilder sb = new StringBuilder(); + + for (int y = 0; y < rowCount; y++) + { + for (int x = 0; x < columnCount; x++) + { + int index = (y * columnCount) + x + 1; + sb.Append($":{fileName}{index}:"); + } + + if (y + 1 < rowCount) + { + sb.AppendLine(); + } + } + + string text = sb.ToString(); + + Clipboard.SetText(text); + } } } \ No newline at end of file diff --git a/ShareX.MediaLib/Forms/ImageSplitterForm.resx b/ShareX.MediaLib/Forms/ImageSplitterForm.resx index b10c56758..9ebfb67d4 100644 --- a/ShareX.MediaLib/Forms/ImageSplitterForm.resx +++ b/ShareX.MediaLib/Forms/ImageSplitterForm.resx @@ -144,7 +144,7 @@ $this - 10 + 11 True @@ -171,7 +171,7 @@ $this - 9 + 10 True @@ -198,7 +198,7 @@ $this - 8 + 9 120, 36 @@ -223,7 +223,7 @@ $this - 7 + 8 120, 60 @@ -247,7 +247,7 @@ $this - 6 + 7 120, 12 @@ -268,7 +268,7 @@ $this - 5 + 6 True @@ -295,7 +295,7 @@ $this - 4 + 5 120, 84 @@ -316,7 +316,7 @@ $this - 3 + 4 408, 11 @@ -340,7 +340,7 @@ $this - 2 + 3 408, 83 @@ -364,13 +364,13 @@ $this - 1 + 2 16, 112 - 424, 24 + 208, 24 10 @@ -388,6 +388,30 @@ $this + 1 + + + 232, 112 + + + 208, 24 + + + 11 + + + Copy Discord emoji syntax + + + btnCopyDiscordEmoji + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0