Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Color.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
9class Color;
10
13
15class [[nodiscard]] Color
16{
17public:
19 Color() = default;
20 Color(const Color &inRHS) = default;
21 explicit constexpr Color(uint32 inColor) : mU32(inColor) { }
22 constexpr Color(uint8 inRed, uint8 inGreen, uint8 inBlue, uint8 inAlpha = 255) : r(inRed), g(inGreen), b(inBlue), a(inAlpha) { }
23 constexpr Color(ColorArg inRHS, uint8 inAlpha) : r(inRHS.r), g(inRHS.g), b(inRHS.b), a(inAlpha) { }
24
26 inline bool operator == (ColorArg inRHS) const { return mU32 == inRHS.mU32; }
27 inline bool operator != (ColorArg inRHS) const { return mU32 != inRHS.mU32; }
28
30 uint32 GetUInt32() const { return mU32; }
31
33 inline uint8 operator () (uint inIdx) const { JPH_ASSERT(inIdx < 4); return (&r)[inIdx]; }
34 inline uint8 & operator () (uint inIdx) { JPH_ASSERT(inIdx < 4); return (&r)[inIdx]; }
35
37 inline Vec4 ToVec4() const { return Vec4(r, g, b, a) / 255.0f; }
38
40 inline uint8 GetIntensity() const { return uint8((uint32(r) * 54 + g * 183 + b * 19) >> 8); }
41
43 static Color sGetDistinctColor(int inIndex);
44
46 static const Color sBlack;
47 static const Color sDarkRed;
48 static const Color sRed;
49 static const Color sDarkGreen;
50 static const Color sGreen;
51 static const Color sDarkBlue;
52 static const Color sBlue;
53 static const Color sYellow;
54 static const Color sPurple;
55 static const Color sCyan;
56 static const Color sOrange;
57 static const Color sDarkOrange;
58 static const Color sGrey;
59 static const Color sLightGrey;
60 static const Color sWhite;
61
62 union
63 {
65 struct
66 {
71 };
72 };
73};
74
75static_assert(is_trivial<Color>(), "Is supposed to be a trivial type!");
76
uint32_t uint32
Definition: Core.h:312
unsigned int uint
Definition: Core.h:309
#define JPH_NAMESPACE_END
Definition: Core.h:240
uint8_t uint8
Definition: Core.h:310
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
Class that holds an RGBA color with 8-bits per component.
Definition: Color.h:16
static const Color sDarkRed
Definition: Color.h:47
uint8 b
Blue channel.
Definition: Color.h:69
static const Color sBlack
Predefined colors.
Definition: Color.h:46
uint32 mU32
Combined value for red, green, blue and alpha.
Definition: Color.h:64
static const Color sBlue
Definition: Color.h:52
constexpr Color(ColorArg inRHS, uint8 inAlpha)
Definition: Color.h:23
static const Color sPurple
Definition: Color.h:54
static const Color sGreen
Definition: Color.h:50
static const Color sWhite
Definition: Color.h:60
Color()=default
Constructors.
uint8 a
Alpha channel.
Definition: Color.h:70
constexpr Color(uint32 inColor)
Definition: Color.h:21
static const Color sDarkOrange
Definition: Color.h:57
uint8 g
Green channel.
Definition: Color.h:68
static const Color sLightGrey
Definition: Color.h:59
static const Color sOrange
Definition: Color.h:56
static const Color sDarkBlue
Definition: Color.h:51
Color(const Color &inRHS)=default
Vec4 ToVec4() const
Convert to Vec4 with range [0, 1].
Definition: Color.h:37
uint8 r
Red channel.
Definition: Color.h:67
static const Color sDarkGreen
Definition: Color.h:49
static const Color sGrey
Definition: Color.h:58
static const Color sCyan
Definition: Color.h:55
uint32 GetUInt32() const
Convert to uint32.
Definition: Color.h:30
static const Color sRed
Definition: Color.h:48
static const Color sYellow
Definition: Color.h:53
uint8 GetIntensity() const
Get grayscale intensity of color.
Definition: Color.h:40
constexpr Color(uint8 inRed, uint8 inGreen, uint8 inBlue, uint8 inAlpha=255)
Definition: Color.h:22
Definition: Vec4.h:14