Creating Live Path Effects
Instructions for making Live Path Effects.
It is best to put your new effect in the /live_effects directory. Copy lpe-skeleton.cpp and lpe-skeleton.h to your files (say lpe-youreffect.cpp and lpe-youreffect.h), and rename everything from skeleton to your name.
Add your effect to the enumeration in effect.h: "enum EffectType". This way, Inkscape knows how to refer to your effect.
Add your effect to the "const Util::EnumData<EffectType> LPETypeData[INVALID_LPE]" array in /live_effects/effect.cpp. This way, Inkscape knows how to tell the user what the name of the effect is and also how to write its name to SVG.
One more thing to do: add your files to /live_effects/Makefile_insert. (Be aware of the spaces and tabs in that file!)
That's all! Now your effect should pop up in the LivePathEffect dialog in Inkscape! But your effect won't do anything now, it would just pass along the original path. Time to start writing the main machinery of your cool effect!
Write your effect:
The effect code should go into a doEffect function. The doEffect function receives the original path, and should return the path that results from your effect.
You have to choose between 4 doEffect functions and implement just one of them. There is a "chain" of these functions. The first doEffect function calls the second, which calls the 3rd, which calls the 4th. The 4th returns its result to the 3rd which returns its result to the 2nd which returns it to the first and finally Inkscape receives the result. But all these standard functions do nothing real, they just change the path from one type to another. You have to determine which type is most convenient for you and overload that function. This means you put your own doEffect function in the place where normally the standard function would be called.
These are the doEffect functions in the order in which they are called:
1. void doEffect (SPCurve * curve)
2. NArtBpath * doEffect (NArtBpath * path_in)
3. std::vector<Geom::Path> doEffect (std::vector<Geom::Path> & path_in)
4. Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
It is easy to replace the standard doEffect function with yours. Let's say you want to create your effect with the path types of the 3rd function. You have to declare that one for your effect in lpe-youreffect.h: they are already writting down in there, you just have to un-comment the one you want, and you can delete the other doEffect functions. You must do the same in lpe-youreffect.cpp.
It is best to have a look at the doEffect functions of lpe-slant.cpp and lpe-skeleton.cpp to see what is possible and how to implement something!
- RealParam: a number of type 'gdouble'. (see lpe-slant.cpp to learn how to use this type)
- PointParam: a parameter that describes a coordinate on the page (see lpe-skeletal.cpp to learn how to use this type)
- PathParam: a parameter that is a path. (see lpe-skeletal.cpp to learn how to use this type)
- EnumParam: a parameter that lets the user choose between a number of options from a dropdown box. (see lpe-skeletal.cpp to learn how to use this type)