Added rectangle & rounded rectangle drawing drop shadow support

This commit is contained in:
Jaex 2016-11-29 19:24:41 +03:00
parent ea5fd4cea1
commit f28e913a11
2 changed files with 25 additions and 7 deletions

View file

@ -35,6 +35,14 @@ public abstract class BaseDrawingShape : BaseShape
public int BorderSize { 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()
{
BorderColor = AnnotationOptions.BorderColor;

View file

@ -36,33 +36,43 @@ public class RectangleDrawingShape : BaseDrawingShape
public int CornerRadius { get; set; }
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;
Pen pen = null;
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;
if (BorderSize.IsEvenNumber())
if (borderSize.IsEvenNumber())
{
g.PixelOffsetMode = PixelOffsetMode.Half;
}
}
g.DrawRoundedRectangle(brush, pen, Rectangle, CornerRadius);
g.DrawRoundedRectangle(brush, pen, rect, cornerRadius);
g.SmoothingMode = SmoothingMode.None;
g.PixelOffsetMode = PixelOffsetMode.Default;