mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-05 20:54:31 +13:00
Added rectangle & rounded rectangle drawing drop shadow support
This commit is contained in:
parent
ea5fd4cea1
commit
f28e913a11
2 changed files with 25 additions and 7 deletions
|
@ -35,6 +35,14 @@ public abstract class BaseDrawingShape : BaseShape
|
||||||
public int BorderSize { get; set; }
|
public int BorderSize { get; set; }
|
||||||
public Color FillColor { get; set; }
|
public Color FillColor { get; set; }
|
||||||
|
|
||||||
|
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 bool IsShapeVisible => IsBorderVisible || IsFillVisible;
|
||||||
|
public bool IsBorderVisible => BorderSize > 0 && BorderColor.A > 0;
|
||||||
|
public bool IsFillVisible => FillColor.A > 0;
|
||||||
|
|
||||||
public override void OnConfigLoad()
|
public override void OnConfigLoad()
|
||||||
{
|
{
|
||||||
BorderColor = AnnotationOptions.BorderColor;
|
BorderColor = AnnotationOptions.BorderColor;
|
||||||
|
|
|
@ -36,33 +36,43 @@ public class RectangleDrawingShape : BaseDrawingShape
|
||||||
public int CornerRadius { get; set; }
|
public int CornerRadius { get; set; }
|
||||||
|
|
||||||
public override void OnDraw(Graphics g)
|
public override void OnDraw(Graphics g)
|
||||||
|
{
|
||||||
|
if (Shadow && IsBorderVisible)
|
||||||
|
{
|
||||||
|
DrawRectangle(g, ShadowColor, BorderSize, Color.Transparent, Rectangle.LocationOffset(ShadowDirection), CornerRadius);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangle(g, BorderColor, BorderSize, FillColor, Rectangle, CornerRadius);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawRectangle(Graphics g, Color borderColor, int borderSize, Color fillColor, Rectangle rect, int cornerRadius)
|
||||||
{
|
{
|
||||||
Brush brush = null;
|
Brush brush = null;
|
||||||
Pen pen = null;
|
Pen pen = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (FillColor.A > 0)
|
if (IsFillVisible)
|
||||||
{
|
{
|
||||||
brush = new SolidBrush(FillColor);
|
brush = new SolidBrush(fillColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BorderSize > 0 && BorderColor.A > 0)
|
if (IsBorderVisible)
|
||||||
{
|
{
|
||||||
pen = new Pen(BorderColor, BorderSize);
|
pen = new Pen(borderColor, borderSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CornerRadius > 0)
|
if (cornerRadius > 0)
|
||||||
{
|
{
|
||||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
|
||||||
if (BorderSize.IsEvenNumber())
|
if (borderSize.IsEvenNumber())
|
||||||
{
|
{
|
||||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawRoundedRectangle(brush, pen, Rectangle, CornerRadius);
|
g.DrawRoundedRectangle(brush, pen, rect, cornerRadius);
|
||||||
|
|
||||||
g.SmoothingMode = SmoothingMode.None;
|
g.SmoothingMode = SmoothingMode.None;
|
||||||
g.PixelOffsetMode = PixelOffsetMode.Default;
|
g.PixelOffsetMode = PixelOffsetMode.Default;
|
||||||
|
|
Loading…
Reference in a new issue