diff options
| author | Jabiertxof <jtx@jtx> | 2016-12-29 20:32:45 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx> | 2016-12-29 20:32:45 +0000 |
| commit | f69e17d45c7311cb8430caa03f4f41be63ac9279 (patch) | |
| tree | 2966bf1f547ed4ea401ec09ee62c6124445bdd48 /src | |
| parent | Some fixes on translations and make legacy compatible (diff) | |
| download | inkscape-f69e17d45c7311cb8430caa03f4f41be63ac9279.tar.gz inkscape-f69e17d45c7311cb8430caa03f4f41be63ac9279.zip | |
Add sp_shape to LPE chain and fixing transforms
(bzr r15356.1.4)
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/effect.cpp | 41 | ||||
| -rw-r--r-- | src/live_effects/effect.h | 9 | ||||
| -rw-r--r-- | src/live_effects/lpe-clone-original.cpp | 33 | ||||
| -rw-r--r-- | src/live_effects/lpe-clone-original.h | 4 | ||||
| -rw-r--r-- | src/sp-lpe-item.cpp | 6 |
5 files changed, 60 insertions, 33 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index cfd393b87..81a512d23 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -356,7 +356,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) sp_lpe_item(NULL), current_zoom(1), upd_params(true), - sp_curve(NULL), + sp_shape(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { @@ -392,9 +392,9 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector<Geom::Point> sNP) +Effect::setSelectedNodePoints(std::vector<Geom::Point> selected_np) { - selectedNodesPoints = sNP; + selected_nodes_points = selected_np; } void @@ -404,16 +404,16 @@ Effect::setCurrentZoom(double cZ) } bool -Effect::isNodePointSelected(Geom::Point const &nodePoint) const +Effect::isNodePointSelected(Geom::Point const &node_point) const { - if (selectedNodesPoints.size() > 0) { + if (selected_nodes_points.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector<Geom::Point>::const_iterator i = selectedNodesPoints.begin(); - i != selectedNodesPoints.end(); ++i) { + for (std::vector<Geom::Point>::const_iterator i = selected_nodes_points.begin(); + i != selected_nodes_points.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); - Geom::Point p2(nodePoint[X],nodePoint[Y]); + Geom::Point p2(node_point[X], node_point[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; @@ -446,20 +446,24 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast<SPLPEItem *>(lpeitem); - /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector();*/ + SPShape * shape = dynamic_cast<SPShape *>(sp_lpe_item); + if(shape){ + setCurrentShape(shape); + } doOnApply(lpeitem); } void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast<SPLPEItem *>(lpeitem); - //printf("(SPLPEITEM*) %p\n", sp_lpe_item); + //Groups set shape in performPathEffect before each call to doEffect SPShape * shape = dynamic_cast<SPShape *>(sp_lpe_item); if(shape){ - setSPCurve(shape->getCurve()); + setCurrentShape(shape); } + //printf("(SPLPEITEM*) %p\n", sp_lpe_item); doBeforeEffect(lpeitem); + if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { sp_lpe_item->apply_to_clippath(sp_lpe_item); sp_lpe_item->apply_to_mask(sp_lpe_item); @@ -467,10 +471,15 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) update_helperpath(); } -void Effect::setSPCurve(SPCurve *curve) -{ - sp_curve = curve; - pathvector_before_effect = curve->get_pathvector(); +void Effect::setCurrentShape(SPShape * shape){ + if(shape){ + sp_shape = shape; + if (!(sp_curve = sp_shape->getCurve())) { + // oops + return; + } + pathvector_before_effect = sp_curve->get_pathvector(); + } } /** * Effects can have a parameter path set before they are applied by accepting a nonzero number of diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index e975deb05..5dfa3de29 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -73,8 +73,8 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); - void setSPCurve(SPCurve *curve); - + SPShape * getCurrentShape(){ return sp_shape; }; + void setCurrentShape(SPShape * shape); /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, * e.g., waiting for a parameter path either before the effect is created or when it needs a @@ -164,9 +164,10 @@ protected: // instead of normally 'splitting' the path into continuous pwd2 paths and calling doEffect_pwd2 for each. bool concatenate_before_pwd2; - SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them.z + SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. double current_zoom; - std::vector<Geom::Point> selectedNodesPoints; + std::vector<Geom::Point> selected_nodes_points; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 7072ad161..8176f3811 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -37,10 +37,12 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); apply_to_clippath_and_mask = true; + preserve_position_changed = !preserve_position; + preserve_affine = Geom::identity(); } void -LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes) +LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root) { SPDocument * document = SP_ACTIVE_DOCUMENT; if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { @@ -49,7 +51,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co for (std::vector<SPObject * >::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes); + cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes, false); index++; } } @@ -65,7 +67,15 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co Geom::Affine affine_origin = SP_ITEM(origin)->transform; //dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); if (preserve_position) { - SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin ; + Geom::Affine dest_affine = Geom::identity(); + if (root) { + dest_affine *= Geom::Translate(preserve_affine.translation()); + preserve_affine = Geom::identity(); + } + dest_affine *= Geom::Translate(affine_dest.translation()); + dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); + dest_affine *= affine_origin; + SP_ITEM(dest)->transform = dest_affine; } else { SP_ITEM(dest)->transform = affine_origin ; } @@ -131,6 +141,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co void LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ original_bbox(lpeitem); + if ( preserve_position_changed != preserve_position ) { + if (!preserve_position) { + preserve_affine = SP_ITEM(sp_lpe_item)->transform; + } + preserve_position_changed = preserve_position; + } if (linked_path.linksToPath()) { //Legacy staff Glib::ustring attributes_value("d"); attributes.param_setValue(attributes_value); @@ -142,11 +158,7 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ linked_path.param_readSVGValue(""); } if (linked_item.linksToItem()) { - cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue()); - SPShape * shape = dynamic_cast<SPShape *>(sp_lpe_item); - if(shape){ - this->setSPCurve(shape->getCurve()); - } + cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } @@ -205,7 +217,10 @@ LPECloneOriginal::~LPECloneOriginal() void LPECloneOriginal::doEffect (SPCurve * curve) { - curve->set_pathvector(pathvector_before_effect); + SPShape * shape = getCurrentShape(); + if(shape){ + curve->set_pathvector(shape->getCurve()->get_pathvector()); + } } } // namespace LivePathEffect diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index e232135eb..e8a9a7419 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -29,7 +29,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); virtual Gtk::Widget * newWidget(); - void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); private: OriginalPathParam linked_path; @@ -38,6 +38,8 @@ private: BoolParam preserve_position; TextParam attributes; TextParam style_attributes; + bool preserve_position_changed; + Geom::Affine preserve_affine; LPECloneOriginal(const LPECloneOriginal&); LPECloneOriginal& operator=(const LPECloneOriginal&); }; diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index f5c930404..c7a800041 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -241,12 +241,12 @@ bool SPLPEItem::performPathEffect(SPCurve *curve, SPShape *current, bool is_clip } if (!is_clip_or_mask || (is_clip_or_mask && lpe->apply_to_clippath_and_mask)) { // Groups have their doBeforeEffect called elsewhere + if (SP_IS_GROUP(this) && current) { + lpe->setCurrentShape(current); + } if (!SP_IS_GROUP(this)) { lpe->doBeforeEffect_impl(this); } - if (SP_IS_GROUP(this) && current) { - lpe->setSPCurve(current->getCurve()); - } try { lpe->doEffect(curve); } |
