summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-powermask.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2017-06-07 19:34:53 +0000
committerjabiertxof <info@marker.es>2017-06-07 19:34:53 +0000
commitef4db6f8483312a558b512e8a1ad11fc95872886 (patch)
treea8a146800a323f3878e5fe45dcb5e14d0a60ac0f /src/live_effects/lpe-powermask.cpp
parentUpdate to trunk (diff)
downloadinkscape-ef4db6f8483312a558b512e8a1ad11fc95872886.tar.gz
inkscape-ef4db6f8483312a558b512e8a1ad11fc95872886.zip
Working on powermask LPE
(bzr r15722)
Diffstat (limited to 'src/live_effects/lpe-powermask.cpp')
-rw-r--r--src/live_effects/lpe-powermask.cpp181
1 files changed, 124 insertions, 57 deletions
diff --git a/src/live_effects/lpe-powermask.cpp b/src/live_effects/lpe-powermask.cpp
index bbe0dff40..a49d4c493 100644
--- a/src/live_effects/lpe-powermask.cpp
+++ b/src/live_effects/lpe-powermask.cpp
@@ -11,6 +11,7 @@
#include "sp-path.h"
#include "sp-shape.h"
#include "sp-defs.h"
+#include "style.h"
#include "sp-item-group.h"
#include "svg/svg.h"
#include "ui/tools-switch.h"
@@ -24,10 +25,21 @@ namespace LivePathEffect {
LPEPowerMask::LPEPowerMask(LivePathEffectObject *lpeobject)
: Effect(lpeobject),
- inverse(_("Inverse mask"), _("Inverse mask"), "inverse", &wr, this, false)
+ invert(_("Invert mask"), _("Invert mask"), "invert", &wr, this, false),
+ wrap(_("Wrap filtered clip data"), _("Wrap filtered clip data"), "wrap", &wr, this, false),
+ background(_("Add background to mask"), _("Add background to mask"), "background", &wr, this, false),
+ background_style(_("Background Style"), _("CSS to background"), "background_style", &wr, this,"fill:#ffffff;opacity:0.7;")
+
{
- registerParameter(&inverse);
+ registerParameter(&invert);
+ registerParameter(&wrap);
+ registerParameter(&background);
+ registerParameter(&background_style);
+ background_style.param_hide_canvas_text();
hide_mask = false;
+ previous_invert = !invert;
+ previous_wrap = !wrap;
+ previous_background_style = "";
}
LPEPowerMask::~LPEPowerMask() {}
@@ -35,7 +47,7 @@ LPEPowerMask::~LPEPowerMask() {}
void
LPEPowerMask::doBeforeEffect (SPLPEItem const* lpeitem){
original_bbox(lpeitem);
- const Glib::ustring uri = (Glib::ustring)sp_lpe_item->getRepr()->attribute("mask-path");
+ const Glib::ustring uri = (Glib::ustring)sp_lpe_item->getRepr()->attribute("mask");
SPMask *mask = SP_ITEM(lpeitem)->mask_ref->getObject();
Geom::Point topleft = Geom::Point(boundingbox_X.min() - 5,boundingbox_Y.max() + 5);
Geom::Point topright = Geom::Point(boundingbox_X.max() + 5,boundingbox_Y.max() + 5);
@@ -49,12 +61,12 @@ LPEPowerMask::doBeforeEffect (SPLPEItem const* lpeitem){
mask_box.close();
//mask *= sp_lpe_item->i2dt_affine();
if(mask) {
- setInverse();
+ setMask();
}
}
void
-LPEPowerMask::setInverse(){
+LPEPowerMask::setMask(){
SPMask *mask = SP_ITEM(sp_lpe_item)->mask_ref->getObject();
SPObject *elemref = NULL;
SPDocument * document = SP_ACTIVE_DOCUMENT;
@@ -65,55 +77,111 @@ LPEPowerMask::setInverse(){
Inkscape::XML::Node *box = NULL;
Inkscape::XML::Node *filter = NULL;
SPDefs * defs = document->getDefs();
- if (inverse) {
-// if (!(elemref = document->getObjectById((Glib::ustring)mask->getId() + (Glib::ustring)"_transparentbox"))) {
-// std::vector<SPObject*> mask_list = mask->childList(true);
-// box = xml_doc->createElement("svg:path");
-// box->setAttribute("id", (Glib::ustring)mask->getId() + (Glib::ustring)"_transparentbox");
-// box->setAttribute("style", "fill:#000");
-// gchar * box_str = sp_svg_write_path( mask_box );
-// box->setAttribute("d" , box_str);
-// g_free(box_str);
-// elemref = mask->appendChildRepr(box);
-// box->setPosition(mask_list.size());
-// Inkscape::GC::release(box);
-// mask_list.clear();
-// }
-// if (!(elemref = document->getObjectById((Glib::ustring)mask->getId() + (Glib::ustring)"_inverse"))) {
-// filter = xml_doc->createElement("svg:filter");
-// filter->setAttribute("id", (Glib::ustring)mask->getId() + (Glib::ustring)"_inverse");
-// filter->setAttribute("color-interpolation-filters", "sRGB");
-// filter->setAttribute("height", "100");
-// filter->setAttribute("width", "100");
-// filter->setAttribute("x", "-50");
-// filter->setAttribute("y", "-50");
-// Inkscape::XML::Node *primitive1 = xml_doc->createElement("svg:feColorMatrix");
-// primitive1->setAttribute("id", (Glib::ustring)mask->getId() + (Glib::ustring)"_primitive1");
-// primitive1->setAttribute("values", "1");
-// primitive1->setAttribute("type", "saturate");
-// primitive1->setAttribute("result", "fbSourceGraphic");
-// Inkscape::XML::Node *primitive2 = xml_doc->createElement("svg:feColorMatrix");
-// primitive2->setAttribute("id", (Glib::ustring)mask->getId() + (Glib::ustring)"_primitive2");
-// primitive2->setAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0 ");
-// primitive2->setAttribute("in", "fbSourceGraphic");
-// elemref = defs->appendChildRepr(filter);
-// filter->appendChild(primitive1);
-// filter->appendChild(primitive2);
-// Inkscape::GC::release(filter);
-// Inkscape::GC::release(primitive1);
-// Inkscape::GC::release(primitive2);
-// }
-// mask->getRepr()->setAttribute("css", (Glib::ustring)"filter:#" + (Glib::ustring)mask->getId() + (Glib::ustring)"_inverse");
+ Glib::ustring mask_id = (Glib::ustring)mask->getId();
+ Glib::ustring box_id = mask_id + (Glib::ustring)"_transparentbox";
+ Glib::ustring filter_id = mask_id + (Glib::ustring)"_inverse";
+ Glib::ustring filter_uri = (Glib::ustring)"url(#" + mask_id + (Glib::ustring)"_inverse)";
+ if (previous_invert != invert || previous_wrap != wrap) {
+ if (invert) {
+ if (!(elemref = document->getObjectById(filter_id))) {
+ filter = xml_doc->createElement("svg:filter");
+ filter->setAttribute("id", filter_id.c_str());
+ filter->setAttribute("color-interpolation-filters", "sRGB");
+ filter->setAttribute("height", "100");
+ filter->setAttribute("width", "100");
+ filter->setAttribute("x", "-50");
+ filter->setAttribute("y", "-50");
+ Inkscape::XML::Node *primitive1 = xml_doc->createElement("svg:feColorMatrix");
+ Glib::ustring primitive1_id = (mask_id + (Glib::ustring)"_primitive1").c_str();
+ primitive1->setAttribute("id", primitive1_id.c_str());
+ primitive1->setAttribute("values", "1");
+ primitive1->setAttribute("type", "saturate");
+ primitive1->setAttribute("result", "fbSourceGraphic");
+ Inkscape::XML::Node *primitive2 = xml_doc->createElement("svg:feColorMatrix");
+ Glib::ustring primitive2_id = (mask_id + (Glib::ustring)"_primitive2").c_str();
+ primitive2->setAttribute("id", primitive2_id.c_str());
+ primitive2->setAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0 ");
+ primitive2->setAttribute("in", "fbSourceGraphic");
+ elemref = defs->appendChildRepr(filter);
+ filter->appendChild(primitive1);
+ filter->appendChild(primitive2);
+ Inkscape::GC::release(filter);
+ Inkscape::GC::release(primitive1);
+ Inkscape::GC::release(primitive2);
+ }
+ } else {
+ if ((elemref = document->getObjectById(filter_id))) {
+ elemref->deleteObject(true);
+ }
+ filter_uri = "";
+ }
+ std::vector<SPObject*> mask_list = mask->childList(true);
+ for ( std::vector<SPObject*>::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) {
+ SPItem * mask_data = SP_ITEM(*iter);
+ if (! strcmp(mask_data->getId(), box_id.c_str())){
+ continue;
+ }
+ Glib::ustring mask_data_id = (Glib::ustring)mask_data->getId();
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ if(mask_data->getRepr()->attribute("style")) {
+ sp_repr_css_attr_add_from_string(css, mask_data->getRepr()->attribute("style"));
+ }
+ char const* filter = sp_repr_css_property (css, "filter", "");
+ if(!filter ||! strcmp(filter, filter_uri.c_str())) {
+ if (filter_uri.empty()) {
+ sp_repr_css_set_property (css, "filter", NULL);
+ } else {
+ sp_repr_css_set_property (css, "filter", filter_uri.c_str());
+ }
+ Glib::ustring css_str;
+ sp_repr_css_write_string(css, css_str);
+ mask_data->getRepr()->setAttribute("style", css_str.c_str());
+ } else if(wrap){
+ Glib::ustring g_data_id = mask_data_id + (Glib::ustring)"_container";
+ Inkscape::XML::Node * container = xml_doc->createElement("svg:g");
+ container->setAttribute("id", g_data_id.c_str());
+ mask->appendChildRepr(container);
+ container->setPosition(mask_data->getPosition());
+ container->appendChild(mask_data->getRepr());
+ Inkscape::GC::release(container);
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ if (filter_uri.empty()) {
+ sp_repr_css_set_property (css, "filter", NULL);
+ } else {
+ sp_repr_css_set_property (css, "filter", filter_uri.c_str());
+ }
+ Glib::ustring css_str;
+ sp_repr_css_write_string(css, css_str);
+ container->setAttribute("style", css_str.c_str());
+ }
+ }
+ }
+ if (background) {
+ if ((elemref = document->getObjectById(box_id))) {
+ if (strcmp(previous_background_style, background_style.param_getSVGValue())) {
+ elemref->getRepr()->setAttribute("style", background_style.param_getSVGValue());
+ }
+ } else {
+ std::vector<SPObject*> mask_list = mask->childList(true);
+ box = xml_doc->createElement("svg:path");
+ box->setAttribute("id", box_id.c_str());
+ box->setAttribute("style", background_style.param_getSVGValue());
+ gchar * box_str = sp_svg_write_path( mask_box );
+ box->setAttribute("d" , box_str);
+ g_free(box_str);
+ elemref = mask->appendChildRepr(box);
+ box->setPosition(mask_list.size());
+ Inkscape::GC::release(box);
+ mask_list.clear();
+ }
} else {
-// if ((elemref = document->getObjectById((Glib::ustring)mask->getId() + (Glib::ustring)"_transparentbox"))) {
-// elemref->deleteObject(true);
-// }
-
-// if ((elemref = document->getObjectById((Glib::ustring)mask->getId() + (Glib::ustring)"_inverse"))) {
-// elemref->deleteObject(true);
-// }
- //mask->getRepr()->setAttribute("css", NULL);
+ if ((elemref = document->getObjectById(box_id))) {
+ elemref->deleteObject(true);
+ }
}
+ previous_invert = invert;
+ previous_wrap = wrap;
+ previous_background_style = background_style.param_getSVGValue();
}
void
@@ -161,9 +229,6 @@ LPEPowerMask::newWidget()
if ((*it)->widget_is_visible) {
Parameter * param = *it;
Gtk::Widget * widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget());
- if(param->param_key == "grid") {
- widg = NULL;
- }
Glib::ustring * tip = param->param_getTooltip();
if (widg) {
vbox->pack_start(*widg, true, true, 2);
@@ -193,8 +258,10 @@ LPEPowerMask::doOnRemove (SPLPEItem const* /*lpeitem*/)
SPMask *mask = SP_ITEM(sp_lpe_item)->mask_ref->getObject();
if(!keep_paths) {
if(mask) {
- inverse.param_setValue(false);
- setInverse();
+ invert.param_setValue(false);
+ wrap.param_setValue(false);
+ background.param_setValue(false);
+ setMask();
}
}
}