2 using System.Collections.Generic;
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()
284 Table.Pinball.Alarms.UnregisterIntervalAlarm(Animate);
288 AnimationActive =
false;
301 public override void Trigger(Table.TableElementData TableElementData)
305 int FadeValue = TableElementData.Value;
306 if (FadeMode ==
FadeModeEnum.OnOff) FadeValue = (FadeValue < 1 ? 0 : 255);
307 ControlAnimation(FadeValue);
314 private bool InitOK =
false;
322 public override void Init(Table.Table Table)
329 if (BitmapFilePattern.IsValid)
332 string Filename = BitmapFilePattern.GetFirstMatchingFile(Table.Pinball.GlobalConfig.GetReplaceValuesDictionary()).FullName;
333 if (!Filename.IsNullOrWhiteSpace())
338 BM = Table.Bitmaps[Filename];
342 Log.
Exception(
"MatrixBitmapAnimationEffectBase {0} cant initialize. Could not load file {1}.".Build(Name, Filename), E);
346 if (BM.
Frames.ContainsKey(BitmapFrameNumber))
348 int StepCount = AnimationFrameCount;
349 switch (AnimationStepDirection)
352 if ((BitmapFrameNumber + (StepCount * AnimationStepSize)) > BM.
Frames.Count)
354 StepCount = (BM.
Frames.Count - BitmapFrameNumber) / AnimationStepSize;
360 for (
int s = 0; s < StepCount; s++)
363 Pixels[s] = BM.
Frames[BitmapFrameNumber + s].GetClip(AreaWidth, AreaHeight, BitmapLeft, BitmapTop, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
375 for (
int s = 0; s < StepCount; s++)
377 Pixels[s] = BM.
Frames[BitmapFrameNumber].GetClip(AreaWidth, AreaHeight, BitmapLeft+s*AnimationStepSize, BitmapTop, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
385 for (
int s = 0; s < StepCount; s++)
387 Pixels[s] = BM.
Frames[BitmapFrameNumber].GetClip(AreaWidth, AreaHeight, BitmapLeft, BitmapTop + s * AnimationStepSize, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
394 for (
int s = 0; s < StepCount; s++)
396 Pixels[s] = BM.
Frames[BitmapFrameNumber].GetClip(AreaWidth, AreaHeight, BitmapLeft, BitmapTop, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
401 Log.
Debug(
"BitmapAnimationEffectBase. Grabbed image clips: W: {0}, H:{1}, BML: {2}, BMT: {3}, BMW: {4}, BMH: {5}, Steps: {6}".Build(
new object[] { AreaWidth, AreaHeight, BitmapLeft, BitmapTop, BitmapWidth, BitmapHeight, StepCount }));
407 Log.
Warning(
"MatrixBitmapAnimationEffectBase {0} cant initialize. Frame {1} does not exist in source image {2}.".Build(Name, BitmapFrameNumber, Filename));
413 Log.
Warning(
"MatrixBitmapAnimationEffectBase {0} cant initialize. No file matches the BitmapFilePattern {1} is invalid".Build(Name, BitmapFilePattern.ToString()));
418 Log.
Warning(
"MatrixBitmapAnimationEffectBase {0} cant initialize. The BitmapFilePattern {1} is invalid".Build(Name, BitmapFilePattern.ToString()));
422 InitOK = (Pixels != null && MatrixLayer != null);
The namespace DirectOutput.Cab.Toys contains all toy related classes.
Struct holding the data for a single pixel in a bitmap.
Base class for effects targeting a matrix of toys (e.g. addressable ledstrip)
static void Warning(string Message)
Writes a warning message to the log.
A simple logger used to record important events and exceptions.
override void Finish()
Finishes the effect and releases object references
static void Debug(string Message="")
Writes the specified debug message to the log file.
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
FadeModeEnum
Defines the fading behaviour.
FastBitmapDataExtractModeEnum
The enum defines how the pixels are extracted from the source image.
MatrixAnimationStepDirectionEnum
Dictionary< int, FastBitmap > Frames
AnimationBehaviourEnum
This enum describes the different supported behaviours for animations.
Namespace for objects dealing with layers
override void Trigger(Table.TableElementData TableElementData)
Triggers the effect with the given data.
The namespace DirectOutput.General contains classes for general use.
A file pattern class used to lookup files matching a specified pattern.
override void Init(Table.Table Table)
Initializes the effect. Resolves object references, extracts source image data.
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.