mirror of https://github.com/ShareX/ShareX.git
Code refactoring
This commit is contained in:
parent
59e7450b62
commit
019c9a7dae
|
@ -260,24 +260,24 @@ namespace ShareX.HelpersLib
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap ApplyCutOutEffect(Bitmap bmp, AnchorStyles effectEdge, CutOutEffectType effectType, int effectSize, Color cutOutBackgroundColor)
|
private static Bitmap ApplyCutOutEffect(Bitmap bmp, AnchorStyles effectEdge, CutOutEffectType effectType, int effectSize, Color backgroundColor)
|
||||||
{
|
{
|
||||||
switch (effectType)
|
switch (effectType)
|
||||||
{
|
{
|
||||||
case CutOutEffectType.None:
|
case CutOutEffectType.None:
|
||||||
return bmp;
|
return bmp;
|
||||||
case CutOutEffectType.ZigZag:
|
case CutOutEffectType.ZigZag:
|
||||||
return TornEdges(bmp, effectSize, effectSize, effectEdge, false, false, cutOutBackgroundColor);
|
return TornEdges(bmp, effectSize, effectSize, effectEdge, false, false, backgroundColor);
|
||||||
case CutOutEffectType.TornEdge:
|
case CutOutEffectType.TornEdge:
|
||||||
return TornEdges(bmp, effectSize, effectSize * 2, effectEdge, false, true, cutOutBackgroundColor);
|
return TornEdges(bmp, effectSize, effectSize * 2, effectEdge, false, true, backgroundColor);
|
||||||
case CutOutEffectType.Wave:
|
case CutOutEffectType.Wave:
|
||||||
return WavyEdges(bmp, effectSize, effectSize * 5, effectEdge, cutOutBackgroundColor);
|
return WavyEdges(bmp, effectSize, effectSize * 5, effectEdge, backgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap CutOutBitmapMiddle(Bitmap bmp, Orientation orientation, int start, int size, CutOutEffectType effectType, int effectSize, Color cutOutBackgroundColor)
|
public static Bitmap CutOutBitmapMiddle(Bitmap bmp, Orientation orientation, int start, int size, CutOutEffectType effectType, int effectSize, Color backgroundColor)
|
||||||
{
|
{
|
||||||
if (bmp != null && size > 0)
|
if (bmp != null && size > 0)
|
||||||
{
|
{
|
||||||
|
@ -290,7 +290,7 @@ namespace ShareX.HelpersLib
|
||||||
: new Rectangle(0, 0, bmp.Width, Math.Min(start, bmp.Height));
|
: new Rectangle(0, 0, bmp.Width, Math.Min(start, bmp.Height));
|
||||||
firstPart = CropBitmap(bmp, r);
|
firstPart = CropBitmap(bmp, r);
|
||||||
AnchorStyles effectEdge = orientation == Orientation.Horizontal ? AnchorStyles.Right : AnchorStyles.Bottom;
|
AnchorStyles effectEdge = orientation == Orientation.Horizontal ? AnchorStyles.Right : AnchorStyles.Bottom;
|
||||||
firstPart = ApplyCutOutEffect(firstPart, effectEdge, effectType, effectSize, cutOutBackgroundColor);
|
firstPart = ApplyCutOutEffect(firstPart, effectEdge, effectType, effectSize, backgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cutDimension = orientation == Orientation.Horizontal ? bmp.Width : bmp.Height;
|
int cutDimension = orientation == Orientation.Horizontal ? bmp.Width : bmp.Height;
|
||||||
|
@ -302,7 +302,7 @@ namespace ShareX.HelpersLib
|
||||||
: new Rectangle(0, end, bmp.Width, bmp.Height - end);
|
: new Rectangle(0, end, bmp.Width, bmp.Height - end);
|
||||||
secondPart = CropBitmap(bmp, r);
|
secondPart = CropBitmap(bmp, r);
|
||||||
AnchorStyles effectEdge = orientation == Orientation.Horizontal ? AnchorStyles.Left : AnchorStyles.Top;
|
AnchorStyles effectEdge = orientation == Orientation.Horizontal ? AnchorStyles.Left : AnchorStyles.Top;
|
||||||
secondPart = ApplyCutOutEffect(secondPart, effectEdge, effectType, effectSize, cutOutBackgroundColor);
|
secondPart = ApplyCutOutEffect(secondPart, effectEdge, effectType, effectSize, backgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstPart != null && secondPart != null)
|
if (firstPart != null && secondPart != null)
|
||||||
|
@ -1844,7 +1844,12 @@ namespace ShareX.HelpersLib
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap WavyEdges(Bitmap bmp, int waveDepth, int waveRange, AnchorStyles sides, Color cutOutBackgroundColor)
|
public static Bitmap WavyEdges(Bitmap bmp, int waveDepth, int waveRange, AnchorStyles sides)
|
||||||
|
{
|
||||||
|
return WavyEdges(bmp, waveDepth, waveRange, sides, Color.Transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Bitmap WavyEdges(Bitmap bmp, int waveDepth, int waveRange, AnchorStyles sides, Color backgroundColor)
|
||||||
{
|
{
|
||||||
if (waveDepth < 1 || waveRange < 1 || sides == AnchorStyles.None)
|
if (waveDepth < 1 || waveRange < 1 || sides == AnchorStyles.None)
|
||||||
{
|
{
|
||||||
|
@ -1928,22 +1933,31 @@ namespace ShareX.HelpersLib
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bmpResult = bmp.CreateEmptyBitmap();
|
Bitmap bmpResult = bmp.CreateEmptyBitmap();
|
||||||
|
|
||||||
using (bmp)
|
using (bmp)
|
||||||
using (Graphics g = Graphics.FromImage(bmpResult))
|
using (Graphics g = Graphics.FromImage(bmpResult))
|
||||||
using (TextureBrush brush = new TextureBrush(bmp))
|
using (TextureBrush brush = new TextureBrush(bmp))
|
||||||
{
|
{
|
||||||
|
if (backgroundColor.A > 0)
|
||||||
|
{
|
||||||
|
g.Clear(backgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
g.SetHighQuality();
|
g.SetHighQuality();
|
||||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||||
if (cutOutBackgroundColor.A > 0)
|
|
||||||
{
|
|
||||||
g.Clear(cutOutBackgroundColor);
|
|
||||||
}
|
|
||||||
g.FillPolygon(brush, points.ToArray());
|
g.FillPolygon(brush, points.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
return bmpResult;
|
return bmpResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges, bool random, Color cutOutBackgroundColor)
|
public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges, bool random)
|
||||||
|
{
|
||||||
|
return TornEdges(bmp, tornDepth, tornRange, sides, curvedEdges, random, Color.Transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges, bool random, Color backgroundColor)
|
||||||
{
|
{
|
||||||
if (tornDepth < 1 || tornRange < 1 || sides == AnchorStyles.None)
|
if (tornDepth < 1 || tornRange < 1 || sides == AnchorStyles.None)
|
||||||
{
|
{
|
||||||
|
@ -2030,12 +2044,13 @@ namespace ShareX.HelpersLib
|
||||||
using (Graphics g = Graphics.FromImage(bmpResult))
|
using (Graphics g = Graphics.FromImage(bmpResult))
|
||||||
using (TextureBrush brush = new TextureBrush(bmp))
|
using (TextureBrush brush = new TextureBrush(bmp))
|
||||||
{
|
{
|
||||||
|
if (backgroundColor.A > 0)
|
||||||
|
{
|
||||||
|
g.Clear(backgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
g.SetHighQuality();
|
g.SetHighQuality();
|
||||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||||
if (cutOutBackgroundColor.A > 0)
|
|
||||||
{
|
|
||||||
g.Clear(cutOutBackgroundColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
Point[] fillPoints = points.Distinct().ToArray();
|
Point[] fillPoints = points.Distinct().ToArray();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Design;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.ImageEffectsLib
|
namespace ShareX.ImageEffectsLib
|
||||||
|
@ -46,9 +45,6 @@ namespace ShareX.ImageEffectsLib
|
||||||
[DefaultValue(true)]
|
[DefaultValue(true)]
|
||||||
public bool CurvedEdges { get; set; }
|
public bool CurvedEdges { get; set; }
|
||||||
|
|
||||||
[DefaultValue(typeof(Color), "Transparent"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
|
|
||||||
public Color CutOutBackgroundColor { get; set; }
|
|
||||||
|
|
||||||
public TornEdge()
|
public TornEdge()
|
||||||
{
|
{
|
||||||
this.ApplyDefaultPropertyValues();
|
this.ApplyDefaultPropertyValues();
|
||||||
|
@ -56,7 +52,7 @@ namespace ShareX.ImageEffectsLib
|
||||||
|
|
||||||
public override Bitmap Apply(Bitmap bmp)
|
public override Bitmap Apply(Bitmap bmp)
|
||||||
{
|
{
|
||||||
return ImageHelpers.TornEdges(bmp, Depth, Range, Sides, CurvedEdges, true, CutOutBackgroundColor);
|
return ImageHelpers.TornEdges(bmp, Depth, Range, Sides, CurvedEdges, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetSummary()
|
protected override string GetSummary()
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Design;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.ImageEffectsLib
|
namespace ShareX.ImageEffectsLib
|
||||||
|
@ -48,12 +47,9 @@ namespace ShareX.ImageEffectsLib
|
||||||
this.ApplyDefaultPropertyValues();
|
this.ApplyDefaultPropertyValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
[DefaultValue(typeof(Color), "Transparent"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
|
|
||||||
public Color CutOutBackgroundColor { get; set; }
|
|
||||||
|
|
||||||
public override Bitmap Apply(Bitmap bmp)
|
public override Bitmap Apply(Bitmap bmp)
|
||||||
{
|
{
|
||||||
return ImageHelpers.WavyEdges(bmp, Depth, Range, Sides, CutOutBackgroundColor);
|
return ImageHelpers.WavyEdges(bmp, Depth, Range, Sides);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetSummary()
|
protected override string GetSummary()
|
||||||
|
|
|
@ -324,7 +324,7 @@ namespace ShareX.ScreenCaptureLib.Properties {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Cut out background color.
|
/// Looks up a localized string similar to Cut out background color....
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string CutOutBackgroundColor {
|
internal static string CutOutBackgroundColor {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -831,6 +831,6 @@ Would you like to save the changes before closing the image editor?</value>
|
||||||
<value>..\Resources\control-record-green.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
<value>..\Resources\control-record-green.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="CutOutBackgroundColor" xml:space="preserve">
|
<data name="CutOutBackgroundColor" xml:space="preserve">
|
||||||
<value>Cut out background color</value>
|
<value>Cut out background color...</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue