mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added maintain aspect ratio to image resize dialog
This commit is contained in:
parent
8dbbcad272
commit
757e4b0e1d
2 changed files with 55 additions and 10 deletions
|
@ -51,7 +51,6 @@ private void InitializeComponent()
|
||||||
0,
|
0,
|
||||||
0});
|
0});
|
||||||
this.nudWidth.Name = "nudWidth";
|
this.nudWidth.Name = "nudWidth";
|
||||||
this.nudWidth.ValueChanged += new System.EventHandler(this.nudWidth_ValueChanged);
|
|
||||||
//
|
//
|
||||||
// nudHeight
|
// nudHeight
|
||||||
//
|
//
|
||||||
|
@ -62,7 +61,6 @@ private void InitializeComponent()
|
||||||
0,
|
0,
|
||||||
0});
|
0});
|
||||||
this.nudHeight.Name = "nudHeight";
|
this.nudHeight.Name = "nudHeight";
|
||||||
this.nudHeight.ValueChanged += new System.EventHandler(this.nudHeight_ValueChanged);
|
|
||||||
//
|
//
|
||||||
// lblWidth
|
// lblWidth
|
||||||
//
|
//
|
||||||
|
@ -77,8 +75,11 @@ private void InitializeComponent()
|
||||||
// cbAspectRatio
|
// cbAspectRatio
|
||||||
//
|
//
|
||||||
resources.ApplyResources(this.cbAspectRatio, "cbAspectRatio");
|
resources.ApplyResources(this.cbAspectRatio, "cbAspectRatio");
|
||||||
|
this.cbAspectRatio.Checked = true;
|
||||||
|
this.cbAspectRatio.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||||
this.cbAspectRatio.Name = "cbAspectRatio";
|
this.cbAspectRatio.Name = "cbAspectRatio";
|
||||||
this.cbAspectRatio.UseVisualStyleBackColor = true;
|
this.cbAspectRatio.UseVisualStyleBackColor = true;
|
||||||
|
this.cbAspectRatio.CheckedChanged += new System.EventHandler(this.cbAspectRatio_CheckedChanged);
|
||||||
//
|
//
|
||||||
// btnOK
|
// btnOK
|
||||||
//
|
//
|
||||||
|
|
|
@ -39,17 +39,26 @@ public partial class ImageSizeForm : Form
|
||||||
{
|
{
|
||||||
public Size Result { get; private set; }
|
public Size Result { get; private set; }
|
||||||
|
|
||||||
public ImageSizeForm()
|
private double widthRatio, heightRatio;
|
||||||
|
private bool ignoreValueChanged = true;
|
||||||
|
|
||||||
|
public ImageSizeForm(Size size)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Icon = ShareXResources.Icon;
|
Icon = ShareXResources.Icon;
|
||||||
}
|
|
||||||
|
|
||||||
public ImageSizeForm(Size size) : this()
|
|
||||||
{
|
|
||||||
Result = size;
|
Result = size;
|
||||||
|
widthRatio = (double)size.Width / size.Height;
|
||||||
|
heightRatio = (double)size.Height / size.Width;
|
||||||
|
|
||||||
nudWidth.SetValue(size.Width);
|
nudWidth.SetValue(size.Width);
|
||||||
nudHeight.SetValue(size.Height);
|
nudHeight.SetValue(size.Height);
|
||||||
|
VerifySize();
|
||||||
|
|
||||||
|
nudWidth.TextChanged += NudWidth_TextChanged;
|
||||||
|
nudHeight.TextChanged += NudHeight_TextChanged;
|
||||||
|
|
||||||
|
ignoreValueChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifySize()
|
private void VerifySize()
|
||||||
|
@ -57,19 +66,54 @@ private void VerifySize()
|
||||||
btnOK.Enabled = nudWidth.Value > 0 && nudHeight.Value > 0;
|
btnOK.Enabled = nudWidth.Value > 0 && nudHeight.Value > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyWidthAspectRatio()
|
||||||
|
{
|
||||||
|
if (!ignoreValueChanged)
|
||||||
|
{
|
||||||
|
if (cbAspectRatio.Checked)
|
||||||
|
{
|
||||||
|
ignoreValueChanged = true;
|
||||||
|
nudHeight.Value = (int)Math.Round((double)nudWidth.Value * heightRatio);
|
||||||
|
ignoreValueChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
VerifySize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyHeightAspectRatio()
|
||||||
|
{
|
||||||
|
if (!ignoreValueChanged)
|
||||||
|
{
|
||||||
|
if (cbAspectRatio.Checked)
|
||||||
|
{
|
||||||
|
ignoreValueChanged = true;
|
||||||
|
nudWidth.Value = (int)Math.Round((double)nudHeight.Value * widthRatio);
|
||||||
|
ignoreValueChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
VerifySize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ResizeSizeForm_Shown(object sender, EventArgs e)
|
private void ResizeSizeForm_Shown(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.ForceActivate();
|
this.ForceActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudWidth_ValueChanged(object sender, EventArgs e)
|
private void NudWidth_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
VerifySize();
|
ApplyWidthAspectRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudHeight_ValueChanged(object sender, EventArgs e)
|
private void NudHeight_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
VerifySize();
|
ApplyHeightAspectRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cbAspectRatio_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ApplyWidthAspectRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnOK_Click(object sender, EventArgs e)
|
private void btnOK_Click(object sender, EventArgs e)
|
||||||
|
|
Loading…
Reference in a new issue