mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Next step for having the settings of effects stored in the greenshot.ini, using a TypeConverter this seems to work. An important change to the IniValue.cs: here a default value is created when the ini doesn't have a value yet. This used to be just "null". Next step would be that settings forms get a reset/default button. [skip ci]
This commit is contained in:
parent
941551945d
commit
8cb2dedb87
8 changed files with 263 additions and 44 deletions
|
@ -25,6 +25,7 @@ using System.Drawing;
|
||||||
using Greenshot.Drawing.Fields;
|
using Greenshot.Drawing.Fields;
|
||||||
using GreenshotPlugin.UnmanagedHelpers;
|
using GreenshotPlugin.UnmanagedHelpers;
|
||||||
using Greenshot.IniFile;
|
using Greenshot.IniFile;
|
||||||
|
using Greenshot.Core;
|
||||||
|
|
||||||
namespace Greenshot.Configuration {
|
namespace Greenshot.Configuration {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -57,6 +58,12 @@ namespace Greenshot.Configuration {
|
||||||
[IniProperty("SuppressSaveDialogAtClose", Description="Suppressed the 'do you want to save' dialog when closing the editor.", DefaultValue="False")]
|
[IniProperty("SuppressSaveDialogAtClose", Description="Suppressed the 'do you want to save' dialog when closing the editor.", DefaultValue="False")]
|
||||||
public bool SuppressSaveDialogAtClose;
|
public bool SuppressSaveDialogAtClose;
|
||||||
|
|
||||||
|
[IniProperty("DropShadowEffectSettings", Description = "Settings for the drop shadow effect.")]
|
||||||
|
public DropShadowEffect DropShadowEffectSettings;
|
||||||
|
|
||||||
|
[IniProperty("TornEdgeEffectSettings", Description = "Settings for the torn edge effect.")]
|
||||||
|
public TornEdgeEffect TornEdgeEffectSettings;
|
||||||
|
|
||||||
public override void AfterLoad() {
|
public override void AfterLoad() {
|
||||||
base.AfterLoad();
|
base.AfterLoad();
|
||||||
if (RecentColors == null) {
|
if (RecentColors == null) {
|
||||||
|
|
|
@ -152,7 +152,7 @@ namespace Greenshot.Forms {
|
||||||
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
||||||
this.buttonOK.TabIndex = 11;
|
this.buttonOK.TabIndex = 11;
|
||||||
this.buttonOK.UseVisualStyleBackColor = true;
|
this.buttonOK.UseVisualStyleBackColor = true;
|
||||||
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
|
this.buttonOK.Click += new System.EventHandler(this.ButtonOK_Click);
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
|
|
|
@ -27,20 +27,33 @@ using GreenshotPlugin.Core;
|
||||||
namespace Greenshot.Forms {
|
namespace Greenshot.Forms {
|
||||||
public partial class DropShadowSettingsForm : BaseForm {
|
public partial class DropShadowSettingsForm : BaseForm {
|
||||||
private DropShadowEffect effect;
|
private DropShadowEffect effect;
|
||||||
|
|
||||||
public DropShadowSettingsForm(DropShadowEffect effect) {
|
public DropShadowSettingsForm(DropShadowEffect effect) {
|
||||||
this.effect = effect;
|
this.effect = effect;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Icon = GreenshotResources.getGreenshotIcon();
|
this.Icon = GreenshotResources.getGreenshotIcon();
|
||||||
|
ShowSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply the settings from the effect to the view
|
||||||
|
/// </summary>
|
||||||
|
private void ShowSettings() {
|
||||||
trackBar1.Value = (int)(effect.Darkness * 40);
|
trackBar1.Value = (int)(effect.Darkness * 40);
|
||||||
offsetX.Value = effect.ShadowOffset.X;
|
offsetX.Value = effect.ShadowOffset.X;
|
||||||
offsetY.Value = effect.ShadowOffset.Y;
|
offsetY.Value = effect.ShadowOffset.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonOK_Click(object sender, EventArgs e) {
|
private void ButtonOK_Click(object sender, EventArgs e) {
|
||||||
effect.Darkness = (float)trackBar1.Value / (float)40;
|
effect.Darkness = (float)trackBar1.Value / (float)40;
|
||||||
effect.ShadowOffset = new Point((int)offsetX.Value, (int)offsetY.Value);
|
effect.ShadowOffset = new Point((int)offsetX.Value, (int)offsetY.Value);
|
||||||
effect.ShadowSize = (int)thickness.Value;
|
effect.ShadowSize = (int)thickness.Value;
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonReset_Click(object sender, EventArgs e) {
|
||||||
|
effect.Reset();
|
||||||
|
ShowSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1253,7 +1253,7 @@ namespace Greenshot {
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
void AddDropshadowToolStripMenuItemClick(object sender, EventArgs e) {
|
void AddDropshadowToolStripMenuItemClick(object sender, EventArgs e) {
|
||||||
DropShadowEffect dropShadowEffect= new DropShadowEffect();
|
DropShadowEffect dropShadowEffect = editorConfiguration.DropShadowEffectSettings;
|
||||||
// TODO: Use the dropshadow settings form to make it possible to change the default values
|
// TODO: Use the dropshadow settings form to make it possible to change the default values
|
||||||
DialogResult result = new DropShadowSettingsForm(dropShadowEffect).ShowDialog(this);
|
DialogResult result = new DropShadowSettingsForm(dropShadowEffect).ShowDialog(this);
|
||||||
if (result == DialogResult.OK) {
|
if (result == DialogResult.OK) {
|
||||||
|
@ -1283,7 +1283,7 @@ namespace Greenshot {
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
void TornEdgesToolStripMenuItemClick(object sender, EventArgs e) {
|
void TornEdgesToolStripMenuItemClick(object sender, EventArgs e) {
|
||||||
TornEdgeEffect tornEdgeEffect = new TornEdgeEffect();
|
TornEdgeEffect tornEdgeEffect = editorConfiguration.TornEdgeEffectSettings;
|
||||||
// TODO: Use the dropshadow settings form to make it possible to change the default values
|
// TODO: Use the dropshadow settings form to make it possible to change the default values
|
||||||
DialogResult result = new TornEdgeSettingsForm(tornEdgeEffect).ShowDialog(this);
|
DialogResult result = new TornEdgeSettingsForm(tornEdgeEffect).ShowDialog(this);
|
||||||
if (result == DialogResult.OK) {
|
if (result == DialogResult.OK) {
|
||||||
|
|
4
Greenshot/Forms/TornEdgeSettingsForm.Designer.cs
generated
4
Greenshot/Forms/TornEdgeSettingsForm.Designer.cs
generated
|
@ -166,7 +166,7 @@ namespace Greenshot.Forms {
|
||||||
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
||||||
this.buttonOK.TabIndex = 20;
|
this.buttonOK.TabIndex = 20;
|
||||||
this.buttonOK.UseVisualStyleBackColor = true;
|
this.buttonOK.UseVisualStyleBackColor = true;
|
||||||
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
|
this.buttonOK.Click += new System.EventHandler(this.ButtonOK_Click);
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
|
@ -348,7 +348,7 @@ namespace Greenshot.Forms {
|
||||||
this.shadowCheckbox.Size = new System.Drawing.Size(110, 17);
|
this.shadowCheckbox.Size = new System.Drawing.Size(110, 17);
|
||||||
this.shadowCheckbox.TabIndex = 1;
|
this.shadowCheckbox.TabIndex = 1;
|
||||||
this.shadowCheckbox.UseVisualStyleBackColor = true;
|
this.shadowCheckbox.UseVisualStyleBackColor = true;
|
||||||
this.shadowCheckbox.CheckedChanged += new System.EventHandler(this.shadowCheckbox_CheckedChanged);
|
this.shadowCheckbox.CheckedChanged += new System.EventHandler(this.ShadowCheckbox_CheckedChanged);
|
||||||
//
|
//
|
||||||
// TornEdgeSettingsForm
|
// TornEdgeSettingsForm
|
||||||
//
|
//
|
||||||
|
|
|
@ -31,6 +31,10 @@ namespace Greenshot.Forms {
|
||||||
this.effect = effect;
|
this.effect = effect;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Icon = GreenshotResources.getGreenshotIcon();
|
this.Icon = GreenshotResources.getGreenshotIcon();
|
||||||
|
ShowSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowSettings() {
|
||||||
shadowCheckbox.Checked = effect.GenerateShadow;
|
shadowCheckbox.Checked = effect.GenerateShadow;
|
||||||
shadowDarkness.Value = (int)(effect.Darkness * 40);
|
shadowDarkness.Value = (int)(effect.Darkness * 40);
|
||||||
offsetX.Value = effect.ShadowOffset.X;
|
offsetX.Value = effect.ShadowOffset.X;
|
||||||
|
@ -44,7 +48,7 @@ namespace Greenshot.Forms {
|
||||||
left.Checked = effect.Edges[3];
|
left.Checked = effect.Edges[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonOK_Click(object sender, EventArgs e) {
|
private void ButtonOK_Click(object sender, EventArgs e) {
|
||||||
effect.Darkness = (float)shadowDarkness.Value / (float)40;
|
effect.Darkness = (float)shadowDarkness.Value / (float)40;
|
||||||
effect.ShadowOffset = new Point((int)offsetX.Value, (int)offsetY.Value);
|
effect.ShadowOffset = new Point((int)offsetX.Value, (int)offsetY.Value);
|
||||||
effect.ShadowSize = (int)thickness.Value;
|
effect.ShadowSize = (int)thickness.Value;
|
||||||
|
@ -56,7 +60,12 @@ namespace Greenshot.Forms {
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shadowCheckbox_CheckedChanged(object sender, EventArgs e) {
|
private void ButtonReset_Click(object sender, EventArgs e) {
|
||||||
|
effect.Reset();
|
||||||
|
ShowSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShadowCheckbox_CheckedChanged(object sender, EventArgs e) {
|
||||||
thickness.Enabled = shadowCheckbox.Checked;
|
thickness.Enabled = shadowCheckbox.Checked;
|
||||||
offsetX.Enabled = shadowCheckbox.Checked;
|
offsetX.Enabled = shadowCheckbox.Checked;
|
||||||
offsetY.Enabled = shadowCheckbox.Checked;
|
offsetY.Enabled = shadowCheckbox.Checked;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
using GreenshotPlugin.Core;
|
using GreenshotPlugin.Core;
|
||||||
using log4net;
|
using log4net;
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
|
@ -32,17 +33,28 @@ namespace Greenshot.Core {
|
||||||
/// Interface to describe an effect
|
/// Interface to describe an effect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IEffect {
|
public interface IEffect {
|
||||||
|
/// <summary>
|
||||||
|
/// Apply this IEffect to the supplied sourceImage.
|
||||||
|
/// In the process of applying the supplied matrix will be modified to represent the changes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sourceImage">Image to apply the effect to</param>
|
||||||
|
/// <param name="matrix">Matrix with the modifications like rotate, translate etc. this can be used to calculate the new location of elements on a canvas</param>
|
||||||
|
/// <returns>new image with applied effect</returns>
|
||||||
Image Apply(Image sourceImage, Matrix matrix);
|
Image Apply(Image sourceImage, Matrix matrix);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reset all values to their defaults
|
||||||
|
/// </summary>
|
||||||
|
void Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DropShadowEffect
|
/// DropShadowEffect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[TypeConverter(typeof(EffectConverter))]
|
||||||
public class DropShadowEffect : IEffect {
|
public class DropShadowEffect : IEffect {
|
||||||
public DropShadowEffect() {
|
public DropShadowEffect() {
|
||||||
Darkness = 0.6f;
|
Reset();
|
||||||
ShadowSize = 7;
|
|
||||||
ShadowOffset = new Point(-1, -1);
|
|
||||||
}
|
}
|
||||||
public float Darkness {
|
public float Darkness {
|
||||||
get;
|
get;
|
||||||
|
@ -56,32 +68,25 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Reset() {
|
||||||
|
Darkness = 0.6f;
|
||||||
|
ShadowSize = 7;
|
||||||
|
ShadowOffset = new Point(-1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual Image Apply(Image sourceImage, Matrix matrix) {
|
public virtual Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.CreateShadow(sourceImage, Darkness, ShadowSize, ShadowOffset, matrix, PixelFormat.Format32bppArgb);
|
return ImageHelper.CreateShadow(sourceImage, Darkness, ShadowSize, ShadowOffset, matrix, PixelFormat.Format32bppArgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.AppendFormat("Darkness:{0:F2}|ShadowSize:{1}|ShadowOffset:{2},{3}", Darkness, ShadowSize, ShadowOffset.X, ShadowOffset.Y);
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ApplySettings(string settings) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TornEdgeEffect extends on DropShadowEffect
|
/// TornEdgeEffect extends on DropShadowEffect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[TypeConverter(typeof(EffectConverter))]
|
||||||
public class TornEdgeEffect : DropShadowEffect {
|
public class TornEdgeEffect : DropShadowEffect {
|
||||||
public TornEdgeEffect() : base() {
|
public TornEdgeEffect() : base() {
|
||||||
ShadowSize = 7;
|
Reset();
|
||||||
ToothHeight = 12;
|
|
||||||
HorizontalToothRange = 20;
|
|
||||||
VerticalToothRange = 20;
|
|
||||||
Edges = new bool[] {true, true, true, true};
|
|
||||||
GenerateShadow = true;
|
|
||||||
}
|
}
|
||||||
public int ToothHeight {
|
public int ToothHeight {
|
||||||
get;
|
get;
|
||||||
|
@ -104,6 +109,15 @@ namespace Greenshot.Core {
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Reset() {
|
||||||
|
base.Reset();
|
||||||
|
ShadowSize = 7;
|
||||||
|
ToothHeight = 12;
|
||||||
|
HorizontalToothRange = 20;
|
||||||
|
VerticalToothRange = 20;
|
||||||
|
Edges = new bool[] { true, true, true, true };
|
||||||
|
GenerateShadow = true;
|
||||||
|
}
|
||||||
public override Image Apply(Image sourceImage, Matrix matrix) {
|
public override Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
Image tmpTornImage = ImageHelper.CreateTornEdge(sourceImage, ToothHeight, HorizontalToothRange, VerticalToothRange, Edges);
|
Image tmpTornImage = ImageHelper.CreateTornEdge(sourceImage, ToothHeight, HorizontalToothRange, VerticalToothRange, Edges);
|
||||||
if (GenerateShadow) {
|
if (GenerateShadow) {
|
||||||
|
@ -113,16 +127,6 @@ namespace Greenshot.Core {
|
||||||
}
|
}
|
||||||
return tmpTornImage;
|
return tmpTornImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.AppendFormat("{0}|GenerateShadow:{1}|ToothHeight:{2}|HorizontalToothRange:{3}|VerticalToothRange:{4}|Edges:{5},{6},{7},{8}", base.ToString(), GenerateShadow, ToothHeight, HorizontalToothRange, VerticalToothRange, Edges[0], Edges[1], Edges[2], Edges[3]);
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ApplySettings(string settings) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -132,6 +136,9 @@ namespace Greenshot.Core {
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.CreateGrayscale(sourceImage);
|
return ImageHelper.CreateGrayscale(sourceImage);
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
// No settings to reset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -143,6 +150,9 @@ namespace Greenshot.Core {
|
||||||
public MonochromeEffect(byte threshold) {
|
public MonochromeEffect(byte threshold) {
|
||||||
this.threshold = threshold;
|
this.threshold = threshold;
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
// TODO: Modify the threshold to have a default, which is reset here
|
||||||
|
}
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.CreateMonochrome(sourceImage, threshold);
|
return ImageHelper.CreateMonochrome(sourceImage, threshold);
|
||||||
}
|
}
|
||||||
|
@ -153,9 +163,7 @@ namespace Greenshot.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AdjustEffect : IEffect {
|
public class AdjustEffect : IEffect {
|
||||||
public AdjustEffect() : base() {
|
public AdjustEffect() : base() {
|
||||||
Contrast = 1f;
|
Reset();
|
||||||
Brightness = 1f;
|
|
||||||
Gamma = 1f;
|
|
||||||
}
|
}
|
||||||
public float Contrast {
|
public float Contrast {
|
||||||
get;
|
get;
|
||||||
|
@ -169,6 +177,11 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
Contrast = 1f;
|
||||||
|
Brightness = 1f;
|
||||||
|
Gamma = 1f;
|
||||||
|
}
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.Adjust(sourceImage, Brightness, Contrast, Gamma);
|
return ImageHelper.Adjust(sourceImage, Brightness, Contrast, Gamma);
|
||||||
}
|
}
|
||||||
|
@ -180,12 +193,15 @@ namespace Greenshot.Core {
|
||||||
public class ReduceColorsEffect : IEffect {
|
public class ReduceColorsEffect : IEffect {
|
||||||
private static ILog LOG = LogManager.GetLogger(typeof(ReduceColorsEffect));
|
private static ILog LOG = LogManager.GetLogger(typeof(ReduceColorsEffect));
|
||||||
public ReduceColorsEffect() : base() {
|
public ReduceColorsEffect() : base() {
|
||||||
Colors = 256;
|
Reset();
|
||||||
}
|
}
|
||||||
public int Colors {
|
public int Colors {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
Colors = 256;
|
||||||
|
}
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
using (WuQuantizer quantizer = new WuQuantizer((Bitmap)sourceImage)) {
|
using (WuQuantizer quantizer = new WuQuantizer((Bitmap)sourceImage)) {
|
||||||
int colorCount = quantizer.GetColorCount();
|
int colorCount = quantizer.GetColorCount();
|
||||||
|
@ -208,6 +224,9 @@ namespace Greenshot.Core {
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.CreateNegative(sourceImage);
|
return ImageHelper.CreateNegative(sourceImage);
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
// No settings to reset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -215,8 +234,7 @@ namespace Greenshot.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BorderEffect : IEffect {
|
public class BorderEffect : IEffect {
|
||||||
public BorderEffect() {
|
public BorderEffect() {
|
||||||
Width = 2;
|
Reset();
|
||||||
Color = Color.Black;
|
|
||||||
}
|
}
|
||||||
public Color Color {
|
public Color Color {
|
||||||
get;
|
get;
|
||||||
|
@ -226,6 +244,10 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
Width = 2;
|
||||||
|
Color = Color.Black;
|
||||||
|
}
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.CreateBorder(sourceImage, Width, Color, sourceImage.PixelFormat, matrix);
|
return ImageHelper.CreateBorder(sourceImage, Width, Color, sourceImage.PixelFormat, matrix);
|
||||||
}
|
}
|
||||||
|
@ -242,6 +264,9 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
// Angle doesn't have a default value
|
||||||
|
}
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
RotateFlipType flipType;
|
RotateFlipType flipType;
|
||||||
if (Angle == 90) {
|
if (Angle == 90) {
|
||||||
|
@ -280,6 +305,9 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
// values don't have a default value
|
||||||
|
}
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.ResizeImage(sourceImage, MaintainAspectRatio, Width, Height, matrix);
|
return ImageHelper.ResizeImage(sourceImage, MaintainAspectRatio, Width, Height, matrix);
|
||||||
}
|
}
|
||||||
|
@ -316,8 +344,170 @@ namespace Greenshot.Core {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
public void Reset() {
|
||||||
|
// values don't have a default value
|
||||||
|
}
|
||||||
public Image Apply(Image sourceImage, Matrix matrix) {
|
public Image Apply(Image sourceImage, Matrix matrix) {
|
||||||
return ImageHelper.ResizeCanvas(sourceImage, BackgroundColor, Left, Right, Top, Bottom, matrix);
|
return ImageHelper.ResizeCanvas(sourceImage, BackgroundColor, Left, Right, Top, Bottom, matrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EffectConverter : TypeConverter {
|
||||||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
|
||||||
|
if (sourceType == typeof(string)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return base.CanConvertFrom(context, sourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
|
||||||
|
if (destinationType == typeof(string)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (destinationType == typeof(DropShadowEffect)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (destinationType == typeof(TornEdgeEffect)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return base.CanConvertTo(context, destinationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
|
||||||
|
// to string
|
||||||
|
if (destinationType == typeof(string)) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (value.GetType() == typeof(DropShadowEffect)) {
|
||||||
|
DropShadowEffect effect = value as DropShadowEffect;
|
||||||
|
RetrieveDropShadowEffectValues(effect, sb);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
if (value.GetType() == typeof(TornEdgeEffect)) {
|
||||||
|
TornEdgeEffect effect = value as TornEdgeEffect;
|
||||||
|
RetrieveDropShadowEffectValues(effect, sb);
|
||||||
|
sb.Append("|");
|
||||||
|
RetrieveTornEdgeEffectValues(effect, sb);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// from string
|
||||||
|
if (value.GetType() == typeof(string)) {
|
||||||
|
string settings = value as string;
|
||||||
|
if (destinationType == typeof(DropShadowEffect)) {
|
||||||
|
DropShadowEffect effect = new DropShadowEffect();
|
||||||
|
ApplyDropShadowEffectValues(settings, effect);
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
if (destinationType == typeof(TornEdgeEffect)) {
|
||||||
|
TornEdgeEffect effect = new TornEdgeEffect();
|
||||||
|
ApplyDropShadowEffectValues(settings, effect);
|
||||||
|
ApplyTornEdgeEffectValues(settings, effect);
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base.ConvertTo(context, culture, value, destinationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
|
||||||
|
if (value != null && value.GetType() == typeof(string)) {
|
||||||
|
string settings = value as string;
|
||||||
|
if (settings.Contains("ToothHeight")) {
|
||||||
|
return ConvertTo(context, culture, value, typeof(TornEdgeEffect));
|
||||||
|
} else {
|
||||||
|
return ConvertTo(context, culture, value, typeof(DropShadowEffect));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base.ConvertFrom(context, culture, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyDropShadowEffectValues(string valuesString, DropShadowEffect effect) {
|
||||||
|
string[] values = valuesString.Split('|');
|
||||||
|
foreach(string nameValuePair in values) {
|
||||||
|
string[] pair = nameValuePair.Split(':');
|
||||||
|
switch (pair[0]) {
|
||||||
|
case "Darkness" :
|
||||||
|
float darkness;
|
||||||
|
if (float.TryParse(pair[1], out darkness)) {
|
||||||
|
effect.Darkness = darkness;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "ShadowSize":
|
||||||
|
int shadowSize;
|
||||||
|
if (int.TryParse(pair[1], out shadowSize)) {
|
||||||
|
effect.ShadowSize = shadowSize;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "ShadowOffset":
|
||||||
|
Point shadowOffset = new Point();
|
||||||
|
int shadowOffsetX;
|
||||||
|
int shadowOffsetY;
|
||||||
|
string[] coordinates = pair[1].Split(',');
|
||||||
|
if (int.TryParse(coordinates[0], out shadowOffsetX)) {
|
||||||
|
shadowOffset.X = shadowOffsetX;
|
||||||
|
}
|
||||||
|
if (int.TryParse(coordinates[1], out shadowOffsetY)) {
|
||||||
|
shadowOffset.Y = shadowOffsetY;
|
||||||
|
}
|
||||||
|
effect.ShadowOffset = shadowOffset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyTornEdgeEffectValues(string valuesString, TornEdgeEffect effect) {
|
||||||
|
string[] values = valuesString.Split('|');
|
||||||
|
foreach (string nameValuePair in values) {
|
||||||
|
string[] pair = nameValuePair.Split(':');
|
||||||
|
switch (pair[0]) {
|
||||||
|
case "GenerateShadow":
|
||||||
|
bool generateShadow;
|
||||||
|
if (bool.TryParse(pair[1], out generateShadow)) {
|
||||||
|
effect.GenerateShadow = generateShadow;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "ToothHeight":
|
||||||
|
int toothHeight;
|
||||||
|
if (int.TryParse(pair[1], out toothHeight)) {
|
||||||
|
effect.ToothHeight = toothHeight;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "HorizontalToothRange":
|
||||||
|
int horizontalToothRange;
|
||||||
|
if (int.TryParse(pair[1], out horizontalToothRange)) {
|
||||||
|
effect.HorizontalToothRange = horizontalToothRange;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "VerticalToothRange":
|
||||||
|
int verticalToothRange;
|
||||||
|
if (int.TryParse(pair[1], out verticalToothRange)) {
|
||||||
|
effect.VerticalToothRange = verticalToothRange;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "Edges":
|
||||||
|
string[] edges = pair[1].Split(',');
|
||||||
|
bool edge;
|
||||||
|
if (bool.TryParse(edges[0], out edge)) {
|
||||||
|
effect.Edges[0] = edge;
|
||||||
|
}
|
||||||
|
if (bool.TryParse(edges[1], out edge)) {
|
||||||
|
effect.Edges[1] = edge;
|
||||||
|
}
|
||||||
|
if (bool.TryParse(edges[2], out edge)) {
|
||||||
|
effect.Edges[2] = edge;
|
||||||
|
}
|
||||||
|
if (bool.TryParse(edges[3], out edge)) {
|
||||||
|
effect.Edges[3] = edge;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RetrieveDropShadowEffectValues(DropShadowEffect effect, StringBuilder sb) {
|
||||||
|
sb.AppendFormat("Darkness:{0:F2}|ShadowSize:{1}|ShadowOffset:{2},{3}", effect.Darkness, effect.ShadowSize, effect.ShadowOffset.X, effect.ShadowOffset.Y);
|
||||||
|
}
|
||||||
|
private void RetrieveTornEdgeEffectValues(TornEdgeEffect effect, StringBuilder sb) {
|
||||||
|
sb.AppendFormat("GenerateShadow:{0}|ToothHeight:{1}|HorizontalToothRange:{2}|VerticalToothRange:{3}|Edges:{4},{5},{6},{7}", effect.GenerateShadow, effect.ToothHeight, effect.HorizontalToothRange, effect.VerticalToothRange, effect.Edges[0], effect.Edges[1], effect.Edges[2], effect.Edges[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -305,7 +305,7 @@ namespace Greenshot.IniFile {
|
||||||
Value = defaultValueFromConfig;
|
Value = defaultValueFromConfig;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (propertyValue != null) {
|
} else if (!string.IsNullOrEmpty(propertyValue)) {
|
||||||
if (valueType.IsGenericType && valueType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) {
|
if (valueType.IsGenericType && valueType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) {
|
||||||
// We are dealing with a generic type that is nullable
|
// We are dealing with a generic type that is nullable
|
||||||
valueType = Nullable.GetUnderlyingType(valueType);
|
valueType = Nullable.GetUnderlyingType(valueType);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue