DirectOuput Framework R2
DirectOutput framework R2 for virtual pinball cabinets
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
MatrixEffectBase.cs
Go to the documentation of this file.
1 using DirectOutput.Cab.Toys.Layer;
2 using System.Xml.Serialization;
3 using DirectOutput.Cab.Toys;
4 
5 namespace DirectOutput.FX.MatrixFX
6 {
10  public abstract class MatrixEffectBase<MatrixElementType> : EffectBase
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 
230  }
231 
232  this.Table = Table;
233  }
234 
235 
236 
240  public override void Finish()
241  {
242  MatrixLayer = null;
243  Matrix = null;
244  Table = null;
245  base.Finish();
246  }
247  }
248 }