gwnavruntime/visualsystem/color.h Source File

color.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
11 
12 namespace Kaim
13 {
14 
16 class Color
17 {
18  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualSystem)
19 
20 public:
21  Color() : r(0), g(0), b(0), a(255) {}
22  Color(const Color& c) { Set(c.r, c.g, c.b, c.a); }
23  Color(const Color& c, KyUInt8 a) { Set(c.r, c.g, c.b, a); }
24  Color(KyUInt8 r, KyUInt8 g, KyUInt8 b, KyUInt8 a = 255) { Set(r, g, b, a); }
25  Color(KyUInt32 rgba) { Set(rgba >> 24, (rgba >> 16) & 0xFF, (rgba >> 8) & 0xFF, rgba & 0xFF); }
26 
27  static Color Fade(Color c, KyFloat32 fade) { return Color(KyUInt8(c.r * fade), KyUInt8(c.g * fade), KyUInt8(c.b * fade), c.a); }
28 
29  bool IsVisible() const { return a != 0; }
30  bool IsOpaque() const { return a == 255; }
31  bool IsTransparent() const { return a != 255; }
32 
33  bool operator==(const Color& c) const { return r == c.r && g == c.g && b == c.b && a == c.a; }
34  bool operator!=(const Color& c) const { return !operator==(c); }
35 
36  void Set(KyUInt8 r_, KyUInt8 g_, KyUInt8 b_, KyUInt8 a_ = 255) { r = r_; g = g_; b = b_; a = a_; }
37  void Set(const Color& c, KyUInt8 a_) { r = c.r; g = c.g; b = c.b; a = a_; }
38 
40  void SetFloat(KyFloat32 r_, KyFloat32 g_, KyFloat32 b_, KyFloat32 a_ = 1.0f)
41  {
42  Set(KyUInt8(r_ * 255.0f), KyUInt8(g_ * 255.0f), KyUInt8(b_ * 255.0f), KyUInt8(a_ * 255.0f));
43  }
44 
45 public:
50 
51 public:
53  static Color GetDistinctColor(KyUInt32 index);
54 
59  static Color GetDistinctColor(const KyUInt32 index, const Color* customPalette, KyUInt32 nbColorsInPalette);
60 
61  // White, Grey, Back
62  static const KyUInt32 White = 0xFFFFFFFF;
63  static const KyUInt32 LightGrey = 0xD3D3D3FF;
64  static const KyUInt32 Grey = 0x808080FF;
65  static const KyUInt32 DimGrey = 0x696969FF;
66  static const KyUInt32 Black = 0x000000FF;
67 
68  // Main colors
69  static const KyUInt32 Red = 0xFF0000FF;
70  static const KyUInt32 Green = 0x00FF00FF; // aka CSS Lime
71  static const KyUInt32 Blue = 0x0000FFFF;
72  static const KyUInt32 Magenta = 0xFF00FFFF; // aka CSS Fuchsia
73  static const KyUInt32 Cyan = 0x00FFFFFF;
74  static const KyUInt32 Yellow = 0xFFFF00FF;
75  static const KyUInt32 Orange = 0xFFA500FF;
76 
77  // Red-Yellow
78  static const KyUInt32 Khaki = 0xF0E68CFF;
79  static const KyUInt32 Tan = 0xD2B48CFF;
80  static const KyUInt32 Chocolate = 0xD2691EFF;
81  static const KyUInt32 Salmon = 0xFA8072FF;
82  static const KyUInt32 OrangeRed = 0xFF4500FF;
83  static const KyUInt32 Brown = 0xA52A2AFF;
84 
85  // Greens
86  static const KyUInt32 GreenYellow = 0xADFF2FFF;
87  static const KyUInt32 LightGreen = 0x90EE90FF;
88  static const KyUInt32 LightSeaGreen = 0x20B2AAFF;
89  static const KyUInt32 DarkSeaGreen = 0x8FBC8FFF;
90  static const KyUInt32 Teal = 0x008080FF;
91 
92  // Blues-Aquas
93  static const KyUInt32 SkyBlue = 0x87CEEBFF;
94  static const KyUInt32 DeepSkyBlue = 0x00BFFFFF;
95  static const KyUInt32 RoyalBlue = 0x4169E1FF;
96  static const KyUInt32 MediumBlue = 0x0000CDFF; // the default NavMesh color
97 
98  // Magentas
99  static const KyUInt32 Violet = 0xEE82EEFF;
100  static const KyUInt32 HotPink = 0xFF69B4FF;
101  static const KyUInt32 MediumPurple = 0x9370DBFF;
102  static const KyUInt32 Purple = 0x800080FF;
103 
104  // Invisible
105  static const KyUInt32 TransparentBlack = 0xFFFFFF00;
106  static const KyUInt32 Invisible = 0xFFFFFF00;
107 };
108 
109 inline void SwapEndianness(Endianness::Target, Color&) {} // nothing to swap
110 
111 typedef KY_DEPRECATED(Color VisualColor); // VisualColor deprecated since 2.17.0, use Color instead
112 
113 }
114 
Color(KyUInt32 rgba)
w parameters in [0, 255] a=0 is fully transparent, a=255 is opaque
Definition: color.h:25
KyUInt8 a
alpha
Definition: color.h:49
KyUInt8 b
blue
Definition: color.h:48
KyUInt8 g
green
Definition: color.h:47
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
KyUInt8 r
red
Definition: color.h:46
Color()
opaque black
Definition: color.h:21
void SetFloat(KyFloat32 r_, KyFloat32 g_, KyFloat32 b_, KyFloat32 a_=1.0f)
parameters in [0.0f, 1.0f], a=0.0f is fully transparent, a=1.0f is fully opaque
Definition: color.h:40
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
bool IsOpaque() const
alpha == 255
Definition: color.h:30
#define KY_DEPRECATED(expr)
The compiler issues a warning when a deprecated function or typedef is used.
Definition: types.h:93
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
RGBA color.
Definition: color.h:16
bool IsTransparent() const
alpha != 255
Definition: color.h:31
bool IsVisible() const
alpha != 0
Definition: color.h:29
static Color GetDistinctColor(KyUInt32 index)
Retrieves the color with the specified index within a limited internal palette of 31 distinct colors...
Definition: color.cpp:40
std::uint8_t KyUInt8
uint8_t
Definition: types.h:27
float KyFloat32
float
Definition: types.h:32