Kiwano Engine v1.3.x
Color.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Common.h>
23
24namespace kiwano
25{
31/*
32 * \~chinese
33 * @brief 颜色
34 * @details
35 * 使用枚举表示颜色: @code Color blue = Color::Blue; @endcode
36 * 使用 RGB 表示一个颜色: @code Color red = Color(255, 0, 0); @endcode
37 * 使用 RGBA 表示一个带透明度的颜色: @code Color not_white = Color(255, 255, 255, 0.5f); @endcode
38 * 使用一个16进制整型值表示 RGB 颜色: @code Color black(0x000000); @endcode
39 */
40class KGE_API Color
41{
42public:
46 Color();
47
54 Color(float r, float g, float b, float alpha = 1.0f);
55
62 Color(int r, int g, int b, float alpha = 1.0f);
63
68 Color(uint32_t rgb, float alpha = 1.0f);
69
75 static Color Rgb(float r, float g, float b);
76
82 static Color Rgb(int r, int g, int b);
83
87 static Color Rgb(uint32_t rgb);
88
94 static Color Rgba(float r, float g, float b, float alpha);
95
102 static Color Rgba(int r, int g, int b, float alpha);
103
108 static Color Rgba(uint32_t rgb, float alpha);
109
110 bool operator==(const Color& rhs) const;
111
112 bool operator!=(const Color& rhs) const;
113
114public:
117 enum Value : uint32_t
118 {
119 Black = 0x000000,
120 Blue = 0x0000FF,
121 BlueViolet = 0x8A2BE2,
122 Brown = 0xA52A2A,
123 Chocolate = 0xD2691E,
124 DarkBlue = 0x00008B,
125 DarkGray = 0xA9A9A9,
126 DarkGreen = 0x006400,
127 DarkOrange = 0xFF8C00,
128 DarkRed = 0x8B0000,
129 DarkViolet = 0x9400D3,
130 ForestGreen = 0x228B22,
131 Gold = 0xFFD700,
132 Gray = 0x808080,
133 Green = 0x008000,
134 GreenYellow = 0xADFF2F,
135 LightBlue = 0xADD8E6,
136 LightCyan = 0xE0FFFF,
137 LightGreen = 0x90EE90,
138 LightGray = 0xD3D3D3,
139 LightPink = 0xFFB6C1,
140 LightSeaGreen = 0x20B2AA,
141 LightSkyBlue = 0x87CEFA,
142 LightYellow = 0xFFFFE0,
143 Orange = 0xFFA500,
144 OrangeRed = 0xFF4500,
145 Pink = 0xFFC0CB,
146 Purple = 0x800080,
147 Red = 0xFF0000,
148 Silver = 0xC0C0C0,
149 SkyBlue = 0x87CEEB,
150 Snow = 0xFFFAFA,
151 Violet = 0xEE82EE,
152 Wheat = 0xF5DEB3,
153 White = 0xFFFFFF,
154 WhiteSmoke = 0xF5F5F5,
155 Wood = 0xDEB887,
156 Yellow = 0xFFFF00,
157 YellowGreen = 0x9ACD32
158 };
159
162 static const Color Transparent;
163
164public:
165 float r;
166 float g;
167 float b;
168 float a;
169};
170
173inline bool Color::operator==(const Color& rhs) const
174{
175 return r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a;
176}
177
178inline bool Color::operator!=(const Color& rhs) const
179{
180 return !((*this) == rhs);
181}
182} // namespace kiwano
Definition: Color.h:41
static const Color Transparent
透明色
Definition: Color.h:162
float a
Alpha值
Definition: Color.h:168
float r
红色值
Definition: Color.h:165
Value
常见颜色枚举
Definition: Color.h:118
float b
蓝色值
Definition: Color.h:167
float g
绿色值
Definition: Color.h:166