mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Added gradient support to text shadow
This commit is contained in:
parent
fc4087049c
commit
736968bc4d
1 changed files with 38 additions and 8 deletions
|
@ -92,11 +92,17 @@ public Font Font
|
|||
[DefaultValue(false)]
|
||||
public bool DrawTextShadow { get; set; }
|
||||
|
||||
[DefaultValue(typeof(Point), "0, 5")]
|
||||
public Point TextShadowOffset { get; set; }
|
||||
|
||||
[DefaultValue(typeof(Color), "125, 0, 0, 0"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
|
||||
public Color TextShadowColor { get; set; }
|
||||
|
||||
[DefaultValue(typeof(Point), "0, 5")]
|
||||
public Point TextShadowOffset { get; set; }
|
||||
[DefaultValue(false)]
|
||||
public bool TextShadowUseGradient { get; set; }
|
||||
|
||||
[Editor(typeof(GradientEditor), typeof(UITypeEditor))]
|
||||
public GradientInfo TextShadowGradient { get; set; }
|
||||
|
||||
public DrawTextEx()
|
||||
{
|
||||
|
@ -104,9 +110,10 @@ public DrawTextEx()
|
|||
|
||||
TextGradient = new GradientInfo();
|
||||
AddDefaultGradient(TextGradient);
|
||||
|
||||
TextOutlineGradient = new GradientInfo();
|
||||
AddDefaultGradient(TextOutlineGradient);
|
||||
TextShadowGradient = new GradientInfo();
|
||||
AddDefaultGradient(TextShadowGradient);
|
||||
}
|
||||
|
||||
private void AddDefaultGradient(GradientInfo gradientInfo)
|
||||
|
@ -183,7 +190,7 @@ public override Bitmap Apply(Bitmap bmp)
|
|||
}
|
||||
|
||||
// Draw text shadow
|
||||
if (DrawTextShadow && TextShadowColor.A > 0)
|
||||
if (DrawTextShadow && ((!TextShadowUseGradient && TextShadowColor.A > 0) || (TextShadowUseGradient && TextShadowGradient.IsVisible)))
|
||||
{
|
||||
using (Matrix matrix = new Matrix())
|
||||
{
|
||||
|
@ -191,12 +198,34 @@ public override Bitmap Apply(Bitmap bmp)
|
|||
gp.Transform(matrix);
|
||||
|
||||
if (DrawTextOutline && TextOutlineSize > 0)
|
||||
{
|
||||
if (TextShadowUseGradient)
|
||||
{
|
||||
using (LinearGradientBrush textShadowBrush = TextShadowGradient.GetGradientBrush(
|
||||
Rectangle.Round(textRectangle).Offset(TextOutlineSize + 1).LocationOffset(TextShadowOffset)))
|
||||
using (Pen textShadowPen = new Pen(textShadowBrush, TextOutlineSize) { LineJoin = LineJoin.Round })
|
||||
{
|
||||
g.DrawPath(textShadowPen, gp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (Pen textShadowPen = new Pen(TextShadowColor, TextOutlineSize) { LineJoin = LineJoin.Round })
|
||||
{
|
||||
g.DrawPath(textShadowPen, gp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TextShadowUseGradient)
|
||||
{
|
||||
using (Brush textShadowBrush = TextShadowGradient.GetGradientBrush(
|
||||
Rectangle.Round(textRectangle).Offset(1).LocationOffset(TextShadowOffset)))
|
||||
{
|
||||
g.FillPath(textShadowBrush, gp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (Brush textShadowBrush = new SolidBrush(TextShadowColor))
|
||||
|
@ -204,6 +233,7 @@ public override Bitmap Apply(Bitmap bmp)
|
|||
g.FillPath(textShadowBrush, gp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix.Reset();
|
||||
matrix.Translate(-TextShadowOffset.X, -TextShadowOffset.Y);
|
||||
|
|
Loading…
Reference in a new issue