WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
RGBColor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Xml.Serialization;
7 
8 namespace DirectOutput.General.Color
9 {
10 
14  public class RGBColor
15  {
16 
17 
18 
19 
20 
21  private int _BrightnessRed;
22 
27  [XmlIgnoreAttribute]
28  public int Red
29  {
30  get { return _BrightnessRed; }
31  set { _BrightnessRed = value.Limit(0,255); }
32  }
33 
34  private int _BrightnessGreen;
35 
40  [XmlIgnoreAttribute]
41  public int Green
42  {
43  get { return _BrightnessGreen; }
44  set { _BrightnessGreen = value.Limit(0, 255); }
45  }
46 
47  private int _BrightnessBlue;
52  [XmlIgnoreAttribute]
53  public int Blue
54  {
55  get { return _BrightnessBlue; }
56  set { _BrightnessBlue = value.Limit(0, 255); }
57  }
58 
59 
64  public string HexColor
65  {
66  get
67  {
68  return "#{0:X2}{1:X2}{2:X2}".Build(Red, Green,Blue);
69  }
70  set {
71  SetColor(value);
72  }
73  }
74 
82  public bool SetColor(int Red, int Green, int Blue)
83  {
84  this.Red = Red;
85  this.Blue = Blue;
86  this.Green = Green;
87  return true;
88  }
89 
96  public bool SetColor(string Color)
97  {
98  if ((Color.Length == 6 && Color.IsHexString()) || (Color.Length == 7 && Color.StartsWith("#") && Color.IsHexString(1, 6)))
99  {
100  int Offset;
101  if (Color.StartsWith("#"))
102  {
103  Offset = 1;
104  }
105  else
106  {
107  Offset = 0;
108  }
109  SetColor(Color.Substring(0 + Offset, 2).HexToInt(), Color.Substring(2 + Offset, 2).HexToInt(), Color.Substring(4 + Offset, 2).HexToInt());
110  return true;
111  };
112 
113  string[] SplitColors = Color.Split(',');
114  if (SplitColors.Length == 3)
115  {
116  bool ColorsOK = true;
117  foreach (string C in SplitColors)
118  {
119  if (C.IsInteger())
120  {
121  ColorsOK = false;
122  }
123  }
124  if (ColorsOK)
125  {
126  SetColor(int.Parse(SplitColors[0]), int.Parse(SplitColors[1]), int.Parse(SplitColors[2]));
127  return true;
128  }
129  }
130  return false;
131  }
132 
133  #region Contructor
134  public RGBColor() { }
138 
145  public RGBColor(int BrightnessRed, int BrightnessGreen, int BrightnessBlue){
146  SetColor(BrightnessRed, BrightnessGreen, BrightnessBlue);
147  }
153  public RGBColor(string Color)
154  {
155  SetColor(Color);
156  }
157 
158 
159  #endregion
160  }
161 }
RGBColor(string Color)
Initializes a new instance of the RGBColor class. The parameter string Color ist first parsed for he...
Definition: RGBColor.cs:153
This class stores information on RGB colors used for toys and effects (e.g. RGBLed).
Definition: RGBColor.cs:14
bool SetColor(string Color)
Sets the RGB components of the Color. The parameter string Color ist first parsed for hexadecimal c...
Definition: RGBColor.cs:96
bool SetColor(int Red, int Green, int Blue)
Sets the RGB components of the Color.
Definition: RGBColor.cs:82
The namespace DirectOutput.General contains classes for general use.
RGBColor(int BrightnessRed, int BrightnessGreen, int BrightnessBlue)
Initializes a new instance of the RGBColor class.
Definition: RGBColor.cs:145