CPF/CPF.ReoGrid/Rendering/BorderPainter.cs
2024-06-24 10:15:59 +08:00

100 lines
2.7 KiB
C#

using System;
using CPF.Drawing;
using CPF.ReoGrid.Drawing;
namespace CPF.ReoGrid.Rendering
{
internal sealed class BorderPainter : IDisposable
{
public static BorderPainter Instance
{
get
{
bool flag = BorderPainter.instance == null;
if (flag)
{
BorderPainter.instance = new BorderPainter();
}
return BorderPainter.instance;
}
}
private BorderPainter()
{
CPFPen cpfpen = new CPFPen(Color.Black, 1f);
this.pens[1] = cpfpen;
cpfpen = new CPFPen(Color.Black, 1f);
cpfpen.DashStyle = DashStyles.Dash;
this.pens[3] = cpfpen;
cpfpen = new CPFPen(Color.Black, 1f);
cpfpen.DashStyle = DashStyles.Dot;
this.pens[2] = cpfpen;
cpfpen = new CPFPen(Color.Black, 3f);
this.pens[4] = cpfpen;
cpfpen = new CPFPen(Color.Black, 1f);
this.pens[5] = cpfpen;
cpfpen = new CPFPen(Color.Black, 1f);
cpfpen.DashStyle = DashStyles.DashDot;
this.pens[6] = cpfpen;
cpfpen = new CPFPen(Color.Black, 1f);
cpfpen.DashStyle = DashStyles.DashDotDot;
this.pens[7] = cpfpen;
cpfpen = new CPFPen(Color.Black, 2f);
cpfpen.DashStyle = DashStyles.DashDot;
this.pens[8] = cpfpen;
cpfpen = new CPFPen(Color.Black, 2f);
cpfpen.DashStyle = DashStyles.DashDotDot;
this.pens[9] = cpfpen;
cpfpen = new CPFPen(Color.Black, 2f);
cpfpen.DashStyle = DashStyles.Dot;
this.pens[11] = cpfpen;
cpfpen = new CPFPen(Color.Black, 2f);
cpfpen.DashStyle = DashStyles.Dash;
this.pens[10] = cpfpen;
cpfpen = new CPFPen(Color.Black, 2f);
this.pens[12] = cpfpen;
cpfpen = new CPFPen(Color.Black, 3f);
this.pens[13] = cpfpen;
}
public void DrawLine(DrawingContext g, float x, float y, float x2, float y2, RangeBorderStyle style)
{
this.DrawLine(g, x, y, x2, y2, style.Style, style.Color, null);
}
public void DrawLine(DrawingContext g, float x, float y, float x2, float y2, BorderLineStyle style, Color color, CPFPen bgPen = null)
{
bool flag = style == BorderLineStyle.None;
if (!flag)
{
CPFPen cpfpen = this.pens[(int)style];
Stroke stroke = cpfpen.Stroke;
Brush brush = cpfpen.Brush;
Point point = new Point(ref x, ref y);
Point point2 = new Point(ref x2, ref y2);
g.DrawLine(stroke, brush, point, point2);
bool flag2 = style == BorderLineStyle.DoubleLine && bgPen != null;
if (flag2)
{
lock (bgPen)
{
stroke = bgPen.Stroke;
Brush brush2 = bgPen.Brush;
point = new Point(ref x, ref y);
point2 = new Point(ref x2, ref y2);
g.DrawLine(stroke, brush2, point, point2);
}
}
}
}
public void Dispose()
{
}
private static BorderPainter instance;
private readonly CPFPen[] pens = new CPFPen[14];
}
}