WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ColorConfig.cs
Go to the documentation of this file.
1 using System;
4 
5 
6 namespace DirectOutput.LedControl.Loader
7 {
8 
12  public class ColorConfig
13  {
19  {
20  return new RGBAColorNamed(Name,Red, Green,Blue,Alpha);
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 = (int)(Values[0].ToInteger().Limit(0, 48) * 5.3125);
88  Green = (int)(Values[1].ToInteger().Limit(0, 48) * 5.3125);
89  Blue = (int)(Values[2].ToInteger().Limit(0, 48) * 5.3125);
90  Alpha = (Red + Green + Blue == 0 ? 0 : 255);
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 = (int)(Values[0].ToInteger().Limit(0, 48)* 5.3125);
97  Green = (int)(Values[1].ToInteger().Limit(0, 48)* 5.3125);
98  Blue = (int)(Values[2].ToInteger().Limit(0, 48)* 5.3125);
99  Alpha = (int)(Values[2].ToInteger().Limit(0, 48) * 5.3125);
100  return;
101 
102  }
103  else if (NameValues[1].StartsWith("#") && (NameValues[1].Length==7 || NameValues[1].Length==9) && NameValues[1].Substring(1).IsHexString())
104  {
105  RGBAColor C = new RGBAColor();
106  if(C.SetColor(NameValues[1])) {
107  Name = NameValues[0];
108  Red=C.Red;
109  Green=C.Green;
110  Blue=C.Blue;
111  Alpha=C.Alpha;
112  return;
113  }
114  C=null;
115 
116  }
117  }
118  Log.Warning("Line {0} has a unknown structure or contains wrong data.".Build(ColorConfigDataLine));
119  if (ThrowExceptions)
120  {
121  throw new Exception("Line {0} has a unknown structure or contains wrong data.".Build(ColorConfigDataLine));
122  }
123  return;
124  }
125 
126 
130  public ColorConfig() { }
131 
139  public ColorConfig(string ColorConfigDataLine, bool ThrowExceptions = false)
140  {
141  ParseLedcontrolData(ColorConfigDataLine, ThrowExceptions);
142 
143  }
144  }
145 }
This class stores information on colors used for toys and effects (e.g. RGBLed).
Definition: RGBAColor.cs:14
The namespace DirectOutput.Cab.Toys contains all toy related classes.
static void Warning(string Message)
Writes a warning message to the log.
Definition: Log.cs:134
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
int Red
Brightness for Red.
Definition: RGBAColor.cs:27
RGBAColorNamed GetCabinetColor()
Gets a cabinet RGBAColor object representing the values in the ColorConfig object-.
Definition: ColorConfig.cs:18
int Green
Brightness for Green.
Definition: RGBAColor.cs:40
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
Definition: Cab.cs:16
ColorConfig()
Initializes a new instance of the ColorConfig class.
Definition: ColorConfig.cs:130
Color configuration from a LedControl file.
Definition: ColorConfig.cs:12
int Blue
Brightness for Blue.
Definition: RGBAColor.cs:52
int Alpha
Alpha value for the color.
Definition: RGBAColor.cs:64
ColorConfig(string ColorConfigDataLine, bool ThrowExceptions=false)
Initializes a new instance of the ColorConfig class. Parses the ledcontrol data for a color definitio...
Definition: ColorConfig.cs:139
bool SetColor(int Red, int Green, int Blue, int Alpha)
Sets the RGBA components of the Color.
Definition: RGBAColor.cs:115
Namespace for objects dealing with layers
void ParseLedcontrolData(string ColorConfigDataLine, bool ThrowExceptions=false)
Parses the ledcontrol data for a color definition.
Definition: ColorConfig.cs:75
The namespace DirectOutput.General contains classes for general use.
This class stores information on colors used for toys (e.g. RGBLed).