Code

New LPE: Text label
authorcilix42 <cilix42@users.sourceforge.net>
Wed, 30 Jul 2008 10:57:48 +0000 (10:57 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Wed, 30 Jul 2008 10:57:48 +0000 (10:57 +0000)
src/live_effects/Makefile_insert
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-text_label.cpp [new file with mode: 0644]
src/live_effects/lpe-text_label.h [new file with mode: 0644]

index b67e44051b47bfa8ce0ce3b2b8e48e46e4fabbbe..ea432e4c37a442714bfb4182e167c25c19830009 100644 (file)
@@ -68,5 +68,7 @@ live_effects_liblive_effects_a_SOURCES = \
        live_effects/lpe-offset.cpp     \
        live_effects/lpe-offset.h       \
        live_effects/lpe-ruler.cpp      \
-       live_effects/lpe-ruler.h
+       live_effects/lpe-ruler.h        \
+       live_effects/lpe-text_label.cpp \
+       live_effects/lpe-text_label.h
 
index d365880a6689ae1a086c858a1df1f18db16354ca..701b46d36e63433a9ef4aefa79822c280623f14c 100644 (file)
@@ -63,6 +63,7 @@
 #include "live_effects/lpe-ruler.h"
 #include "live_effects/lpe-boolops.h"
 #include "live_effects/lpe-interpolate.h"
+#include "live_effects/lpe-text_label.h"
 // end of includes
 
 namespace Inkscape {
@@ -98,6 +99,7 @@ const Util::EnumData<EffectType> LPETypeData[] = {
     {SPIRO,                 N_("Spiro spline"),            "spiro"},
     {CURVE_STITCH,          N_("Stitch Sub-Paths"),        "curvestitching"},
     {TANGENT_TO_CURVE,      N_("Tangent to curve"),        "tangent_to_curve"},
+    {TEXT_LABEL,            N_("Text label"),              "text_label"},
     {VONKOCH,               N_("VonKoch"),                 "vonkoch"},
 };
 const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData));
@@ -187,6 +189,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
         case INTERPOLATE:
             neweffect = static_cast<Effect*> ( new LPEInterpolate(lpeobj) );
             break;
+        case TEXT_LABEL:
+            neweffect = static_cast<Effect*> ( new LPETextLabel(lpeobj) );
+            break;
         default:
             g_warning("LivePathEffect::Effect::New   called with invalid patheffect type (%d)", lpenr);
             neweffect = NULL;
index 37170eae0897d6b2a274f4b749ab5b3131f943c2..859c0ff7bccf474a47a71ff0d7d86515a76d4aa3 100644 (file)
@@ -79,6 +79,7 @@ enum EffectType {
     RULER,
     BOOLOPS,
     INTERPOLATE,
+    TEXT_LABEL,
     INVALID_LPE // This must be last
 };
 
diff --git a/src/live_effects/lpe-text_label.cpp b/src/live_effects/lpe-text_label.cpp
new file mode 100644 (file)
index 0000000..c986dbd
--- /dev/null
@@ -0,0 +1,61 @@
+#define INKSCAPE_LPE_TEXT_LABEL_CPP
+/** \file
+ * LPE <text_label> implementation
+ */
+/*
+ * 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-text_label.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPETextLabel::LPETextLabel(LivePathEffectObject *lpeobject) :
+    Effect(lpeobject),
+    label(_("Label"), _("Text label attached to the path"), "label", &wr, this, "This is a label")
+{
+    registerParameter( dynamic_cast<Parameter *>(&label) );
+}
+
+LPETextLabel::~LPETextLabel()
+{
+
+}
+
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPETextLabel::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
+{
+    using namespace Geom;
+
+    double t = (pwd2_in.cuts.front() + pwd2_in.cuts.back()) / 2;
+    Point pos(pwd2_in.valueAt(t));
+    Point dir(unit_vector(derivative(pwd2_in).valueAt(t)));
+    Point n(-rot90(dir) * 30);
+
+    double angle = angle_between(dir, Point(1,0));
+    label.setPos(pos + n);
+    label.setAnchor(std::sin(angle), -std::cos(angle));
+
+    return pwd2_in;
+}
+
+} //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-text_label.h b/src/live_effects/lpe-text_label.h
new file mode 100644 (file)
index 0000000..58db5ec
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef INKSCAPE_LPE_TEXT_LABEL_H
+#define INKSCAPE_LPE_TEXT_LABEL_H
+
+/** \file
+ * LPE <text_label> implementation
+ */
+/*
+ * 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/text.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPETextLabel : public Effect {
+public:
+    LPETextLabel(LivePathEffectObject *lpeobject);
+    virtual ~LPETextLabel();
+
+    virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
+
+private:
+    TextParam label;
+
+    LPETextLabel(const LPETextLabel&);
+    LPETextLabel& operator=(const LPETextLabel&);
+};
+
+} //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 :