libosmscout 1.1.1
Loading...
Searching...
No Matches
Color.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_UTIL_COLOR_H
2#define OSMSCOUT_UTIL_COLOR_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2012 Tim Teulings
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
24
25#include <string>
26
29
30namespace osmscout {
31
38 class OSMSCOUT_API Color CLASS_FINAL
39 {
40 public:
41 static const Color BLACK;
42 static const Color WHITE;
43
44 static const Color RED;
45 static const Color GREEN;
46 static const Color BLUE;
47
48 static const Color SILVER;
49 static const Color GRAY;
50 static const Color MAROON;
51 static const Color PURPLE;
52 static const Color FUCHSIA;
53 static const Color LIME;
54 static const Color OLIVE;
55 static const Color YELLOW;
56 static const Color NAVY;
57 static const Color TEAL;
58 static const Color AQUA;
59
60 static const Color LIGHT_GRAY;
61 static const Color DARK_GRAY;
62 static const Color DARK_RED;
63 static const Color DARK_GREEN;
64 static const Color DARK_YELLOW;
65 static const Color DARK_BLUE;
66 static const Color DARK_FUCHSIA;
67 static const Color DARK_AQUA;
68
69 static const Color LUCENT_WHITE;
70
71 private:
72 double r=1.0;
73 double g=0.0;
74 double b=0.0;
75 double a=0.0;
76
77 public:
78 Color() = default;
79 ~Color() = default;
80
81 Color(double r,
82 double g,
83 double b,
84 double a) noexcept
85 : r(r),
86 g(g),
87 b(b),
88 a(a)
89 {
90 assert(r>=0.0 && r<=1.0);
91 assert(g>=0.0 && g<=1.0);
92 assert(b>=0.0 && b<=1.0);
93 assert(a>=0.0 && a<=1.0);
94 }
95
96 Color(double r,
97 double g,
98 double b) noexcept
99 : r(r),
100 g(g),
101 b(b),
102 a(1.0)
103 {
104 assert(r>=0.0 && r<=1.0);
105 assert(g>=0.0 && g<=1.0);
106 assert(b>=0.0 && b<=1.0);
107 assert(a>=0.0 && a<=1.0);
108 }
109
110 double GetR() const
111 {
112 return r;
113 }
114
115 double GetG() const
116 {
117 return g;
118 }
119
120 double GetB() const
121 {
122 return b;
123 }
124
125 double GetA() const
126 {
127 return a;
128 }
129
130 bool IsSolid() const
131 {
132 return a==1.0;
133 }
134
135 bool IsVisible() const
136 {
137 return a>0.0;
138 }
139
140 Color Lighten(double factor) const
141 {
142 return Color(r+(1-r)*factor,
143 g+(1-g)*factor,
144 b+(1-b)*factor,
145 a);
146 }
147
148 Color Darken(double factor) const
149 {
150 return Color(r-r*factor,
151 g-g*factor,
152 b-b*factor,
153 a);
154 }
155
156 Color Alpha(double newAlpha) const
157 {
158 return Color(r,
159 g,
160 b,
161 newAlpha);
162 }
163
165 {
166 double grey=(r+g+b)/3.0;
167 return Color(grey,
168 grey,
169 grey,
170 a);
171 }
172
173 std::string ToHexString() const;
174
175 bool operator==(const Color& other) const
176 {
177 return r==other.r && g==other.g && b==other.b && a==other.a;
178 }
179
180 bool operator!=(const Color& other) const
181 {
182 return r!=other.r || g!=other.g || b!=other.b || a!=other.a;
183 }
184
185 bool operator<(const Color& other) const;
186
187 static bool IsHexString(const std::string& hexString);
188
201 static Color FromHexString(const std::string& hexString);
202
203 static bool FromHexString(const std::string& hexString, Color &color);
204
213 static bool FromW3CKeywordString(const std::string& colorKeyword, Color &color);
214 };
215}
216
217#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
double GetB() const
Definition Color.h:120
static const Color DARK_FUCHSIA
Definition Color.h:66
static const Color GRAY
Definition Color.h:49
bool operator<(const Color &other) const
double GetA() const
Definition Color.h:125
Color(double r, double g, double b, double a) noexcept
Definition Color.h:81
Color(double r, double g, double b) noexcept
Definition Color.h:96
static const Color NAVY
Definition Color.h:56
static Color FromHexString(const std::string &hexString)
std::string ToHexString() const
double GetG() const
Definition Color.h:115
double GetR() const
Definition Color.h:110
static const Color MAROON
Definition Color.h:50
static const Color GREEN
Definition Color.h:45
static const Color DARK_AQUA
Definition Color.h:67
static bool FromHexString(const std::string &hexString, Color &color)
static bool FromW3CKeywordString(const std::string &colorKeyword, Color &color)
static const Color SILVER
Definition Color.h:48
static bool IsHexString(const std::string &hexString)
bool IsSolid() const
Definition Color.h:130
static const Color TEAL
Definition Color.h:57
Color Lighten(double factor) const
Definition Color.h:140
static const Color DARK_RED
Definition Color.h:62
static const Color PURPLE
Definition Color.h:51
bool IsVisible() const
Definition Color.h:135
static const Color DARK_GRAY
Definition Color.h:61
static const Color LIGHT_GRAY
Definition Color.h:60
static const Color DARK_YELLOW
Definition Color.h:64
static const Color DARK_BLUE
Definition Color.h:65
bool operator!=(const Color &other) const
Definition Color.h:180
static const Color BLUE
Definition Color.h:46
static const Color AQUA
Definition Color.h:58
static const Color YELLOW
Definition Color.h:55
Color Darken(double factor) const
Definition Color.h:148
static const Color DARK_GREEN
Definition Color.h:63
static const Color OLIVE
Definition Color.h:54
Color Decolor() const
Definition Color.h:164
static const Color FUCHSIA
Definition Color.h:52
Color Alpha(double newAlpha) const
Definition Color.h:156
static const Color LIME
Definition Color.h:53
static const Color WHITE
Definition Color.h:42
static const Color RED
Definition Color.h:44
static const Color LUCENT_WHITE
Definition Color.h:69
bool operator==(const Color &other) const
Definition Color.h:175
static const Color BLACK
Definition Color.h:41
Definition Area.h:39