summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-06-11 15:34:03 +0000
committerjabiertxof <info@marker.es>2016-06-11 15:34:03 +0000
commitd6b2e2cdeb563026cc9f4633e687a607b095da87 (patch)
treeb25e3e95e5e96782232e65d0d9889fcb12c2f285 /src/live_effects
parentFixing satellites bug on erase (diff)
parentA little cleaning up of attributes. (diff)
downloadinkscape-d6b2e2cdeb563026cc9f4633e687a607b095da87.tar.gz
inkscape-d6b2e2cdeb563026cc9f4633e687a607b095da87.zip
update to trunk
(bzr r13645.1.147)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/effect.cpp1
-rw-r--r--src/live_effects/lpe-perspective-envelope.cpp120
-rw-r--r--src/live_effects/lpe-perspective-envelope.h3
-rw-r--r--src/live_effects/parameter/path.cpp28
4 files changed, 138 insertions, 14 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index cee872f9f..0a78b199e 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -714,6 +714,7 @@ Effect::getParameter(const char * key)
{
Glib::ustring stringkey(key);
+ if (param_vector.empty()) return NULL;
std::vector<Parameter *>::iterator it = param_vector.begin();
while (it != param_vector.end()) {
Parameter * param = *it;
diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp
index 5b29df4a7..ae951dfc9 100644
--- a/src/live_effects/lpe-perspective-envelope.cpp
+++ b/src/live_effects/lpe-perspective-envelope.cpp
@@ -42,6 +42,7 @@ LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject)
Effect(lpeobject),
horizontal_mirror(_("Mirror movements in horizontal"), _("Mirror movements in horizontal"), "horizontal_mirror", &wr, this, false),
vertical_mirror(_("Mirror movements in vertical"), _("Mirror movements in vertical"), "vertical_mirror", &wr, this, false),
+ overflow_perspective(_("Overflow perspective"), _("Overflow perspective"), "overflow_perspective", &wr, this, false),
deform_type(_("Type"), _("Select the type of deformation"), "deform_type", DeformationTypeConverter, &wr, this, DEFORMATION_PERSPECTIVE),
up_left_point(_("Top Left"), _("Top Left - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "up_left_point", &wr, this),
up_right_point(_("Top Right"), _("Top Right - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "up_right_point", &wr, this),
@@ -52,6 +53,7 @@ LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject)
registerParameter(&deform_type);
registerParameter(&horizontal_mirror);
registerParameter(&vertical_mirror);
+ registerParameter(&overflow_perspective);
registerParameter(&up_left_point);
registerParameter(&up_right_point);
registerParameter(&down_left_point);
@@ -76,11 +78,107 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve)
}
double projmatrix[3][3];
if(deform_type == DEFORMATION_PERSPECTIVE) {
- std::vector<Geom::Point> handles(4);
- handles[0] = down_left_point;
- handles[1] = up_left_point;
- handles[2] = up_right_point;
- handles[3] = down_right_point;
+ if (!overflow_perspective && handles.size() == 4) {
+ bool move0 = false;
+ if (handles[0] != down_left_point) {
+ move0 = true;
+ }
+ bool move1 = false;
+ if (handles[1] != up_left_point) {
+ move1 = true;
+ }
+ bool move2 = false;
+ if (handles[2] != up_right_point) {
+ move2 = true;
+ }
+ bool move3 = false;
+ if (handles[3] != down_right_point) {
+ move3 = true;
+ }
+ handles.resize(4);
+ handles[0] = down_left_point;
+ handles[1] = up_left_point;
+ handles[2] = up_right_point;
+ handles[3] = down_right_point;
+ Geom::Line line_a(handles[3],handles[1]);
+ Geom::Line line_b(handles[1],handles[2]);
+ Geom::Line line_c(handles[2],handles[3]);
+ int position_a = Geom::sgn(Geom::cross(handles[3] - handles[1], handles[0] - handles[1]));
+ int position_b = Geom::sgn(Geom::cross(handles[1] - handles[2], handles[0] - handles[2]));
+ int position_c = Geom::sgn(Geom::cross(handles[2] - handles[3], handles[0] - handles[3]));
+ if (position_a != 1 && move0) {
+ Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[0]));
+ down_left_point.param_setValue(point_a, true);
+ }
+ if (position_b == 1 && move0) {
+ Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[0]));
+ down_left_point.param_setValue(point_b, true);
+ }
+ if (position_c == 1 && move0) {
+ Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[0]));
+ down_left_point.param_setValue(point_c, true);
+ }
+ line_a.setPoints(handles[0],handles[2]);
+ line_b.setPoints(handles[2],handles[3]);
+ line_c.setPoints(handles[3],handles[0]);
+ position_a = Geom::sgn(Geom::cross(handles[0] - handles[2], handles[1] - handles[2]));
+ position_b = Geom::sgn(Geom::cross(handles[2] - handles[3], handles[1] - handles[3]));
+ position_c = Geom::sgn(Geom::cross(handles[3] - handles[0], handles[1] - handles[0]));
+ if (position_a != 1 && move1) {
+ Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[1]));
+ up_left_point.param_setValue(point_a, true);
+ }
+ if (position_b == 1 && move1) {
+ Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[1]));
+ up_left_point.param_setValue(point_b, true);
+ }
+ if (position_c == 1 && move1) {
+ Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[1]));
+ up_left_point.param_setValue(point_c, true);
+ }
+ line_a.setPoints(handles[1],handles[3]);
+ line_b.setPoints(handles[3],handles[0]);
+ line_c.setPoints(handles[0],handles[1]);
+ position_a = Geom::sgn(Geom::cross(handles[1] - handles[3], handles[2] - handles[3]));
+ position_b = Geom::sgn(Geom::cross(handles[3] - handles[0], handles[2] - handles[0]));
+ position_c = Geom::sgn(Geom::cross(handles[0] - handles[1], handles[2] - handles[1]));
+ if (position_a != 1 && move2) {
+ Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[2]));
+ up_right_point.param_setValue(point_a, true);
+ }
+ if (position_b == 1 && move2) {
+ Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[2]));
+ up_right_point.param_setValue(point_b, true);
+ }
+ if (position_c == 1 && move2) {
+ Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[2]));
+ up_right_point.param_setValue(point_c, true);
+ }
+ line_a.setPoints(handles[2],handles[0]);
+ line_b.setPoints(handles[0],handles[1]);
+ line_c.setPoints(handles[1],handles[2]);
+ position_a = Geom::sgn(Geom::cross(handles[2] - handles[0], handles[3] - handles[0]));
+ position_b = Geom::sgn(Geom::cross(handles[0] - handles[1], handles[3] - handles[1]));
+ position_c = Geom::sgn(Geom::cross(handles[1] - handles[2], handles[3] - handles[2]));
+ if (position_a != 1 && move3) {
+ Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[3]));
+ down_right_point.param_setValue(point_a, true);
+ }
+ if (position_b == 1 && move3) {
+ Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[3]));
+ down_right_point.param_setValue(point_b, true);
+ }
+ if (position_c == 1 && move3) {
+ Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[3]));
+ down_right_point.param_setValue(point_c, true);
+ }
+ } else {
+ handles.resize(4);
+ handles[0] = down_left_point;
+ handles[1] = up_left_point;
+ handles[2] = up_right_point;
+ handles[3] = down_right_point;
+ }
std::vector<Geom::Point> source_handles(4);
source_handles[0] = Geom::Point(boundingbox_X.min(), boundingbox_Y.max());
source_handles[1] = Geom::Point(boundingbox_X.min(), boundingbox_Y.min());
@@ -206,14 +304,14 @@ LPEPerspectiveEnvelope::projectPoint(Geom::Point p)
double delta_y = boundingbox_Y.max() - p[Y];
Geom::Coord x_ratio = (delta_x * -1) / width;
Geom::Coord y_ratio = delta_y / height;
- Geom::Line* horiz = new Geom::Line();
- Geom::Line* vert = new Geom::Line();
- vert->setPoints (pointAtRatio(y_ratio,down_left_point,up_left_point),pointAtRatio(y_ratio,down_right_point,up_right_point));
- horiz->setPoints (pointAtRatio(x_ratio,down_left_point,down_right_point),pointAtRatio(x_ratio,up_left_point,up_right_point));
+ Geom::Line horiz;
+ Geom::Line vert;
+ vert.setPoints (pointAtRatio(y_ratio,down_left_point,up_left_point),pointAtRatio(y_ratio,down_right_point,up_right_point));
+ horiz.setPoints (pointAtRatio(x_ratio,down_left_point,down_right_point),pointAtRatio(x_ratio,up_left_point,up_right_point));
- OptCrossing crossPoint = intersection(*horiz,*vert);
+ OptCrossing crossPoint = intersection(horiz,vert);
if(crossPoint) {
- return horiz->pointAt(Geom::Coord(crossPoint->ta));
+ return horiz.pointAt(Geom::Coord(crossPoint->ta));
} else {
return p;
}
diff --git a/src/live_effects/lpe-perspective-envelope.h b/src/live_effects/lpe-perspective-envelope.h
index dd14dc212..727b7839d 100644
--- a/src/live_effects/lpe-perspective-envelope.h
+++ b/src/live_effects/lpe-perspective-envelope.h
@@ -60,12 +60,13 @@ private:
BoolParam horizontal_mirror;
BoolParam vertical_mirror;
+ BoolParam overflow_perspective;
EnumParam<unsigned> deform_type;
PointParam up_left_point;
PointParam up_right_point;
PointParam down_left_point;
PointParam down_right_point;
-
+ std::vector<Geom::Point> handles;
LPEPerspectiveEnvelope(const LPEPerspectiveEnvelope&);
LPEPerspectiveEnvelope& operator=(const LPEPerspectiveEnvelope&);
};
diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp
index 7ea1d465c..bed191e83 100644
--- a/src/live_effects/parameter/path.cpp
+++ b/src/live_effects/parameter/path.cpp
@@ -73,7 +73,21 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip,
PathParam::~PathParam()
{
remove_link();
-
+ using namespace Inkscape::UI;
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop) {
+ if (tools_isactive(desktop, TOOLS_NODES)) {
+ SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem();
+ if (item != NULL) {
+ Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context);
+ std::set<ShapeRecord> shapes;
+ ShapeRecord r;
+ r.item = item;
+ shapes.insert(r);
+ nt->_multipath->setItems(shapes);
+ }
+ }
+ }
g_free(defvalue);
}
@@ -207,6 +221,9 @@ PathParam::param_newWidget()
void
PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt)
{
+ SPDocument *document = dt->getDocument();
+ bool saved = DocumentUndo::getUndoSensitive(document);
+ DocumentUndo::setUndoSensitive(document, false);
using namespace Inkscape::UI;
// TODO remove the tools_switch atrocity.
@@ -220,14 +237,20 @@ PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt)
r.role = SHAPE_ROLE_LPE_PARAM;
r.edit_transform = item->i2dt_affine(); // TODO is it right?
+ r.edit_transform *= item->transform.inverse();
if (!href) {
r.item = reinterpret_cast<SPItem*>(param_effect->getLPEObj());
r.lpe_key = param_key;
+ Geom::PathVector stored_pv = _pathvector;
+ param_write_to_repr("M0,0 L1,0");
+ const char *svgd = sp_svg_write_path(stored_pv);
+ param_write_to_repr(svgd);
} else {
r.item = ref.getObject();
}
shapes.insert(r);
nt->_multipath->setItems(shapes);
+ DocumentUndo::setUndoSensitive(document, saved);
}
void
@@ -435,7 +458,8 @@ PathParam::paste_param_path(const char *svgd)
SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem();
if (item != NULL) {
Geom::PathVector path_clipboard = sp_svg_read_pathv(svgd);
- path_clipboard *= item->i2doc_affine().inverse();
+ path_clipboard *= item->i2doc_affine().inverse() * item->transform;
+ path_clipboard *= Geom::Translate(path_clipboard.initialPoint() - _pathvector.initialPoint()).inverse();
svgd = sp_svg_write_path( path_clipboard );
}