About
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.
ColorSwatchData*
const colorSwatchData = ColorSwatchData::Alloc(
doc,
false);
if (colorSwatchData == nullptr)
AutoFree<ColorSwatchData> freeData;
freeData.Assign(colorSwatchData);
const Int groupCount = colorSwatchData->GetGroupCount();
for (
Int i = 0;
i < groupCount; ++
i)
{
ColorSwatchGroup* group = colorSwatchData->GetGroupAtIndex(
i);
if (group)
{
const Int colorCount = group->GetColorCount();
for (
Int c = 0;
c < colorCount; ++
c)
{
if (group->GetColor(
c, color, &selected) && selected)
{
Material* const mat = Material::Alloc();
if (mat == nullptr)
const Vector rgb { color.
r, color.
g, color.
b };
doc->InsertMaterial(mat);
}
}
}
}
Py_ssize_t i
Definition: abstract.h:645
NONE
Definition: asset_browser.h:1
Py_UNICODE c
Definition: unicodeobject.h:1200
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
#define ConstDescID(...)
Definition: lib_description.h:592
@ MATERIAL_COLOR_COLOR
Definition: mmaterial.h:56
maxon::Bool Bool
Definition: ge_sys_math.h:46
maxon::Int Int
Definition: ge_sys_math.h:55
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
const char * doc
Definition: pyerrors.h:226
A color consisting of three components R, G, B and an alpha.
Definition: col4.h:16
Allocation/Deallocation
ColorSwatchGroups can be created using the usual tools. This is typically not needed.
- ColorSwatchGroup::Alloc(): Creates a new ColorSwatchGroup.
- ColorSwatchGroup::Free(): Deletes the given ColorSwatchGroup.
Access
ColorSwatchGroup elements are stored in a ColorSwatchData object. See ColorSwatchData Color Groups
- ColorSwatchData::GetGroupCount(): Returns the number of groups stored.
- ColorSwatchData::GetGroupAtIndex(): Returns the group stored at the given index.
- ColorSwatchData::AddGroup(): Adds a new group to the ColorSwatchData.
- ColorSwatchData::RemoveGroup(): Removes the group with the given index.
- ColorSwatchData::RemoveSelectedItems(): Removes selected groups and colors.
Selection
A ColorSwatchGroup can be selected:
- ColorSwatchGroup::IsGroupSelected(): Returns true if the group is selected.
- ColorSwatchGroup::SelectGroup(): Selects or deselects the group.
const Int groupCount = colorSwatchData->GetGroupCount();
for (
Int i = 0;
i < groupCount; ++
i)
{
const ColorSwatchGroup*
const group = colorSwatchData->GetGroupAtIndex(
i);
if (group == nullptr)
if (group->IsGroupSelected())
{
}
}
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
Name
A ColorSwatchGroup can be identified by a name:
- ColorSwatchGroup::GetName(): Returns the name of the group.
- ColorSwatchGroup::SetName(): Sets the name of the group.
ColorSwatchGroup* const group = colorSwatchData->AddGroup();
if (group == nullptr)
group->SetName("This is a new group");
Colors
A ColorSwatchGroup stores multiple colors and their selection state. The colors are obtained with:
- ColorSwatchGroup::GetColorCount(): Returns the number of stored colors.
- ColorSwatchGroup::GetColor(): Returns the color stored at the given index.
- ColorSwatchGroup::GetColors(): Copies the colors to the given maxon::BaseArray.
const Int colorCount = group->GetColorCount();
for (
Int c = 0;
c < colorCount; ++
c)
{
if (!group->GetColor(
c, color))
}
Colors can be edited with:
- ColorSwatchGroup::GetColorEditable(): Returns a pointer to the color at the given index.
- ColorSwatchGroup::SetColor(): Sets the color and selection status at the given index.
New colors are added with:
- ColorSwatchGroup::AddColor(): Adds the given color to the group.
- ColorSwatchGroup::AddColors(): Adds the colors stored in the given maxon::BaseArray to the group.
Random random;
{
group->AddColor(color, false);
}
group->SortColors();
Float64 Float
Definition: apibase.h:196
const char const char grammar * g
Definition: parsetok.h:52
The selection status of a color can be utilized with these functions:
- ColorSwatchGroup::IsColorSelected(): Returns true if the color stored at the given index is selected.
- ColorSwatchGroup::SelectColor(): Selects or deselects the color at the given index.
- ColorSwatchGroup::RemoveSelectedColors(): Removes selected colors from the group.
- ColorSwatchGroup::InvertSelection(): Switches the selection status for all colors.
Further utility functions are:
- ColorSwatchGroup::RemoveColor(): Removes the color stored at the given index.
- ColorSwatchGroup::HasDuplicatedColors(): Returns true if the group contains duplicated colors.
- ColorSwatchGroup::RemoveDuplicatedColors(): Removes duplicated colors from the group.
- ColorSwatchGroup::SortColors(): Sorts the colors based on their HSV values.
- ColorSwatchGroup::Reset(): Removes all colors.
- ColorSwatchGroup::Merge(): Merges the colors from the given ColorSwatchGroup.
Further Reading