mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 04:06:05 +13:00
Added text shadow
This commit is contained in:
parent
678ef0b1b0
commit
37c3b7aa18
7 changed files with 18 additions and 13 deletions
|
@ -37,7 +37,7 @@ public abstract class BaseDrawingShape : BaseShape
|
|||
|
||||
public bool Shadow { get; set; } = true;
|
||||
public Color ShadowColor { get; set; } = Color.FromArgb(125, 0, 0, 0);
|
||||
public Point ShadowDirection { get; set; } = new Point(0, 1);
|
||||
public Point ShadowOffset { get; set; } = new Point(0, 1);
|
||||
|
||||
public bool IsShapeVisible => IsBorderVisible || IsFillVisible;
|
||||
public bool IsBorderVisible => BorderSize > 0 && BorderColor.A > 0;
|
||||
|
|
|
@ -37,7 +37,7 @@ public override void OnDraw(Graphics g)
|
|||
{
|
||||
if (Shadow && IsBorderVisible)
|
||||
{
|
||||
DrawEllipse(g, ShadowColor, BorderSize, Color.Transparent, Rectangle.LocationOffset(ShadowDirection));
|
||||
DrawEllipse(g, ShadowColor, BorderSize, Color.Transparent, Rectangle.LocationOffset(ShadowOffset));
|
||||
}
|
||||
|
||||
DrawEllipse(g, BorderColor, BorderSize, FillColor, Rectangle);
|
||||
|
|
|
@ -111,7 +111,7 @@ public override void OnDraw(Graphics g)
|
|||
{
|
||||
if (Shadow)
|
||||
{
|
||||
DrawFreehand(g, ShadowColor, BorderSize, positions.Select(x => x.Add(ShadowDirection)).ToArray());
|
||||
DrawFreehand(g, ShadowColor, BorderSize, positions.Select(x => x.Add(ShadowOffset)).ToArray());
|
||||
}
|
||||
|
||||
DrawFreehand(g, BorderColor, BorderSize, positions.ToArray());
|
||||
|
|
|
@ -58,7 +58,7 @@ public override void OnDraw(Graphics g)
|
|||
{
|
||||
if (Shadow)
|
||||
{
|
||||
DrawLine(g, ShadowColor, BorderSize, StartPosition.Add(ShadowDirection), EndPosition.Add(ShadowDirection), CenterPosition.Add(ShadowDirection));
|
||||
DrawLine(g, ShadowColor, BorderSize, StartPosition.Add(ShadowOffset), EndPosition.Add(ShadowOffset), CenterPosition.Add(ShadowOffset));
|
||||
}
|
||||
|
||||
DrawLine(g, BorderColor, BorderSize, StartPosition, EndPosition, CenterPosition);
|
||||
|
|
|
@ -39,7 +39,7 @@ public override void OnDraw(Graphics g)
|
|||
{
|
||||
if (Shadow && IsBorderVisible)
|
||||
{
|
||||
DrawRectangle(g, ShadowColor, BorderSize, Color.Transparent, Rectangle.LocationOffset(ShadowDirection), CornerRadius);
|
||||
DrawRectangle(g, ShadowColor, BorderSize, Color.Transparent, Rectangle.LocationOffset(ShadowOffset), CornerRadius);
|
||||
}
|
||||
|
||||
DrawRectangle(g, BorderColor, BorderSize, FillColor, Rectangle, CornerRadius);
|
||||
|
|
|
@ -164,7 +164,7 @@ public override void OnDraw(Graphics g)
|
|||
gpTail.Dispose();
|
||||
}
|
||||
|
||||
DrawText(g);
|
||||
DrawText(g, Text, TextOptions.Color, TextOptions, Rectangle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,19 +58,24 @@ public override void OnDraw(Graphics g)
|
|||
{
|
||||
base.OnDraw(g);
|
||||
|
||||
DrawText(g);
|
||||
if (Shadow)
|
||||
{
|
||||
DrawText(g, Text, ShadowColor, TextOptions, Rectangle.LocationOffset(ShadowOffset));
|
||||
}
|
||||
|
||||
DrawText(g, Text, TextOptions.Color, TextOptions, Rectangle);
|
||||
}
|
||||
|
||||
protected void DrawText(Graphics g)
|
||||
protected void DrawText(Graphics g, string text, Color textColor, TextDrawingOptions options, Rectangle rect)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Text) && Rectangle.Width > 10 && Rectangle.Height > 10)
|
||||
if (!string.IsNullOrEmpty(text) && rect.Width > 10 && rect.Height > 10)
|
||||
{
|
||||
using (Font font = new Font(TextOptions.Font, TextOptions.Size, TextOptions.Style))
|
||||
using (Brush textBrush = new SolidBrush(TextOptions.Color))
|
||||
using (StringFormat sf = new StringFormat { Alignment = TextOptions.AlignmentHorizontal, LineAlignment = TextOptions.AlignmentVertical })
|
||||
using (Font font = new Font(options.Font, options.Size, options.Style))
|
||||
using (Brush textBrush = new SolidBrush(textColor))
|
||||
using (StringFormat sf = new StringFormat { Alignment = options.AlignmentHorizontal, LineAlignment = options.AlignmentVertical })
|
||||
{
|
||||
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||
g.DrawString(Text, font, textBrush, Rectangle, sf);
|
||||
g.DrawString(text, font, textBrush, rect, sf);
|
||||
g.TextRenderingHint = TextRenderingHint.SystemDefault;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue