2 using System.Collections.Generic;
5 using DirectOutput.Cab.Toys.Layer;
6 using DirectOutput.Cab.Color;
8 namespace DirectOutput.FX.RGBAFX
16 private const int FadingRefreshIntervalMs = 30;
30 get {
return _RetriggerBehaviour; }
31 set { _RetriggerBehaviour = value; }
45 get {
return _FadeMode; }
46 set { _FadeMode = value; }
51 private int _FadeInactiveDurationMs = 500;
59 public int FadeInactiveDurationMs
61 get {
return _FadeInactiveDurationMs; }
62 set { _FadeInactiveDurationMs = value; }
66 private int _FadeActiveDurationMs = 500;
74 public int FadeActiveDurationMs
76 get {
return _FadeActiveDurationMs; }
77 set { _FadeActiveDurationMs = value; }
82 float[] Current =
new float[4];
83 float[] Step =
new float[4];
84 float[] Target =
new float[4];
85 bool IsFading =
false;
87 private void StartFading(
bool Active)
89 Table.Pinball.Alarms.UnregisterAlarm(FadingStep);
91 RGBAColor TargetColor = (Active ? ActiveColor : InactiveColor);
93 int Duration = (Active ? FadeActiveDurationMs : FadeInactiveDurationMs);
94 int Steps = Duration / FadingRefreshIntervalMs;
108 CurrentColor = (!Active ? ActiveColor.GetRGBAColor() : InactiveColor.GetRGBAColor());
112 Current[0] = CurrentColor.
Red;
113 Current[1] = CurrentColor.
Green;
114 Current[2] = CurrentColor.
Blue;
115 Current[3] = CurrentColor.
Alpha;
117 Target[0] = TargetColor.
Red;
118 Target[1] = TargetColor.
Green;
119 Target[2] = TargetColor.
Blue;
120 Target[3] = TargetColor.
Alpha;
122 for (
int i = 0; i < 4; i++)
124 Step[i] = (Target[i] - Current[i]) / Steps;
135 private void FadingStep()
137 bool ContinueFading =
false;
138 for (
int i = 0; i < 4; i++)
142 Current[i] += Step[i];
143 if (Current[i] < Target[i] && Current[i] < 255)
145 ContinueFading =
true;
149 Current[i] = Target[i];
153 else if (Step[i] < 0)
155 Current[i] += Step[i];
156 if (Current[i] > Target[i] && Current[i] > 0)
158 ContinueFading =
true;
162 Current[i] = Target[i];
168 RGBAToy.
Layers[Layer].Set((
int)Current[0], (
int)Current[1], (
int)Current[2], (
int)Current[3]);
172 Table.Pinball.Alarms.RegisterAlarm(FadingRefreshIntervalMs, FadingStep);
194 get {
return _ActiveColor; }
195 set { _ActiveColor = value; }
209 get {
return _InactiveColor; }
210 set { _InactiveColor = value; }
215 bool LastTriggerState =
false;
221 public override void Trigger(Table.TableElementData TableElementData)
225 bool TriggerState = (TableElementData == null || TableElementData.Value != 0);
227 if (TriggerState != LastTriggerState || IsFading ==
false || RetriggerBehaviour ==
RetriggerBehaviourEnum.RestartEffect)
229 StartFading(TriggerState);
232 LastTriggerState = TriggerState;
239 public override void Finish()
243 Table.Pinball.Alarms.UnregisterAlarm(FadingStep);