Last active
March 17, 2017 11:51
-
-
Save fwilleke80/9954c4b0c504d3c3ae239373b689b0d3 to your computer and use it in GitHub Desktop.
[C4D] Dynamic descriptions. Add description elements to an existing description at runtime by calling these functions from NodeData::GetDDescription().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "c4d-dynamicdescription.h" | |
Bool IsSingleID(const DescID &id, const DescID *singleid) | |
{ | |
return !singleid || id.IsPartOf(*singleid, NULL); | |
} | |
Bool DescriptionAddCycle(Description *description, Int32 id, Int32 groupId, const String &name, const BaseContainer &cycleItems, BaseContainer *cycleIcons, Int32 defaultValue) | |
{ | |
if (!description) | |
return false; | |
const DescID *singleId = description->GetSingleDescID(); | |
if (!singleId || IsSingleID(id, singleId)) | |
{ | |
BaseContainer params = GetCustomDataTypeDefault(DTYPE_LONG); | |
params.SetString(DESC_NAME, name); | |
params.SetInt32(DESC_DEFAULT, defaultValue); | |
params.SetInt32(DESC_ANIMATE, DESC_ANIMATE_ON); | |
params.SetInt32(DESC_CUSTOMGUI, CUSTOMGUI_CYCLE); | |
params.SetContainer(DESC_CYCLE, cycleItems); | |
if (cycleIcons) | |
params.SetContainer(DESC_CYCLEICONS, *cycleIcons); | |
return description->SetParameter(DescLevel(id, DTYPE_LONG, 0), params, groupId); | |
} | |
return true; | |
} | |
Bool DescriptionAddCheckbox(Description *description, Int32 id, Int32 groupId, const String &name, Bool defaultValue) | |
{ | |
if (!description) | |
return false; | |
const DescID *singleId = description->GetSingleDescID(); | |
if (!singleId || IsSingleID(id, singleId)) | |
{ | |
BaseContainer params = GetCustomDataTypeDefault(DTYPE_BOOL); | |
params.SetString(DESC_NAME, name); | |
params.SetBool(DESC_DEFAULT, defaultValue); | |
params.SetInt32(DESC_ANIMATE, DESC_ANIMATE_ON); | |
return description->SetParameter(DescLevel(id, DTYPE_BOOL, 0), params, groupId); | |
} | |
return true; | |
} | |
Bool DescriptionAddString(Description *description, Int32 id, Int32 groupId, const String &name, const String &defaultValue) | |
{ | |
if (!description) | |
return false; | |
const DescID *singleId = description->GetSingleDescID(); | |
if (!singleId || IsSingleID(id, singleId)) | |
{ | |
BaseContainer params = GetCustomDataTypeDefault(DTYPE_STRING); | |
params.SetString(DESC_NAME, name); | |
params.SetString(DESC_DEFAULT, defaultValue); | |
params.SetInt32(DESC_ANIMATE, DESC_ANIMATE_ON); | |
return description->SetParameter(DescLevel(id, DTYPE_STRING, 0), params, groupId); | |
} | |
return true; | |
} | |
Bool DescriptionAddLink(Description *description, Int32 id, Int32 groupId, const String &name, const BaseContainer &acceptList) | |
{ | |
if (!description) | |
return false; | |
const DescID *singleId = description->GetSingleDescID(); | |
if (!singleId || IsSingleID(id, singleId)) | |
{ | |
BaseContainer params = GetCustomDataTypeDefault(DTYPE_BASELISTLINK); | |
params.SetString(DESC_NAME, name); | |
params.SetInt32(DESC_ANIMATE, DESC_ANIMATE_ON); | |
params.SetContainer(DESC_ACCEPT, acceptList); | |
return description->SetParameter(DescLevel(id, DTYPE_BASELISTLINK, 0), params, groupId); | |
} | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DYNAMICDESCRIPTION_H__ | |
#define DYNAMICDESCRIPTION_H__ | |
#include "c4d.h" | |
/// Check if 'id' is a single id | |
Bool IsSingleID(const DescID &id, const DescID *singleid); | |
/// Add a new LONG CYCLE element to the description. Cycle items may have icons. | |
/// @param[in] description The description that should receive the new element | |
/// @param[in] id The resource ID of the new element (make sure it doesn't conflict with an existing ID) | |
/// @param[in] groupId The resource ID of the attribute group the new element should be added to | |
/// @param[in] name The name of the element | |
/// @param[in] cycleItems BaseContainer with names of cycle items | |
/// @param[in] cycleIcons Optional pointer to BaseContainer with IDs of cycle items' icons | |
/// @param[in] defaultValue The index of the cycle item that should be selected by default | |
/// @return False if an error occurred, otherwise true | |
Bool DescriptionAddCycle(Description *description, Int32 id, Int32 groupId, const String &name, const BaseContainer &cycleItems, BaseContainer *cycleIcons = nullptr, Int32 defaultValue = 0); | |
/// Add a new LONG CYCLE element to the description | |
/// @param[in] description The description that should receive the new element | |
/// @param[in] id The resource ID of the new element (make sure it doesn't conflict with an existing ID) | |
/// @param[in] groupId The resource ID of the attribute group the new element should be added to | |
/// @param[in] name The name of the element | |
/// @param[in] defaultValue The default value | |
/// @return False if an error occurred, otherwise true | |
Bool DescriptionAddCheckbox(Description *description, Int32 id, Int32 groupId, const String &name, Bool defaultValue = false); | |
/// Add a new LONG CYCLE element to the description | |
/// @param[in] description The description that should receive the new element | |
/// @param[in] id The resource ID of the new element (make sure it doesn't conflict with an existing ID) | |
/// @param[in] groupId The resource ID of the attribute group the new element should be added to | |
/// @param[in] name The name of the element | |
/// @param[in] defaultValue The default string | |
/// @return False if an error occurred, otherwise true | |
Bool DescriptionAddString(Description *description, Int32 id, Int32 groupId, const String &name, const String &defaultValue = ""); | |
/// Add a new LONG CYCLE element to the description | |
/// @param[in] description The description that should receive the new element | |
/// @param[in] id The resource ID of the new element (make sure it doesn't conflict with an existing ID) | |
/// @param[in] groupId The resource ID of the attribute group the new element should be added to | |
/// @param[in] name The name of the element | |
/// @param[in] acceptList BaseContainer with IDs of acceptable objects for this linkbox | |
/// @return False if an error occurred, otherwise true | |
Bool DescriptionAddLink(Description *description, Int32 id, Int32 groupId, const String &name, const BaseContainer &acceptList); | |
#endif // DYNAMICDESCRIPTION_H__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment