Skip to content

Instantly share code, notes, and snippets.

@lukpazera
Last active November 25, 2015 13:26
Show Gist options
  • Save lukpazera/f816188955336c655ac0 to your computer and use it in GitHub Desktop.
Save lukpazera/f816188955336c655ac0 to your computer and use it in GitHub Desktop.
How to add gradient channel to an item.
/*
* An example on how to add gradient channel to a custom item.
* Gradient will also have default 1.0 flat value.
*/
LxResult
CPackage::pkg_SetupChannels (
ILxUnknownID addChan)
{
CLxUser_AddChannel ac (addChan);
ac.NewChannel (GRADIENT_CHAN_NAME, LXsTYPE_PERCENT);
ac.SetGradient (LXsTYPE_PERCENT);
ac.SetDefault (1.0, 0.0);
return LXe_OK;
}
/*
* And here, on the instance gradient can be initialized with some keys.
* m_item is a cached interface of the instanced item.
*/
LxResult
CInstance::pins_Newborn (ILxUnknownID original_obj, unsigned flags)
{
CLxUser_Scene scene;
CLxUser_ChannelWrite chan_write;
CLxUser_Envelope envelope;
CLxUser_Keyframe keyframe;
if (!m_item.test () || !m_item.GetContext (scene))
return LXe_FAILED;
scene.SetChannels (chan_write, LXs_ACTIONLAYER_SETUP);
if (chan_write.Envelope (m_item, m_item.ChannelIndex (GRADIENT_CHAN_NAME), envelope))
{
if (keyframe.fromEnvObject (envelope)) {
keyframe.AddF (0.0, 1.0);
keyframe.AddF (1.0, 0.0);
}
}
return LXe_OK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment