Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Color.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Core module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_COLOR_HPP
8 #define NAZARA_COLOR_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/String.hpp>
12 #include <Nazara/Math/Vector3.hpp>
13 
14 namespace Nz
15 {
16  struct SerializationContext;
17 
18  class Color
19  {
20  public:
21  inline Color();
22  inline Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha = 255);
23  inline explicit Color(UInt8 lightness);
24  inline Color(UInt8 color[3], UInt8 alpha = 255);
25  inline Color(const Color& color) = default;
26  inline ~Color() = default;
27 
28  inline bool IsOpaque() const;
29 
30  inline String ToString() const;
31 
32  inline Color operator+(const Color& angles) const;
33  inline Color operator*(const Color& angles) const;
34 
35  inline Color operator+=(const Color& angles);
36  inline Color operator*=(const Color& angles);
37 
38  inline bool operator==(const Color& angles) const;
39  inline bool operator!=(const Color& angles) const;
40 
41  static inline Color FromCMY(float cyan, float magenta, float yellow);
42  static inline Color FromCMYK(float cyan, float magenta, float yellow, float black);
43  static inline Color FromHSL(UInt8 hue, UInt8 saturation, UInt8 lightness);
44  static inline Color FromHSV(float hue, float saturation, float value);
45  static inline Color FromXYZ(const Vector3f& vec);
46  static inline Color FromXYZ(float x, float y, float z);
47  static inline void ToCMY(const Color& color, float* cyan, float* magenta, float* yellow);
48  static inline void ToCMYK(const Color& color, float* cyan, float* magenta, float* yellow, float* black);
49  static inline void ToHSL(const Color& color, UInt8* hue, UInt8* saturation, UInt8* lightness);
50  static inline void ToHSV(const Color& color, float* hue, float* saturation, float* value);
51  static inline void ToXYZ(const Color& color, Vector3f* vec);
52  static inline void ToXYZ(const Color& color, float* x, float* y, float* z);
53 
54  UInt8 r, g, b, a;
55 
56  static NAZARA_CORE_API const Color Black;
57  static NAZARA_CORE_API const Color Blue;
58  static NAZARA_CORE_API const Color Cyan;
59  static NAZARA_CORE_API const Color Green;
60  static NAZARA_CORE_API const Color Magenta;
61  static NAZARA_CORE_API const Color Orange;
62  static NAZARA_CORE_API const Color Red;
63  static NAZARA_CORE_API const Color Yellow;
64  static NAZARA_CORE_API const Color White;
65 
66  private:
67  static float Hue2RGB(float v1, float v2, float vH);
68  };
69 
70  inline bool Serialize(SerializationContext& context, const Color& color);
71  inline bool Unserialize(SerializationContext& context, Color* color);
72 }
73 
74 std::ostream& operator<<(std::ostream& out, const Nz::Color& color);
75 
76 #include <Nazara/Core/Color.inl>
77 
78 #endif // NAZARA_COLOR_HPP
Core class that represents a color.
Definition: Color.hpp:18
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
static void ToXYZ(const Color &color, Vector3f *vec)
Converts RGB representation to XYZ.
Definition: Color.inl:547
Color operator+=(const Color &angles)
Adds the color to this.
Definition: Color.inl:144
bool Unserialize(SerializationContext &context, bool *value)
Unserializes a boolean.
Definition: Algorithm.inl:279
bool operator!=(const Color &angles) const
Checks whether the two colors are equal.
Definition: Color.inl:180
static Color FromHSV(float hue, float saturation, float value)
Converts HSV representation to RGB.
Definition: Color.inl:266
Core class that represents a string.
Definition: String.hpp:22
Color operator+(const Color &angles) const
Adds two colors together.
Definition: Color.inl:106
bool IsOpaque() const
Return true is the color has no degree of transparency.
Definition: Color.inl:76
static void ToCMYK(const Color &color, float *cyan, float *magenta, float *yellow, float *black)
Converts RGB representation to CMYK.
Definition: Color.inl:402
static void ToHSV(const Color &color, float *hue, float *saturation, float *value)
Converts RGB representation to HSV.
Definition: Color.inl:494
String ToString() const
Converts this to string.
Definition: Color.inl:86
Color operator*=(const Color &angles)
Multiplies the color to this.
Definition: Color.inl:156
Color operator*(const Color &angles) const
Multiplies two colors together.
Definition: Color.inl:125
Structure containing a serialization/unserialization context states.
Definition: SerializationContext.hpp:18
Color()
Constructs a Color object by default.
Definition: Color.inl:22
static Color FromHSL(UInt8 hue, UInt8 saturation, UInt8 lightness)
Converts HSL representation to RGB.
Definition: Color.inl:227
static Color FromXYZ(const Vector3f &vec)
Converts XYZ representation to RGB.
Definition: Color.inl:335
bool Serialize(SerializationContext &context, bool value)
Serializes a boolean.
Definition: Algorithm.inl:214
bool operator==(const Color &angles) const
Checks whether the two colors are equal.
Definition: Color.inl:168
static void ToCMY(const Color &color, float *cyan, float *magenta, float *yellow)
Converts RGB representation to CMYK.
Definition: Color.inl:386
static Color FromCMYK(float cyan, float magenta, float yellow, float black)
Converts CMYK representation to RGB.
Definition: Color.inl:211
static void ToHSL(const Color &color, UInt8 *hue, UInt8 *saturation, UInt8 *lightness)
Converts RGB representation to HSL.
Definition: Color.inl:435
static Color FromCMY(float cyan, float magenta, float yellow)
Converts CMY representation to RGB.
Definition: Color.inl:196