Added shadow to rectangle drawing

This commit is contained in:
Jaex 2016-05-03 20:58:18 +03:00
parent 401f8a0c3c
commit 42fb490c4c
6 changed files with 31 additions and 17 deletions

View file

@ -55,16 +55,24 @@ public static void DrawRectangleShadow(this Graphics g, Rectangle rect, Color sh
{
int currentAlpha = (int)MathHelpers.Lerp(shadowMaxAlpha, shadowMinAlpha, (float)i / (shadowDepth - 1));
using (Pen pen = new Pen(Color.FromArgb(currentAlpha, shadowColor)))
if (currentAlpha > 0)
{
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);
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);
g.DrawRectangleProper(pen, shadowRect);
}
}
}
}
public static void DrawRoundedRectangle(this Graphics g, Pen pen, Rectangle rect, float radius)
{
g.DrawRoundedRectangle(null, pen, rect, radius);
}
public static void DrawRoundedRectangle(this Graphics g, Brush brush, Pen pen, Rectangle rect, float radius)
{
using (GraphicsPath gp = new GraphicsPath())

View file

@ -140,6 +140,10 @@ public enum FFmpegPaletteUseDither
public enum ShapeType
{
[Description("Drawing: Rectangle")]
DrawingRectangle,
[Description("Drawing: Rounded rectangle")]
DrawingRoundedRectangle,
[Description("Region: Rectangle")]
RegionRectangle,
[Description("Region: Rounded rectangle")]
@ -149,11 +153,7 @@ public enum ShapeType
[Description("Region: Triangle")]
RegionTriangle,
[Description("Region: Diamond")]
RegionDiamond,
[Description("Drawing: Rectangle")]
DrawingRectangle,
[Description("Drawing: Rounded rectangle")]
DrawingRoundedRectangle
RegionDiamond
}
public enum RegionAnnotateMode

View file

@ -112,7 +112,7 @@ public bool IsCurrentShapeTypeRegion
}
public Color BorderColor { get; set; } = Color.Red;
public int BorderSize { get; set; } = 2;
public int BorderSize { get; set; } = 1;
public Color FillColor { get; set; } = Color.Transparent;
public float RoundedRectangleRadius { get; set; } = 25;

View file

@ -35,9 +35,9 @@ namespace ShareX.ScreenCaptureLib
{
public abstract class BaseDrawingShape : BaseShape
{
public Color BorderColor { get; set; } = Color.Red;
public Color FillColor { get; set; } = Color.Transparent;
public int BorderSize { get; set; } = 2;
public Color BorderColor { get; set; }
public Color FillColor { get; set; }
public int BorderSize { get; set; }
public abstract void Draw(Graphics g);

View file

@ -27,8 +27,10 @@ You should have received a copy of the GNU General Public License
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
@ -46,11 +48,15 @@ public override void Draw(Graphics g)
}
}
if (BorderColor != Color.Transparent)
if (BorderColor != Color.Transparent && BorderSize > 0)
{
using (Pen pen = new Pen(BorderColor, BorderSize))
Rectangle rect = Rectangle.Offset(BorderSize - 1);
g.DrawRectangleShadow(rect.Offset(1), Color.FromArgb(150, 150, 150), 3, 100, 10, new Padding(1));
using (Pen pen = new Pen(BorderColor, BorderSize) { Alignment = PenAlignment.Inset })
{
g.DrawRectangleProper(pen, Rectangle);
g.DrawRectangleProper(pen, rect);
}
}
}

View file

@ -50,7 +50,7 @@ public override void Draw(Graphics g)
brush = new SolidBrush(FillColor);
}
if (BorderColor != Color.Transparent)
if (BorderColor != Color.Transparent && BorderSize > 0)
{
pen = new Pen(BorderColor, BorderSize);
}