Color Functions Manual
Along with the
ColorSwatchData
and
ColorSwatchGroup
types these utility functions were introduced to handle colors. The functions are defined in the
lib_colorchooser.h
header file.
These functions convert a given RGB color value to a formatted String :
// access MATERIAL_COLOR_COLOR parameter GeData data; if (!material-> GetParameter ( MATERIAL_COLOR_COLOR , data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
The following functions allow easy conversion of colors stored in different formats.
These functions convert float colors (0.0 ... 1.0) to 8-bit colors (0 .. 255):
These functions convert float colors (0.0 ... 1.0) to 16-bit colors (0 .. 65536):
Also, a Kelvin color temperature can be converted:
These functions are used to calculate color palettes based on the given input color.
// access MATERIAL_COLOR_COLOR parameter GeData data; if (!material-> GetParameter ( MATERIAL_COLOR_COLOR , data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
// the original color const 向量 color = data. GetVector (); maxon::BaseArray<Vector> results;
// calculate the complementary color if (! ColorHarmonyGetComplementary (color, false , results)) return maxon::UnknownError( MAXON_SOURCE_LOCATION );
// check if the result contains both the original and complementary color if (results. GetCount () != 2) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
// get the result color const 向量 complementaryColor = results[1];
// create new material with complementary color BaseMaterial * const newMaterial = BaseMaterial::Alloc ( Mmaterial ); if (newMaterial == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); newMaterial-> SetParameter ( MATERIAL_COLOR_COLOR , complementaryColor, DESCFLAGS_SET::NONE ); doc-> InsertMaterial (newMaterial);