ColorSwatchGroup Manual

内容表

关于

A ColorSwatchGroup stores multiple colors as maxon::ColorA . The group itself and the colors can be selected. ColorSwatchGroup elements are stored and handled using ColorSwatchData objects. The class is defined in the lib_colorchooser.h header file.

// This example loops through all colors of all color groups of the given BaseDocument. // For each selected color a new material is created.

// load document color swatches ColorSwatchData * const colorSwatchData = ColorSwatchData::Alloc (doc, false ); if (colorSwatchData == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// AutoFree takes ownership AutoFree<ColorSwatchData> freeData; freeData. 赋值 (colorSwatchData);

// loop through groups const Int groupCount = colorSwatchData-> GetGroupCount ();

for ( Int i = 0; i < groupCount; ++i) { ColorSwatchGroup * group = colorSwatchData-> GetGroupAtIndex (i); if (group) { // loop through colors const Int colorCount = group-> GetColorCount ();
for ( Int c = 0; c < colorCount; ++c) { maxon::ColorA color; Bool selected = false ;

// get color and check if it is selected if (group-> GetColor (c, color, &selected) && selected) { // create new material 材质 * const mat = Material::Alloc (); if (mat == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// use color const 向量 rgb { color. r , color. g , color. b }; mat-> SetParameter ( MATERIAL_COLOR_COLOR , rgb, DESCFLAGS_SET::NONE ); doc-> InsertMaterial (mat); } } } }

Allocation/Deallocation

ColorSwatchGroups can be created using the usual tools. This is typically not needed.

Access

ColorSwatchGroup elements are stored in a ColorSwatchData object. See ColorSwatchData Color Groups

Selection

A ColorSwatchGroup can be selected:

// This example loops through all groups and prints the names of the selected groups. const Int groupCount = colorSwatchData-> GetGroupCount (); for ( Int i = 0; i < groupCount; ++i) { const ColorSwatchGroup * const group = colorSwatchData-> GetGroupAtIndex (i); if (group == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// check if a group could be accessed // and if that group is selected if (group-> IsGroupSelected ()) { ApplicationOutput ( "Group " + group-> GetName () + " is selected." ); } }

名称

A ColorSwatchGroup can be identified by a name:

// This example adds a new color group. ColorSwatchGroup * const group = colorSwatchData-> AddGroup (); if (group == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); group-> SetName ( "This is a new group" );

Colors

A ColorSwatchGroup stores multiple colors and their selection state. The colors are obtained with:

// This example prints the values of all colors of the given group. const Int colorCount = group-> GetColorCount (); for ( Int c = 0; c < colorCount; ++c) { maxon::ColorA color;

// access the color with the index 'c' if (!group-> GetColor (c, color)) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); ApplicationOutput ( "Color: @" , color); }

Colors can be edited with:

New colors are added with:

// This example adds ten random colors to the given group. Random random; for ( Int c = 0; c < 10; ++c) { const maxon::Float r = random. Get01 (); const maxon::Float g = random. Get01 (); const maxon::Float b = random. Get01 (); const maxon::ColorA color(r, g, b, 1.0); group-> AddColor (color, false ); } group-> SortColors ();

The selection status of a color can be utilized with these functions:

Further utility functions are:

延伸阅读

maxon::Col4::b
T b
定义: col4.h:35
Int
maxon::Int Int
定义: ge_sys_math.h:62
ColorSwatchData
定义: lib_colorchooser.h:405
AutoFree::Assign
void Assign(TYPE *p)
定义: ge_autoptr.h:225
maxon::Col4::r
T r
定义: col4.h:33
AutoFree
定义: ge_autoptr.h:151
ColorSwatchGroup::GetColorCount
Int GetColorCount() const
ColorSwatchGroup::GetName
String GetName() const
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
maxon::Float
Float64 Float
定义: apibase.h:193
ColorSwatchGroup::SetName
void SetName(String name)
DESCFLAGS_SET::NONE
@ NONE
None.
ColorSwatchData::GetGroupAtIndex
ColorSwatchGroup * GetGroupAtIndex(Int index, SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT)
maxon::Col4
A color consisting of three components R, G, B and an alpha.
定义: col4.h:14
BaseDocument::InsertMaterial
void InsertMaterial(BaseMaterial *mat, BaseMaterial *pred=nullptr, Bool checknames=false)
ColorSwatchGroup::SortColors
void SortColors()
Sorts colors in the group based in their HSV values.
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
maxon::Vec3< maxon::Float64, 1 >
材质
定义: c4d_basematerial.h:240
Material::Alloc
static Material * Alloc()
ColorSwatchGroup::IsGroupSelected
Bool IsGroupSelected() const
ColorSwatchData::Alloc
static ColorSwatchData * Alloc(BaseDocument *doc=nullptr, Bool global=false)
ColorSwatchGroup
定义: lib_colorchooser.h:217
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
maxon::Col4::g
T g
定义: col4.h:34
ColorSwatchData::GetGroupCount
Int GetGroupCount(SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT) const
Random::Get01
Float Get01(void)
ColorSwatchGroup::AddColor
Int AddColor(const maxon::ColorA &color, Bool selected=false, Int insertAt=-1)
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
MATERIAL_COLOR_COLOR
@ MATERIAL_COLOR_COLOR
定义: mmaterial.h:56
Random
定义: c4d_tools.h:811
ColorSwatchData::AddGroup
ColorSwatchGroup * AddGroup(SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT, const String &name=String(), Bool selected=false, Int insertAt=-1, const ColorAlphaArray &colors=ColorAlphaArray())
ColorSwatchGroup::GetColor
Bool GetColor(Int index, maxon::ColorA &color, Bool *selected=nullptr) const

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1