summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-08-01 17:39:57 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-08-01 17:39:57 +0000
commit2df2ad74531a0aa0f221db556f26dd6505e1a61f (patch)
treec0f9dd711aef5d79aa33bca8b4352def6166f0be /src/live_effects
parentFormerly static function used for snapping is now a private member of KnotHol... (diff)
downloadinkscape-2df2ad74531a0aa0f221db556f26dd6505e1a61f.tar.gz
inkscape-2df2ad74531a0aa0f221db556f26dd6505e1a61f.zip
Make LPE knotholder handles snap
(bzr r6506)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/lpe-angle_bisector.cpp8
-rw-r--r--src/live_effects/lpe-copy_rotate.cpp7
-rw-r--r--src/live_effects/lpe-parallel.cpp8
-rw-r--r--src/live_effects/lpe-perp_bisector.cpp23
-rw-r--r--src/live_effects/lpe-perp_bisector.h2
-rw-r--r--src/live_effects/lpe-perspective_path.cpp6
-rw-r--r--src/live_effects/lpe-tangent_to_curve.cpp20
7 files changed, 49 insertions, 25 deletions
diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp
index 41c11fc5e..179d46a52 100644
--- a/src/live_effects/lpe-angle_bisector.cpp
+++ b/src/live_effects/lpe-angle_bisector.cpp
@@ -106,7 +106,9 @@ KnotHolderEntityLeftEnd::knot_set(NR::Point const &p, NR::Point const &/*origin*
{
LPEAngleBisector *lpe = get_effect(item);
- double lambda = Geom::nearest_point(p.to_2geom(), lpe->ptA, lpe->dir);
+ NR::Point const s = snap_knot_position(p);
+
+ double lambda = Geom::nearest_point(s.to_2geom(), lpe->ptA, lpe->dir);
lpe->length_left.param_set_value(-lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
@@ -117,7 +119,9 @@ KnotHolderEntityRightEnd::knot_set(NR::Point const &p, NR::Point const &/*origin
{
LPEAngleBisector *lpe = get_effect(item);
- double lambda = Geom::nearest_point(p.to_2geom(), lpe->ptA, lpe->dir);
+ NR::Point const s = snap_knot_position(p);
+
+ double lambda = Geom::nearest_point(s.to_2geom(), lpe->ptA, lpe->dir);
lpe->length_right.param_set_value(lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp
index 142b6eb64..9c475d46a 100644
--- a/src/live_effects/lpe-copy_rotate.cpp
+++ b/src/live_effects/lpe-copy_rotate.cpp
@@ -124,9 +124,11 @@ KnotHolderEntityAngle::knot_set(NR::Point const &p, NR::Point const &/*origin*/,
{
LPECopyRotate* lpe = get_effect(item);
+ NR::Point const s = snap_knot_position(p);
+
// I first suspected the minus sign to be a bug in 2geom but it is
// likely due to SVG's choice of coordinate system orientation (max)
- lpe->angle.param_set_value(rad_to_deg(-angle_between(lpe->dir, p.to_2geom() - lpe->origin)));
+ lpe->angle.param_set_value(rad_to_deg(-angle_between(lpe->dir, s.to_2geom() - lpe->origin)));
if (state & GDK_SHIFT_MASK) {
lpe->dist_angle_handle = L2(lpe->B - lpe->A);
} else {
@@ -144,7 +146,8 @@ KnotHolderEntityAngle::knot_get()
// I first suspected the minus sign to be a bug in 2geom but it is
// likely due to SVG's choice of coordinate system orientation (max)
Point d = lpe->dir * Rotate(-deg_to_rad(lpe->angle)) * lpe->dist_angle_handle;
- return lpe->origin + d;
+
+ return snap_knot_position(lpe->origin + d);
}
} // namespace CR
diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp
index e0e156263..e6d49b0b2 100644
--- a/src/live_effects/lpe-parallel.cpp
+++ b/src/live_effects/lpe-parallel.cpp
@@ -114,7 +114,9 @@ KnotHolderEntityLeftEnd::knot_set(NR::Point const &p, NR::Point const &/*origin*
LPEParallel *lpe = get_effect(item);
- double lambda = L2(p - lpe->offset_pt) * sgn(dot(p.to_2geom() - lpe->offset_pt, lpe->dir));
+ NR::Point const s = snap_knot_position(p);
+
+ double lambda = L2(s - lpe->offset_pt) * sgn(dot(s.to_2geom() - lpe->offset_pt, lpe->dir));
lpe->length_left.param_set_value(-lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
@@ -127,7 +129,9 @@ KnotHolderEntityRightEnd::knot_set(NR::Point const &p, NR::Point const &/*origin
LPEParallel *lpe = get_effect(item);
- double lambda = L2(p - lpe->offset_pt) * sgn(dot(p.to_2geom() - lpe->offset_pt, lpe->dir));
+ NR::Point const s = snap_knot_position(p);
+
+ double lambda = L2(s - lpe->offset_pt) * sgn(dot(s.to_2geom() - lpe->offset_pt, lpe->dir));
lpe->length_right.param_set_value(lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp
index c4146a1d9..f9aca2ada 100644
--- a/src/live_effects/lpe-perp_bisector.cpp
+++ b/src/live_effects/lpe-perp_bisector.cpp
@@ -25,15 +25,18 @@ namespace Inkscape {
namespace LivePathEffect {
namespace PB {
-class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityEnd : public LPEKnotHolderEntity {
+public:
+ void bisector_end_set(NR::Point const &p, bool left = true);
+};
+
+class KnotHolderEntityLeftEnd : public KnotHolderEntityEnd {
public:
virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
virtual NR::Point knot_get();
};
-class KnotHolderEntityRightEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityRightEnd : public KnotHolderEntityEnd {
public:
virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
virtual NR::Point knot_get();
@@ -64,14 +67,14 @@ KnotHolderEntityRightEnd::knot_get() {
}
void
-bisector_end_set(SPItem *item, NR::Point const &p, bool left) {
+KnotHolderEntityEnd::bisector_end_set(NR::Point const &p, bool left) {
Inkscape::LivePathEffect::LPEPerpBisector *lpe =
dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)));
+ if (!lpe) return;
- if (!lpe)
- return;
+ NR::Point const s = snap_knot_position(p);
- double lambda = Geom::nearest_point(p.to_2geom(), lpe->M, lpe->perp_dir);
+ double lambda = Geom::nearest_point(s.to_2geom(), lpe->M, lpe->perp_dir);
if (left) {
lpe->C = lpe->M + lpe->perp_dir * lambda;
lpe->length_left.param_set_value(lambda);
@@ -86,12 +89,12 @@ bisector_end_set(SPItem *item, NR::Point const &p, bool left) {
void
KnotHolderEntityLeftEnd::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) {
- bisector_end_set(item, p);
+ bisector_end_set(p);
}
void
KnotHolderEntityRightEnd::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) {
- bisector_end_set(item, p, false);
+ bisector_end_set(p, false);
}
/**
diff --git a/src/live_effects/lpe-perp_bisector.h b/src/live_effects/lpe-perp_bisector.h
index 19fb7d23e..1544eb4ff 100644
--- a/src/live_effects/lpe-perp_bisector.h
+++ b/src/live_effects/lpe-perp_bisector.h
@@ -24,6 +24,7 @@ namespace LivePathEffect {
namespace PB {
// we need a separate namespace to avoid clashes with LPETangentToCurve
+ class KnotHolderEntityEnd;
class KnotHolderEntityLeftEnd;
class KnotHolderEntityRightEnd;
void bisector_end_set(SPItem *item, NR::Point const &p, bool left);
@@ -42,6 +43,7 @@ public:
doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
/* the knotholder entity functions must be declared friends */
+ friend class PB::KnotHolderEntityEnd;
friend class PB::KnotHolderEntityLeftEnd;
friend class PB::KnotHolderEntityRightEnd;
friend void PB::bisector_end_set(SPItem *item, NR::Point const &p, bool left = true);
diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp
index e3397a20e..998554241 100644
--- a/src/live_effects/lpe-perspective_path.cpp
+++ b/src/live_effects/lpe-perspective_path.cpp
@@ -168,8 +168,10 @@ KnotHolderEntityOffset::knot_set(NR::Point const &p, NR::Point const &origin, gu
LPEPerspectivePath* lpe = get_effect(item);
- lpe->offsetx.param_set_value((p - origin)[NR::X]);
- lpe->offsety.param_set_value(-(p - origin)[NR::Y]); // additional minus sign is due to coordinate system flipping
+ NR::Point const s = snap_knot_position(p);
+
+ lpe->offsetx.param_set_value((s - origin)[NR::X]);
+ lpe->offsety.param_set_value(-(s - origin)[NR::Y]); // additional minus sign is due to coordinate system flipping
// FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp
index 33188382c..0d21b38e0 100644
--- a/src/live_effects/lpe-tangent_to_curve.cpp
+++ b/src/live_effects/lpe-tangent_to_curve.cpp
@@ -113,9 +113,11 @@ get_effect(SPItem *item)
void
KnotHolderEntityAttachPt::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
{
- using namespace Geom;
-
- LPETangentToCurve* lpe = get_effect(item);
+ using namespace Geom;
+
+ LPETangentToCurve* lpe = get_effect(item);
+
+ NR::Point const s = snap_knot_position(p);
// FIXME: There must be a better way of converting the path's SPCurve* to pwd2.
SPCurve *curve = sp_path_get_curve_for_edit (SP_PATH(item));
@@ -125,7 +127,7 @@ KnotHolderEntityAttachPt::knot_set(NR::Point const &p, NR::Point const &/*origin
pwd2.concat(pathv[i].toPwSb());
}
- double t0 = nearest_point(p.to_2geom(), pwd2);
+ double t0 = nearest_point(s.to_2geom(), pwd2);
lpe->t_attach.param_set_value(t0);
// FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
@@ -136,8 +138,10 @@ void
KnotHolderEntityLeftEnd::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
{
LPETangentToCurve *lpe = get_effect(item);
-
- double lambda = Geom::nearest_point(p.to_2geom(), lpe->ptA, lpe->derivA);
+
+ NR::Point const s = snap_knot_position(p);
+
+ double lambda = Geom::nearest_point(s.to_2geom(), lpe->ptA, lpe->derivA);
lpe->length_left.param_set_value(-lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
@@ -148,7 +152,9 @@ KnotHolderEntityRightEnd::knot_set(NR::Point const &p, NR::Point const &/*origin
{
LPETangentToCurve *lpe = get_effect(item);
- double lambda = Geom::nearest_point(p.to_2geom(), lpe->ptA, lpe->derivA);
+ NR::Point const s = snap_knot_position(p);
+
+ double lambda = Geom::nearest_point(s.to_2geom(), lpe->ptA, lpe->derivA);
lpe->length_right.param_set_value(lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);