-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScriptCore.cs
More file actions
130 lines (111 loc) · 3.76 KB
/
Copy pathScriptCore.cs
File metadata and controls
130 lines (111 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
using SkiaSharp;
using Ephemera.NBagOfTricks;
namespace NProcessing.Script
{
public partial class ScriptCore
{
#region Fields - internal
/// <summary>My logger.</summary>
readonly Logger _logger = LogManager.CreateLogger("Script");
/// <summary>Script randomizer.</summary>
Random _rand = new();
/// <summary>Loop option.</summary>
internal bool _loop = true;
/// <summary>Redraw option.</summary>
internal bool _redraw = false;
/// <summary>Current working object to draw on.</summary>
#nullable disable
internal SKCanvas _canvas;
#endregion
#region Fields - graphics/processing
/// <summary>Current font to draw with.</summary>
readonly SKPaint _textPaint = new()
{
TextSize = 12,
Color = SKColors.Black,
Typeface = SKTypeface.FromFamilyName("Arial"),
TextAlign = SKTextAlign.Left,
IsAntialias = true
};
/// <summary>Current pen to draw with.</summary>
readonly SKPaint _pen = new()
{
Color = SKColors.Black,
Style = SKPaintStyle.Stroke,
IsStroke = true,
StrokeWidth = 1,
FilterQuality = SKFilterQuality.High,
IsAntialias = true
};
/// <summary>Current brush to draw with.</summary>
readonly SKPaint _fill = new()
{
Color = SKColors.Transparent,
Style = SKPaintStyle.Fill,
IsStroke = false,
FilterQuality = SKFilterQuality.High,
IsAntialias = true
};
/// <summary>Current drawing points.</summary>
readonly List<SKPoint> _vertexes = [];
/// <summary>General purpose stack</summary>
readonly Stack<SKMatrix> _matrixStack = [];
/// <summary>Background color.</summary>
SKColor _bgColor = SKColors.LightGray;
/// <summary>Smoothing option.</summary>
bool _smooth = true;
#endregion
#region Properties - accessible by host and script
/// <summary>Main -> Script</summary>
public double RealTime { get; set; } = 0.0;
/// <summary>Main -> Script -> Main</summary>
public int FrameRate { get; set; } = 0;
#endregion
#region Lifecycle
/// <summary>
/// Constructor.
/// </summary>
public ScriptCore()
{
ResetVars();
}
/// <summary>
/// Ugly way to deal with static vars in color class.
/// </summary>
public void ResetVars()
{
Script.color.ResetMode();
}
#endregion
#region Private functions
/// <summary>Handle unimplemented script elements that we can safely ignore but do tell the user.</summary>
/// <param name="name"></param>
/// <param name="desc"></param>
void NotImpl(string name, string desc = "")
{
_logger.Warn($"{name} not implemented. {desc}");
}
/// <summary>Bounds check a color definition./// </summary>
/// <param name="r"></param>
/// <param name="g"></param>
/// <param name="b"></param>
/// <param name="a"></param>
/// <returns></returns>
SKColor SafeColor(double r, double g, double b, double a)
{
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
a = constrain(a, 0, 255);
return new SKColor((byte)r, (byte)g, (byte)b, (byte)a);
}
#endregion
}
}