Rhino C++ API  8.6
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ON_Color Class Reference

#include <opennurbs_color.h>

Public Types

enum  RGBA_byte_index : unsigned int { kRedByteIndex = 0, kGreenByteIndex = 1, kBlueByteIndex = 2, kAlphaByteIndex = 3 }
 
enum  RGBA_shift : unsigned int
 
enum  TextFormat : unsigned char {
  TextFormat::Unset = 0, TextFormat::FractionalRGB = 1, TextFormat::FractionalRGBa = 2, TextFormat::FractionalRGBA = 3,
  TextFormat::DecimalRGB = 4, TextFormat::DecimalRGBa = 5, TextFormat::DecimalRGBA = 6, TextFormat::HexadecimalRGB = 7,
  TextFormat::HexadecimalRGBa = 8, TextFormat::HexadecimalRGBA = 9, TextFormat::HSV = 10, TextFormat::HSVa = 11,
  TextFormat::HSVA = 12, TextFormat::HashRGB = 13, TextFormat::HashRGBa = 14, TextFormat::HashRGBA = 15
}
 

Public Member Functions

 ON_Color ()=default
 
 ON_Color (const ON_Color &)=default
 
 ON_Color (int red, int green, int blue)
 Sets A = 0. More...
 
 ON_Color (int red, int green, int blue, int alpha)
 
 ON_Color (unsigned int colorref)
 
 ~ON_Color ()=default
 
int Alpha () const
 ( 0 to 255 ) (0 = opaque, 255 = transparent) More...
 
int Blue () const
 ( 0 to 255 ) More...
 
int Compare (const ON_Color &) const
 < 0 if this < arg, 0 ir this==arg, > 0 if this > arg More...
 
double FractionAlpha () const
 ( 0.0 to 1.0 ) (0.0 = opaque, 1.0 = transparent) More...
 
double FractionBlue () const
 ( 0.0 to 1.0 ) More...
 
double FractionGreen () const
 ( 0.0 to 1.0 ) More...
 
double FractionRed () const
 ( 0.0 to 1.0 ) More...
 
int Green () const
 ( 0 to 255 ) More...
 
double Hue () const
 
bool IsSet () const
 
Returns
True if this color is not equal to ON_Color::Unset.
More...
 
bool IsUnset () const
 
Returns
True if this color is equal to ON_Color::Unset.
More...
 
 operator unsigned int () const
 Conversion to Windows COLORREF in little endian RGBA order. More...
 
ON_Coloroperator= (const ON_Color &)=default
 
int Red () const
 ( 0 to 255 ) More...
 
double Saturation () const
 Returns 0.0 (gray) to 1.0 (saturated) More...
 
void SetAlpha (int alpha)
 
void SetFractionalAlpha (double alpha)
 
void SetFractionalRGB (double red, double green, double blue)
 
void SetFractionalRGBA (double red, double green, double blue, double alpha)
 input args More...
 
void SetHSV (double h, double s, double v)
 Specify a color using HSV (hue, saturation, value). If h, s or v are not in the open interval (ON_UNSET_FLOAT,ON_UNSET_POSITIVE_FLOAT), then this color is set to ON_Color::UnsetColor. More...
 
void SetRGB (int red, int green, int blue)
 
void SetRGBA (int red, int green, int blue, int alpha)
 
const ON_wString ToString (ON_Color::TextFormat format, wchar_t separator, bool bFormatUnsetColor) const
 
const ON_wString ToString (ON_Color::TextFormat format, wchar_t separator, bool bFormatUnsetColor, class ON_TextLog &ignored_parameter) const
 
void ToText (ON_Color::TextFormat format, wchar_t separator, bool bFormatUnsetColor, class ON_TextLog &text_log) const
 
double Value () const
 Returns 0.0 (black) to 1.0 (white) More...
 
unsigned int WindowsRGB () const
 

Static Public Member Functions

static const ON_Color FromHueInRadians (double hue_in_radians)
 Get the saturated color with the specified hue. More...
 
static const ON_Color RandomColor ()
 
static const ON_Color RandomColor (ON__UINT32 seed)
 
static const ON_Color RandomColor (ON__UINT32 seed, ON_Interval hue_range, ON_Interval saturation_range, ON_Interval value_range)
 
static const ON_Color RandomColor (ON_Interval hue_range, ON_Interval saturation_range, ON_Interval value_range)
 

Static Public Attributes

static const ON_Color Black
 0x00000000u More...
 
static const ON_Color Gray105
 R = G = B = 105 (medium dark) More...
 
static const ON_Color Gray126
 R = G = B = 128 (medium) More...
 
static const ON_Color Gray160
 R = G = B = 160 (medium light) More...
 
static const ON_Color Gray230
 R = G = B = 230 (light) More...
 
static const ON_Color Gray250
 R = G = B = 250 (lightest) More...
 
static const ON_Color SaturatedBlue
 0x00FF0000u on little endan, 0x0000FF00u on big endian More...
 
static const ON_Color SaturatedCyan
 0x00FFFF00u on little endan, 0x00FFFF00u on big endian More...
 
static const ON_Color SaturatedGold
 0x0000BFFFu on little endan, 0xFFBF0000u on big endian More...
 
static const ON_Color SaturatedGreen
 0x0000FF00u on little endan, 0x00FF0000u on big endian More...
 
static const ON_Color SaturatedMagenta
 0x00FF00FFu on little endan, 0xFF00FF00u on big endian More...
 
static const ON_Color SaturatedRed
 0x000000FFu on little endan, 0xFF000000u on big endian More...
 
static const ON_Color SaturatedYellow
 0x0000FFFFu on little endan, 0xFFFF0000u on big endian More...
 
static const ON_Color UnsetColor
 0xFFFFFFFFu More...
 
static const ON_Color White
 0x00FFFFFFu on little endan, 0xFFFFFF00u on big endian More...
 

Detailed Description

Copyright (c) 1993-2022 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. Class ON_Color

Member Enumeration Documentation

◆ RGBA_byte_index

enum ON_Color::RGBA_byte_index : unsigned int

If you need to use byte indexing to convert RGBA components to and from an unsigned int ON_Color value and want your code to work on both little and big endian computers, then use the RGBA_byte_index enum.

unsigned int u; unsigned char* rgba = rbga[ON_Color::kRedByteIndex] = red value 0 to 255. rbga[ON_Color::kGreenByteIndex] = green value 0 to 255. rbga[ON_Color::kBlueByteIndex] = blue value 0 to 255. rbga[ON_Color::kAlphaByteIndex] = alpha value 0 to 255. ON_Color color = u;

Enumerator
kRedByteIndex 

same for both little and big endian computers.

kGreenByteIndex 
kBlueByteIndex 
kAlphaByteIndex 

◆ RGBA_shift

enum ON_Color::RGBA_shift : unsigned int

If you need to use shifting to convert RGBA components to and from an unsigned int ON_COlor value and you want your code to work on both little and big endian computers, use the RGBA_shift enum.

unsigned int u = 0; u |= ((((unsigned int)red) & 0xFFU) << ON_Color::RGBA_shift::kRedShift); u |= ((((unsigned int)green) & 0xFFU) << ON_Color::RGBA_shift::kGreenShift); u |= ((((unsigned int)blue) & 0xFFU) << ON_Color::RGBA_shift::kBlueShift); u |= ((((unsigned int)alpha) & 0xFFU) << ON_Color::RGBA_shift::kAlphaShift); ON_Color color = u;

◆ TextFormat

enum ON_Color::TextFormat : unsigned char
strong
Enumerator
Unset 

summary> Indicates no format has been selected. Empty text is created. /summary> summary> red,green,blue as floating point values from 0.0 to 1.0. /summary>

FractionalRGB 

summary> red,green,blue as floating point values from 0.0 to 1.0. alpha is appended if it is not zero. /summary>

FractionalRGBa 

summary> red,green,blue,alpha as floating point values from 0.0 to 1.0. /summary>

FractionalRGBA 

summary> red,green,blue as decimal integers from 0 to 255. /summary>

DecimalRGB 

summary> red,green,blue as decimal integers from 0 to 255. alpha is appended if it is not zero. /summary>

DecimalRGBa 

summary> red,green,blue,alpha as decimal integers from 0 to 255. /summary>

DecimalRGBA 

summary> red,green,blue as hexadecimal integers from 0 to 255. /summary>

HexadecimalRGB 

summary> red,green,blue as hexadecimal integers from 0 to 255. alpha is appended if it is not zero. /summary>

HexadecimalRGBa 

summary> red,green,blue,alpha as hexadecimal integers from 0 to 255. /summary>

HexadecimalRGBA 

summary> hue (0 to 2pi), saturation (0 to 1), value (0 to 1) as floating point values. /summary>

HSV 

summary> hue (0 to 2pi), saturation (0 to 1), value (0 to 1) as floating point values. alpha (0 to 1) is appended if it is not zero. /summary>

HSVa 

summary> hue (0 to 2pi), saturation (0 to 1), value (0 to 1), alpha (0 to 1) as floating point values. /summary>

HSVA 

summary> red,green,blue as two hex digit hexadecimal numbers preceded with a hash. (#RRGGBB) /summary>

HashRGB 

summary> red,green,blue as two hex digit hexadecimal numbers preceded with a hash. alpha is appended if it is not zero. (#RRGGBBaa) /summary>

HashRGBa 

summary> red,green,blue,alpha as two hex digit hexadecimal numbers preceded with a hash. (#RRGGBBAA). /summary>

HashRGBA 

Constructor & Destructor Documentation

◆ ON_Color() [1/5]

ON_Color::ON_Color ( )
default

◆ ~ON_Color()

ON_Color::~ON_Color ( )
default

◆ ON_Color() [2/5]

ON_Color::ON_Color ( const ON_Color )
default

◆ ON_Color() [3/5]

ON_Color::ON_Color ( int  red,
int  green,
int  blue 
)

Sets A = 0.

Parameters
red( 0 to 255 )
green( 0 to 255 )
blue( 0 to 255 )

◆ ON_Color() [4/5]

ON_Color::ON_Color ( int  red,
int  green,
int  blue,
int  alpha 
)
Parameters
red( 0 to 255 )
green( 0 to 255 )
blue( 0 to 255 )
alpha( 0 to 255 ) (0 = opaque, 255 = transparent)

◆ ON_Color() [5/5]

ON_Color::ON_Color ( unsigned int  colorref)

Parameters: colorref - [in] Windows COLORREF in little endian RGBA order.

Member Function Documentation

◆ Alpha()

int ON_Color::Alpha ( ) const

( 0 to 255 ) (0 = opaque, 255 = transparent)

◆ Blue()

int ON_Color::Blue ( ) const

( 0 to 255 )

◆ Compare()

int ON_Color::Compare ( const ON_Color ) const

< 0 if this < arg, 0 ir this==arg, > 0 if this > arg

◆ FractionAlpha()

double ON_Color::FractionAlpha ( ) const

( 0.0 to 1.0 ) (0.0 = opaque, 1.0 = transparent)

◆ FractionBlue()

double ON_Color::FractionBlue ( ) const

( 0.0 to 1.0 )

◆ FractionGreen()

double ON_Color::FractionGreen ( ) const

( 0.0 to 1.0 )

◆ FractionRed()

double ON_Color::FractionRed ( ) const

( 0.0 to 1.0 )

◆ FromHueInRadians()

static const ON_Color ON_Color::FromHueInRadians ( double  hue_in_radians)
static

Get the saturated color with the specified hue.

Parameters
hue_in_radians0 = red, pi/3 = yellow, 2pi/3 = green, pi = cyan, 4pi/3 = blue, 5pi/3 = magenta, 2pi = red
Returns
A saturated color with the specified hue.

◆ Green()

int ON_Color::Green ( ) const

( 0 to 255 )

◆ Hue()

double ON_Color::Hue ( ) const

Hue() returns an angle in radians in the range 0 to 2*pi. 0 = red, pi/3 = yellow, 2pi/3 = green, pi = cyan, 4pi/3 = blue, 5pi/3 = magenta, 2pi = red

◆ IsSet()

bool ON_Color::IsSet ( ) const

Returns
True if this color is not equal to ON_Color::Unset.

◆ IsUnset()

bool ON_Color::IsUnset ( ) const

Returns
True if this color is equal to ON_Color::Unset.

◆ operator unsigned int()

ON_Color::operator unsigned int ( ) const

Conversion to Windows COLORREF in little endian RGBA order.

◆ operator=()

ON_Color& ON_Color::operator= ( const ON_Color )
default

◆ RandomColor() [1/4]

static const ON_Color ON_Color::RandomColor ( )
static

Returns: A random color.

◆ RandomColor() [2/4]

static const ON_Color ON_Color::RandomColor ( ON__UINT32  seed)
static

Returns: A color generated from seed. The color for a given seed will always be the same.

◆ RandomColor() [3/4]

static const ON_Color ON_Color::RandomColor ( ON__UINT32  seed,
ON_Interval  hue_range,
ON_Interval  saturation_range,
ON_Interval  value_range 
)
static

Parameters: seed - [in] hue_range - [in] range of hues. Use ON_Interval::ZeroToTwoPi for all hues. 0 = red, pi/3 = yellow, 2pi/3 = green, pi = cyan, 4pi/3 = blue, 5pi/3 = magenta, 2pi = red saturation_range - [in] range of saturations. Use ON_Interval::ZeroToOne for all saturations. value_range - [in] range of values. Use ON_Interval::ZeroToOne for all values. Returns: A color generated from seed. The color for a given seed will always be the same.

◆ RandomColor() [4/4]

static const ON_Color ON_Color::RandomColor ( ON_Interval  hue_range,
ON_Interval  saturation_range,
ON_Interval  value_range 
)
static

Parameters: seed - [in] hue_range - [in] range of hues. Use ON_Interval::ZeroToTwoPi for all hues. 0 = red, pi/3 = yellow, 2pi/3 = green, pi = cyan, 4pi/3 = blue, 5pi/3 = magenta, 2pi = red saturation_range - [in] range of saturations. Use ON_Interval::ZeroToOne for all saturations. value_range - [in] range of values. Use ON_Interval::ZeroToOne for all values. Returns: A color generated from seed. The color for a given seed will always be the same.

◆ Red()

int ON_Color::Red ( ) const

( 0 to 255 )

◆ Saturation()

double ON_Color::Saturation ( ) const

Returns 0.0 (gray) to 1.0 (saturated)

◆ SetAlpha()

void ON_Color::SetAlpha ( int  alpha)
Parameters
alphaalpha in range 0 to 255 (0 = opaque, 255 = transparent)

◆ SetFractionalAlpha()

void ON_Color::SetFractionalAlpha ( double  alpha)
Parameters
alphaalpha in range 0.0 to 1.0 (0.0 = opaque, 1.0 = transparent)

◆ SetFractionalRGB()

void ON_Color::SetFractionalRGB ( double  red,
double  green,
double  blue 
)
Parameters
redred in range 0.0 to 1.0
greengreen in range 0.0 to 1.0
blueblue in range 0.0 to 1.0

◆ SetFractionalRGBA()

void ON_Color::SetFractionalRGBA ( double  red,
double  green,
double  blue,
double  alpha 
)

input args

Parameters
redred in range 0.0 to 1.0
greengreen in range 0.0 to 1.0
blueblue in range 0.0 to 1.0
alphaalpha in range 0.0 to 1.0 (0.0 = opaque, 1.0 = transparent)

◆ SetHSV()

void ON_Color::SetHSV ( double  h,
double  s,
double  v 
)

Specify a color using HSV (hue, saturation, value). If h, s or v are not in the open interval (ON_UNSET_FLOAT,ON_UNSET_POSITIVE_FLOAT), then this color is set to ON_Color::UnsetColor.

Parameters
hhue in radians 0 = red, pi/3 = yellow, 2pi/3 = green, pi = cyan, 4pi/3 = blue, 5pi/3 = magenta, 2pi = red
ssatuation 0.0 = gray, 1.0 = saturated
vvalue 0=black, 1.0 = bright

summary> Formats used by ON_Color::ToText() and ON_Color::ToString(). /summary>

◆ SetRGB()

void ON_Color::SetRGB ( int  red,
int  green,
int  blue 
)
Parameters
redred in range 0 to 255
greengreen in range 0 to 255
blueblue in range 0 to 255

◆ SetRGBA()

void ON_Color::SetRGBA ( int  red,
int  green,
int  blue,
int  alpha 
)
Parameters
redred in range 0 to 255
greengreen in range 0 to 255
blueblue in range 0 to 255
alphaalpha in range 0 to 255 (0 = opaque, 255 = transparent)

◆ ToString() [1/2]

const ON_wString ON_Color::ToString ( ON_Color::TextFormat  format,
wchar_t  separator,
bool  bFormatUnsetColor 
) const

Parameters: format - [in] separator - [in] Separarates the values. 0 to use UNICODE comma. (Ignored when the format is HashRGB*.) character to separate numbers (unicode code point - UTF-16 surrogate pairs not supported) pass 0 for default. bFormatUnsetColor - [in] If true, ON_Color::UnsetColor will return "UnsetColor". Otherwise ON_Color::UnsetColor will return the empty string.

◆ ToString() [2/2]

const ON_wString ON_Color::ToString ( ON_Color::TextFormat  format,
wchar_t  separator,
bool  bFormatUnsetColor,
class ON_TextLog ignored_parameter 
) const

MISTAKE - BUT IT SNUCK INTO THE SDK - IGNORE

◆ ToText()

void ON_Color::ToText ( ON_Color::TextFormat  format,
wchar_t  separator,
bool  bFormatUnsetColor,
class ON_TextLog text_log 
) const

Parameters: format - [in] If format is ON_Color::TextFormat::Unset, then text_log.ColorFormat is used. separator - [in] 0 to use UNICODE comma. (Ignored when the format is HashRGB*.) character to separate numbers (unicode code point - UTF-16 surrogate pairs not supported) pass 0 for default. bFormatUnsetColor - [in] If true, ON_Color::UnsetColor will return "UnsetColor". Otherwise ON_Color::UnsetColor will return the empty string. text_log - [in] destination of the text.

◆ Value()

double ON_Color::Value ( ) const

Returns 0.0 (black) to 1.0 (white)

◆ WindowsRGB()

unsigned int ON_Color::WindowsRGB ( ) 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.

Member Data Documentation

◆ Black

const ON_Color ON_Color::Black
static

0x00000000u

◆ Gray105

const ON_Color ON_Color::Gray105
static

R = G = B = 105 (medium dark)

◆ Gray126

const ON_Color ON_Color::Gray126
static

R = G = B = 128 (medium)

◆ Gray160

const ON_Color ON_Color::Gray160
static

R = G = B = 160 (medium light)

◆ Gray230

const ON_Color ON_Color::Gray230
static

R = G = B = 230 (light)

◆ Gray250

const ON_Color ON_Color::Gray250
static

R = G = B = 250 (lightest)

◆ m_color

unsigned int ON_Color::m_color = 0

On little endian (Intel) computers, m_color has the same byte order as Windows COLORREF values. On little endian computers, m_color = 0xaabbggrr as an unsigned int value. On big endian computers, m_color = 0xrrggbbaa as an unsigned int value rr = red component 0-255 gg = grean component 0-255 bb = blue component 0-255 aa = alpha 0-255. 0 means opaque, 255 means transparent.

◆ m_RGBA

unsigned char ON_Color::m_RGBA[4]

m_colorComponent is a 4 unsigned byte array in RGBA order red component = m_RGBA[ON_Color::RGBA_byte::kRed] grean component = m_RGBA[ON_Color::RGBA_byte::kGreen] blue component = m_RGBA[ON_Color::RGBA_byte::kBlue] alpha component = m_RGBA[ON_Color::RGBA_byte::kAlpha]

◆ SaturatedBlue

const ON_Color ON_Color::SaturatedBlue
static

0x00FF0000u on little endan, 0x0000FF00u on big endian

◆ SaturatedCyan

const ON_Color ON_Color::SaturatedCyan
static

0x00FFFF00u on little endan, 0x00FFFF00u on big endian

◆ SaturatedGold

const ON_Color ON_Color::SaturatedGold
static

0x0000BFFFu on little endan, 0xFFBF0000u on big endian

◆ SaturatedGreen

const ON_Color ON_Color::SaturatedGreen
static

0x0000FF00u on little endan, 0x00FF0000u on big endian

◆ SaturatedMagenta

const ON_Color ON_Color::SaturatedMagenta
static

0x00FF00FFu on little endan, 0xFF00FF00u on big endian

◆ SaturatedRed

const ON_Color ON_Color::SaturatedRed
static

0x000000FFu on little endan, 0xFF000000u on big endian

◆ SaturatedYellow

const ON_Color ON_Color::SaturatedYellow
static

0x0000FFFFu on little endan, 0xFFFF0000u on big endian

◆ UnsetColor

const ON_Color ON_Color::UnsetColor
static

0xFFFFFFFFu

◆ White

const ON_Color ON_Color::White
static

0x00FFFFFFu on little endan, 0xFFFFFF00u on big endian