2 using System.Collections.Generic;
5 using DirectOutput.General.BitmapHandling;
6 using DirectOutput.General;
7 using DirectOutput.Cab.Toys.Layer;
9 namespace DirectOutput.FX.MatrixFX
11 public abstract class MatrixBitmapAnimationEffectBase<MatrixElementType> : MatrixEffectBase<MatrixElementType>
23 get {
return _AnimationStepDirection; }
24 set { _AnimationStepDirection = value; }
27 private int _AnimationStepSize = 1;
35 public int AnimationStepSize
37 get {
return _AnimationStepSize; }
38 set { _AnimationStepSize = value; }
42 private int _AnimationFrameCount = 1;
50 public int AnimationFrameCount
52 get {
return _AnimationFrameCount; }
53 set { _AnimationFrameCount = value.Limit(1,
int.MaxValue); }
66 get {
return _AnimationBehaviour; }
67 set { _AnimationBehaviour = value; }
71 private int _AnimationFrameDurationMs = 30;
79 public int AnimationFrameDurationMs
81 get {
return _AnimationFrameDurationMs; }
82 set { _AnimationFrameDurationMs = value.Limit(1,
int.MaxValue); }
87 private int _BitmapFrameNumber = 0;
95 public int BitmapFrameNumber
97 get {
return _BitmapFrameNumber; }
98 set { _BitmapFrameNumber = value; }
101 private int _BitmapTop = 0;
111 get {
return _BitmapTop; }
112 set { _BitmapTop = value.Limit(0,
int.MaxValue); }
115 private int _BitmapLeft = 0;
123 public int BitmapLeft
125 get {
return _BitmapLeft; }
126 set { _BitmapLeft = value.Limit(0,
int.MaxValue); }
129 private int _BitmapWidth = -1;
137 public int BitmapWidth
139 get {
return _BitmapWidth; }
140 set { _BitmapWidth = value.Limit(-1,
int.MaxValue); }
143 private int _BitmapHeight = -1;
151 public int BitmapHeight
153 get {
return _BitmapHeight; }
154 set { _BitmapHeight = value.Limit(-1,
int.MaxValue); }
168 get {
return _DataExtractMode; }
169 set { _DataExtractMode = value; }
184 get {
return _BitmapFilePattern; }
185 set { _BitmapFilePattern = value; }
191 private bool AnimationActive =
false;
192 private int AnimationStep = 0;
193 private int AnimationFadeValue = 0;
194 private void Animate()
198 for (
int y = 0; y < AreaHeight; y++)
200 int yd = y + AreaTop;
201 for (
int x = 0; x < AreaWidth; x++)
203 int xd = x + AreaLeft;
204 MatrixLayer[xd, yd] = GetEffectValue(AnimationFadeValue, Pixels[AnimationStep][x, y]);
211 if (AnimationStep >= Pixels.GetUpperBound(0))
224 MatrixElementType Off = GetEffectValue(0,
new PixelData());
226 for (
int y = AreaTop; y <= AreaBottom; y++)
229 for (
int x = AreaLeft; x <= AreaRight; x++)
231 MatrixLayer[x, y] = Off;
244 protected abstract MatrixElementType GetEffectValue(
int TriggerValue,
PixelData Pixel);
247 private void ControlAnimation(
int FadeValue)
252 this.AnimationFadeValue = FadeValue;
254 if (!AnimationActive)
256 AnimationActive =
true;
262 Table.Pinball.Alarms.RegisterIntervalAlarm(AnimationFrameDurationMs, Animate);
277 private void StopAnimation()
281 Table.Pinball.Alarms.UnregisterIntervalAlarm(Animate);
283 AnimationActive =
false;
296 public override void Trigger(Table.TableElementData TableElementData)
300 int FadeValue = TableElementData.Value;
301 if (FadeMode ==
FadeModeEnum.OnOff) FadeValue = (FadeValue < 1 ? 0 : 255);
302 ControlAnimation(FadeValue);
309 private bool InitOK =
false;
317 public override void Init(Table.Table Table)
324 if (BitmapFilePattern.IsValid)
327 string Filename = BitmapFilePattern.GetFirstMatchingFile().FullName;
328 if (!Filename.IsNullOrWhiteSpace())
333 BM = Table.Bitmaps[Filename];
337 Log.
Exception(
"MatrixBitmapAnimationEffectBase {0} cant initialize. Could not load file {1}.".Build(Name, Filename), E);
341 if (BM.
Frames.ContainsKey(BitmapFrameNumber))
343 int StepCount = AnimationFrameCount;
344 switch (AnimationStepDirection)
347 if ((BitmapFrameNumber + (StepCount * AnimationStepSize)) > BM.
Frames.Count)
349 StepCount = (BM.
Frames.Count - BitmapFrameNumber) / AnimationStepSize;
354 for (
int s = 0; s < StepCount; s++)
356 Pixels[s] = BM.
Frames[BitmapFrameNumber + s].GetClip(AreaWidth, AreaHeight, BitmapLeft, BitmapTop, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
368 for (
int s = 0; s < StepCount; s++)
370 Pixels[s] = BM.
Frames[BitmapFrameNumber].GetClip(AreaWidth, AreaHeight, BitmapLeft+s*AnimationStepSize, BitmapTop, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
378 for (
int s = 0; s < StepCount; s++)
380 Pixels[s] = BM.
Frames[BitmapFrameNumber].GetClip(AreaWidth, AreaHeight, BitmapLeft, BitmapTop + s * AnimationStepSize, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
387 for (
int s = 0; s < StepCount; s++)
389 Pixels[s] = BM.
Frames[BitmapFrameNumber].GetClip(AreaWidth, AreaHeight, BitmapLeft, BitmapTop, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
399 Log.
Warning(
"MatrixBitmapAnimationEffectBase {0} cant initialize. Frame {1} does not exist in source image {2}.".Build(Name, BitmapFrameNumber, Filename));
405 Log.
Warning(
"MatrixBitmapAnimationEffectBase {0} cant initialize. No file matches the BitmapFilePattern {1} is invalid".Build(Name, BitmapFilePattern.ToString()));
410 Log.
Warning(
"MatrixBitmapAnimationEffectBase {0} cant initialize. The BitmapFilePattern {1} is invalid".Build(Name, BitmapFilePattern.ToString()));
414 InitOK = (Pixels != null && MatrixLayer != null);
421 public override void Finish()