It looks like color swatches and gradients both take an RGBA Array like so. (Although I am not sure about where the knot value for the gradients comes from yet, perhaps it takes it from the Alpha?).
ColorAlphaArray arr;
arr.Append(maxon::ColorA(1, 0, 0, 1)) iferr_ignore(""_s);
arr.Append(maxon::ColorA(0, 1, 0, 1)) iferr_ignore(""_s);
HandleMouseDrag(msg, DRAGTYPE_RGBA_ARRAY, &arr, 0);
But how to do I extract these from a preset?
I should also point out that I am loading my lib4d by calling SDKBrowser::RegisterPresetLibrary(...)
I am then iterating over all the presets and checking the preset type to see if they are ID_GRADIENTGUI_BROWSERPRESET or ColorSwatchData::browserPresetType.
If the preset type is ColorSwatchData::browserPresetType then I would expect the following to work, but it does not.
ColorSwatchData *swatch = ColorSwatchData::Alloc(GetActiveDocument());
if (swatch)
{
if (swatch->LoadPreset(_browserURL, false))
{
if (swatch->GetGroupCount() > 0)
{
ColorSwatchGroup *group = swatch->GetGroupAtIndex(0);
if (group)
{
ColorAlphaArray arr;
group->GetColors(arr);
HandleMouseDrag(msg, DRAGTYPE_RGBA_ARRAY, &arr, 0);
}
}
}
ColorSwatchData::Free(swatch);
}
So instead I tried to see if I could simple cast the preset data myself, but calling it like this does not work either.
Int32 plugin_id;
BaseContainer bc;
void *data = nullptr;
Int length = 0;
//Where _db_index is the index returned from my registered preset library, and _browserURL is the SDKBrowserURL to the actual preset within the library itself.
if (SDKBrowser::LoadPreset(_db_index, _browserURL, plugin_id, &bc, &data, &length))
{
if (plugin_id == ColorSwatchData::browserPresetType)
{
//Note: The data does not appear to be ColorSwatchData, I can not simply cast it as shown below
ColorSwatchData* swatch = (ColorSwatchData*)data;
ColorSwatchGroup *group = swatch->GetGroupAtIndex(0);
if (group)
{
ColorAlphaArray arr;
group->GetColors(arr);
HandleMouseDrag(msg, DRAGTYPE_RGBA_ARRAY, &arr, 0);
}
}
}
Trying to load it as a document doesn't work either. The error message when trying to load the document from the in memory file says that the document doesn't seem to exist.
Filename readFileName("temp.doc");
readFileName.SetMemoryReadMode(data, length, true);
maxon::String err;
BaseDocument *pLoadedDoc = LoadDocument(readFileName, SCENEFILTER::NONE, nullptr, &err);
if (pLoadedDoc)
{
ColorSwatchData *swatchDoc = ColorSwatchData::Alloc(pLoadedDoc);
if (swatchDoc)
{
ColorSwatchGroup *group = swatch->GetGroupAtIndex(0);
if (group)
{
ColorAlphaArray arr;
group->GetColors(arr);
HandleMouseDrag(msg, DRAGTYPE_RGBA_ARRAY, &arr, 0);
}
ColorSwatchData::Free(swatchDoc);
}
BaseDocument::Free(pLoadedDoc);
}
So far I have not found a solution for gradients either.