summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-08-18 00:32:26 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-08-18 00:32:26 +0000
commitcb3a86cca0122bd58099787b02c82fd04fc5c000 (patch)
tree4a169b935bac96505d1b14d1924920e9db0a6711 /src
parentcast for EnumParam (diff)
downloadinkscape-cb3a86cca0122bd58099787b02c82fd04fc5c000.tar.gz
inkscape-cb3a86cca0122bd58099787b02c82fd04fc5c000.zip
New LPE to draw infinite lines (cut by a limiting bounding box), rays and segments
(bzr r6641)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/Makefile_insert4
-rw-r--r--src/live_effects/effect.cpp5
-rw-r--r--src/live_effects/effect.h1
-rw-r--r--src/live_effects/lpe-line_segment.cpp103
-rw-r--r--src/live_effects/lpe-line_segment.h63
5 files changed, 175 insertions, 1 deletions
diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert
index 85f58d06d..3b136d204 100644
--- a/src/live_effects/Makefile_insert
+++ b/src/live_effects/Makefile_insert
@@ -72,4 +72,6 @@ live_effects_liblive_effects_a_SOURCES = \
live_effects/lpe-text_label.cpp \
live_effects/lpe-text_label.h \
live_effects/lpe-path_length.cpp \
- live_effects/lpe-path_length.h
+ live_effects/lpe-path_length.h \
+ live_effects/lpe-line_segment.cpp \
+ live_effects/lpe-line_segment.h
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index 64653863b..3f12345ae 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -64,6 +64,7 @@
#include "live_effects/lpe-interpolate.h"
#include "live_effects/lpe-text_label.h"
#include "live_effects/lpe-path_length.h"
+#include "live_effects/lpe-line_segment.h"
// end of includes
namespace Inkscape {
@@ -87,6 +88,7 @@ const Util::EnumData<EffectType> LPETypeData[] = {
{INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"},
{KNOT, N_("Knot"), "knot"},
{LATTICE, N_("Lattice Deformation"), "lattice"},
+ {LINE_SEGMENT, N_("Line Segment"), "line_segment"},
{MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"},
{OFFSET, N_("Offset"), "offset"},
{PARALLEL, N_("Parallel"), "parallel"},
@@ -196,6 +198,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
case PATH_LENGTH:
neweffect = static_cast<Effect*> ( new LPEPathLength(lpeobj) );
break;
+ case LINE_SEGMENT:
+ neweffect = static_cast<Effect*> ( new LPELineSegment(lpeobj) );
+ break;
default:
g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr);
neweffect = NULL;
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index 51ca6a558..c01cab5c3 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -80,6 +80,7 @@ enum EffectType {
INTERPOLATE,
TEXT_LABEL,
PATH_LENGTH,
+ LINE_SEGMENT,
INVALID_LPE // This must be last
};
diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp
new file mode 100644
index 000000000..7c1cb9f3e
--- /dev/null
+++ b/src/live_effects/lpe-line_segment.cpp
@@ -0,0 +1,103 @@
+#define INKSCAPE_LPE_LINE_SEGMENT_CPP
+
+/** \file
+ * LPE <line_segment> implementation
+ */
+
+/*
+ * Authors:
+ * Maximilian Albert
+ *
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/lpe-line_segment.h"
+
+#include <2geom/pathvector.h>
+#include <2geom/geom.h>
+#include <2geom/bezier-curve.h>
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+static const Util::EnumData<EndType> EndTypeData[] = {
+ {END_CLOSED , N_("Closed"), "closed"},
+ {END_OPEN_LEFT , N_("Open left"), "open_left"},
+ {END_OPEN_RIGHT , N_("Open right"), "open_right"},
+ {END_OPEN_BOTH , N_("Open both"), "open_both"},
+};
+static const Util::EnumDataConverter<EndType> EndTypeConverter(EndTypeData, sizeof(EndTypeData)/sizeof(*EndTypeData));
+
+LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ end_type(_("End type"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH)
+{
+ /* register all your parameters here, so Inkscape knows which parameters this effect has: */
+ registerParameter( dynamic_cast<Parameter *>(&end_type) );
+}
+
+LPELineSegment::~LPELineSegment()
+{
+
+}
+
+void
+LPELineSegment::doBeforeEffect (SPLPEItem *lpeitem)
+{
+ SPDocument *document = SP_OBJECT_DOCUMENT(lpeitem);
+ w = sp_document_width(document);
+ h = sp_document_height(document);
+
+}
+
+std::vector<Geom::Path>
+LPELineSegment::doEffect_path (std::vector<Geom::Path> const & path_in)
+{
+ std::vector<Geom::Path> output;
+
+ A = Geom::initialPoint(path_in);
+ B = Geom::finalPoint(path_in);
+
+ Geom::Point E(0,0);
+ Geom::Point F(0,h);
+ Geom::Point G(w,h);
+ Geom::Point H(w,0);
+
+ std::vector<Geom::Point> intersections = Geom::rect_line_intersect(E, G, A, B);
+
+ if (intersections.size() < 2) {
+ g_print ("Possible error - no intersection with limiting bounding box.\n");
+ return path_in;
+ }
+
+ if (end_type == END_OPEN_RIGHT || end_type == END_OPEN_BOTH) {
+ A = intersections[0];
+ }
+
+ if (end_type == END_OPEN_LEFT || end_type == END_OPEN_BOTH) {
+ B = intersections[1];
+ }
+
+ Geom::Path path(A);
+ path.appendNew<Geom::LineSegment>(B);
+
+ output.push_back(path);
+
+ 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-line_segment.h b/src/live_effects/lpe-line_segment.h
new file mode 100644
index 000000000..ffd93317a
--- /dev/null
+++ b/src/live_effects/lpe-line_segment.h
@@ -0,0 +1,63 @@
+#ifndef INKSCAPE_LPE_LINE_SEGMENT_H
+#define INKSCAPE_LPE_LINE_SEGMENT_H
+
+/** \file
+ * LPE <line_segment> implementation
+ */
+
+/*
+ * Authors:
+ * Maximilian Albert
+ *
+ * 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/enum.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+enum EndType {
+ END_CLOSED,
+ END_OPEN_LEFT,
+ END_OPEN_RIGHT,
+ END_OPEN_BOTH
+};
+
+class LPELineSegment : public Effect {
+public:
+ LPELineSegment(LivePathEffectObject *lpeobject);
+ virtual ~LPELineSegment();
+
+ virtual void doBeforeEffect (SPLPEItem *lpeitem);
+
+ virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in);
+
+private:
+ EnumParam<EndType> end_type;
+
+ Geom::Point A, B; // intersections of the line segment with the limiting bounding box
+ Geom::Coord w, h; // document width and height
+
+ LPELineSegment(const LPELineSegment&);
+ LPELineSegment& operator=(const LPELineSegment&);
+};
+
+} //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 :