From 4d09b4cff522c920f6a6d8d095b0c44c58a806fb Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 4 Dec 2015 16:12:30 +0200 Subject: [PATCH] Added shadow to region (annotate) rectangle drawing --- .../Extensions/GraphicsExtensions.cs | 17 +++++++++++++++++ .../Forms/RectangleAnnotate.cs | 17 +++++++++++------ .../RectangleAnnotateOptions.cs | 7 +++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/ShareX.HelpersLib/Extensions/GraphicsExtensions.cs b/ShareX.HelpersLib/Extensions/GraphicsExtensions.cs index 85b4e5dc4..cdca73f17 100644 --- a/ShareX.HelpersLib/Extensions/GraphicsExtensions.cs +++ b/ShareX.HelpersLib/Extensions/GraphicsExtensions.cs @@ -25,6 +25,7 @@ using System.Drawing; using System.Drawing.Drawing2D; +using System.Windows.Forms; namespace ShareX.HelpersLib { @@ -48,6 +49,22 @@ public static void DrawRectangleProper(this Graphics g, Pen pen, int x, int y, i DrawRectangleProper(g, pen, new Rectangle(x, y, width, height)); } + public static void DrawRectangleShadow(this Graphics g, Rectangle rect, Color shadowColor, int shadowDepth, int shadowMaxAlpha, int shadowMinAlpha, Padding shadowDirection) + { + for (int i = 0; i < shadowDepth; i++) + { + int currentAlpha = (int)MathHelpers.Lerp(shadowMaxAlpha, shadowMinAlpha, (float)i / (shadowDepth - 1)); + + using (Pen pen = new Pen(Color.FromArgb(currentAlpha, shadowColor))) + { + Rectangle shadowRect = new Rectangle(rect.X + -shadowDirection.Left * i, rect.Y + -shadowDirection.Top * i, + rect.Width + (shadowDirection.Left + shadowDirection.Right) * i, rect.Height + (shadowDirection.Top + shadowDirection.Bottom) * i); + + g.DrawRectangleProper(pen, shadowRect); + } + } + } + public static void DrawRoundedRectangle(this Graphics g, Brush brush, Pen pen, Rectangle rect, float radius) { using (GraphicsPath gp = new GraphicsPath()) diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleAnnotate.cs b/ShareX.ScreenCaptureLib/Forms/RectangleAnnotate.cs index f9f21da0d..b5891f223 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleAnnotate.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleAnnotate.cs @@ -349,15 +349,13 @@ protected override void OnPaint(PaintEventArgs e) Graphics g = e.Graphics; g.InterpolationMode = InterpolationMode.NearestNeighbor; - g.SmoothingMode = SmoothingMode.HighQuality; + g.SmoothingMode = SmoothingMode.HighSpeed; g.CompositingMode = CompositingMode.SourceCopy; g.DrawImage(backgroundImage, ScreenRectangle0Based); g.CompositingMode = CompositingMode.SourceOver; if (Mode == RegionAnnotateMode.Rectangle) { - g.SmoothingMode = SmoothingMode.HighSpeed; - if (isMouseDown) { DrawRectangle(g); @@ -366,12 +364,12 @@ protected override void OnPaint(PaintEventArgs e) { DrawRectangleMarker(g); } - - g.SmoothingMode = SmoothingMode.HighQuality; } else if (Mode == RegionAnnotateMode.Pen) { + g.SmoothingMode = SmoothingMode.HighQuality; DrawDot(g); + g.SmoothingMode = SmoothingMode.HighSpeed; } if (Options.ShowTips) @@ -491,9 +489,16 @@ private void DrawLine(Graphics g) private void DrawRectangle(Graphics g) { + Rectangle rect = SelectionRectangle0Based.Offset(Options.DrawingRectangleBorderSize - 1); + + if (Options.DrawingRectangleShadow) + { + g.DrawRectangleShadow(rect.Offset(1), Color.DarkGray, 3, 128, 20, new Padding(1)); + } + using (Pen pen = new Pen(Options.DrawingPenColor, Options.DrawingRectangleBorderSize) { Alignment = PenAlignment.Inset }) { - g.DrawRectangleProper(pen, SelectionRectangle0Based.Offset(Options.DrawingRectangleBorderSize - 1)); + g.DrawRectangleProper(pen, rect); } } diff --git a/ShareX.ScreenCaptureLib/RectangleAnnotateOptions.cs b/ShareX.ScreenCaptureLib/RectangleAnnotateOptions.cs index fb112cf52..8e676ca02 100644 --- a/ShareX.ScreenCaptureLib/RectangleAnnotateOptions.cs +++ b/ShareX.ScreenCaptureLib/RectangleAnnotateOptions.cs @@ -37,12 +37,12 @@ public class RectangleAnnotateOptions [DefaultValue(true), Description("Show hotkey tips.")] public bool ShowTips { get; set; } - [DefaultValue(typeof(Color), "0, 230, 0"), Description("Color of pen and rectangle border.")] + [DefaultValue(typeof(Color), "255, 0, 0"), Description("Color of pen and rectangle border.")] public Color DrawingPenColor { get; set; } private int drawingPenSize; - [DefaultValue(7), Description("Size of pen.")] + [DefaultValue(5), Description("Size of pen.")] public int DrawingPenSize { get @@ -70,6 +70,9 @@ public int DrawingRectangleBorderSize } } + [DefaultValue(true), Description("Draw shadow around rectangle.")] + public bool DrawingRectangleShadow { get; set; } + public RectangleAnnotateOptions() { this.ApplyDefaultPropertyValues();