ImageBeautifierForm improvements

This commit is contained in:
Jaex 2023-05-30 17:56:52 +03:00
parent 35c07115ce
commit fbbf58c954
3 changed files with 55 additions and 15 deletions

View file

@ -46,6 +46,7 @@ private void InitializeComponent()
this.tlpMain = new System.Windows.Forms.TableLayoutPanel();
this.pbPreview = new ShareX.HelpersLib.MyPictureBox();
this.pOptions = new System.Windows.Forms.Panel();
this.btnResetOptions = new System.Windows.Forms.Button();
this.lblBackgroundImageFilePath = new System.Windows.Forms.Label();
this.btnBackgroundImageFilePathBrowse = new System.Windows.Forms.Button();
this.cbBackgroundType = new System.Windows.Forms.ComboBox();
@ -56,7 +57,6 @@ private void InitializeComponent()
this.btnCopy = new System.Windows.Forms.Button();
this.pbBackground = new System.Windows.Forms.PictureBox();
this.ttMain = new System.Windows.Forms.ToolTip(this.components);
this.btnResetOptions = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.tbMargin)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tbPadding)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tbRoundedCorner)).BeginInit();
@ -86,6 +86,7 @@ private void InitializeComponent()
this.tbMargin.TabIndex = 1;
this.tbMargin.TickFrequency = 10;
this.tbMargin.Scroll += new System.EventHandler(this.tbMargin_Scroll);
this.tbMargin.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tbMargin_MouseUp);
//
// lblPadding
//
@ -107,6 +108,7 @@ private void InitializeComponent()
this.tbPadding.TabIndex = 4;
this.tbPadding.TickFrequency = 10;
this.tbPadding.Scroll += new System.EventHandler(this.tbPadding_Scroll);
this.tbPadding.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tbPadding_MouseUp);
//
// cbSmartPadding
//
@ -140,6 +142,7 @@ private void InitializeComponent()
this.tbRoundedCorner.TabIndex = 8;
this.tbRoundedCorner.TickFrequency = 5;
this.tbRoundedCorner.Scroll += new System.EventHandler(this.tbRoundedCorner_Scroll);
this.tbRoundedCorner.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tbRoundedCorner_MouseUp);
//
// lblShadowSize
//
@ -274,6 +277,17 @@ private void InitializeComponent()
this.pOptions.Size = new System.Drawing.Size(329, 755);
this.pOptions.TabIndex = 0;
//
// btnResetOptions
//
this.btnResetOptions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnResetOptions.Location = new System.Drawing.Point(8, 656);
this.btnResetOptions.Name = "btnResetOptions";
this.btnResetOptions.Size = new System.Drawing.Size(312, 32);
this.btnResetOptions.TabIndex = 23;
this.btnResetOptions.Text = "Reset options...";
this.btnResetOptions.UseVisualStyleBackColor = true;
this.btnResetOptions.Click += new System.EventHandler(this.btnResetOptions_Click);
//
// lblBackgroundImageFilePath
//
this.lblBackgroundImageFilePath.Location = new System.Drawing.Point(13, 432);
@ -371,16 +385,6 @@ private void InitializeComponent()
this.pbBackground.TabStop = false;
this.pbBackground.Click += new System.EventHandler(this.pbBackground_Click);
//
// btnResetOptions
//
this.btnResetOptions.Location = new System.Drawing.Point(8, 656);
this.btnResetOptions.Name = "btnResetOptions";
this.btnResetOptions.Size = new System.Drawing.Size(312, 32);
this.btnResetOptions.TabIndex = 23;
this.btnResetOptions.Text = "Reset options...";
this.btnResetOptions.UseVisualStyleBackColor = true;
this.btnResetOptions.Click += new System.EventHandler(this.btnResetOptions_Click);
//
// ImageBeautifierForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);

View file

@ -25,6 +25,7 @@
using ShareX.HelpersLib;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -41,7 +42,8 @@ public partial class ImageBeautifierForm : Form
public event Action<Bitmap> UploadImageRequested;
public event Action<Bitmap> PrintImageRequested;
private bool isReady, isBusy, isPending;
private bool isReady, isBusy, isPending, pendingQuickRender;
private string title;
private ImageBeautifierForm(ImageBeautifierOptions options = null)
{
@ -54,6 +56,7 @@ private ImageBeautifierForm(ImageBeautifierOptions options = null)
InitializeComponent();
ShareXResources.ApplyTheme(this);
title = Text;
LoadOptions();
}
@ -133,7 +136,7 @@ private void UpdateBackgroundPreview()
}
}
private async Task UpdatePreview()
private async Task UpdatePreview(bool quickRender = false)
{
if (isReady)
{
@ -142,6 +145,7 @@ private async Task UpdatePreview()
if (isBusy)
{
isPending = true;
pendingQuickRender = quickRender;
}
else
{
@ -149,7 +153,16 @@ private async Task UpdatePreview()
UpdateOptions();
Bitmap resultImage = await Options.RenderAsync(SourceImage);
ImageBeautifierOptions options = Options.Copy();
if (quickRender)
{
options.ShadowSize = 0;
}
Stopwatch renderTime = Stopwatch.StartNew();
Bitmap resultImage = await options.RenderAsync(SourceImage);
renderTime.Stop();
if (IsDisposed)
{
@ -157,6 +170,11 @@ private async Task UpdatePreview()
return;
}
if (HelpersOptions.DevMode)
{
Text = $"{title} - Render time: {renderTime.ElapsedMilliseconds} ms";
}
PreviewImage?.Dispose();
PreviewImage = resultImage;
pbPreview.LoadImage(PreviewImage);
@ -167,7 +185,7 @@ private async Task UpdatePreview()
{
isPending = false;
await UpdatePreview();
await UpdatePreview(pendingQuickRender);
}
}
}
@ -198,11 +216,21 @@ private async void ImageBeautifierForm_Shown(object sender, EventArgs e)
}
private async void tbMargin_Scroll(object sender, EventArgs e)
{
await UpdatePreview(true);
}
private async void tbMargin_MouseUp(object sender, MouseEventArgs e)
{
await UpdatePreview();
}
private async void tbPadding_Scroll(object sender, EventArgs e)
{
await UpdatePreview(true);
}
private async void tbPadding_MouseUp(object sender, MouseEventArgs e)
{
await UpdatePreview();
}
@ -213,6 +241,11 @@ private async void cbSmartPadding_CheckedChanged(object sender, EventArgs e)
}
private async void tbRoundedCorner_Scroll(object sender, EventArgs e)
{
await UpdatePreview(true);
}
private async void tbRoundedCorner_MouseUp(object sender, MouseEventArgs e)
{
await UpdatePreview();
}

View file

@ -120,6 +120,9 @@
<metadata name="ttMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="ttMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>58</value>
</metadata>