Added freehand shadow

This commit is contained in:
Jaex 2016-11-29 20:02:01 +03:00
parent efe88bde57
commit 5e14b35eb7

View file

@ -27,6 +27,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq;
namespace ShareX.ScreenCaptureLib namespace ShareX.ScreenCaptureLib
{ {
@ -34,29 +35,29 @@ public class FreehandDrawingShape : BaseDrawingShape
{ {
public override ShapeType ShapeType { get; } = ShapeType.DrawingFreehand; public override ShapeType ShapeType { get; } = ShapeType.DrawingFreehand;
public override bool IsValidShape => points.Count > 0; public override bool IsValidShape => positions.Count > 0;
public Point LastPosition public Point LastPosition
{ {
get get
{ {
if (points.Count > 0) if (positions.Count > 0)
{ {
return points[points.Count - 1]; return positions[positions.Count - 1];
} }
return Point.Empty; return Point.Empty;
} }
set set
{ {
if (points.Count > 0) if (positions.Count > 0)
{ {
points[points.Count - 1] = value; positions[positions.Count - 1] = value;
} }
} }
} }
private List<Point> points = new List<Point>(); private List<Point> positions = new List<Point>();
private bool isPolygonMode; private bool isPolygonMode;
public override bool Intersects(Point position) public override bool Intersects(Point position)
@ -80,16 +81,16 @@ public override void OnUpdate()
{ {
Point pos = InputManager.MousePosition0Based; Point pos = InputManager.MousePosition0Based;
if (points.Count == 0 || (!Manager.IsProportionalResizing && LastPosition != pos)) if (positions.Count == 0 || (!Manager.IsProportionalResizing && LastPosition != pos))
{ {
points.Add(pos); positions.Add(pos);
} }
if (Manager.IsProportionalResizing) if (Manager.IsProportionalResizing)
{ {
if (!isPolygonMode) if (!isPolygonMode)
{ {
points.Add(pos); positions.Add(pos);
} }
LastPosition = pos; LastPosition = pos;
@ -97,7 +98,7 @@ public override void OnUpdate()
isPolygonMode = Manager.IsProportionalResizing; isPolygonMode = Manager.IsProportionalResizing;
Rectangle = points.CreateRectangle(); Rectangle = positions.CreateRectangle();
} }
} }
else if (Manager.IsMoving) else if (Manager.IsMoving)
@ -108,21 +109,31 @@ public override void OnUpdate()
public override void OnDraw(Graphics g) public override void OnDraw(Graphics g)
{ {
if (points.Count > 0 && BorderSize > 0 && BorderColor.A > 0) if (Shadow)
{
DrawFreehand(g, ShadowColor, BorderSize, positions.Select(x => x.Add(ShadowDirection)).ToArray());
}
DrawFreehand(g, BorderColor, BorderSize, positions.ToArray());
}
private void DrawFreehand(Graphics g, Color borderColor, int borderSize, Point[] points)
{
if (points.Length > 0 && borderSize > 0 && borderColor.A > 0)
{ {
g.SmoothingMode = SmoothingMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality;
if (points.Count == 1) if (points.Length == 1)
{ {
using (Brush brush = new SolidBrush(BorderColor)) using (Brush brush = new SolidBrush(borderColor))
{ {
Rectangle rect = new Rectangle((int)(points[0].X - BorderSize / 2f), (int)(points[0].Y - BorderSize / 2f), BorderSize, BorderSize); Rectangle rect = new Rectangle((int)(points[0].X - borderSize / 2f), (int)(points[0].Y - borderSize / 2f), borderSize, borderSize);
g.FillEllipse(brush, rect); g.FillEllipse(brush, rect);
} }
} }
else else
{ {
using (Pen pen = new Pen(BorderColor, BorderSize) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round }) using (Pen pen = new Pen(borderColor, borderSize) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round })
{ {
g.DrawLines(pen, points.ToArray()); g.DrawLines(pen, points.ToArray());
} }
@ -134,9 +145,9 @@ public override void OnDraw(Graphics g)
public override void Move(int x, int y) public override void Move(int x, int y)
{ {
for (int i = 0; i < points.Count; i++) for (int i = 0; i < positions.Count; i++)
{ {
points[i] = points[i].Add(x, y); positions[i] = positions[i].Add(x, y);
} }
Rectangle = Rectangle.LocationOffset(x, y); Rectangle = Rectangle.LocationOffset(x, y);