Removed DrawFinal from BaseDrawing, renamed Draw to OnDraw

This commit is contained in:
Jaex 2016-05-21 15:26:49 +03:00
parent ea9f3f2312
commit 1233a7e29c
13 changed files with 47 additions and 62 deletions

View file

@ -208,13 +208,13 @@ protected override void Draw(Graphics g)
// Draw effect shapes // Draw effect shapes
foreach (BaseEffectShape effectShape in ShapeManager.EffectShapes) foreach (BaseEffectShape effectShape in ShapeManager.EffectShapes)
{ {
effectShape.Draw(g); effectShape.OnDraw(g);
} }
// Draw drawing shapes // Draw drawing shapes
foreach (BaseDrawingShape drawingShape in ShapeManager.DrawingShapes) foreach (BaseDrawingShape drawingShape in ShapeManager.DrawingShapes)
{ {
drawingShape.Draw(g); drawingShape.OnDraw(g);
} }
// Draw animated rectangle on hover area // Draw animated rectangle on hover area

View file

@ -32,15 +32,27 @@
namespace ShareX.ScreenCaptureLib namespace ShareX.ScreenCaptureLib
{ {
public class ArrowDrawingShape : LineDrawingShape public class ArrowDrawingShape : BaseDrawingShape
{ {
public override ShapeType ShapeType { get; } = ShapeType.DrawingArrow; public override ShapeType ShapeType { get; } = ShapeType.DrawingArrow;
public override NodeType NodeType { get; } = NodeType.Line;
public override Pen CreatePen() public override void OnDraw(Graphics g)
{ {
Pen pen = base.CreatePen(); if (BorderSize > 0 && BorderColor.A > 0)
pen.CustomEndCap = new AdjustableArrowCap(4, 6); {
return pen; g.SmoothingMode = SmoothingMode.HighQuality;
using (Pen pen = new Pen(BorderColor, BorderSize))
using (AdjustableArrowCap arrowCap = new AdjustableArrowCap(4, 6))
{
pen.CustomEndCap = arrowCap;
g.DrawLine(pen, StartPosition, EndPosition);
}
g.SmoothingMode = SmoothingMode.None;
}
} }
} }
} }

View file

@ -53,21 +53,6 @@ public override void ApplyShapeConfig()
AnnotationOptions.FillColor = FillColor; AnnotationOptions.FillColor = FillColor;
} }
public virtual void Draw(Graphics g) public abstract void OnDraw(Graphics g);
{
using (Pen borderPen = new Pen(Color.Black))
using (Pen borderDotPen = new Pen(Color.White))
{
borderDotPen.DashPattern = new float[] { 2, 2 };
g.DrawRectangleProper(borderPen, Rectangle);
g.DrawRectangleProper(borderDotPen, Rectangle);
}
}
public virtual void DrawFinal(Graphics g, Bitmap bmp)
{
Draw(g);
}
} }
} }

View file

@ -38,7 +38,7 @@ public class EllipseDrawingShape : BaseDrawingShape
{ {
public override ShapeType ShapeType { get; } = ShapeType.DrawingEllipse; public override ShapeType ShapeType { get; } = ShapeType.DrawingEllipse;
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{ {
g.SmoothingMode = SmoothingMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality;

View file

@ -37,13 +37,13 @@ public class LineDrawingShape : BaseDrawingShape
public override ShapeType ShapeType { get; } = ShapeType.DrawingLine; public override ShapeType ShapeType { get; } = ShapeType.DrawingLine;
public override NodeType NodeType { get; } = NodeType.Line; public override NodeType NodeType { get; } = NodeType.Line;
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{ {
if (BorderSize > 0 && BorderColor.A > 0) if (BorderSize > 0 && BorderColor.A > 0)
{ {
g.SmoothingMode = SmoothingMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality;
using (Pen pen = CreatePen()) using (Pen pen = new Pen(BorderColor, BorderSize))
{ {
g.DrawLine(pen, StartPosition, EndPosition); g.DrawLine(pen, StartPosition, EndPosition);
} }
@ -51,10 +51,5 @@ public override void Draw(Graphics g)
g.SmoothingMode = SmoothingMode.None; g.SmoothingMode = SmoothingMode.None;
} }
} }
public virtual Pen CreatePen()
{
return new Pen(BorderColor, BorderSize);
}
} }
} }

View file

@ -38,7 +38,7 @@ public class RectangleDrawingShape : BaseDrawingShape
{ {
public override ShapeType ShapeType { get; } = ShapeType.DrawingRectangle; public override ShapeType ShapeType { get; } = ShapeType.DrawingRectangle;
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{ {
if (FillColor.A > 0) if (FillColor.A > 0)
{ {

View file

@ -51,7 +51,7 @@ public override void ApplyShapeConfig()
AnnotationOptions.RoundedRectangleRadius = (int)Radius; AnnotationOptions.RoundedRectangleRadius = (int)Radius;
} }
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{ {
Brush brush = null; Brush brush = null;
Pen pen = null; Pen pen = null;

View file

@ -58,14 +58,7 @@ public override void ApplyShapeConfig()
AnnotationOptions.TextFillColor = FillColor; AnnotationOptions.TextFillColor = FillColor;
} }
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{
base.Draw(g);
DrawFinal(g, null);
}
public override void DrawFinal(Graphics g, Bitmap bmp)
{ {
if (FillColor.A > 0) if (FillColor.A > 0)
{ {
@ -96,6 +89,16 @@ public override void DrawFinal(Graphics g, Bitmap bmp)
} }
} }
public override void OnShapeCreated()
{
UpdateText();
}
public override void OnShapeDoubleClicked()
{
UpdateText();
}
private void UpdateText() private void UpdateText()
{ {
Manager.PauseForm(); Manager.PauseForm();
@ -109,15 +112,5 @@ private void UpdateText()
Manager.ResumeForm(); Manager.ResumeForm();
} }
public override void OnShapeCreated()
{
UpdateText();
}
public override void OnShapeDoubleClicked()
{
UpdateText();
}
} }
} }

View file

@ -33,11 +33,11 @@ namespace ShareX.ScreenCaptureLib
{ {
public abstract class BaseEffectShape : BaseShape public abstract class BaseEffectShape : BaseShape
{ {
public abstract void Draw(Graphics g); public abstract void OnDraw(Graphics g);
public virtual void DrawFinal(Graphics g, Bitmap bmp) public virtual void OnDrawFinal(Graphics g, Bitmap bmp)
{ {
Draw(g); OnDraw(g);
} }
} }
} }

View file

@ -50,7 +50,7 @@ public override void ApplyShapeConfig()
AnnotationOptions.BlurRadius = BlurRadius; AnnotationOptions.BlurRadius = BlurRadius;
} }
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{ {
if (BlurRadius > 1) if (BlurRadius > 1)
{ {
@ -77,7 +77,7 @@ public override void Draw(Graphics g)
} }
} }
public override void DrawFinal(Graphics g, Bitmap bmp) public override void OnDrawFinal(Graphics g, Bitmap bmp)
{ {
if (BlurRadius > 1) if (BlurRadius > 1)
{ {

View file

@ -50,7 +50,7 @@ public override void ApplyShapeConfig()
AnnotationOptions.HighlightColor = HighlightColor; AnnotationOptions.HighlightColor = HighlightColor;
} }
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{ {
using (Brush brush = new SolidBrush(Color.FromArgb(100, HighlightColor))) using (Brush brush = new SolidBrush(Color.FromArgb(100, HighlightColor)))
{ {
@ -74,7 +74,7 @@ public override void Draw(Graphics g)
} }
} }
public override void DrawFinal(Graphics g, Bitmap bmp) public override void OnDrawFinal(Graphics g, Bitmap bmp)
{ {
using (Bitmap croppedImage = ImageHelpers.CropBitmap(bmp, Rectangle)) using (Bitmap croppedImage = ImageHelpers.CropBitmap(bmp, Rectangle))
{ {

View file

@ -50,7 +50,7 @@ public override void ApplyShapeConfig()
AnnotationOptions.PixelateSize = PixelSize; AnnotationOptions.PixelateSize = PixelSize;
} }
public override void Draw(Graphics g) public override void OnDraw(Graphics g)
{ {
if (PixelSize > 1) if (PixelSize > 1)
{ {
@ -77,7 +77,7 @@ public override void Draw(Graphics g)
} }
} }
public override void DrawFinal(Graphics g, Bitmap bmp) public override void OnDrawFinal(Graphics g, Bitmap bmp)
{ {
if (PixelSize > 1) if (PixelSize > 1)
{ {

View file

@ -1159,7 +1159,7 @@ public Image RenderOutputImage(Image img)
{ {
if (shape != null) if (shape != null)
{ {
shape.DrawFinal(g, bmp); shape.OnDrawFinal(g, bmp);
} }
} }
@ -1167,7 +1167,7 @@ public Image RenderOutputImage(Image img)
{ {
if (shape != null) if (shape != null)
{ {
shape.DrawFinal(g, bmp); shape.OnDraw(g);
} }
} }
} }