diff options
| author | Maximilian Albert <maximilian.albert@gmail.com> | 2008-06-04 13:12:05 +0000 |
|---|---|---|
| committer | cilix42 <cilix42@users.sourceforge.net> | 2008-06-04 13:12:05 +0000 |
| commit | 86fc050f0b6eabd1ddf706661b968588f24b0367 (patch) | |
| tree | ccc3ddd0bef90b12454826295e59b3e60e4a47d6 /src/live_effects/effect.cpp | |
| parent | C++ify knotholders (diff) | |
| download | inkscape-86fc050f0b6eabd1ddf706661b968588f24b0367.tar.gz inkscape-86fc050f0b6eabd1ddf706661b968588f24b0367.zip | |
Factor out 'create and apply' code for LPEs so that it can be called from everywhere
(bzr r5798)
Diffstat (limited to 'src/live_effects/effect.cpp')
| -rw-r--r-- | src/live_effects/effect.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 639ad93a4..765d0a59b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -16,6 +16,8 @@ #include "desktop.h" #include "inkscape.h" #include "document.h" +#include "document-private.h" +#include "xml/document.h" #include <glibmm/i18n.h> #include "live_effects/lpeobject.h" @@ -147,6 +149,32 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) return neweffect; } +void +Effect::createAndApply(const char* name, SPDocument *doc, SPItem *item) +{ + // Path effect definition + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect"); + repr->setAttribute("effect", name); + + SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to <defs> and assigns the 'id' attribute + const gchar * repr_id = repr->attribute("id"); + Inkscape::GC::release(repr); + + gchar *href = g_strdup_printf("#%s", repr_id); + sp_lpe_item_add_path_effect(SP_LPE_ITEM(item), href, true); + g_free(href); + + sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Create and apply path effect")); +} + +void +Effect::createAndApply(EffectType type, SPDocument *doc, SPItem *item) +{ + createAndApply(LPETypeConverter.get_key(type).c_str(), doc, item); +} + Effect::Effect(LivePathEffectObject *lpeobject) : oncanvasedit_it(0), is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true), |
