libosmscout
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
libosmscout
include
osmscout
util
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
23
#include <
osmscout/lib/CoreImportExport.h
>
24
25
#include <string>
26
27
#include <
osmscout/system/Assert.h
>
28
#include <
osmscout/system/Compiler.h
>
29
30
namespace
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
164
Color
Decolor
()
const
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
Assert.h
Compiler.h
CoreImportExport.h
OSMSCOUT_API
#define OSMSCOUT_API
Definition
CoreImportExport.h:45
osmscout::CLASS_FINAL
Definition
Area.h:88
osmscout::CLASS_FINAL::GetB
double GetB() const
Definition
Color.h:120
osmscout::CLASS_FINAL::DARK_FUCHSIA
static const Color DARK_FUCHSIA
Definition
Color.h:66
osmscout::CLASS_FINAL::GRAY
static const Color GRAY
Definition
Color.h:49
osmscout::CLASS_FINAL::operator<
bool operator<(const Color &other) const
osmscout::CLASS_FINAL::GetA
double GetA() const
Definition
Color.h:125
osmscout::CLASS_FINAL::Color
Color(double r, double g, double b, double a) noexcept
Definition
Color.h:81
osmscout::CLASS_FINAL::Color
Color(double r, double g, double b) noexcept
Definition
Color.h:96
osmscout::CLASS_FINAL::NAVY
static const Color NAVY
Definition
Color.h:56
osmscout::CLASS_FINAL::FromHexString
static Color FromHexString(const std::string &hexString)
osmscout::CLASS_FINAL::ToHexString
std::string ToHexString() const
osmscout::CLASS_FINAL::~Color
~Color()=default
osmscout::CLASS_FINAL::GetG
double GetG() const
Definition
Color.h:115
osmscout::CLASS_FINAL::GetR
double GetR() const
Definition
Color.h:110
osmscout::CLASS_FINAL::MAROON
static const Color MAROON
Definition
Color.h:50
osmscout::CLASS_FINAL::GREEN
static const Color GREEN
Definition
Color.h:45
osmscout::CLASS_FINAL::DARK_AQUA
static const Color DARK_AQUA
Definition
Color.h:67
osmscout::CLASS_FINAL::FromHexString
static bool FromHexString(const std::string &hexString, Color &color)
osmscout::CLASS_FINAL::FromW3CKeywordString
static bool FromW3CKeywordString(const std::string &colorKeyword, Color &color)
osmscout::CLASS_FINAL::SILVER
static const Color SILVER
Definition
Color.h:48
osmscout::CLASS_FINAL::IsHexString
static bool IsHexString(const std::string &hexString)
osmscout::CLASS_FINAL::IsSolid
bool IsSolid() const
Definition
Color.h:130
osmscout::CLASS_FINAL::TEAL
static const Color TEAL
Definition
Color.h:57
osmscout::CLASS_FINAL::Lighten
Color Lighten(double factor) const
Definition
Color.h:140
osmscout::CLASS_FINAL::DARK_RED
static const Color DARK_RED
Definition
Color.h:62
osmscout::CLASS_FINAL::PURPLE
static const Color PURPLE
Definition
Color.h:51
osmscout::CLASS_FINAL::IsVisible
bool IsVisible() const
Definition
Color.h:135
osmscout::CLASS_FINAL::DARK_GRAY
static const Color DARK_GRAY
Definition
Color.h:61
osmscout::CLASS_FINAL::LIGHT_GRAY
static const Color LIGHT_GRAY
Definition
Color.h:60
osmscout::CLASS_FINAL::DARK_YELLOW
static const Color DARK_YELLOW
Definition
Color.h:64
osmscout::CLASS_FINAL::DARK_BLUE
static const Color DARK_BLUE
Definition
Color.h:65
osmscout::CLASS_FINAL::operator!=
bool operator!=(const Color &other) const
Definition
Color.h:180
osmscout::CLASS_FINAL::BLUE
static const Color BLUE
Definition
Color.h:46
osmscout::CLASS_FINAL::AQUA
static const Color AQUA
Definition
Color.h:58
osmscout::CLASS_FINAL::YELLOW
static const Color YELLOW
Definition
Color.h:55
osmscout::CLASS_FINAL::Darken
Color Darken(double factor) const
Definition
Color.h:148
osmscout::CLASS_FINAL::DARK_GREEN
static const Color DARK_GREEN
Definition
Color.h:63
osmscout::CLASS_FINAL::OLIVE
static const Color OLIVE
Definition
Color.h:54
osmscout::CLASS_FINAL::Decolor
Color Decolor() const
Definition
Color.h:164
osmscout::CLASS_FINAL::FUCHSIA
static const Color FUCHSIA
Definition
Color.h:52
osmscout::CLASS_FINAL::Alpha
Color Alpha(double newAlpha) const
Definition
Color.h:156
osmscout::CLASS_FINAL::LIME
static const Color LIME
Definition
Color.h:53
osmscout::CLASS_FINAL::WHITE
static const Color WHITE
Definition
Color.h:42
osmscout::CLASS_FINAL::RED
static const Color RED
Definition
Color.h:44
osmscout::CLASS_FINAL::LUCENT_WHITE
static const Color LUCENT_WHITE
Definition
Color.h:69
osmscout::CLASS_FINAL::operator==
bool operator==(const Color &other) const
Definition
Color.h:175
osmscout::CLASS_FINAL::Color
Color()=default
osmscout::CLASS_FINAL::BLACK
static const Color BLACK
Definition
Color.h:41
osmscout
Definition
Area.h:39
Generated by
1.17.0