From 2c971fd0dd67269a5ecd6c3323071e8b0b08bf1b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 1 Nov 2017 11:23:50 +0100 Subject: Add widget to color and some refactoring --- src/live_effects/lpe-powermask.cpp | 160 ++++++++++++++++++------------------- src/live_effects/lpe-powermask.h | 8 +- src/object-set.h | 2 +- src/selection-chemistry.cpp | 25 +++++- src/verbs.cpp | 10 +++ src/verbs.h | 2 + 6 files changed, 117 insertions(+), 90 deletions(-) (limited to 'src') 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 mask_list = mask->childList(true); - container->setPosition(-1); - Inkscape::GC::release(container); - for ( std::vector::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 item_list = sp_item_group_item_list(SP_GROUP(elemref)); - for ( std::vector::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 mask_list = mask->childList(true); +// container->setPosition(-1); +// Inkscape::GC::release(container); +// for ( std::vector::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 item_list = sp_item_group_item_list(SP_GROUP(elemref)); + for ( std::vector::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 mask_list = mask->childList(true); for ( std::vector::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 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::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::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::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, -- cgit v1.2.3 From 66b464e2f07106e2b270517c13205464727f281f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 1 Nov 2017 22:13:21 +0100 Subject: Added inverse mask and clippath --- src/live_effects/lpe-powermask.cpp | 60 +++++++++++++++++++++----------------- src/live_effects/lpe-powermask.h | 1 + src/selection-chemistry.cpp | 1 + 3 files changed, 35 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-powermask.cpp b/src/live_effects/lpe-powermask.cpp index a0ba42ddf..0d48b1b77 100644 --- a/src/live_effects/lpe-powermask.cpp +++ b/src/live_effects/lpe-powermask.cpp @@ -19,7 +19,6 @@ #include "uri.h" #include "extract-uri.h" #include - // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -41,12 +40,14 @@ LPEPowerMask::LPEPowerMask(LivePathEffectObject *lpeobject) registerParameter(&hide_mask); registerParameter(&background); registerParameter(&background_color); + previous_color = background_color.get_value(); } LPEPowerMask::~LPEPowerMask() {} void LPEPowerMask::doBeforeEffect (SPLPEItem const* lpeitem){ + //To avoid close of color dialog and better performance on change color SPObject * mask = SP_ITEM(sp_lpe_item)->mask_ref->getObject(); if(hide_mask && mask) { SP_ITEM(sp_lpe_item)->mask_ref->detach(); @@ -60,35 +61,40 @@ LPEPowerMask::doBeforeEffect (SPLPEItem const* lpeitem){ } mask = SP_ITEM(sp_lpe_item)->mask_ref->getObject(); if (mask) { - uri.param_setValue(Glib::ustring(extract_uri(sp_lpe_item->getRepr()->attribute("mask"))), true); - SP_ITEM(sp_lpe_item)->mask_ref->detach(); - Geom::OptRect bbox = sp_lpe_item->visualBounds(); - if(!bbox) { - return; - } - if (uri.param_getSVGValue()) { - try { - SP_ITEM(sp_lpe_item)->mask_ref->attach(Inkscape::URI(uri.param_getSVGValue())); - } catch (Inkscape::BadURIException &e) { - g_warning("%s", e.what()); - SP_ITEM(sp_lpe_item)->mask_ref->detach(); - } + if (previous_color != background_color.get_value()) { + previous_color = background_color.get_value(); + setMask(); } else { + uri.param_setValue(Glib::ustring(extract_uri(sp_lpe_item->getRepr()->attribute("mask"))), true); SP_ITEM(sp_lpe_item)->mask_ref->detach(); + Geom::OptRect bbox = sp_lpe_item->visualBounds(); + if(!bbox) { + return; + } + if (uri.param_getSVGValue()) { + try { + SP_ITEM(sp_lpe_item)->mask_ref->attach(Inkscape::URI(uri.param_getSVGValue())); + } catch (Inkscape::BadURIException &e) { + g_warning("%s", e.what()); + SP_ITEM(sp_lpe_item)->mask_ref->detach(); + } + } else { + SP_ITEM(sp_lpe_item)->mask_ref->detach(); + } + Geom::Rect bboxrect = (*bbox); + bboxrect.expandBy(1); + Geom::Point topleft = bboxrect.corner(0); + Geom::Point topright = bboxrect.corner(1); + Geom::Point bottomright = bboxrect.corner(2); + Geom::Point bottomleft = bboxrect.corner(3); + mask_box.clear(); + mask_box.start(topleft); + mask_box.appendNew(topright); + mask_box.appendNew(bottomright); + mask_box.appendNew(bottomleft); + mask_box.close(); + setMask(); } - Geom::Rect bboxrect = (*bbox); - bboxrect.expandBy(1); - Geom::Point topleft = bboxrect.corner(0); - Geom::Point topright = bboxrect.corner(1); - Geom::Point bottomright = bboxrect.corner(2); - Geom::Point bottomleft = bboxrect.corner(3); - mask_box.clear(); - mask_box.start(topleft); - mask_box.appendNew(topright); - mask_box.appendNew(bottomright); - mask_box.appendNew(bottomleft); - mask_box.close(); - setMask(); } } diff --git a/src/live_effects/lpe-powermask.h b/src/live_effects/lpe-powermask.h index 44bf56333..eb2640867 100644 --- a/src/live_effects/lpe-powermask.h +++ b/src/live_effects/lpe-powermask.h @@ -33,6 +33,7 @@ private: BoolParam background; ColorPickerParam background_color; Geom::Path mask_box; + guint32 previous_color; }; } //namespace LivePathEffect diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 24113f976..43e7d8af5 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -4028,6 +4028,7 @@ void ObjectSet::setClipGroup() lpe->getRepr()->setAttribute("inverse", "true"); lpe->getRepr()->setAttribute("flatten", "false"); lpe->getRepr()->setAttribute("hide_clip", "false"); + dynamic_cast(lpe)->convertShapes(); } else { Effect::createAndApply(POWERMASK, doc, item); Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); -- cgit v1.2.3 From cba70f5669c6a38321157fbb84a8511033b7b41e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Thu, 2 Nov 2017 21:14:20 +0100 Subject: Remove unrelated code --- src/live_effects/lpe-powermask.cpp | 220 ++++++++++++++++++------------------- src/live_effects/lpe-powermask.h | 9 +- 2 files changed, 114 insertions(+), 115 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-powermask.cpp b/src/live_effects/lpe-powermask.cpp index 0d48b1b77..05510f258 100644 --- a/src/live_effects/lpe-powermask.cpp +++ b/src/live_effects/lpe-powermask.cpp @@ -13,12 +13,12 @@ #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" #include "extract-uri.h" #include + // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -29,25 +29,25 @@ 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_color(_("Background color and opacity"), _("Set color and opacity of the background"), "background_color", &wr, this, 0xffffffff) + background_style(_("Background Style"), _("CSS to background"), "background_style", &wr, this,"fill:#ffffff;opacity:1;") { registerParameter(&uri); registerParameter(&invert); - //registerParameter(&wrap); + registerParameter(&wrap); registerParameter(&hide_mask); registerParameter(&background); - registerParameter(&background_color); - previous_color = background_color.get_value(); + registerParameter(&background_style); + //lock.param_setValue(false); + background_style.param_hide_canvas_text(); } LPEPowerMask::~LPEPowerMask() {} void LPEPowerMask::doBeforeEffect (SPLPEItem const* lpeitem){ - //To avoid close of color dialog and better performance on change color SPObject * mask = SP_ITEM(sp_lpe_item)->mask_ref->getObject(); if(hide_mask && mask) { SP_ITEM(sp_lpe_item)->mask_ref->detach(); @@ -61,40 +61,35 @@ LPEPowerMask::doBeforeEffect (SPLPEItem const* lpeitem){ } mask = SP_ITEM(sp_lpe_item)->mask_ref->getObject(); if (mask) { - if (previous_color != background_color.get_value()) { - previous_color = background_color.get_value(); - setMask(); - } else { - uri.param_setValue(Glib::ustring(extract_uri(sp_lpe_item->getRepr()->attribute("mask"))), true); - SP_ITEM(sp_lpe_item)->mask_ref->detach(); - Geom::OptRect bbox = sp_lpe_item->visualBounds(); - if(!bbox) { - return; - } - if (uri.param_getSVGValue()) { - try { - SP_ITEM(sp_lpe_item)->mask_ref->attach(Inkscape::URI(uri.param_getSVGValue())); - } catch (Inkscape::BadURIException &e) { - g_warning("%s", e.what()); - SP_ITEM(sp_lpe_item)->mask_ref->detach(); - } - } else { + uri.param_setValue(Glib::ustring(extract_uri(sp_lpe_item->getRepr()->attribute("mask"))), true); + SP_ITEM(sp_lpe_item)->mask_ref->detach(); + Geom::OptRect bbox = sp_lpe_item->visualBounds(); + if(!bbox) { + return; + } + if (uri.param_getSVGValue()) { + try { + SP_ITEM(sp_lpe_item)->mask_ref->attach(Inkscape::URI(uri.param_getSVGValue())); + } catch (Inkscape::BadURIException &e) { + g_warning("%s", e.what()); SP_ITEM(sp_lpe_item)->mask_ref->detach(); } - Geom::Rect bboxrect = (*bbox); - bboxrect.expandBy(1); - Geom::Point topleft = bboxrect.corner(0); - Geom::Point topright = bboxrect.corner(1); - Geom::Point bottomright = bboxrect.corner(2); - Geom::Point bottomleft = bboxrect.corner(3); - mask_box.clear(); - mask_box.start(topleft); - mask_box.appendNew(topright); - mask_box.appendNew(bottomright); - mask_box.appendNew(bottomleft); - mask_box.close(); - setMask(); + } else { + SP_ITEM(sp_lpe_item)->mask_ref->detach(); } + Geom::Rect bboxrect = (*bbox); + bboxrect.expandBy(1); + Geom::Point topleft = bboxrect.corner(0); + Geom::Point topright = bboxrect.corner(1); + Geom::Point bottomright = bboxrect.corner(2); + Geom::Point bottomleft = bboxrect.corner(3); + mask_box.clear(); + mask_box.start(topleft); + mask_box.appendNew(topright); + mask_box.appendNew(bottomright); + mask_box.appendNew(bottomleft); + mask_box.close(); + setMask(); } } @@ -150,57 +145,56 @@ LPEPowerMask::setMask(){ filter->appendChild(primitive2); Inkscape::GC::release(primitive2); } -//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 mask_list = mask->childList(true); -// container->setPosition(-1); -// Inkscape::GC::release(container); -// for ( std::vector::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 item_list = sp_item_group_item_list(SP_GROUP(elemref)); - for ( std::vector::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); + 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 mask_list = mask->childList(true); + container->setPosition(-1); + Inkscape::GC::release(container); + for ( std::vector::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 item_list = sp_item_group_item_list(SP_GROUP(elemref)); + for ( std::vector::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); } - sp_object_ref(elemref, 0 ); - elemref->deleteObject(true); - sp_object_unref(elemref); } -// } std::vector mask_list = mask->childList(true); for ( std::vector::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) { SPItem * mask_data = SP_ITEM(*iter); @@ -235,28 +229,7 @@ LPEPowerMask::setMask(){ box->setAttribute("id", box_id.c_str()); exist = false; } - 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()); + 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); @@ -282,6 +255,33 @@ 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 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::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::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 +289,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 eb2640867..a54424e2f 100644 --- a/src/live_effects/lpe-powermask.h +++ b/src/live_effects/lpe-powermask.h @@ -6,11 +6,10 @@ * * 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 { @@ -23,17 +22,17 @@ 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; - ColorPickerParam background_color; + TextParam background_style; Geom::Path mask_box; - guint32 previous_color; }; } //namespace LivePathEffect -- cgit v1.2.3 From 08382df305f91a07349031e785500eb7be34872c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Fri, 3 Nov 2017 00:14:28 +0100 Subject: Move finctions away object sets --- src/live_effects/lpe-powerclip.cpp | 19 +++++++++++++++++++ src/live_effects/lpe-powerclip.h | 2 ++ src/live_effects/lpe-powermask.cpp | 18 ++++++++++++++++++ src/live_effects/lpe-powermask.h | 3 +++ src/object-set.h | 2 +- src/selection-chemistry.cpp | 26 ++------------------------ src/verbs.cpp | 11 +++++++++-- 7 files changed, 54 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-powerclip.cpp b/src/live_effects/lpe-powerclip.cpp index 40a9cdbfb..18276270d 100644 --- a/src/live_effects/lpe-powerclip.cpp +++ b/src/live_effects/lpe-powerclip.cpp @@ -395,6 +395,25 @@ LPEPowerClip::flattenClip(SPItem * clip_data, Geom::PathVector &path_in) } } +void sp_inverse_powerclip(Inkscape::Selection *sel) { + if (!sel->isEmpty()) { + auto selList = sel->items(); + for(auto i = boost::rbegin(selList); i != boost::rend(selList); ++i) { + SPLPEItem* lpeitem = dynamic_cast(*i); + if (lpeitem) { + Effect::createAndApply(POWERCLIP, SP_ACTIVE_DOCUMENT, lpeitem); + Effect* lpe = lpeitem->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"); + dynamic_cast(lpe)->convertShapes(); + } + } + } +} + }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-powerclip.h b/src/live_effects/lpe-powerclip.h index 38485b798..6f99d220f 100644 --- a/src/live_effects/lpe-powerclip.h +++ b/src/live_effects/lpe-powerclip.h @@ -38,6 +38,8 @@ private: bool convert_shapes; }; +void sp_inverse_powerclip(Inkscape::Selection *sel); + } //namespace LivePathEffect } //namespace Inkscape #endif diff --git a/src/live_effects/lpe-powermask.cpp b/src/live_effects/lpe-powermask.cpp index 05510f258..b7c88584b 100644 --- a/src/live_effects/lpe-powermask.cpp +++ b/src/live_effects/lpe-powermask.cpp @@ -303,6 +303,24 @@ LPEPowerMask::doOnRemove (SPLPEItem const* lpeitem) } } +void sp_inverse_powerclip(Inkscape::Selection *sel) { + if (!sel->isEmpty()) { + auto selList = sel->items(); + for(auto i = boost::rbegin(selList); i != boost::rend(selList); ++i) { + SPLPEItem* lpeitem = dynamic_cast(*i); + if (lpeitem) { + Effect::createAndApply(POWERMASK, SP_ACTIVE_DOCUMENT, lpeitem); + Effect* lpe = lpeitem->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"); + } + } + } +} + }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-powermask.h b/src/live_effects/lpe-powermask.h index a54424e2f..d2d87fd41 100644 --- a/src/live_effects/lpe-powermask.h +++ b/src/live_effects/lpe-powermask.h @@ -35,6 +35,9 @@ private: Geom::Path mask_box; }; +void sp_inverse_powermask(Inkscape::Selection *sel); + } //namespace LivePathEffect } //namespace Inkscape + #endif diff --git a/src/object-set.h b/src/object-set.h index 2e57966e6..a8061593a 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, bool inverse = false); + void setMask(bool apply_clip_path, bool apply_to_layer = false, bool skip_undo = 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 43e7d8af5..0bd611163 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -95,8 +95,6 @@ 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" @@ -3864,7 +3862,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, bool inverse) + void ObjectSet::setMask(bool apply_clip_path, bool apply_to_layer, bool skip_undo) { if(!desktop() && apply_to_layer) return; @@ -4018,27 +4016,7 @@ 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"); - dynamic_cast(lpe)->convertShapes(); - } 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::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); ++i) { diff --git a/src/verbs.cpp b/src/verbs.cpp index 962196d06..27fc29dd4 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -85,6 +85,9 @@ #include "ui/icon-names.h" #include "ui/tools/node-tool.h" #include "ui/dialog/save-template-dialog.h" +#include "live_effects/effect.h" +#include "live_effects/lpe-powerclip.h" +#include "live_effects/lpe-powermask.h" using Inkscape::DocumentUndo; using Inkscape::UI::Dialog::ActionAlign; @@ -1593,7 +1596,9 @@ void ObjectVerb::perform( SPAction *action, void *data) sel->setMask(false, false); break; case SP_VERB_OBJECT_SET_INVERSE_MASK: - sel->setMask(false, false, false, true); + sel->setMask(false, false); + using Inkscape::LivePathEffect; + sp_inverse_powermask(sp_action_get_selection(action)); break; case SP_VERB_OBJECT_EDIT_MASK: sel->editMask(false); @@ -1605,7 +1610,9 @@ void ObjectVerb::perform( SPAction *action, void *data) sel->setMask(true, false); break; case SP_VERB_OBJECT_SET_INVERSE_CLIPPATH: - sel->setMask(true, false, false, true); + sel->setMask(true, false); + using Inkscape::LivePathEffect; + sp_inverse_powerclip(sp_action_get_selection(action)); break; case SP_VERB_OBJECT_CREATE_CLIP_GROUP: sel->setClipGroup(); -- cgit v1.2.3 From bc776cf2ee8744fb0b49cb3ef9f53e835515624b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Fri, 3 Nov 2017 02:17:35 +0100 Subject: Rename wrong named function --- src/live_effects/lpe-powermask.cpp | 2 +- src/verbs.cpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-powermask.cpp b/src/live_effects/lpe-powermask.cpp index b7c88584b..396a3b3ca 100644 --- a/src/live_effects/lpe-powermask.cpp +++ b/src/live_effects/lpe-powermask.cpp @@ -303,7 +303,7 @@ LPEPowerMask::doOnRemove (SPLPEItem const* lpeitem) } } -void sp_inverse_powerclip(Inkscape::Selection *sel) { +void sp_inverse_powermask(Inkscape::Selection *sel) { if (!sel->isEmpty()) { auto selList = sel->items(); for(auto i = boost::rbegin(selList); i != boost::rend(selList); ++i) { diff --git a/src/verbs.cpp b/src/verbs.cpp index 27fc29dd4..d0975af16 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1597,8 +1597,7 @@ void ObjectVerb::perform( SPAction *action, void *data) break; case SP_VERB_OBJECT_SET_INVERSE_MASK: sel->setMask(false, false); - using Inkscape::LivePathEffect; - sp_inverse_powermask(sp_action_get_selection(action)); + Inkscape::LivePathEffect::sp_inverse_powermask(sp_action_get_selection(action)); break; case SP_VERB_OBJECT_EDIT_MASK: sel->editMask(false); @@ -1611,8 +1610,7 @@ void ObjectVerb::perform( SPAction *action, void *data) break; case SP_VERB_OBJECT_SET_INVERSE_CLIPPATH: sel->setMask(true, false); - using Inkscape::LivePathEffect; - sp_inverse_powerclip(sp_action_get_selection(action)); + Inkscape::LivePathEffect::sp_inverse_powerclip(sp_action_get_selection(action)); break; case SP_VERB_OBJECT_CREATE_CLIP_GROUP: sel->setClipGroup(); -- cgit v1.2.3 From a97a9d336818d0efc675c0578f8d02136f0836e7 Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Fri, 3 Nov 2017 23:52:11 +0100 Subject: Add Ignore Gtk::Overlay if GTK=3.0 --- src/ui/dialog/symbols.cpp | 34 +++++++++++++++++++++++++++++----- src/ui/dialog/symbols.h | 3 ++- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 2380ba56f..727fdf4f2 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -108,13 +108,14 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : preview_document(0), instanceConns() { - /******************** Table *************************/ - table = new Gtk::Grid(); + + /******************** Table *************************/ + auto table = new Gtk::Grid(); table->set_margin_left(3); table->set_margin_right(3); table->set_margin_top(4); // panel is a cloked Gtk::VBox - _getContents()->pack_start(* Gtk::manage(table), Gtk::PACK_EXPAND_WIDGET); + _getContents()->pack_start(*Gtk::manage(table), Gtk::PACK_EXPAND_WIDGET); guint row = 0; /******************** Symbol Sets *************************/ @@ -125,6 +126,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : symbol_set->append(_("All symbols sets")); symbol_set->set_active_text(_("Current Document")); symbol_set->set_hexpand(); + table->attach(*Gtk::manage(symbol_set),1,row,1,1); sigc::connection connSet = symbol_set->signal_changed().connect( sigc::mem_fun(*this, &SymbolsDialog::rebuild)); @@ -187,13 +189,16 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : scroller->add(*Gtk::manage(icon_view)); scroller->set_hexpand(); scroller->set_vexpand(); +#if GTK_CHECK_VERSION(3,2,4) overlay = new Gtk::Overlay(); overlay->set_hexpand(); overlay->set_vexpand(); overlay->add(* scroller); scroller->set_size_request(100, 250); table->attach(*Gtk::manage(overlay),0,row,2,1); - +#else + table->attach(*Gtk::manage(scroller),0,row,2,1); +#endif ++row; /******************** Progress *******************************/ @@ -319,6 +324,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : SPDefs *defs = current_document->getDefs(); /*************************Overlays******************************/ +#if GTK_CHECK_VERSION(3,2,4) //Loading overlay_opacity = new Gtk::Image(); overlay_opacity->set(getOverlay(overlay_opacity, "overlay", 1000)); @@ -348,7 +354,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : overlay->add_overlay(* overlay_icon); overlay->add_overlay(* overlay_title); overlay->add_overlay(* overlay_desc); - +#endif sigc::connection defsModifiedConn = defs->connectModified(sigc::mem_fun(*this, &SymbolsDialog::defsModified)); instanceConns.push_back(defsModifiedConn); @@ -369,7 +375,9 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : desk_track.connectDesktopChanged( sigc::mem_fun(*this, &SymbolsDialog::setTargetDesktop) ); instanceConns.push_back( desktopChangeConn ); desk_track.connect(GTK_WIDGET(gobj())); +#if GTK_CHECK_VERSION(3,2,4) overlay->hide(); +#endif } SymbolsDialog::~SymbolsDialog() @@ -930,6 +938,7 @@ void SymbolsDialog::unsensitive(GdkEventKey* evt) bool SymbolsDialog::callbackSymbols(){ Glib::ustring current = symbol_set->get_active_text(); +#if GTK_CHECK_VERSION(3,2,4) if (current == _("All symbols sets") && search->get_text() != _("Loading documents...")) { @@ -954,17 +963,22 @@ bool SymbolsDialog::callbackSymbols(){ overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); } } +#endif if (current == _("All symbols sets") && search->get_text() == _("Loading documents...") ) { +#if GTK_CHECK_VERSION(3,2,4) overlay_opacity->show(); +#endif if (!all_docs_processed) { +#if GTK_CHECK_VERSION(3,2,4) overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Loading all symbol sets ...")) + Glib::ustring("")); overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("When run for the first time, search will be slow.\nPlease wait ...")) + Glib::ustring("")); overlay_icon->show(); overlay_title->show(); overlay_icon->set_from_icon_name("searching", iconsize); overlay_desc->show(); +#endif } size_t counter = 0; for(auto const &symbol_document_map : symbol_sets) { @@ -981,19 +995,23 @@ bool SymbolsDialog::callbackSymbols(){ progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); return true; } +#if GTK_CHECK_VERSION(3,2,4) overlay_icon->hide(); overlay_title->hide(); overlay_desc->hide(); +#endif progress_bar->set_fraction(1.0); all_docs_processed = true; addSymbols(); search->set_text("Documents done, searchig inside..."); return true; } else if (l.size()) { +#if GTK_CHECK_VERSION(3,2,4) overlay_opacity->show(); overlay_icon->hide(); overlay_title->hide(); overlay_desc->hide(); +#endif for (auto symbol_data = l.begin(); symbol_data != l.end();) { Glib::ustring doc_title = symbol_data->first; SPSymbol * symbol = symbol_data->second; @@ -1028,6 +1046,7 @@ bool SymbolsDialog::callbackSymbols(){ return true; } } +#if GTK_CHECK_VERSION(3,2,4) if (!icons_found && !search_str.empty()) { overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); @@ -1038,6 +1057,7 @@ bool SymbolsDialog::callbackSymbols(){ } else { overlay_opacity->hide(); } +#endif sensitive = false; search->set_text(search_str); sensitive = true; @@ -1067,12 +1087,14 @@ void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { l = container_symbols_tmp; container_symbols_tmp.clear(); if (!number_symbols) { +#if GTK_CHECK_VERSION(3,2,4) overlay_icon->set_from_icon_name("none", iconsize); overlay_icon->show(); overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); overlay_title->show(); overlay_desc->show(); +#endif sensitive = false; search->set_text(search_str); sensitive = true; @@ -1100,12 +1122,14 @@ void SymbolsDialog::addSymbols() { l = container_symbols; container_symbols.clear(); if (!number_symbols) { +#if GTK_CHECK_VERSION(3,2,4) overlay_icon->set_from_icon_name("none", iconsize); overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); overlay_icon->show(); overlay_title->show(); overlay_desc->show(); +#endif sensitive = false; search->set_text(search_str); sensitive = true; diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 13ba9caf9..ebd56d5e0 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -128,12 +128,13 @@ private: Gtk::Button* more; Gtk::Button* fewer; Gtk::HBox* tools; +#if GTK_CHECK_VERSION(3,2,4) Gtk::Overlay* overlay; +#endif Gtk::Image* overlay_icon; Gtk::Image* overlay_opacity; Gtk::Label* overlay_title; Gtk::Label* overlay_desc; - Gtk::Grid* table; Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fit_symbol; Gtk::IconSize iconsize; -- cgit v1.2.3