DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
ColorConfig.cs
Go to the documentation of this file.
1 using System;
2 using DirectOutput.Cab.Toys.Layer;
3 using DirectOutput.Cab.Color;
4 
5 
6 namespace DirectOutput.LedControl.Loader
7 {
8 
12  public class ColorConfig
13  {
18  public RGBAColorNamed GetCabinetColor()
19  {
20  return new RGBAColorNamed(Name,(int)(Red * 5.3125), (int)(Green * 5.3125), (int)(Blue * 5.3125), (int)(Alpha * 5.3125));
21  }
22 
29  public string Name { get; set; }
30 
37  public int Red { get; set; }
44  public int Green { get; set; }
51  public int Blue { get; set; }
52 
53 
54 
55  private int _Alpha;
56 
63  public int Alpha
64  {
65  get { return _Alpha; }
66  set { _Alpha = value; }
67  }
68 
75  public void ParseLedcontrolData(string ColorConfigDataLine, bool ThrowExceptions = false)
76  {
77  //Black=5,5,5
78 
79  //Split Name and Value portion of line apart.
80  string[] NameValues = ColorConfigDataLine.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
81  if (NameValues.Length == 2)
82  {
83  string[] Values = NameValues[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
84  if (Values.Length == 3 && Values[0].IsInteger() && Values[1].IsInteger() && Values[2].IsInteger())
85  {
86  Name = NameValues[0];
87  Red = Values[0].ToInteger();
88  Green = Values[1].ToInteger();
89  Blue = Values[2].ToInteger();
90  Alpha = (Red + Green + Blue == 0 ? 0 : 48);
91  return;
92  }
93  else if (Values.Length == 4 && Values[0].IsInteger() && Values[1].IsInteger() && Values[2].IsInteger() && Values[3].IsInteger())
94  {
95  Name = NameValues[0];
96  Red = Values[0].ToInteger();
97  Green = Values[1].ToInteger();
98  Blue = Values[2].ToInteger();
99  Alpha = Values[2].ToInteger();
100  return;
101 
102  }
103  }
104  Log.Warning("Line {0} has a unknown structure or contains wrong data.".Build(ColorConfigDataLine));
105  if (ThrowExceptions)
106  {
107  throw new Exception("Line {0} has a unknown structure or contains wrong data.".Build(ColorConfigDataLine));
108  }
109  return;
110  }
111 
112 
116  public ColorConfig() { }
117 
125  public ColorConfig(string ColorConfigDataLine, bool ThrowExceptions = false)
126  {
127  ParseLedcontrolData(ColorConfigDataLine, ThrowExceptions);
128 
129  }
130  }
131 }