forked from louipc/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opennurbs_color.h
138 lines (114 loc) · 3.9 KB
/
opennurbs_color.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_COLOR_INC_)
#define OPENNURBS_COLOR_INC_
///////////////////////////////////////////////////////////////////////////////
//
// Class ON_Color
//
class ON_CLASS ON_Color
{
public:
// Constructors & Conversions - also default copy and assignment
static const ON_Color UnsetColor; // 0xFFFFFFFF
// Default is R = 0, G = 0, B = 0, A = 0
ON_Color();
// Sets A = 0
ON_Color(
int red, // ( 0 to 255 )
int green, // ( 0 to 255 )
int blue // ( 0 to 255 )
);
ON_Color(
int red, // ( 0 to 255 )
int green, // ( 0 to 255 )
int blue, // ( 0 to 255 )
int alpha // ( 0 to 255 ) (0 = opaque, 255 = transparent)
);
// Construct from Windows COLORREF
ON_Color(unsigned int);
// Conversion to Windows COLORREF
operator unsigned int() const;
/*
Description:
Call this function when the color is needed in a
Windows COLORREF format with alpha = 0;
Returns
A Windows COLOREF with alpha = 0.
*/
unsigned int WindowsRGB() const;
// < 0 if this < arg, 0 ir this==arg, > 0 if this > arg
int Compare( const ON_Color& ) const;
int Red() const; // ( 0 to 255 )
int Green() const; // ( 0 to 255 )
int Blue() const; // ( 0 to 255 )
int Alpha() const; // ( 0 to 255 ) (0 = opaque, 255 = transparent)
double FractionRed() const; // ( 0.0 to 1.0 )
double FractionGreen() const; // ( 0.0 to 1.0 )
double FractionBlue() const; // ( 0.0 to 1.0 )
double FractionAlpha() const; // ( 0.0 to 1.0 ) (0.0 = opaque, 1.0 = transparent)
void SetRGB(
int red, // red in range 0 to 255
int green, // green in range 0 to 255
int blue // blue in range 0 to 255
);
void SetFractionalRGB(
double red, // red in range 0.0 to 1.0
double green, // green in range 0.0 to 1.0
double blue // blue in range 0.0 to 1.0
);
void SetAlpha(
int alpha // alpha in range 0 to 255 (0 = opaque, 255 = transparent)
);
void SetFractionalAlpha(
double alpha // alpha in range 0.0 to 1.0 (0.0 = opaque, 1.0 = transparent)
);
void SetRGBA(
int red, // red in range 0 to 255
int green, // green in range 0 to 255
int blue, // blue in range 0 to 255
int alpha // alpha in range 0 to 255 (0 = opaque, 255 = transparent)
);
// input args
void SetFractionalRGBA(
double red, // red in range 0.0 to 1.0
double green, // green in range 0.0 to 1.0
double blue, // blue in range 0.0 to 1.0
double alpha // alpha in range 0.0 to 1.0 (0.0 = opaque, 1.0 = transparent)
);
// Hue() returns an angle in the range 0 to 2*pi
//
// 0 = red, pi/3 = yellow, 2*pi/3 = green,
// pi = cyan, 4*pi/3 = blue,5*pi/3 = magenta,
// 2*pi = red
double Hue() const;
// Returns 0.0 (gray) to 1.0 (saturated)
double Saturation() const;
// Returns 0.0 (black) to 1.0 (white)
double Value() const;
void SetHSV(
double h, // hue in radians 0 to 2*pi
double s, // satuation 0.0 = gray, 1.0 = saturated
double v // value
);
private:
// m_color is in Windows COLORREF format.
//
// 0xaabbggrr, rr= red component 0-255, etc. (little endian order)
// aa=0 means opaque, aa=255 means transparent.
unsigned int m_color;
};
#endif