ShareX/ShareX.ImageEffectsLib/WatermarkForm.cs

241 lines
8.2 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2017-01-11 21:39:40 +13:00
Copyright (c) 2007-2017 ShareX Team
2013-11-03 23:53:49 +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)
2014-12-11 09:25:20 +13:00
using ShareX.HelpersLib;
2013-11-03 23:53:49 +13:00
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
namespace ShareX.ImageEffectsLib
2013-11-03 23:53:49 +13:00
{
public partial class WatermarkForm : Form
2013-11-03 23:53:49 +13:00
{
private WatermarkConfig config;
2013-11-03 23:53:49 +13:00
private bool IsGuiReady;
public WatermarkForm(WatermarkConfig watermarkConfig)
2013-11-03 23:53:49 +13:00
{
InitializeComponent();
Icon = ShareXResources.Icon;
config = watermarkConfig;
CodeMenu.Create<CodeMenuEntryFilename>(txtWatermarkText, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn);
2013-11-03 23:53:49 +13:00
}
private void WatermarkUI_Load(object sender, EventArgs e)
{
if (cboWatermarkType.Items.Count == 0)
{
cboWatermarkType.Items.AddRange(Enum.GetNames(typeof(WatermarkType)));
2013-11-03 23:53:49 +13:00
}
cboWatermarkType.SelectedIndex = (int)config.Type;
2013-11-03 23:53:49 +13:00
if (chkWatermarkPosition.Items.Count == 0)
{
chkWatermarkPosition.Items.AddRange(Helpers.GetEnumNamesProper<ContentAlignment>());
2013-11-03 23:53:49 +13:00
}
2013-11-17 23:33:21 +13:00
chkWatermarkPosition.SelectedIndex = config.Placement.GetIndex();
nudWatermarkOffset.SetValue(config.Offset);
cbWatermarkAutoHide.Checked = config.Text.AutoHide;
2013-11-03 23:53:49 +13:00
txtWatermarkText.Text = config.Text.Text;
lblWatermarkFont.Text = new FontConverter().ConvertToInvariantString(config.Text.TextFont);
btnTextColor.Color = config.Text.TextColor;
cbWatermarkDrawBackground.Checked = config.Text.DrawBackground;
btnBorderColor.Color = config.Text.BorderColor;
nudWatermarkCornerRadius.SetValue(config.Text.CornerRadius);
btnBackgroundColor.Color = config.Text.BackgroundColor;
cbWatermarkUseGradient.Checked = config.Text.UseGradient;
btnBackgroundColor2.Color = config.Text.BackgroundColor2;
2013-11-14 08:39:36 +13:00
2013-11-03 23:53:49 +13:00
if (cbWatermarkGradientType.Items.Count == 0)
{
cbWatermarkGradientType.Items.AddRange(Helpers.GetEnumNamesProper<LinearGradientMode>());
2013-11-03 23:53:49 +13:00
}
cbWatermarkGradientType.SelectedIndex = (int)config.Text.GradientType;
2013-11-03 23:53:49 +13:00
txtWatermarkImageLocation.Text = config.Image.ImageLocation;
2013-11-03 23:53:49 +13:00
IsGuiReady = true;
UpdatePreview();
}
private void WatermarkUI_Resize(object sender, EventArgs e)
{
Refresh();
}
private void UpdatePreview()
{
if (IsGuiReady)
{
using (Bitmap bmp = new Bitmap(pbPreview.ClientSize.Width, pbPreview.ClientSize.Height))
{
config.Apply(bmp);
2013-11-03 23:53:49 +13:00
pbPreview.LoadImage(bmp);
}
}
}
private void cboWatermarkType_SelectedIndexChanged(object sender, EventArgs e)
{
config.Type = (WatermarkType)cboWatermarkType.SelectedIndex;
UpdatePreview();
}
private void cbWatermarkPosition_SelectedIndexChanged(object sender, EventArgs e)
{
2013-11-17 23:33:21 +13:00
config.Placement = Helpers.GetEnumFromIndex<ContentAlignment>(chkWatermarkPosition.SelectedIndex);
UpdatePreview();
}
private void nudWatermarkOffset_ValueChanged(object sender, EventArgs e)
{
2013-11-17 23:33:21 +13:00
config.Offset = (int)nudWatermarkOffset.Value;
UpdatePreview();
}
private void cbWatermarkAutoHide_CheckedChanged(object sender, EventArgs e)
{
config.Text.AutoHide = cbWatermarkAutoHide.Checked;
UpdatePreview();
}
private void txtWatermarkText_TextChanged(object sender, EventArgs e)
{
config.Text.Text = txtWatermarkText.Text;
UpdatePreview();
}
private void btnWatermarkFont_Click(object sender, EventArgs e)
2013-11-03 23:53:49 +13:00
{
try
2013-11-03 23:53:49 +13:00
{
using (FontDialog fontDialog = new FontDialog())
2013-11-03 23:53:49 +13:00
{
fontDialog.ShowColor = true;
try
{
fontDialog.Font = config.Text.TextFont;
fontDialog.Color = config.Text.TextColor;
}
catch (Exception ex)
{
DebugHelper.WriteException(ex, "Error while initializing font.");
}
if (fontDialog.ShowDialog() == DialogResult.OK)
{
config.Text.TextFont = fontDialog.Font;
config.Text.TextColor = fontDialog.Color;
btnTextColor.Color = config.Text.TextColor;
lblWatermarkFont.Text = new FontConverter().ConvertToInvariantString(config.Text.TextFont);
UpdatePreview();
}
2013-11-03 23:53:49 +13:00
}
}
catch (Exception ex)
2013-11-03 23:53:49 +13:00
{
DebugHelper.WriteException(ex, "Error while setting watermark font.");
2013-11-03 23:53:49 +13:00
}
}
private void btnTextColor_ColorChanged(Color color)
2013-11-03 23:53:49 +13:00
{
config.Text.TextColor = color;
2013-11-03 23:53:49 +13:00
UpdatePreview();
}
private void cbWatermarkDrawBackground_CheckedChanged(object sender, EventArgs e)
{
config.Text.DrawBackground = cbWatermarkDrawBackground.Checked;
UpdatePreview();
}
private void btnBorderColor_ColorChanged(Color color)
2013-11-03 23:53:49 +13:00
{
config.Text.BorderColor = color;
2013-11-03 23:53:49 +13:00
UpdatePreview();
}
private void nudWatermarkCornerRadius_ValueChanged(object sender, EventArgs e)
2013-11-03 23:53:49 +13:00
{
config.Text.CornerRadius = (int)nudWatermarkCornerRadius.Value;
2013-11-03 23:53:49 +13:00
UpdatePreview();
}
private void btnBackgroundColor_ColorChanged(Color color)
2013-11-03 23:53:49 +13:00
{
config.Text.BackgroundColor = color;
2013-11-03 23:53:49 +13:00
UpdatePreview();
}
2013-11-14 08:39:36 +13:00
private void cbWatermarkBackColor2_CheckedChanged(object sender, EventArgs e)
{
config.Text.UseGradient = cbWatermarkUseGradient.Checked;
btnBackgroundColor2.Enabled = config.Text.UseGradient;
cbWatermarkGradientType.Enabled = config.Text.UseGradient;
2013-11-14 08:39:36 +13:00
UpdatePreview();
}
private void cbWatermarkGradientType_SelectedIndexChanged(object sender, EventArgs e)
2013-11-03 23:53:49 +13:00
{
config.Text.GradientType = (LinearGradientMode)cbWatermarkGradientType.SelectedIndex;
2013-11-03 23:53:49 +13:00
UpdatePreview();
}
private void btnBackgroundColor2_ColorChanged(Color color)
2013-11-14 08:39:36 +13:00
{
config.Text.BackgroundColor2 = color;
2013-11-14 08:39:36 +13:00
UpdatePreview();
}
2013-11-03 23:53:49 +13:00
private void txtWatermarkImageLocation_TextChanged(object sender, EventArgs e)
{
if (File.Exists(txtWatermarkImageLocation.Text))
{
config.Image.ImageLocation = txtWatermarkImageLocation.Text;
2013-11-03 23:53:49 +13:00
UpdatePreview();
}
}
private void btwWatermarkBrowseImage_Click(object sender, EventArgs e)
2013-11-03 23:53:49 +13:00
{
2013-11-21 06:45:11 +13:00
string filePath = ImageHelpers.OpenImageFileDialog();
2013-11-21 06:45:11 +13:00
if (!string.IsNullOrEmpty(filePath))
{
txtWatermarkImageLocation.Text = filePath;
}
2013-11-03 23:53:49 +13:00
}
}
}