From 37c3b7aa186a2e40b81961b85ba582adb31ca6bb Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 29 Nov 2016 21:48:19 +0300 Subject: [PATCH] Added text shadow --- .../Shapes/Drawing/BaseDrawingShape.cs | 2 +- .../Shapes/Drawing/EllipseDrawingShape.cs | 2 +- .../Shapes/Drawing/FreehandDrawingShape.cs | 2 +- .../Shapes/Drawing/LineDrawingShape.cs | 2 +- .../Shapes/Drawing/RectangleDrawingShape.cs | 2 +- .../Drawing/SpeechBalloonDrawingShape.cs | 2 +- .../Shapes/Drawing/TextDrawingShape.cs | 19 ++++++++++++------- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs index 3cdf0f9a8..8c1b486d6 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs @@ -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; diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/EllipseDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/EllipseDrawingShape.cs index c33145d68..90267af7e 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/EllipseDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/EllipseDrawingShape.cs @@ -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); diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs index bd363f8c0..1483be9e4 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs @@ -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()); diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs index 66592d76f..961298e0c 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs @@ -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); diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/RectangleDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/RectangleDrawingShape.cs index 9c20f8eb1..5b525e99a 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/RectangleDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/RectangleDrawingShape.cs @@ -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); diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/SpeechBalloonDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/SpeechBalloonDrawingShape.cs index 296b59e08..9e4381957 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/SpeechBalloonDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/SpeechBalloonDrawingShape.cs @@ -164,7 +164,7 @@ public override void OnDraw(Graphics g) gpTail.Dispose(); } - DrawText(g); + DrawText(g, Text, TextOptions.Color, TextOptions, Rectangle); } } diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs index 3866f75ac..321b402b6 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs @@ -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; } }