summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-11-01 10:23:50 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-11-01 10:23:50 +0000
commit2c971fd0dd67269a5ecd6c3323071e8b0b08bf1b (patch)
tree46f82df97d9942e6718e4d26281e10ed89e8a2bb /src
parentFix a bug converting to paths nested LPE with powerstroke (diff)
downloadinkscape-2c971fd0dd67269a5ecd6c3323071e8b0b08bf1b.tar.gz
inkscape-2c971fd0dd67269a5ecd6c3323071e8b0b08bf1b.zip
Add widget to color and some refactoring
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/lpe-powermask.cpp160
-rw-r--r--src/live_effects/lpe-powermask.h8
-rw-r--r--src/object-set.h2
-rw-r--r--src/selection-chemistry.cpp25
-rw-r--r--src/verbs.cpp10
-rw-r--r--src/verbs.h2
6 files changed, 117 insertions, 90 deletions
diff --git a/src/live_effects/lpe-powermask.cpp b/src/live_effects/lpe-powermask.cpp
index 05510f258..a0ba42ddf 100644
--- a/src/live_effects/lpe-powermask.cpp
+++ b/src/live_effects/lpe-powermask.cpp
@@ -13,6 +13,7 @@
#include "style.h"
#include "sp-item-group.h"
#include "svg/svg.h"
+#include "svg/svg-color.h"
#include "ui/tools-switch.h"
#include "path-chemistry.h"
#include "uri.h"
@@ -29,19 +30,17 @@ LPEPowerMask::LPEPowerMask(LivePathEffectObject *lpeobject)
: Effect(lpeobject),
uri("Store the uri of mask", "", "uri", &wr, this, "false", false),
invert(_("Invert mask"), _("Invert mask"), "invert", &wr, this, false),
- wrap(_("Wrap mask data"), _("Wrap mask data allowing previous filters"), "wrap", &wr, this, false),
+ //wrap(_("Wrap mask data"), _("Wrap mask data allowing previous filters"), "wrap", &wr, this, false),
hide_mask(_("Hide mask"), _("Hide mask"), "hide_mask", &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:1;")
+ background_color(_("Background color and opacity"), _("Set color and opacity of the background"), "background_color", &wr, this, 0xffffffff)
{
registerParameter(&uri);
registerParameter(&invert);
- registerParameter(&wrap);
+ //registerParameter(&wrap);
registerParameter(&hide_mask);
registerParameter(&background);
- registerParameter(&background_style);
- //lock.param_setValue(false);
- background_style.param_hide_canvas_text();
+ registerParameter(&background_color);
}
LPEPowerMask::~LPEPowerMask() {}
@@ -145,56 +144,57 @@ LPEPowerMask::setMask(){
filter->appendChild(primitive2);
Inkscape::GC::release(primitive2);
}
- if(wrap && is_visible){
- Glib::ustring g_data_id = mask_id + (Glib::ustring)"_container";
- if((elemref = document->getObjectById(g_data_id))){
- elemref->getRepr()->setPosition(-1);
- } else {
- Inkscape::XML::Node * container = xml_doc->createElement("svg:g");
- container->setAttribute("id", g_data_id.c_str());
- mask->appendChildRepr(container);
- std::vector<SPObject*> mask_list = mask->childList(true);
- container->setPosition(-1);
- Inkscape::GC::release(container);
- for ( std::vector<SPObject*>::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) {
- SPItem * mask_data = SP_ITEM(*iter);
- Inkscape::XML::Node *mask_node = mask_data->getRepr();
- if (! strcmp(mask_data->getId(), box_id.c_str()) ||
- ! strcmp(mask_data->getId(), g_data_id.c_str()))
- {
- continue;
- }
- SPCSSAttr *css = sp_repr_css_attr_new();
- if(mask_node->attribute("style")) {
- sp_repr_css_attr_add_from_string(css, mask_node->attribute("style"));
- }
- char const* filter = sp_repr_css_property (css, "filter", NULL);
- if(!filter || !strcmp(filter, filter_uri.c_str())) {
- sp_repr_css_set_property (css, "filter", NULL);
- }
- Glib::ustring css_str;
- sp_repr_css_write_string(css, css_str);
- mask_node->setAttribute("style", css_str.c_str());
- mask->getRepr()->removeChild(mask_node);
- container->appendChild(mask_node);
- Inkscape::GC::release(mask_node);
- }
- }
- } else {
- Glib::ustring g_data_id = mask_id + (Glib::ustring)"_container";
- if((elemref = document->getObjectById(g_data_id))){
- std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(elemref));
- for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();++iter) {
- Inkscape::XML::Node *mask_node = (*iter)->getRepr();
- elemref->getRepr()->removeChild(mask_node);
- mask->getRepr()->appendChild(mask_node);
- Inkscape::GC::release(mask_node);
- }
- sp_object_ref(elemref, 0 );
- elemref->deleteObject(true);
- sp_object_unref(elemref);
+//Not sure if finaly need to resurrect this
+// if(wrap && is_visible){
+// Glib::ustring g_data_id = mask_id + (Glib::ustring)"_container";
+// if((elemref = document->getObjectById(g_data_id))){
+// elemref->getRepr()->setPosition(-1);
+// } else {
+// Inkscape::XML::Node * container = xml_doc->createElement("svg:g");
+// container->setAttribute("id", g_data_id.c_str());
+// mask->appendChildRepr(container);
+// std::vector<SPObject*> mask_list = mask->childList(true);
+// container->setPosition(-1);
+// Inkscape::GC::release(container);
+// for ( std::vector<SPObject*>::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) {
+// SPItem * mask_data = SP_ITEM(*iter);
+// Inkscape::XML::Node *mask_node = mask_data->getRepr();
+// if (! strcmp(mask_data->getId(), box_id.c_str()) ||
+// ! strcmp(mask_data->getId(), g_data_id.c_str()))
+// {
+// continue;
+// }
+// SPCSSAttr *css = sp_repr_css_attr_new();
+// if(mask_node->attribute("style")) {
+// sp_repr_css_attr_add_from_string(css, mask_node->attribute("style"));
+// }
+// char const* filter = sp_repr_css_property (css, "filter", NULL);
+// if(!filter || !strcmp(filter, filter_uri.c_str())) {
+// sp_repr_css_set_property (css, "filter", NULL);
+// }
+// Glib::ustring css_str;
+// sp_repr_css_write_string(css, css_str);
+// mask_node->setAttribute("style", css_str.c_str());
+// mask->getRepr()->removeChild(mask_node);
+// container->appendChild(mask_node);
+// Inkscape::GC::release(mask_node);
+// }
+// }
+// } else {
+ Glib::ustring g_data_id = mask_id + (Glib::ustring)"_container";
+ if((elemref = document->getObjectById(g_data_id))){
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(elemref));
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();++iter) {
+ Inkscape::XML::Node *mask_node = (*iter)->getRepr();
+ elemref->getRepr()->removeChild(mask_node);
+ mask->getRepr()->appendChild(mask_node);
+ Inkscape::GC::release(mask_node);
}
+ sp_object_ref(elemref, 0 );
+ elemref->deleteObject(true);
+ sp_object_unref(elemref);
}
+// }
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);
@@ -229,7 +229,28 @@ LPEPowerMask::setMask(){
box->setAttribute("id", box_id.c_str());
exist = false;
}
- box->setAttribute("style", background_style.param_getSVGValue());
+ Glib::ustring style;
+ gchar c[32];
+ unsigned const rgb24 = background_color.get_value() >> 8;
+ sprintf(c, "#%06x", rgb24);
+ style = Glib::ustring("fill:") + Glib::ustring(c);
+ Inkscape::SVGOStringStream os;
+ os << SP_RGBA32_A_F(background_color.get_value());
+ style = style + Glib::ustring(";fill-opacity:") + Glib::ustring(os.str());
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ sp_repr_css_attr_add_from_string(css, style.c_str());
+ char const* filter = sp_repr_css_property (css, "filter", NULL);
+ if(!filter || !strcmp(filter, filter_uri.c_str())) {
+ if (invert && is_visible) {
+ sp_repr_css_set_property (css, "filter", filter_uri.c_str());
+ } else {
+ sp_repr_css_set_property (css, "filter", NULL);
+ }
+
+ }
+ Glib::ustring css_str;
+ sp_repr_css_write_string(css, css_str);
+ box->setAttribute("style", css_str.c_str());
gchar * box_str = sp_svg_write_path( mask_box );
box->setAttribute("d" , box_str);
g_free(box_str);
@@ -255,33 +276,6 @@ LPEPowerMask::doEffect (SPCurve * curve)
{
}
-//void
-//LPEPowerMask::transform_multiply(Geom::Affine const& postmul, bool set)
-//{
-// SPMask *mask_path = SP_ITEM(sp_lpe_item)->mask_ref->getObject();
-// if (mask_path && lock) {
-// SPMask *mask_path = SP_ITEM(sp_lpe_item)->mask_ref->getObject();
-// std::vector<SPObject*> mask_path_list = mask_path->childList(true);
-// Glib::ustring mask_id = (Glib::ustring)mask_path->getId();
-// Glib::ustring box_id = mask_id + (Glib::ustring)"_box";
-// for ( std::vector<SPObject*>::const_iterator iter=mask_path_list.begin();iter!=mask_path_list.end();++iter) {
-// SPObject * mask_data = *iter;
-// if (! strcmp(mask_data->getId(), box_id.c_str())){
-// continue;
-// }
-// SP_ITEM(mask_data)->transform *= postmul.inverse();
-// }
-// }
-// //cycle through all parameters. Most parameters will not need transformation, but path and point params
-// for (std::vector<Parameter *>::iterator it = param_vector.begin(); it != param_vector.end(); ++it) {
-// Parameter * param = *it;
-// param->param_transform_multiply(postmul, set);
-// }
-// sp_lpe_item_update_patheffect(SP_LPE_ITEM(sp_lpe_item), false, false);
-//}
-
-
-
void
LPEPowerMask::doOnRemove (SPLPEItem const* lpeitem)
{
@@ -289,7 +283,7 @@ LPEPowerMask::doOnRemove (SPLPEItem const* lpeitem)
SPMask *mask = lpeitem->mask_ref->getObject();
if (mask) {
invert.param_setValue(false);
- wrap.param_setValue(false);
+ //wrap.param_setValue(false);
background.param_setValue(false);
setMask();
SPObject *elemref = NULL;
diff --git a/src/live_effects/lpe-powermask.h b/src/live_effects/lpe-powermask.h
index a54424e2f..44bf56333 100644
--- a/src/live_effects/lpe-powermask.h
+++ b/src/live_effects/lpe-powermask.h
@@ -6,10 +6,11 @@
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-
#include "live_effects/effect.h"
+#include "live_effects/parameter/bool.h"
#include "live_effects/parameter/text.h"
#include "live_effects/parameter/hidden.h"
+#include "live_effects/parameter/colorpicker.h"
namespace Inkscape {
namespace LivePathEffect {
@@ -22,16 +23,15 @@ public:
virtual void doEffect (SPCurve * curve);
virtual void doOnRemove (SPLPEItem const* /*lpeitem*/);
virtual void doOnVisibilityToggled(SPLPEItem const* lpeitem);
- //virtual void transform_multiply(Geom::Affine const& postmul, bool set);
void toggleMaskVisibility();
void setMask();
private:
HiddenParam uri;
BoolParam invert;
- BoolParam wrap;
+ //BoolParam wrap;
BoolParam hide_mask;
BoolParam background;
- TextParam background_style;
+ ColorPickerParam background_color;
Geom::Path mask_box;
};
diff --git a/src/object-set.h b/src/object-set.h
index a8061593a..2e57966e6 100644
--- a/src/object-set.h
+++ b/src/object-set.h
@@ -422,7 +422,7 @@ public:
void tile(bool apply = true); //"Object to Pattern"
void untile();
void createBitmapCopy();
- void setMask(bool apply_clip_path, bool apply_to_layer = false, bool skip_undo = false);
+ void setMask(bool apply_clip_path, bool apply_to_layer = false, bool skip_undo = false, bool inverse = false);
void editMask(bool clip);
void unsetMask(const bool apply_clip_path, const bool skip_undo = false);
void setClipGroup();
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index 0bd611163..24113f976 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -95,6 +95,8 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS;
#include "ui/tool/control-point-selection.h"
#include "ui/tool/multi-path-manipulator.h"
#include "live_effects/effect.h"
+#include "live_effects/lpe-powerclip.h"
+#include "live_effects/lpe-powermask.h"
#include "live_effects/parameter/originalpath.h"
#include "layer-manager.h"
#include "object-set.h"
@@ -3862,7 +3864,7 @@ void ObjectSet::setClipGroup()
* If \a apply_clip_path parameter is true, clipPath is created, otherwise mask
*
*/
- void ObjectSet::setMask(bool apply_clip_path, bool apply_to_layer, bool skip_undo)
+ void ObjectSet::setMask(bool apply_clip_path, bool apply_to_layer, bool skip_undo, bool inverse)
{
if(!desktop() && apply_to_layer)
return;
@@ -4016,7 +4018,26 @@ void ObjectSet::setClipGroup()
}
apply_mask_to->setAttribute(attributeName, Glib::ustring("url(#") + mask_id + ')');
-
+ if (inverse) {
+ using namespace Inkscape::LivePathEffect;
+ if (apply_clip_path) {
+ Effect::createAndApply(POWERCLIP, doc, item);
+ Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
+ lpe->getRepr()->setAttribute("is_inverse", "false");
+ lpe->getRepr()->setAttribute("is_visible", "true");
+ lpe->getRepr()->setAttribute("inverse", "true");
+ lpe->getRepr()->setAttribute("flatten", "false");
+ lpe->getRepr()->setAttribute("hide_clip", "false");
+ } else {
+ Effect::createAndApply(POWERMASK, doc, item);
+ Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
+ lpe->getRepr()->setAttribute("invert", "false");
+ lpe->getRepr()->setAttribute("is_visible", "true");
+ lpe->getRepr()->setAttribute("hide_mask", "false");
+ lpe->getRepr()->setAttribute("background", "true");
+ lpe->getRepr()->setAttribute("background_color", "#ffffffff");
+ }
+ }
}
for (std::vector<SPItem*>::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); ++i) {
diff --git a/src/verbs.cpp b/src/verbs.cpp
index c1c108415..962196d06 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -1592,6 +1592,9 @@ void ObjectVerb::perform( SPAction *action, void *data)
case SP_VERB_OBJECT_SET_MASK:
sel->setMask(false, false);
break;
+ case SP_VERB_OBJECT_SET_INVERSE_MASK:
+ sel->setMask(false, false, false, true);
+ break;
case SP_VERB_OBJECT_EDIT_MASK:
sel->editMask(false);
break;
@@ -1601,6 +1604,9 @@ void ObjectVerb::perform( SPAction *action, void *data)
case SP_VERB_OBJECT_SET_CLIPPATH:
sel->setMask(true, false);
break;
+ case SP_VERB_OBJECT_SET_INVERSE_CLIPPATH:
+ sel->setMask(true, false, false, true);
+ break;
case SP_VERB_OBJECT_CREATE_CLIP_GROUP:
sel->setClipGroup();
break;
@@ -2873,12 +2879,16 @@ Verb *Verb::_base_verbs[] = {
INKSCAPE_ICON("object-flip-vertical")),
new ObjectVerb(SP_VERB_OBJECT_SET_MASK, "ObjectSetMask", N_("_Set"),
N_("Apply mask to selection (using the topmost object as mask)"), NULL),
+ new ObjectVerb(SP_VERB_OBJECT_SET_INVERSE_MASK, "ObjectSetInverseMask", N_("_Set Inverse (LPE)"),
+ N_("Apply inverse mask to selection (using the topmost object as mask)"), NULL),
new ObjectVerb(SP_VERB_OBJECT_EDIT_MASK, "ObjectEditMask", N_("_Edit"),
N_("Edit mask"), INKSCAPE_ICON("path-mask-edit")),
new ObjectVerb(SP_VERB_OBJECT_UNSET_MASK, "ObjectUnSetMask", N_("_Release"),
N_("Remove mask from selection"), NULL),
new ObjectVerb(SP_VERB_OBJECT_SET_CLIPPATH, "ObjectSetClipPath", N_("_Set"),
N_("Apply clipping path to selection (using the topmost object as clipping path)"), NULL),
+ new ObjectVerb(SP_VERB_OBJECT_SET_INVERSE_CLIPPATH, "ObjectSetInverseClipPath", N_("_Set Inverse (LPE)"),
+ N_("Apply inverse clipping path to selection (using the topmost object as clipping path)"), NULL),
new ObjectVerb(SP_VERB_OBJECT_CREATE_CLIP_GROUP, "ObjectCreateClipGroup", N_("Create Cl_ip Group"),
N_("Creates a clip group using the selected objects as a base"), NULL),
new ObjectVerb(SP_VERB_OBJECT_EDIT_CLIPPATH, "ObjectEditClipPath", N_("_Edit"),
diff --git a/src/verbs.h b/src/verbs.h
index 7df2d1399..611a8131c 100644
--- a/src/verbs.h
+++ b/src/verbs.h
@@ -192,9 +192,11 @@ enum {
SP_VERB_OBJECT_FLIP_HORIZONTAL,
SP_VERB_OBJECT_FLIP_VERTICAL,
SP_VERB_OBJECT_SET_MASK,
+ SP_VERB_OBJECT_SET_INVERSE_MASK,
SP_VERB_OBJECT_EDIT_MASK,
SP_VERB_OBJECT_UNSET_MASK,
SP_VERB_OBJECT_SET_CLIPPATH,
+ SP_VERB_OBJECT_SET_INVERSE_CLIPPATH,
SP_VERB_OBJECT_CREATE_CLIP_GROUP,
SP_VERB_OBJECT_EDIT_CLIPPATH,
SP_VERB_OBJECT_UNSET_CLIPPATH,