ColorSwatchGroup Class Reference

#include <lib_colorchooser.h>

Detailed Description

This class represents a Color Swatch Group.

Since
R18

Public Member Functions

Bool Merge (ColorSwatchGroup *group)
 
Bool CopyFrom (ColorSwatchGroup *group)
 
String GetName () const
 
void SetName (String name)
 
Int GetColorCount () const
 
Bool GetColor (Int index, maxon::ColorA &color, Bool *selected=nullptr) const
 
maxon::ColorAGetColorEditable (Int index, Bool *selected=nullptr)
 
Bool GetColors (ColorAlphaArray &colors, Bool selectedOnly=false) const
 
Bool SetColor (Int index, const maxon::ColorA &color, Int selected=-1)
 
Int AddColor (const maxon::ColorA &color, Bool selected=false, Int insertAt=-1)
 
Int AddColors (const ColorAlphaArray &colors, Bool selected=false, Bool merge=true, Int insertAt=-1)
 
void Reset ()
 
Bool RemoveColor (Int index, Int removeCount=1)
 
Bool RemoveSelectedColors ()
 
Bool HasDuplicatedColors () const
 
Bool RemoveDuplicatedColors ()
 
void InvertSelection ()
 
Bool SelectColor (Int index, Bool selected)
 
Bool IsColorSelected (Int index) const
 
void SelectGroup (Bool select)
 
Bool IsGroupSelected () const
 
void SortColors ()
 

Private Member Functions

 ColorSwatchGroup ()
 
 ~ColorSwatchGroup ()
 

Alloc/Free

static ColorSwatchGroupAlloc (const String &name=String(), Bool selected=false, const ColorAlphaArray &colors=ColorAlphaArray())
 
static void Free (ColorSwatchGroup *&p)
 

Constructor & Destructor Documentation

◆ ColorSwatchGroup()

ColorSwatchGroup ( )
private

◆ ~ColorSwatchGroup()

~ColorSwatchGroup ( )
private

Member Function Documentation

◆ Alloc()

static ColorSwatchGroup* Alloc ( const String name = String(),
Bool  selected = false,
const ColorAlphaArray colors = ColorAlphaArray() 
)
static

Allocates a swatch group. Destroy the allocated swatch group with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in]nameThe name of the group.
[in]selectedThe selection state of the group.
[in]colorsColors to fill the group with.
Returns
The allocated swatch group, or nullptr if the allocation failed.

◆ Free()

static void Free ( ColorSwatchGroup *&  p)
static

Destructs swatch group allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in]pThe swatch group to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ Merge()

Bool Merge ( ColorSwatchGroup group)

Merges colors from group.

Parameters
[in]groupThe group to merge colors from.
Returns
true if successful, otherwise false.

◆ CopyFrom()

Bool CopyFrom ( ColorSwatchGroup group)

Copies a group.

Parameters
[in]groupThe group to copy from.
Returns
true if successful, otherwise false.

◆ GetName()

String GetName ( ) const

Returns the group name.

Returns
The group name.

◆ SetName()

void SetName ( String  name)

Sets the group name.

Parameters
[in]nameThe new group name.

◆ GetColorCount()

Int GetColorCount ( ) const

Returns the number of colors stored in the group.

Returns
The number of colors stored in the group.

◆ GetColor()

Bool GetColor ( Int  index,
maxon::ColorA color,
Bool selected = nullptr 
) const

Returns the color at the given index.

Parameters
[in]indexThe index of the color. Must be 0 <= index < GetColorCount().
[out]colorThe color value.
[out]selectedOptionally this gets the selection status of the color. Set to nullptr to ignore.
Returns
true if the color could be accessed, otherwise false.

◆ GetColorEditable()

maxon::ColorA* GetColorEditable ( Int  index,
Bool selected = nullptr 
)

Returns the color at the given index.

Parameters
[in]indexThe index of the color. Must be 0 <= index < GetColorCount().
[out]selectedOptionally this gets the selection status of the color. Set to nullptr to ignore.
Returns
A pointer to the color value or nullptr. Can be edited without side effects.

◆ GetColors()

Bool GetColors ( ColorAlphaArray colors,
Bool  selectedOnly = false 
) const

Gets the colors stored in this group.

Parameters
[in]colorsThe list to add the colors to. Stored data is preserved.
[in]selectedOnlySet to true to get only the selected colors, set to false to get all colors.
Returns
true if successful, otherwise false.

◆ SetColor()

Bool SetColor ( Int  index,
const maxon::ColorA color,
Int  selected = -1 
)

Edits the color at the given index.

Parameters
[in]indexThe index of the color. Must be 0 <= index < GetColorCount().
[in]colorThe new color value.
[in]selectedThe new selection status. Possible values are: -1 = keep current selection status unchanged, 0 = unselect, 1 = select.
Returns
true if the color could be changed, otherwise false.

◆ AddColor()

Int AddColor ( const maxon::ColorA color,
Bool  selected = false,
Int  insertAt = -1 
)

Adds a new color to the group.

Parameters
[in]colorThe color value.
[in]selectedThe initial selection state of color.
[in]insertAtThe index of the new color (the list size will increase and the existing elements are moved) or -1 to add it to the end of the list.
Returns
The index of the new color or -1 if an error occurred.

◆ AddColors()

Int AddColors ( const ColorAlphaArray colors,
Bool  selected = false,
Bool  merge = true,
Int  insertAt = -1 
)

Adds colors to this group.

Parameters
[in]colorsThe list with colors to add to.
[in]selectedThe initial selection state of added colors.
[in]mergeSet to true to merge the colors with current group colors. Use insertAt to define the insertion position. Set to false to replace the content of the group.
[in]insertAtIf merge is set to true, this is the index to insert the new colors.
Returns
The index of the new color or -1 if error.

◆ Reset()

void Reset ( )

Removes all colors in this group.

◆ RemoveColor()

Bool RemoveColor ( Int  index,
Int  removeCount = 1 
)

Removes the color at the given index.

Parameters
[in]indexThe index of the color. Must be 0 <= index < GetColorCount().
[in]removeCountNumber of colors to be removed. If removeCnt is higher than what is available at position RemoveColor() will succeed, but will remove only the number of available colors.
Returns
true if the color was successfully removed, otherwise false.

◆ RemoveSelectedColors()

Bool RemoveSelectedColors ( )

Removes all selected colors in the group.

Returns
true if selected colors were successfully removed, otherwise false.

◆ HasDuplicatedColors()

Bool HasDuplicatedColors ( ) const

Checks if the group has duplicated colors.

Returns
true if duplicated colors were found, otherwise false.

◆ RemoveDuplicatedColors()

Bool RemoveDuplicatedColors ( )

Removes duplicated colors in the group.

Returns
true if duplicated colors were found and removed, otherwise false.

◆ InvertSelection()

void InvertSelection ( )

Inverts the selected colors, so the currently selected colors will be unselected and vice-versa.

◆ SelectColor()

Bool SelectColor ( Int  index,
Bool  selected 
)

Selects/unselects the color at the given index.

Parameters
[in]indexThe index of the color. Must be 0 <= index < GetColorCount().
[in]selectedThe new selection status.
Returns
true if the color selection status was successfully set, otherwise false.

◆ IsColorSelected()

Bool IsColorSelected ( Int  index) const

Checks if the color at the given index is selected.

Parameters
[in]indexThe index of the color. Must be 0 <= index < GetColorCount().
Returns
true if the color is selected, false if it is unselected or index is invalid.

◆ SelectGroup()

void SelectGroup ( Bool  select)

Selects the group. This will select/unselect the group icon and all colors in the group.

Parameters
[in]selectThe new selection status.

◆ IsGroupSelected()

Bool IsGroupSelected ( ) const

Checks if the group is selected.

Returns
true if the group is selected, otherwise false.

◆ SortColors()

void SortColors ( )

Sorts colors in the group based in their HSV values.