summaryrefslogtreecommitdiffstats
path: root/src/sp-spiral.cpp
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-09-02 19:51:04 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-09-02 19:51:04 +0000
commit632414c7cdd5f8992c6d6439d25128b82e93d499 (patch)
treecf5b544e03b0b165e8c6fe68e9345d6259f73e62 /src/sp-spiral.cpp
parentForgot to remove "share/ui/units.txt" from "share/ui/Makefile.am". (diff)
downloadinkscape-632414c7cdd5f8992c6d6439d25128b82e93d499.tar.gz
inkscape-632414c7cdd5f8992c6d6439d25128b82e93d499.zip
Fix bug that added transforms to new objects.
(bzr r12475.1.11)
Diffstat (limited to 'src/sp-spiral.cpp')
-rw-r--r--src/sp-spiral.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp
index 43e552d68..6f3a63f6a 100644
--- a/src/sp-spiral.cpp
+++ b/src/sp-spiral.cpp
@@ -35,6 +35,7 @@ static void sp_spiral_update (SPObject *object, SPCtx *ctx, guint flags);
static gchar * sp_spiral_description (SPItem * item);
static void sp_spiral_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
+static Geom::Affine sp_spiral_set_transform(SPItem *item, Geom::Affine const &xform);
static void sp_spiral_set_shape (SPShape *shape);
static void sp_spiral_update_patheffect (SPLPEItem *lpeitem, bool write);
@@ -60,6 +61,7 @@ static void sp_spiral_class_init(SPSpiralClass *klass)
item_class->description = sp_spiral_description;
item_class->snappoints = sp_spiral_snappoints;
+ item_class->set_transform = sp_spiral_set_transform;
lpe_item_class->update_patheffect = sp_spiral_update_patheffect;
@@ -493,6 +495,63 @@ static void sp_spiral_snappoints(SPItem const *item, std::vector<Inkscape::SnapC
}
/**
+ * Set spiral transform
+ */
+static Geom::Affine sp_spiral_set_transform(SPItem *item, Geom::Affine const &xform)
+{
+ // Only set transform with proportional scaling
+ if (!xform.withoutTranslation().isUniformScale()) {
+ return xform;
+ }
+
+ g_assert(item != NULL);
+ g_assert(SP_IS_SPIRAL(item));
+
+ SPSpiral *spiral = SP_SPIRAL(item);
+
+ /* Calculate spiral start in parent coords. */
+ Geom::Point pos( Geom::Point(spiral->cx, spiral->cy) * xform );
+
+ /* This function takes care of translation and scaling, we return whatever parts we can't
+ handle. */
+ Geom::Affine ret(Geom::Affine(xform).withoutTranslation());
+ gdouble const s = hypot(ret[0], ret[1]);
+ if (s > 1e-9) {
+ ret[0] /= s;
+ ret[1] /= s;
+ ret[2] /= s;
+ ret[3] /= s;
+ } else {
+ ret[0] = 1.0;
+ ret[1] = 0.0;
+ ret[2] = 0.0;
+ ret[3] = 1.0;
+ }
+
+ spiral->rad *= s;
+
+ /* Find start in item coords */
+ pos = pos * ret.inverse();
+ spiral->cx = pos[Geom::X];
+ spiral->cy = pos[Geom::Y];
+
+ sp_spiral_set_shape(spiral);
+
+ // Adjust stroke width
+ item->adjust_stroke(s);
+
+ // Adjust pattern fill
+ item->adjust_pattern(xform * ret.inverse());
+
+ // Adjust gradient fill
+ item->adjust_gradient(xform * ret.inverse());
+
+ item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+
+ return ret;
+}
+
+/**
* Return one of the points on the spiral.
*
* \param t specifies how far along the spiral.