summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-line_segment.cpp
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/live_effects/lpe-line_segment.cpp
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/live_effects/lpe-line_segment.cpp')
-rw-r--r--src/live_effects/lpe-line_segment.cpp103
1 files changed, 103 insertions, 0 deletions
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 :