mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-01 04:30:49 +12:00
Added RotateFlip option to "Image" image effect
This commit is contained in:
parent
6ae0a67bf9
commit
2abdf70177
|
@ -413,23 +413,36 @@ public static T[] GetValueFields<T>()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example: "TopLeft" becomes "Top left"
|
// Example: "TopLeft" becomes "Top left"
|
||||||
public static string GetProperName(string name)
|
// Example2: "Rotate180" becomes "Rotate 180"
|
||||||
|
public static string GetProperName(string name, bool keepCase = false)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
bool number = false;
|
||||||
|
|
||||||
for (int i = 0; i < name.Length; i++)
|
for (int i = 0; i < name.Length; i++)
|
||||||
{
|
{
|
||||||
char c = name[i];
|
char c = name[i];
|
||||||
|
|
||||||
if (i > 0 && char.IsUpper(c))
|
if (i > 0 && (char.IsUpper(c) || (!number && char.IsNumber(c))))
|
||||||
{
|
{
|
||||||
sb.Append(' ');
|
sb.Append(' ');
|
||||||
sb.Append(char.ToLowerInvariant(c));
|
|
||||||
|
if (keepCase)
|
||||||
|
{
|
||||||
|
sb.Append(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append(char.ToLowerInvariant(c));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb.Append(c);
|
sb.Append(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
number = char.IsNumber(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
|
|
|
@ -300,6 +300,7 @@
|
||||||
<Compile Include="Settings\TypeNameSerializationBinder.cs" />
|
<Compile Include="Settings\TypeNameSerializationBinder.cs" />
|
||||||
<Compile Include="UITypeEditors\EnumDescriptionConverter.cs" />
|
<Compile Include="UITypeEditors\EnumDescriptionConverter.cs" />
|
||||||
<Compile Include="UITypeEditors\DirectoryNameEditor.cs" />
|
<Compile Include="UITypeEditors\DirectoryNameEditor.cs" />
|
||||||
|
<Compile Include="UITypeEditors\EnumProperNameKeepCaseConverter.cs" />
|
||||||
<Compile Include="UITypeEditors\EnumProperNameConverter.cs" />
|
<Compile Include="UITypeEditors\EnumProperNameConverter.cs" />
|
||||||
<Compile Include="UITypeEditors\GradientEditor.cs" />
|
<Compile Include="UITypeEditors\GradientEditor.cs" />
|
||||||
<Compile Include="UITypeEditors\JsonFileNameEditor.cs" />
|
<Compile Include="UITypeEditors\JsonFileNameEditor.cs" />
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#region License Information (GPL v3)
|
||||||
|
|
||||||
|
/*
|
||||||
|
ShareX - A program that allows you to take screenshots and share any file type
|
||||||
|
Copyright (c) 2007-2020 ShareX Team
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ShareX.HelpersLib
|
||||||
|
{
|
||||||
|
public class EnumProperNameKeepCaseConverter : EnumConverter
|
||||||
|
{
|
||||||
|
private Type enumType;
|
||||||
|
|
||||||
|
public EnumProperNameKeepCaseConverter(Type type) : base(type)
|
||||||
|
{
|
||||||
|
enumType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
|
||||||
|
{
|
||||||
|
return destType == typeof(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
|
||||||
|
{
|
||||||
|
return Helpers.GetProperName(value.ToString(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType)
|
||||||
|
{
|
||||||
|
return srcType == typeof(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||||
|
{
|
||||||
|
foreach (Enum e in Enum.GetValues(enumType).OfType<Enum>())
|
||||||
|
{
|
||||||
|
if (Helpers.GetProperName(e.ToString(), true) == (string)value)
|
||||||
|
{
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Enum.Parse(enumType, (string)value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,6 +52,9 @@ public class DrawImage : ImageEffect
|
||||||
[DefaultValue(typeof(Size), "0, 0")]
|
[DefaultValue(typeof(Size), "0, 0")]
|
||||||
public Size Size { get; set; }
|
public Size Size { get; set; }
|
||||||
|
|
||||||
|
[DefaultValue(ImageRotateFlipType.None), TypeConverter(typeof(EnumProperNameKeepCaseConverter))]
|
||||||
|
public ImageRotateFlipType RotateFlip { get; set; }
|
||||||
|
|
||||||
[DefaultValue(false)]
|
[DefaultValue(false)]
|
||||||
public bool Tile { get; set; }
|
public bool Tile { get; set; }
|
||||||
|
|
||||||
|
@ -99,6 +102,11 @@ public override Bitmap Apply(Bitmap bmp)
|
||||||
{
|
{
|
||||||
if (bmpWatermark != null)
|
if (bmpWatermark != null)
|
||||||
{
|
{
|
||||||
|
if (RotateFlip != ImageRotateFlipType.None)
|
||||||
|
{
|
||||||
|
bmpWatermark.RotateFlip((RotateFlipType)RotateFlip);
|
||||||
|
}
|
||||||
|
|
||||||
Size imageSize;
|
Size imageSize;
|
||||||
|
|
||||||
if (SizeMode == DrawImageSizeMode.AbsoluteSize)
|
if (SizeMode == DrawImageSizeMode.AbsoluteSize)
|
||||||
|
|
|
@ -50,4 +50,16 @@ public enum DrawImageSizeMode // Localized
|
||||||
PercentageOfWatermark,
|
PercentageOfWatermark,
|
||||||
PercentageOfCanvas
|
PercentageOfCanvas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ImageRotateFlipType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Rotate90 = 1,
|
||||||
|
Rotate180 = 2,
|
||||||
|
Rotate270 = 3,
|
||||||
|
FlipX = 4,
|
||||||
|
Rotate90FlipX = 5,
|
||||||
|
FlipY = 6,
|
||||||
|
Rotate90FlipY = 7
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue