Code

New LPE: Ruler
authorcilix42 <cilix42@users.sourceforge.net>
Tue, 15 Jul 2008 12:41:03 +0000 (12:41 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Tue, 15 Jul 2008 12:41:03 +0000 (12:41 +0000)
src/live_effects/Makefile_insert
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-ruler.cpp [new file with mode: 0644]
src/live_effects/lpe-ruler.h [new file with mode: 0644]

index b9f86454612e3364d8f24351586164152df67ab0..d3f50cd9a6043c3fb69d171cfc37d76a4140cfda 100644 (file)
@@ -62,5 +62,7 @@ live_effects_liblive_effects_a_SOURCES = \
        live_effects/lpe-copy_rotate.cpp        \
        live_effects/lpe-copy_rotate.h  \
        live_effects/lpe-offset.cpp     \
-       live_effects/lpe-offset.h
+       live_effects/lpe-offset.h       \
+       live_effects/lpe-ruler.cpp      \
+       live_effects/lpe-ruler.h
 
index 66d2334e018684ad2ed8b74748c9ab8853dfb012..d5ac6dc7485812be8a98564405b48385a204bdcd 100644 (file)
@@ -61,6 +61,7 @@
 #include "live_effects/lpe-parallel.h"
 #include "live_effects/lpe-copy_rotate.h"
 #include "live_effects/lpe-offset.h"
+#include "live_effects/lpe-ruler.h"
 // end of includes
 
 namespace Inkscape {
@@ -93,6 +94,7 @@ const Util::EnumData<EffectType> LPETypeData[INVALID_LPE] = {
     {PARALLEL, N_("Parallel"), "parallel"},
     {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"},
     {OFFSET, N_("Offset"), "offset"},
+    {RULER, N_("Ruler"), "ruler"},
 };
 const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
 
@@ -169,6 +171,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
         case OFFSET:
             neweffect = static_cast<Effect*> ( new LPEOffset(lpeobj) );
             break;
+        case RULER:
+            neweffect = static_cast<Effect*> ( new LPERuler(lpeobj) );
+            break;
         default:
             g_warning("LivePathEffect::Effect::New   called with invalid patheffect type (%d)", lpenr);
             neweffect = NULL;
index dc5d6ec4a1fb6fcdfa18be85b71fcb5123daa13b..eced0a1941b22aaf915514379f7a41b5a23c2517 100644 (file)
@@ -75,6 +75,7 @@ enum EffectType {
     PARALLEL,
     COPY_ROTATE,
     OFFSET,
+    RULER,
     INVALID_LPE // This must be last
 };
 
diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp
new file mode 100644 (file)
index 0000000..5a3f8c2
--- /dev/null
@@ -0,0 +1,79 @@
+#define INKSCAPE_LPE_RULER_CPP
+
+/** \file
+ * LPE <ruler> implementation, see lpe-ruler.cpp.
+ */
+
+/*
+ * Authors:
+ *   Maximilian Albert
+ *   Johan Engelen
+ *
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/lpe-ruler.h"
+#include <2geom/piecewise.h>
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPERuler::LPERuler(LivePathEffectObject *lpeobject) :
+    Effect(lpeobject),
+    mark_distance(_("Mark distance"), _("Distance between ruler marks"), "mark_distance", &wr, this, 50),
+    mark_length(_("Mark length"), _("Length of ruler marks"), "mark_length", &wr, this, 10)
+{
+    registerParameter(dynamic_cast<Parameter *>(&mark_distance));
+    registerParameter(dynamic_cast<Parameter *>(&mark_length));
+
+    mark_distance.param_make_integer();
+    mark_length.param_make_integer();
+}
+
+LPERuler::~LPERuler()
+{
+
+}
+
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
+{
+    using namespace Geom;
+
+    Point A(pwd2_in.firstValue());
+    Point B(pwd2_in.lastValue());
+
+    Piecewise<D2<SBasis> >output(D2<SBasis>(Linear(A[X], B[X]), Linear(A[Y], B[Y])));
+
+    Point dir(unit_vector(B - A));
+    Point n(-rot90(dir) * mark_length);
+    double length = L2(B - A);
+
+    Point C, D;
+    for (int i = 0; i < length; i+=mark_distance) {
+        C = A + dir * i;
+        D = C + n;
+        Piecewise<D2<SBasis> > seg(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
+        output.concat(seg);
+    }
+
+    return output;
+}
+
+/* ######################## */
+
+} //namespace LivePathEffect
+} /* namespace Inkscape */
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/live_effects/lpe-ruler.h b/src/live_effects/lpe-ruler.h
new file mode 100644 (file)
index 0000000..891217c
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef INKSCAPE_LPE_RULER_H
+#define INKSCAPE_LPE_RULER_H
+
+/** \file
+ * LPE <ruler> implementation, see lpe-ruler.cpp.
+ */
+
+/*
+ * Authors:
+ *   Maximilian Albert
+ *   Johan Engelen
+ *
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/effect.h"
+#include "live_effects/parameter/parameter.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPERuler : public Effect {
+public:
+    LPERuler(LivePathEffectObject *lpeobject);
+    virtual ~LPERuler();
+
+    virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
+
+private:
+    ScalarParam mark_distance;
+    ScalarParam mark_length;
+    LPERuler(const LPERuler&);
+    LPERuler& operator=(const LPERuler&);
+};
+
+} //namespace LivePathEffect
+} //namespace Inkscape
+
+#endif
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :