mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added shadow to region (annotate) rectangle drawing
This commit is contained in:
parent
e219decb77
commit
4d09b4cff5
3 changed files with 33 additions and 8 deletions
|
@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
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())
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue