From 2066f0def09c7c91d40931894929a37fbb3c5245 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 23 Mar 2020 23:44:50 +0300 Subject: [PATCH] fixed #4655: Added image alignment option to image combiner tool --- ShareX.HelpersLib/Enums.cs | 7 ++ ShareX.HelpersLib/Helpers/ImageHelpers.cs | 39 +++++- .../Forms/ImageCombinerForm.Designer.cs | 24 +++- ShareX.MediaLib/Forms/ImageCombinerForm.cs | 30 ++++- ShareX.MediaLib/Forms/ImageCombinerForm.resx | 115 +++++++++++------- ShareX.MediaLib/ImageCombinerOptions.cs | 2 + 6 files changed, 165 insertions(+), 52 deletions(-) diff --git a/ShareX.HelpersLib/Enums.cs b/ShareX.HelpersLib/Enums.cs index f35af3e6d..eb39eb1be 100644 --- a/ShareX.HelpersLib/Enums.cs +++ b/ShareX.HelpersLib/Enums.cs @@ -183,4 +183,11 @@ public enum HotkeyStatus Failed, NotConfigured } + + public enum ImageCombinerAlignment + { + LeftOrTop, + Center, + RightOrBottom + } } \ No newline at end of file diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index 2a79a129f..2f788178a 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -1727,11 +1727,12 @@ public static Bitmap LoadImageWithFileDialog() return null; } - public static Bitmap CombineImages(IEnumerable images, Orientation orientation = Orientation.Vertical, int space = 0) + public static Bitmap CombineImages(IEnumerable images, Orientation orientation = Orientation.Vertical, + ImageCombinerAlignment alignment = ImageCombinerAlignment.LeftOrTop, int space = 0) { int width, height; - - int spaceSize = space * (images.Count() - 1); + int imageCount = images.Count(); + int spaceSize = space * (imageCount - 1); if (orientation == Orientation.Vertical) { @@ -1757,12 +1758,40 @@ public static Bitmap CombineImages(IEnumerable images, Orientation orient if (orientation == Orientation.Vertical) { - rect = new Rectangle(0, position, image.Width, image.Height); + int x; + switch (alignment) + { + default: + case ImageCombinerAlignment.LeftOrTop: + x = 0; + break; + case ImageCombinerAlignment.Center: + x = width / 2 - image.Width / 2; + break; + case ImageCombinerAlignment.RightOrBottom: + x = width - image.Width; + break; + } + rect = new Rectangle(x, position, image.Width, image.Height); position += image.Height + space; } else { - rect = new Rectangle(position, 0, image.Width, image.Height); + int y; + switch (alignment) + { + default: + case ImageCombinerAlignment.LeftOrTop: + y = 0; + break; + case ImageCombinerAlignment.Center: + y = height / 2 - image.Height / 2; + break; + case ImageCombinerAlignment.RightOrBottom: + y = height - image.Height; + break; + } + rect = new Rectangle(position, y, image.Width, image.Height); position += image.Width + space; } diff --git a/ShareX.MediaLib/Forms/ImageCombinerForm.Designer.cs b/ShareX.MediaLib/Forms/ImageCombinerForm.Designer.cs index 107a50d0b..27d85fdf0 100644 --- a/ShareX.MediaLib/Forms/ImageCombinerForm.Designer.cs +++ b/ShareX.MediaLib/Forms/ImageCombinerForm.Designer.cs @@ -41,6 +41,8 @@ private void InitializeComponent() this.lblOrientation = new System.Windows.Forms.Label(); this.cbOrientation = new System.Windows.Forms.ComboBox(); this.lblSpacePixel = new System.Windows.Forms.Label(); + this.lblImageAlignment = new System.Windows.Forms.Label(); + this.cbAlignment = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.nudSpace)).BeginInit(); this.SuspendLayout(); // @@ -76,12 +78,13 @@ private void InitializeComponent() // this.lvImages.AllowDrop = true; this.lvImages.AllowItemDrag = true; - resources.ApplyResources(this.lvImages, "lvImages"); this.lvImages.AutoFillColumn = true; this.lvImages.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.chFilepath}); this.lvImages.FullRowSelect = true; this.lvImages.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; + this.lvImages.HideSelection = false; + resources.ApplyResources(this.lvImages, "lvImages"); this.lvImages.Name = "lvImages"; this.lvImages.UseCompatibleStateImageBehavior = false; this.lvImages.View = System.Windows.Forms.View.Details; @@ -122,9 +125,9 @@ private void InitializeComponent() // // cbOrientation // - resources.ApplyResources(this.cbOrientation, "cbOrientation"); this.cbOrientation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbOrientation.FormattingEnabled = true; + resources.ApplyResources(this.cbOrientation, "cbOrientation"); this.cbOrientation.Name = "cbOrientation"; this.cbOrientation.SelectedIndexChanged += new System.EventHandler(this.cbOrientation_SelectedIndexChanged); // @@ -133,6 +136,19 @@ private void InitializeComponent() resources.ApplyResources(this.lblSpacePixel, "lblSpacePixel"); this.lblSpacePixel.Name = "lblSpacePixel"; // + // lblImageAlignment + // + resources.ApplyResources(this.lblImageAlignment, "lblImageAlignment"); + this.lblImageAlignment.Name = "lblImageAlignment"; + // + // cbAlignment + // + this.cbAlignment.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbAlignment.FormattingEnabled = true; + resources.ApplyResources(this.cbAlignment, "cbAlignment"); + this.cbAlignment.Name = "cbAlignment"; + this.cbAlignment.SelectedIndexChanged += new System.EventHandler(this.cbAlignment_SelectedIndexChanged); + // // ImageCombinerForm // this.AcceptButton = this.btnCombine; @@ -140,6 +156,8 @@ private void InitializeComponent() resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Window; + this.Controls.Add(this.cbAlignment); + this.Controls.Add(this.lblImageAlignment); this.Controls.Add(this.lblSpacePixel); this.Controls.Add(this.cbOrientation); this.Controls.Add(this.lblOrientation); @@ -174,5 +192,7 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox cbOrientation; private System.Windows.Forms.ColumnHeader chFilepath; private System.Windows.Forms.Label lblSpacePixel; + private System.Windows.Forms.Label lblImageAlignment; + private System.Windows.Forms.ComboBox cbAlignment; } } \ No newline at end of file diff --git a/ShareX.MediaLib/Forms/ImageCombinerForm.cs b/ShareX.MediaLib/Forms/ImageCombinerForm.cs index 0b538e235..406e85e48 100644 --- a/ShareX.MediaLib/Forms/ImageCombinerForm.cs +++ b/ShareX.MediaLib/Forms/ImageCombinerForm.cs @@ -47,9 +47,31 @@ public ImageCombinerForm(ImageCombinerOptions options) cbOrientation.Items.AddRange(Enum.GetNames(typeof(Orientation))); cbOrientation.SelectedIndex = (int)Options.Orientation; + UpdateAlignmentComboBox(); nudSpace.SetValue(Options.Space); } + private void UpdateAlignmentComboBox() + { + cbAlignment.Items.Clear(); + + // TODO: Translate + if (Options.Orientation == Orientation.Horizontal) + { + cbAlignment.Items.Add("Top"); + cbAlignment.Items.Add("Center"); + cbAlignment.Items.Add("Bottom"); + } + else + { + cbAlignment.Items.Add("Left"); + cbAlignment.Items.Add("Center"); + cbAlignment.Items.Add("Right"); + } + + cbAlignment.SelectedIndex = (int)Options.Alignment; + } + public ImageCombinerForm(ImageCombinerOptions options, IEnumerable imageFiles) : this(options) { if (imageFiles != null) @@ -104,6 +126,12 @@ private void btnMoveDown_Click(object sender, EventArgs e) private void cbOrientation_SelectedIndexChanged(object sender, EventArgs e) { Options.Orientation = (Orientation)cbOrientation.SelectedIndex; + UpdateAlignmentComboBox(); + } + + private void cbAlignment_SelectedIndexChanged(object sender, EventArgs e) + { + Options.Alignment = (ImageCombinerAlignment)cbAlignment.SelectedIndex; } private void nudSpace_ValueChanged(object sender, EventArgs e) @@ -136,7 +164,7 @@ private void btnCombine_Click(object sender, EventArgs e) if (images.Count > 1) { - Bitmap output = ImageHelpers.CombineImages(images, Options.Orientation, Options.Space); + Bitmap output = ImageHelpers.CombineImages(images, Options.Orientation, Options.Alignment, Options.Space); OnProcessRequested(output); } diff --git a/ShareX.MediaLib/Forms/ImageCombinerForm.resx b/ShareX.MediaLib/Forms/ImageCombinerForm.resx index a28e3d5ae..9c26142e5 100644 --- a/ShareX.MediaLib/Forms/ImageCombinerForm.resx +++ b/ShareX.MediaLib/Forms/ImageCombinerForm.resx @@ -141,7 +141,7 @@ $this - 10 + 12 136, 8 @@ -165,7 +165,7 @@ $this - 9 + 11 264, 8 @@ -189,7 +189,7 @@ $this - 8 + 10 392, 8 @@ -213,11 +213,7 @@ $this - 7 - - - - Top, Bottom, Left, Right + 9 Image file path @@ -238,25 +234,22 @@ lvImages - ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.1.1.0, Culture=neutral, PublicKeyToken=null $this - 6 - - - Bottom, Left, Right + 8 - 8, 472 + 8, 496 504, 31 - 5 + 12 Combine images and save/upload depending on after capture settings @@ -271,22 +264,19 @@ $this - 5 - - - Bottom, Left + 7 True - 8, 448 + 8, 472 121, 13 - 6 + 9 Space between images: @@ -301,20 +291,18 @@ $this - 4 - - - Bottom, Left + 6 - 200, 444 + 200, 468 64, 20 - 7 + 10 + Center @@ -328,10 +316,7 @@ $this - 3 - - - Bottom, Left + 5 True @@ -343,7 +328,7 @@ 103, 13 - 8 + 5 Combine orientation: @@ -358,10 +343,7 @@ $this - 2 - - - Bottom, Left + 4 200, 420 @@ -370,7 +352,7 @@ 121, 21 - 9 + 6 cbOrientation @@ -382,22 +364,19 @@ $this - 1 - - - Bottom, Left + 3 True - 272, 448 + 272, 472 33, 13 - 10 + 11 pixels @@ -412,6 +391,54 @@ $this + 2 + + + True + + + 8, 448 + + + 87, 13 + + + 7 + + + Image alignment: + + + lblImageAlignment + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + 200, 444 + + + 120, 21 + + + 8 + + + cbAlignment + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 @@ -421,7 +448,7 @@ 6, 13 - 521, 514 + 521, 536 CenterScreen diff --git a/ShareX.MediaLib/ImageCombinerOptions.cs b/ShareX.MediaLib/ImageCombinerOptions.cs index b9b0e2175..68e33d125 100644 --- a/ShareX.MediaLib/ImageCombinerOptions.cs +++ b/ShareX.MediaLib/ImageCombinerOptions.cs @@ -23,6 +23,7 @@ #endregion License Information (GPL v3) +using ShareX.HelpersLib; using System.Windows.Forms; namespace ShareX.MediaLib @@ -30,6 +31,7 @@ namespace ShareX.MediaLib public class ImageCombinerOptions { public Orientation Orientation { get; set; } = Orientation.Vertical; + public ImageCombinerAlignment Alignment { get; set; } = ImageCombinerAlignment.LeftOrTop; public int Space { get; set; } = 0; } } \ No newline at end of file