From: cilix42 Date: Tue, 15 Jul 2008 12:41:03 +0000 (+0000) Subject: New LPE: Ruler X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2f5c0701b333a695eedb1680beb1adf95c0723da;p=inkscape.git New LPE: Ruler --- diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index b9f864546..d3f50cd9a 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -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 diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 66d2334e0..d5ac6dc74 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -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 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 LPETypeConverter(LPETypeData, INVALID_LPE); @@ -169,6 +171,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case OFFSET: neweffect = static_cast ( new LPEOffset(lpeobj) ); break; + case RULER: + neweffect = static_cast ( new LPERuler(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 dc5d6ec4a..eced0a194 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -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 index 000000000..5a3f8c285 --- /dev/null +++ b/src/live_effects/lpe-ruler.cpp @@ -0,0 +1,79 @@ +#define INKSCAPE_LPE_RULER_CPP + +/** \file + * LPE implementation, see lpe-ruler.cpp. + */ + +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Maximilian Albert 2008 + * + * 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(&mark_distance)); + registerParameter(dynamic_cast(&mark_length)); + + mark_distance.param_make_integer(); + mark_length.param_make_integer(); +} + +LPERuler::~LPERuler() +{ + +} + +Geom::Piecewise > +LPERuler::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) +{ + using namespace Geom; + + Point A(pwd2_in.firstValue()); + Point B(pwd2_in.lastValue()); + + Piecewise >output(D2(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 > seg(D2(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 index 000000000..891217cc5 --- /dev/null +++ b/src/live_effects/lpe-ruler.h @@ -0,0 +1,52 @@ +#ifndef INKSCAPE_LPE_RULER_H +#define INKSCAPE_LPE_RULER_H + +/** \file + * LPE implementation, see lpe-ruler.cpp. + */ + +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Maximilian Albert 2008 + * + * 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 > doEffect_pwd2 (Geom::Piecewise > 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 :