WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
MatrixEffectBase.cs
Go to the documentation of this file.
2 using System.Xml.Serialization;
3 using DirectOutput.Cab.Toys;
4 
5 namespace DirectOutput.FX.MatrixFX
6 {
10  public abstract class MatrixEffectBase<MatrixElementType> : EffectBase, DirectOutput.FX.MatrixFX.IMatrixEffect
11  {
12  #region Config properties
13 
14  private string _ToyName;
15 
22  public string ToyName
23  {
24  get { return _ToyName; }
25  set
26  {
27  if (_ToyName != value)
28  {
29  _ToyName = value;
30  Matrix = null;
31  MatrixLayer = null;
32  }
33  }
34  }
35 
36 
44  protected IMatrixToy<MatrixElementType> Matrix { get; private set; }
45 
46 
47 
48 
49  private float _Width = 100;
50 
57  public float Width
58  {
59  get { return _Width; }
60  set { _Width = value.Limit(0, 100); }
61  }
62 
63  private float _Height = 100;
64 
71  public float Height
72  {
73  get { return _Height; }
74  set { _Height = value.Limit(0, 100); }
75  }
76 
77  private float _Left = 0;
78 
85  public float Left
86  {
87  get { return _Left; }
88  set { _Left = value.Limit(0, 100); }
89  }
90 
91  private float _Top = 0;
92 
99  public float Top
100  {
101  get { return _Top; }
102  set { _Top = value.Limit(0, 100); }
103  }
104 
105 
106 
107 
108  private int _LayerNr = 0;
109 
116  public int LayerNr
117  {
118  get { return _LayerNr; }
119  set { _LayerNr = value; }
120  }
121 
122 
123  private FadeModeEnum _FadeMode = FadeModeEnum.Fade;
124 
131  public FadeModeEnum FadeMode
132  {
133  get { return _FadeMode; }
134  set { _FadeMode = value; }
135  }
136 
137 
138  #endregion
139 
143  [XmlIgnoreAttribute]
144  protected int AreaLeft = 0;
148  [XmlIgnoreAttribute]
149  protected int AreaTop = 0;
153  [XmlIgnoreAttribute]
154  protected int AreaRight = 0;
158  [XmlIgnoreAttribute]
159  protected int AreaBottom = 0;
160 
167  [XmlIgnoreAttribute]
168  protected int AreaWidth
169  {
170  get { return (AreaRight - AreaLeft) + 1; }
171  }
172 
179  [XmlIgnoreAttribute]
180  protected int AreaHeight
181  {
182  get { return (AreaBottom - AreaTop) + 1; }
183  }
184 
191  [XmlIgnoreAttribute]
192  protected Table.Table Table { get; private set; }
193 
194 
195 
196 
204  [XmlIgnoreAttribute]
205  protected MatrixElementType[,] MatrixLayer;
206 
207 
213  public override void Init(Table.Table Table)
214  {
215  if (!ToyName.IsNullOrWhiteSpace() && Table.Pinball.Cabinet.Toys.Contains(ToyName) && Table.Pinball.Cabinet.Toys[ToyName] is IMatrixToy<MatrixElementType>)
216  {
217  Matrix = (IMatrixToy<MatrixElementType>)Table.Pinball.Cabinet.Toys[ToyName];
218  MatrixLayer = Matrix.GetLayer(LayerNr);
219 
220  AreaLeft = (int)((float)Matrix.Width / 100 * Left).Floor().Limit(0, Matrix.Width - 1);
221  AreaTop = (int)((float)Matrix.Height / 100 * Top).Floor().Limit(0, Matrix.Height - 1);
222  AreaRight = (int)((float)Matrix.Width / 100 * (Left + Width).Limit(0, 100)).Floor().Limit(0, Matrix.Width - 1);
223  AreaBottom = (int)((float)Matrix.Height / 100 * (Top + Height).Limit(0, 100)).Floor().Limit(0, Matrix.Height - 1);
224 
225  int Tmp;
226  if (AreaLeft > AreaRight) { Tmp = AreaRight; AreaRight = AreaLeft; AreaLeft = AreaRight; }
227  if (AreaTop > AreaBottom) { Tmp = AreaBottom; AreaBottom = AreaTop; AreaTop = Tmp; }
228 
229  Log.Debug("MatrixBase for {12}. Calculated area size: AreaDef(L:{0}, T:{1}, W:{2}, H:{3}), Matrix(W:{4}, H:{5}), ResultArea(Left: {6}, Top:{7}, Right:{8}, Bottom:{9}, Width:{10}, Height:{11})".Build(new object[] { Left, Top, Width, Height, Matrix.Height, Matrix.Width, AreaLeft, AreaTop, AreaRight, AreaBottom, AreaWidth, AreaHeight, this.GetType().Name }));
230 
231  }
232 
233  this.Table = Table;
234  }
235 
236 
237 
241  public override void Finish()
242  {
243  MatrixLayer = null;
244  Matrix = null;
245  Table = null;
246  base.Finish();
247  }
248  }
249 }
The namespace DirectOutput.Cab.Toys contains all toy related classes.
Base class for effects targeting a matrix of toys (e.g. addressable ledstrip)
Interface for toys having a matrix of elements (e.g. ledstrips)
Definition: IMatrixToy.cs:12
MatrixElementType[,] MatrixLayer
The layer array of a IRGBAMatrix object as specified by the ToyName and the LayerNr. This reference is initialized by the Init method.
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
override void Finish()
Finishes the effect and releases object references
override void Init(Table.Table Table)
Initializes the effect. Resolves object references.
Abstract base class for IEffect objects. This class inherits NamedItemBase and implements IEffect...
Definition: EffectBase.cs:15
static void Debug(string Message="")
Writes the specified debug message to the log file.
Definition: Log.cs:216
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
Definition: Cab.cs:16
FadeModeEnum
Defines the fading behaviour.
Definition: FadeModeEnum.cs:11
Namespace for objects dealing with layers