Hot Door CORE Forum
creating gradients - Printable Version

+- Hot Door CORE Forum (http://hotdoorcore.com/forum)
+-- Forum: All forums (http://hotdoorcore.com/forum/forumdisplay.php?fid=1)
+--- Forum: General discussion (http://hotdoorcore.com/forum/forumdisplay.php?fid=3)
+--- Thread: creating gradients (/showthread.php?tid=275)



creating gradients - Rick Johnson - 02-21-2021

I've been able to modify existing patterns and gradients, but now I need to create new gradients and it's not going well. First I create a gradient that I'm not sure is valid, since I can't put it into the swatches panel to see it, nor have I been able to apply it. I hope someone can help.

First, create a simple gradient. In the SDK is a file SnpGradient.cpp that follows these basic steps in a function CreateLinearGradient() that I've tried to follow.

Code:
hdi::core::Gradient grad = hdi::core::Gradient::create();
grad.setName("test gradient");
grad.setGradientType(hdi::core::Gradient::LinearGradientType);

I can read various member properties, so it appears to be a valid gradient, the default black/white one. I can get and change existing stops, but cannot insert new ones.

Code:
hdi::core::Gradient::Stop stp(0.5, 0.5, hdi::core::ArtColor::blue(), 1);
bool success = grad.insertStopAtIndex(1, stp); <-- ERROR

So I try to at least apply the gradient as-is to a selected path art object tempArt in a currentDocument()->selectedArt() loop.

Code:
hdi::core::PathStyle pStyl = tempArt->path()->style();
hdi::core::ArtColor::GradientStyle gStyl;
gStyl.gradient = grad;
pStyl.useFill = true;
pStyl.fill.color = hdi::core::ArtColor(&gStyl);
tempArt->path()->setStyle(pStyl);

As soon as I leave the matching-art loop I get Thread 1: signal SIGABRT

Does the ArtColor constructor copy the gradient, or merely point to some instance that needs to remain after this function is finished?

currentDocument has functions to count patterns and retrieve them by index, but unfortunately there's no counterparts for gradients so it's difficult to tell if the new gradients exist anywhere. I hope soon patterns and gradients can be added to the document Swatches.

Any suggestions would be very much appreciated.