diff options
| author | Jabiertxof <jabier.arraiza@marker.es> | 2019-05-22 14:56:19 +0000 |
|---|---|---|
| committer | Jabiertxof <jabier.arraiza@marker.es> | 2019-05-22 14:56:19 +0000 |
| commit | ce9af91c8def1e6c4073953bea15154f409e6000 (patch) | |
| tree | 8db7e83dda6dd923aebc221699fd5435b1b2c304 /src | |
| parent | Extract a common expression into a variable/const. (diff) | |
| download | inkscape-ce9af91c8def1e6c4073953bea15154f409e6000.tar.gz inkscape-ce9af91c8def1e6c4073953bea15154f409e6000.zip | |
Allow scale offset in groups using the knot like in paths
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-offset.cpp | 61 | ||||
| -rw-r--r-- | src/live_effects/lpe-offset.h | 2 |
2 files changed, 48 insertions, 15 deletions
diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index 18f597858..0b3d5e2cb 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -146,14 +146,16 @@ LPEOffset::get_nearest_point(Geom::PathVector pathv, Geom::Point point) const Geom::Point LPEOffset::get_default_point(Geom::PathVector pathv) const { - if (SP_IS_GROUP(sp_lpe_item)) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } Geom::Point origin = Geom::Point(Geom::infinity(), Geom::infinity()); Geom::OptRect bbox = pathv.boundsFast(); if (bbox) { - origin = Geom::Point((*bbox).midpoint()[Geom::X],(*bbox).top()); - origin = get_nearest_point(pathv, origin); + if (SP_IS_GROUP(sp_lpe_item)) { + origin = Geom::Point(boundingbox_X.min(),boundingbox_Y.min()); + } else { + origin = Geom::Point((*bbox).midpoint()[Geom::X],(*bbox).top()); + origin = get_nearest_point(pathv, origin); + } + } return origin; } @@ -171,12 +173,22 @@ sp_get_distance_point(Geom::PathVector pathv, Geom::Point origin) { double LPEOffset::sp_get_offset(Geom::Point origin) { + SPGroup * group = dynamic_cast<SPGroup *>(sp_lpe_item); + double ret_offset = 0; + if (group) { + Geom::Point initial = get_default_point(filled_rule_pathv); + ret_offset = Geom::distance(origin, initial); + if (origin[Geom::Y] < initial[Geom::Y]) { + ret_offset *= -1; + } + return Inkscape::Util::Quantity::convert(ret_offset, display_unit.c_str(), unit.get_abbreviation()); + } int winding_value = filled_rule_pathv.winding(origin); bool inset = false; if (winding_value % 2 != 0) { inset = true; } - double ret_offset = 0; + ret_offset = sp_get_distance_point(filled_rule_pathv, origin); if (inset) { ret_offset *= -1; @@ -185,6 +197,12 @@ LPEOffset::sp_get_offset(Geom::Point origin) } void +LPEOffset::addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec) +{ + hp_vec.push_back(helper_path); +} + +void LPEOffset::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem); @@ -193,6 +211,16 @@ LPEOffset::doBeforeEffect (SPLPEItem const* lpeitem) return; } display_unit = document->getDisplayUnit()->abbr.c_str(); + SPGroup const *group = dynamic_cast<SPGroup const *>(lpeitem); + if (group) { + helper_path.clear(); + Geom::Point origin = Geom::Point(boundingbox_X.min(), boundingbox_Y.min()); + Geom::Point endpont = Geom::Point(boundingbox_X.min(), boundingbox_Y.min()); + endpont[Geom::Y] = endpont[Geom::Y] + Inkscape::Util::Quantity::convert(offset, unit.get_abbreviation(), display_unit.c_str()); + Geom::Path hp(origin); + hp.appendNew<Geom::LineSegment>(endpont); + helper_path.push_back(hp); + } } int offset_winding(Geom::PathVector pathvector, Geom::Path path) @@ -466,11 +494,12 @@ void KnotHolderEntityOffsetPoint::knot_ungrabbed(Geom::Point const &p, Geom::Poi void KnotHolderEntityOffsetPoint::knot_set(Geom::Point const &p, Geom::Point const& /*origin*/, guint state) { using namespace Geom; - if (SP_IS_GROUP(item)) { - return; - } + SPGroup * group = dynamic_cast<SPGroup *>(item); LPEOffset* lpe = dynamic_cast<LPEOffset *>(_effect); Geom::Point s = snap_knot_position(p, state); + if (group) { + s[Geom::X] = lpe->boundingbox_X.min(); + } double offset = lpe->sp_get_offset(s); lpe->offset_pt = s; lpe->offset.param_set_value(offset); @@ -481,14 +510,16 @@ void KnotHolderEntityOffsetPoint::knot_set(Geom::Point const &p, Geom::Point con Geom::Point KnotHolderEntityOffsetPoint::knot_get() const { - if (SP_IS_GROUP(item)) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - LPEOffset const * lpe = dynamic_cast<LPEOffset const*> (_effect); + SPGroup * group = dynamic_cast<SPGroup *>(item); + LPEOffset * lpe = dynamic_cast<LPEOffset *> (_effect); Geom::Point nearest = lpe->offset_pt; if (lpe->offset_pt == Geom::Point(Geom::infinity(), Geom::infinity())) { - Geom::PathVector out = SP_SHAPE(item)->getCurve()->get_pathvector(); - nearest = lpe->get_default_point(out); + if (group) { + nearest = Geom::Point(lpe->boundingbox_X.min(), lpe->boundingbox_Y.min()); + } else { + Geom::PathVector out = SP_SHAPE(item)->getCurve()->get_pathvector(); + nearest = lpe->get_default_point(out); + } } return nearest; } diff --git a/src/live_effects/lpe-offset.h b/src/live_effects/lpe-offset.h index 44f42048a..2374791d3 100644 --- a/src/live_effects/lpe-offset.h +++ b/src/live_effects/lpe-offset.h @@ -37,6 +37,7 @@ public: void doBeforeEffect (SPLPEItem const* lpeitem) override; Geom::PathVector doEffect_path (Geom::PathVector const & path_in) override; void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item) override; + void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec) override; void calculateOffset (Geom::PathVector const & path_in); Geom::Point get_default_point(Geom::PathVector pathv) const; Geom::Point get_nearest_point(Geom::PathVector pathv, Geom::Point point) const; @@ -54,6 +55,7 @@ private: Glib::ustring display_unit; KnotHolderEntity * _knot_entity; Geom::PathVector filled_rule_pathv; + Geom::PathVector helper_path; Inkscape::UI::Widget::Scalar *offset_widget; LPEOffset(const LPEOffset&); |
