AWind
Color.h
1 #pragma once
2 /*
3  AWind.h - Arduino window library support for Color TFT LCD Boards
4  Copyright (C)2015 Andrei Degtiarev. All right reserved
5 
6 
7  You can always find the latest version of the library at
8  https://github.com/AndreiDegtiarev/AWind
9 
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the CC BY-NC-SA 3.0 license.
13  Please see the included documents for further information.
14 
15  Commercial use of this library requires you to buy a license that
16  will allow commercial use. This includes using the library,
17  modified or not, as a tool to sell products.
18 
19  The license applies to all part of the library including the
20  examples and tools supplied with the library.
21 */
22 
23 typedef unsigned long ARGB;
24 typedef byte BYTE;
25 typedef void VOID;
27 class Color
28 {
29 public:
30 
31  Color()
32  {
33  Argb = (ARGB)Color::Black;
34  }
35 
40  Color(BYTE r,
41  BYTE g,
42  BYTE b)
43  {
44  Argb = MakeARGB(255, r, g, b);
45  }
46 
47  Color(BYTE a,
48  BYTE r,
49  BYTE g,
50  BYTE b)
51  {
52  Argb = MakeARGB(a, r, g, b);
53  }
54 
55  Color(ARGB argb)
56  {
57  Argb = argb;
58  }
59 
60  BYTE GetAlpha() const
61  {
62  return (BYTE) (Argb >> AlphaShift);
63  }
64 
65  BYTE GetA() const
66  {
67  return GetAlpha();
68  }
69 
70  BYTE GetRed() const
71  {
72  return (BYTE) (Argb >> RedShift);
73  }
74 
75  BYTE GetR() const
76  {
77  return GetRed();
78  }
79 
80  BYTE GetGreen() const
81  {
82  return (BYTE) (Argb >> GreenShift);
83  }
84 
85  BYTE GetG() const
86  {
87  return GetGreen();
88  }
89 
90  BYTE GetBlue() const
91  {
92  return (BYTE) (Argb >> BlueShift);
93  }
94 
95  BYTE GetB() const
96  {
97  return GetBlue();
98  }
99 
100  ARGB GetValue() const
101  {
102  return Argb;
103  }
104 
105  VOID SetValue(ARGB argb)
106  {
107  Argb = argb;
108  }
109 
110 public:
111 
113  enum
114  {
115  AliceBlue = 0xFFF0F8FF,
116  AntiqueWhite = 0xFFFAEBD7,
117  Aqua = 0xFF00FFFF,
118  Aquamarine = 0xFF7FFFD4,
119  Azure = 0xFFF0FFFF,
120  Beige = 0xFFF5F5DC,
121  Bisque = 0xFFFFE4C4,
122  Black = 0xFF000000,
123  BlanchedAlmond = 0xFFFFEBCD,
124  Blue = 0xFF0000FF,
125  BlueViolet = 0xFF8A2BE2,
126  Brown = 0xFFA52A2A,
127  BurlyWood = 0xFFDEB887,
128  CadetBlue = 0xFF5F9EA0,
129  Chartreuse = 0xFF7FFF00,
130  Chocolate = 0xFFD2691E,
131  Coral = 0xFFFF7F50,
132  CornflowerBlue = 0xFF6495ED,
133  Cornsilk = 0xFFFFF8DC,
134  Crimson = 0xFFDC143C,
135  Cyan = 0xFF00FFFF,
136  DarkBlue = 0xFF00008B,
137  DarkCyan = 0xFF008B8B,
138  DarkGoldenrod = 0xFFB8860B,
139  DarkGray = 0xFFA9A9A9,
140  DarkGreen = 0xFF006400,
141  DarkKhaki = 0xFFBDB76B,
142  DarkMagenta = 0xFF8B008B,
143  DarkOliveGreen = 0xFF556B2F,
144  DarkOrange = 0xFFFF8C00,
145  DarkOrchid = 0xFF9932CC,
146  DarkRed = 0xFF8B0000,
147  DarkSalmon = 0xFFE9967A,
148  DarkSeaGreen = 0xFF8FBC8B,
149  DarkSlateBlue = 0xFF483D8B,
150  DarkSlateGray = 0xFF2F4F4F,
151  DarkTurquoise = 0xFF00CED1,
152  DarkViolet = 0xFF9400D3,
153  DeepPink = 0xFFFF1493,
154  DeepSkyBlue = 0xFF00BFFF,
155  DimGray = 0xFF696969,
156  DodgerBlue = 0xFF1E90FF,
157  Firebrick = 0xFFB22222,
158  FloralWhite = 0xFFFFFAF0,
159  ForestGreen = 0xFF228B22,
160  Fuchsia = 0xFFFF00FF,
161  Gainsboro = 0xFFDCDCDC,
162  GhostWhite = 0xFFF8F8FF,
163  Gold = 0xFFFFD700,
164  Goldenrod = 0xFFDAA520,
165  Gray = 0xFF808080,
166  Green = 0xFF008000,
167  GreenYellow = 0xFFADFF2F,
168  Honeydew = 0xFFF0FFF0,
169  HotPink = 0xFFFF69B4,
170  IndianRed = 0xFFCD5C5C,
171  Indigo = 0xFF4B0082,
172  Ivory = 0xFFFFFFF0,
173  Khaki = 0xFFF0E68C,
174  Lavender = 0xFFE6E6FA,
175  LavenderBlush = 0xFFFFF0F5,
176  LawnGreen = 0xFF7CFC00,
177  LemonChiffon = 0xFFFFFACD,
178  LightBlue = 0xFFADD8E6,
179  LightCoral = 0xFFF08080,
180  LightCyan = 0xFFE0FFFF,
181  LightGoldenrodYellow = 0xFFFAFAD2,
182  LightGray = 0xFFD3D3D3,
183  LightGreen = 0xFF90EE90,
184  LightPink = 0xFFFFB6C1,
185  LightSalmon = 0xFFFFA07A,
186  LightSeaGreen = 0xFF20B2AA,
187  LightSkyBlue = 0xFF87CEFA,
188  LightSlateGray = 0xFF778899,
189  LightSteelBlue = 0xFFB0C4DE,
190  LightYellow = 0xFFFFFFE0,
191  Lime = 0xFF00FF00,
192  LimeGreen = 0xFF32CD32,
193  Linen = 0xFFFAF0E6,
194  Magenta = 0xFFFF00FF,
195  Maroon = 0xFF800000,
196  MediumAquamarine = 0xFF66CDAA,
197  MediumBlue = 0xFF0000CD,
198  MediumOrchid = 0xFFBA55D3,
199  MediumPurple = 0xFF9370DB,
200  MediumSeaGreen = 0xFF3CB371,
201  MediumSlateBlue = 0xFF7B68EE,
202  MediumSpringGreen = 0xFF00FA9A,
203  MediumTurquoise = 0xFF48D1CC,
204  MediumVioletRed = 0xFFC71585,
205  MidnightBlue = 0xFF191970,
206  MintCream = 0xFFF5FFFA,
207  MistyRose = 0xFFFFE4E1,
208  Moccasin = 0xFFFFE4B5,
209  NavajoWhite = 0xFFFFDEAD,
210  Navy = 0xFF000080,
211  OldLace = 0xFFFDF5E6,
212  Olive = 0xFF808000,
213  OliveDrab = 0xFF6B8E23,
214  Orange = 0xFFFFA500,
215  OrangeRed = 0xFFFF4500,
216  Orchid = 0xFFDA70D6,
217  PaleGoldenrod = 0xFFEEE8AA,
218  PaleGreen = 0xFF98FB98,
219  PaleTurquoise = 0xFFAFEEEE,
220  PaleVioletRed = 0xFFDB7093,
221  PapayaWhip = 0xFFFFEFD5,
222  PeachPuff = 0xFFFFDAB9,
223  Peru = 0xFFCD853F,
224  Pink = 0xFFFFC0CB,
225  Plum = 0xFFDDA0DD,
226  PowderBlue = 0xFFB0E0E6,
227  Purple = 0xFF800080,
228  Red = 0xFFFF0000,
229  RosyBrown = 0xFFBC8F8F,
230  RoyalBlue = 0xFF4169E1,
231  SaddleBrown = 0xFF8B4513,
232  Salmon = 0xFFFA8072,
233  SandyBrown = 0xFFF4A460,
234  SeaGreen = 0xFF2E8B57,
235  SeaShell = 0xFFFFF5EE,
236  Sienna = 0xFFA0522D,
237  Silver = 0xFFC0C0C0,
238  SkyBlue = 0xFF87CEEB,
239  SlateBlue = 0xFF6A5ACD,
240  SlateGray = 0xFF708090,
241  Snow = 0xFFFFFAFA,
242  SpringGreen = 0xFF00FF7F,
243  SteelBlue = 0xFF4682B4,
244  Tan = 0xFFD2B48C,
245  Teal = 0xFF008080,
246  Thistle = 0xFFD8BFD8,
247  Tomato = 0xFFFF6347,
248  Transparent = 0x00FFFFFF,
249  Turquoise = 0xFF40E0D0,
250  Violet = 0xFFEE82EE,
251  Wheat = 0xFFF5DEB3,
252  White = 0xFFFFFFFF,
253  WhiteSmoke = 0xFFF5F5F5,
254  Yellow = 0xFFFFFF00,
255  YellowGreen = 0xFF9ACD32
256  };
257 
259  enum
260  {
261  AlphaShift = 24,
262  RedShift = 16,
263  GreenShift = 8,
264  BlueShift = 0
265  };
266 
267  enum
268  {
269  AlphaMask = 0xff000000,
270  RedMask = 0x00ff0000,
271  GreenMask = 0x0000ff00,
272  BlueMask = 0x000000ff
273  };
274 
276  static ARGB MakeARGB(BYTE a,
277  BYTE r,
278  BYTE g,
279  BYTE b)
280  {
281  return (((ARGB) (b) << BlueShift) |
282  ((ARGB) (g) << GreenShift) |
283  ((ARGB) (r) << RedShift) |
284  ((ARGB) (a) << AlphaShift));
285  }
286 
287 protected:
288 
289  ARGB Argb;
290 };
Implements definition and operations with color.
Definition: Color.h:27
Color(BYTE r, BYTE g, BYTE b)
Definition: Color.h:40
static ARGB MakeARGB(BYTE a, BYTE r, BYTE g, BYTE b)
Assemble A, R, G, B values into a 32-bit integer.
Definition: Color.h:276