WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
AnalogAlphaToy.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using DirectOutput.Cab.Out;
7 using System.Xml.Serialization;
9 
10 namespace DirectOutput.Cab.Toys.Layer
11 {
16  {
17 
24  [XmlIgnore]
25  public LayerDictionary<AnalogAlpha> Layers { get; private set; }
26 
31  protected int GetResultingValue()
32  {
33  if (Layers.Count > 0)
34  {
35  float Value = 0;
36 
37  foreach (KeyValuePair<int, AnalogAlpha> KV in Layers)
38  {
39  int Alpha = KV.Value.Alpha;
40  if (Alpha != 0)
41  {
42  Value = AlphaMappingTable.AlphaMapping[255 - Alpha, (int)Value] + AlphaMappingTable.AlphaMapping[Alpha, KV.Value.Value];
43  }
44  }
45 
46  return (int)Value;
47  }
48  else
49  {
50  return 0;
51  }
52  }
53 
54 
55  #region Outputs
56 
57  [XmlIgnore]
58  protected IOutput Output;
59 
60 
67  public string OutputName { get; set; }
68 
69 
70  #endregion
71 
72  #region Fading curve
73  private string _FadingCurveName = "Linear";
74  [XmlIgnore]
75  protected Curve FadingCurve = null;
76 
84  public string FadingCurveName
85  {
86  get { return _FadingCurveName; }
87  set { _FadingCurveName = value; }
88  }
89 
90  private void InitFadingCurve(Cabinet Cabinet)
91  {
92  if (Cabinet.Curves.Contains(FadingCurveName))
93  {
94  FadingCurve = Cabinet.Curves[FadingCurveName];
95  }
96  else if (!FadingCurveName.IsNullOrWhiteSpace())
97  {
98  if (Enum.GetNames(typeof(Curve.CurveTypeEnum)).Contains(FadingCurveName))
99  {
101  Enum.TryParse(FadingCurveName, out T);
102  FadingCurve = new Curve(T);
103  }
104  else
105  {
106  FadingCurve = new Curve(Curve.CurveTypeEnum.Linear) { Name = FadingCurveName };
107  Cabinet.Curves.Add(FadingCurveName);
108  }
109  }
110  else
111  {
112  FadingCurve = new Curve(Curve.CurveTypeEnum.Linear);
113  }
114 
115  }
116  #endregion
117 
118 
119 
120  [XmlIgnore]
121  protected Cabinet Cabinet;
122 
123 
128  public override void Init(Cabinet Cabinet)
129  {
130  this.Cabinet = Cabinet;
131  InitOutputs(Cabinet);
132  InitFadingCurve(Cabinet);
133  }
134 
135  private void InitOutputs(Cabinet Cabinet)
136  {
137  if (Cabinet.Outputs.Contains(OutputName))
138  {
139  Output = Cabinet.Outputs[OutputName];
140  }
141  else
142  {
143  Output = null;
144  }
145  }
146 
147 
148 
149 
153  public override void UpdateOutputs()
154  {
155  if (Output != null)
156  {
157 
158  Output.Value = FadingCurve.MapValue(GetResultingValue());
159  }
160  }
161 
162 
166  public override void Finish()
167  {
168  Reset();
169  Output = null;
170  Cabinet = null;
171  base.Finish();
172  }
173 
179  public override void Reset()
180  {
181  Layers.Clear();
182  if (Output != null)
183  {
184  Output.Value = 0;
185  }
186  }
187 
191  public AnalogAlphaToy()
192  {
193  Layers = new LayerDictionary<AnalogAlpha>();
194  }
195  }
196 }
The Cabinet object describes the parts of a pinball cabinet (toys, outputcontrollers, outputs and more).
Definition: Cabinet.cs:17
CurveList Curves
List of named curve objects used to set Curves for toys.
Definition: Cabinet.cs:137
Dictionary for RGBALayer objects.
Common interface for toys supporting analog alpha layers.
bool Contains(string Name)
Checks if a INamedItem object with the specified name exists in the list.
bool Contains(IOutput Output)
Checks if the specified IOutput exists in the list.
CabinetOutputList Outputs
List of IOutput objects representing all outputs of all all output controllers in the cabinet...
Definition: Cabinet.cs:164
byte Value
Value of the output.
Definition: IOutput.cs:18
override void Reset()
Resets the toy. Clears the Layers object and turn off the output (if available). Method must be over...
AnalogAlphaToy()
Initializes a new instance of the AnalogAlphaToy class.
byte MapValue(byte CurvePosition)
Returns the value from the specified curve position.
Definition: Curve.cs:97
override void Init(Cabinet Cabinet)
Initializes the toy.
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
Definition: Cab.cs:16
void Finish()
Finishes the cabinet
Definition: Cabinet.cs:327
DirectOutput.Cab.Out is the namespace for all output controller related classes like different output...
override void Finish()
Resets the toy and releases all references
Common interface for outputs of any output controller. The Output class implements this interface and...
Definition: IOutput.cs:10
This toy handles analog values (0-255) in a layer structure including alpha value (0=completely trans...
override void UpdateOutputs()
Updates the output of the toy.
Base class for toys which need update calls to update the state of their assigned outputs...
CurveTypeEnum
Enumeration of predefined curves.
Definition: Curve.cs:20
Represents a curve which can be used to map values (e.g. adjust a brighnetss value of a led to the br...
Definition: Curve.cs:15
int GetResultingValue()
Gets the analog value which results from the analog values and alpha values in the dirctionary...
The namespace DirectOutput.General contains classes for general use.