|
@@ -8,6 +8,7 @@ using System.Linq;
|
|
|
using System.Numerics;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using FontStyle = System.Drawing.FontStyle;
|
|
|
using Vector2 = System.Numerics.Vector2;
|
|
|
using Vector3 = System.Numerics.Vector3;
|
|
|
using Vector4 = System.Numerics.Vector4;
|
|
@@ -159,11 +160,83 @@ internal class TransformData
|
|
|
|
|
|
internal class DrawData : TransformData
|
|
|
{
|
|
|
- public Graphics Graphics { get; set; }
|
|
|
+ public IGraphics Graphics { get; set; }
|
|
|
|
|
|
protected override void UpdateTransform()
|
|
|
{
|
|
|
base.UpdateTransform();
|
|
|
- Graphics.Transform = ProjectMatrix(Transform);
|
|
|
+ Graphics.SetTransform(ProjectMatrix(Transform));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+public interface IGraphics
|
|
|
+{
|
|
|
+ void SetTransform(Matrix transform);
|
|
|
+
|
|
|
+ void DrawLine(Color color, float thickness, params PointF[] points);
|
|
|
+
|
|
|
+ void FillPolygon(Color color, params PointF[] points);
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Set the current font to be the default font at the given <paramref name="fontSize"/>.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="fontSize">Size of the new font.</param>
|
|
|
+ void SetFont(float fontSize, FontStyle fontStyle = FontStyle.Regular);
|
|
|
+
|
|
|
+ void SetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular);
|
|
|
+
|
|
|
+ void DrawText(string text, Color color, PointF position);
|
|
|
+}
|
|
|
+
|
|
|
+public class GdiGraphics : IGraphics
|
|
|
+{
|
|
|
+ public Graphics Graphics { get; set; }
|
|
|
+
|
|
|
+ private Font Font { get; set; }
|
|
|
+
|
|
|
+ public GdiGraphics(Graphics graphics)
|
|
|
+ {
|
|
|
+ Graphics = graphics;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DrawLine(Color color, float thickness, params PointF[] points)
|
|
|
+ {
|
|
|
+ if(points.Length == 2)
|
|
|
+ {
|
|
|
+ Graphics.DrawLine(new Pen(color, thickness), points[0], points[1]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Graphics.DrawLines(new Pen(color, thickness), points);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DrawText(string text, Color color, PointF position)
|
|
|
+ {
|
|
|
+ Graphics.DrawString(text, Font, new SolidBrush(color), position, StringFormat.GenericTypographic);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void FillPolygon(Color color, params PointF[] points)
|
|
|
+ {
|
|
|
+ Graphics.FillPolygon(new SolidBrush(color), points);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetFont(string fontName, float fontSize, FontStyle fontStyle)
|
|
|
+ {
|
|
|
+ var fontFamily = new FontFamily(fontName);
|
|
|
+ var font = new Font(fontFamily, fontSize, fontStyle);
|
|
|
+ Font = font;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetFont(float fontSize, FontStyle fontStyle)
|
|
|
+ {
|
|
|
+ var fontFamily = SystemFonts.DefaultFont.FontFamily;
|
|
|
+ var font = new Font(fontFamily, fontSize, fontStyle);
|
|
|
+ Font = font;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetTransform(Matrix transform)
|
|
|
+ {
|
|
|
+ Graphics.Transform = transform;
|
|
|
}
|
|
|
}
|