SDL Window Engine  20200905
swe_colors.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_COLORS_
24 #define _SWE_COLORS_
25 
26 #include <string>
27 #include <utility>
28 
29 #include "swe_types.h"
30 #include "swe_tools.h"
31 
33 namespace SWE
34 {
35 
36  class Color;
37  class ColorIndex;
38 
40  class ARGB : public packint4
41  {
42  public:
43  ARGB() : packint4(SDL_ALPHA_OPAQUE, 0, 0, 0) {}
44  ARGB(int a, int r, int g, int b) : packint4(a, r, g, b) {}
45  ARGB(int val) : packint4(val) {}
46  ARGB(const std::string &);
47  virtual ~ARGB() {}
48 
49  int a(void) const;
50  int r(void) const;
51  int g(void) const;
52  int b(void) const;
53 
54  void setA(int v);
55  void setR(int v);
56  void setG(int v);
57  void setB(int v);
58 
59  void setARGB(int v);
60  int getARGB(void) const;
61  bool hasAlpha(void) const;
62  };
63 
65  class Color : public ARGB
66  {
67  public:
69  enum color_t
70  {
71  Black = 0, Navy, DarkBlue, MediumBlue, Blue, DarkGreen, Green, Teal, DarkCyan, DeepSkyBlue,
72  DarkTurquoise, MediumSpringGreen, Lime, SpringGreen, Aqua, Cyan, MidnightBlue, DodgerBlue, LightSeaGreen, ForestGreen,
73  SeaGreen, DarkSlateGray, LimeGreen, MediumSeaGreen, Turquoise, RoyalBlue, SteelBlue, DarkSlateBlue, MediumTurquoise, Indigo,
74  DarkOliveGreen, CadetBlue, CornflowerBlue, MediumAquamarine, DimGray, SlateBlue, OliveDrab, SlateGray, LightSlateGray, MediumSlateBlue,
75  LawnGreen, Chartreuse, Aquamarine, Maroon, Purple, Olive, Gray, SkyBlue, LightSkyBlue, BlueViolet,
76  DarkRed, DarkMagenta, SaddleBrown, DarkSeaGreen, LightGreen, MediumPurple, DarkViolet, PaleGreen, DarkOrchid, Amethyst,
77  YellowGreen, Sienna, Brown, DarkGray, LightBlue, GreenYellow, PaleTurquoise, LightSteelBlue, PowderBlue, FireBrick,
78  DarkGoldenrod, MediumOrchid, RosyBrown, DarkKhaki, Silver, MediumVioletRed, IndianRed, Peru, Chocolate, Tan,
79  LightGrey, Thistle, Orchid, Goldenrod, PaleVioletRed, Crimson, Gainsboro, Plum, BurlyWood, LightCyan,
80  Lavender, DarkSalmon, Violet, PaleGoldenrod, LightCoral, Khaki, AliceBlue, Honeydew, Azure, SandyBrown,
81  Wheat, Beige, WhiteSmoke, MintCream, GhostWhite, Salmon, AntiqueWhite, Linen, LightGoldenrodYellow, OldLace,
82  Red, Fuchsia, Magenta, DeepPink, OrangeRed, Tomato, HotPink, Coral, DarkOrange, LightSalmon,
83  Orange, LightPink, Pink, Gold, PeachPuff, NavajoWhite, Moccasin, Bisque, MistyRose, BlanchedAlmond,
84  PapayaWhip, LavenderBlush, Seashell, Cornsilk, LemonChiffon, FloralWhite, Snow, Yellow, LightYellow, Ivory,
85  White, Transparent /* ColorIndex: 141 */
86  };
87 
88  Color() {}
89  explicit Color(const ARGB & argb) : ARGB(argb) {}
90  Color(int r, int g, int b, int a = SDL_ALPHA_OPAQUE) : ARGB(a, r, g, b) {}
91 #ifdef SWE_SDL12
92  Color(const SDL_Color & col) : ARGB(col.unused, col.r, col.g, col.b) {}
93 #else
94  Color(const SDL_Color & col) : ARGB(col.a, col.r, col.g, col.b) {}
95 #endif
96  Color(const std::string & str) : ARGB(str) {}
97  Color(int color_t, int a = SDL_ALPHA_OPAQUE);
98 
99  SDL_Color toSDLColor(void) const;
100  ColorIndex toColorIndex(void) const;
101  std::string toString(void) const;
102  std::string toHexString(void) const;
103 
104  bool isTransparent(void) const;
105  bool isColor(color_t) const;
106 
107  static Color transparent(void);
108  static Color colorKey(void);
109  static const char* name(color_t);
110  };
111 
114  {
115  u32 val;
116  bool isValid(void) const;
117 
118  public:
119  ColorIndex(int color_t = Color::Black);
120 
121  u32 operator()(void) const;
122  ColorIndex & operator= (int v);
123 
124  u32 index(void) const;
125 
126  bool operator< (const ColorIndex &) const;
127  bool operator> (const ColorIndex &) const;
128  bool operator== (const ColorIndex &) const;
129  bool operator!= (const ColorIndex &) const;
130 
131  bool isTransparent(void) const;
132  Color toColor(void) const;
133  };
134 
137  {
138  FBColors(const ColorIndex & fg = Color::Black, const ColorIndex & bg = Color::Transparent);
139 
140  int bg(void) const;
141  int fg(void) const;
142 
143  Color bgcolor(void) const;
144  Color fgcolor(void) const;
145 
146  void setbg(const ColorIndex &);
147  void setfg(const ColorIndex &);
148  };
149 
150 } // SWE
151 #endif
Definition: swe_types.h:192
класс пары двух цветов (foreground, background)
Definition: swe_colors.h:136
пространство SWE.
Definition: swe_binarybuf.cpp:30
класс цвета
Definition: swe_colors.h:65
базовый класс цвета
Definition: swe_colors.h:40
класс индекса цвета
Definition: swe_colors.h:113
Definition: swe_types.h:127
color_t
набор html цветовых кодов
Definition: swe_colors.h:69