From: cilix42 Date: Tue, 19 Aug 2008 17:52:18 +0000 (+0000) Subject: Don't display canvas text (length info) in lpe-ruler any more; add many more options X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6734d1bacf7a9fc2d5e54e098120a2a94752839c;p=inkscape.git Don't display canvas text (length info) in lpe-ruler any more; add many more options --- diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 6711fe3f0..4b4175296 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -22,22 +22,40 @@ namespace Inkscape { namespace LivePathEffect { +static const Util::EnumData MarkDirData[] = { + {MARKDIR_LEFT , N_("Left"), "left"}, + {MARKDIR_RIGHT , N_("Right"), "right"}, + {MARKDIR_BOTH , N_("Both"), "both"}, +}; +static const Util::EnumDataConverter MarkDirTypeConverter(MarkDirData, sizeof(MarkDirData)/sizeof(*MarkDirData)); + LPERuler::LPERuler(LivePathEffectObject *lpeobject) : Effect(lpeobject), - mark_distance(_("Mark distance"), _("Distance between ruler marks"), "mark_distance", &wr, this, 20), - mark_length(_("Mark length"), _("Length of ruler marks"), "mark_length", &wr, this, 10), - scale(_("Scale factor"), _("Scale factor for ruler distance (only affects on-canvas display of ruler length)"), "scale", &wr, this, 1.0), - info_text(this), - unit(_("Unit"), _("Unit"), "unit", &wr, this) + mark_distance(_("Mark distance"), _("Distance between successive ruler marks"), "mark_distance", &wr, this, 20.0), + mark_length(_("Major length"), _("Length of major ruler marks"), "mark_length", &wr, this, 14.0), + minor_mark_length(_("Minor length"), _("Length of minor ruler marks"), "minor_mark_length", &wr, this, 7.0), + major_mark_steps(_("Major steps"), _("Draw a major mark every ... steps"), "major_mark_steps", &wr, this, 5), + shift(_("Shift marks by"), _("Shift marks by this many steps"), "shift", &wr, this, 0), + mark_dir(_("Mark direction"), _("Direction of marks (when viewing along the path from start to end)"), "mark_dir", MarkDirTypeConverter, &wr, this, MARKDIR_LEFT), + offset(_("Offset"), _("Offset of first mark"), "offset", &wr, this, 0.0), + draw_border_marks(_("Draw border marks?"), _("Check this to draw marks at the beginning and end of the path (even if this means that the distance to adjacent marks is smaller than usual)"), "draw_border_marks", &wr, this, true) { registerParameter(dynamic_cast(&mark_distance)); registerParameter(dynamic_cast(&mark_length)); - registerParameter(dynamic_cast(&scale)); - registerParameter(dynamic_cast(&info_text)); - registerParameter(dynamic_cast(&unit)); - - mark_distance.param_make_integer(); - mark_length.param_make_integer(); + registerParameter(dynamic_cast(&minor_mark_length)); + registerParameter(dynamic_cast(&major_mark_steps)); + registerParameter(dynamic_cast(&shift)); + registerParameter(dynamic_cast(&offset)); + registerParameter(dynamic_cast(&mark_dir)); + registerParameter(dynamic_cast(&draw_border_marks)); + + major_mark_steps.param_make_integer(); + major_mark_steps.param_set_range(1, 1000); + shift.param_make_integer(); + + mark_length.param_set_increments(1.0, 10.0); + minor_mark_length.param_set_increments(1.0, 10.0); + offset.param_set_increments(1.0, 10.0); } LPERuler::~LPERuler() @@ -45,30 +63,33 @@ LPERuler::~LPERuler() } -enum MarkType { - RULER_MARK_BORDER, - RULER_MARK_MAJOR, - RULER_MARK_MINOR -}; +Geom::Point LPERuler::n_major; +Geom::Point LPERuler::n_minor; -static Geom::Piecewise > -ruler_mark(Geom::Point A, Geom::Point n, MarkType marktype) +Geom::Piecewise > +LPERuler::ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType marktype) { using namespace Geom; + n_major = mark_length * n; + n_minor = minor_mark_length * n; + Point C, D; switch (marktype) { - case RULER_MARK_BORDER: - C = A - 1.5 * n; - D = A + 1.5 * n; - break; - case RULER_MARK_MAJOR: + case MARK_MAJOR: C = A; - D = A + 1.5 * n; + D = A + mark_length * n; + if (mark_dir == MARKDIR_BOTH) + C -= n_major; break; - case RULER_MARK_MINOR: + case MARK_MINOR: C = A; - D = A + n; + D = A + n_minor; + if (mark_dir == MARKDIR_BOTH) + C -= n_minor; + break; + default: + // do nothing break; } @@ -83,41 +104,32 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise > const & pwd2_i Point A(pwd2_in.firstValue()); Point B(pwd2_in.lastValue()); + double path_length = L2(B - A); 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); - - /* convert the measured length to the correct unit ... */ - double lengthval = length * scale; - gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit); - - /* ... set it as the canvas text ... */ - gchar *dist = g_strdup_printf("%.2f %s", lengthval, success ? unit.get_abbreviation() : "px"); - info_text.param_setValue(dist); - g_free(dist); - - /* ... and adjust the text's position on canvas */ - double angle = Geom::angle_between(dir, Geom::Point(1,0)); - info_text.setPos((A + B) / 2 + 2.0 * n); - info_text.setAnchor(std::sin(angle), -std::cos(angle)); + Point n(-rot90(dir)); + if (mark_dir == MARKDIR_RIGHT) { + n *= -1.0; + } - /* draw the actual ruler */ - Point C, D; - C = A - n; - D = A + n; - output.concat (ruler_mark(A, n, RULER_MARK_BORDER)); int j = 0; - for (double i = 0; i < length; i += mark_distance, ++j) { - if ((j % 5) == 0) { - output.concat (ruler_mark(A + dir * i, n, RULER_MARK_MAJOR)); + const int mminterval = static_cast(major_mark_steps); + const int j_shift = static_cast(shift) % mminterval; + + /* draw the ruler */ + if (draw_border_marks && (offset != 0.0 || j_shift != 0)) + output.concat (ruler_mark(A, n, MARK_MAJOR)); + for (double i = offset; i < path_length; i += mark_distance, ++j) { + if ((j % mminterval) == j_shift) { + output.concat (ruler_mark(A + dir * i, n, MARK_MAJOR)); } else { - output.concat (ruler_mark(A + dir * i, n, RULER_MARK_MINOR)); + output.concat (ruler_mark(A + dir * i, n, MARK_MINOR)); } } - output.concat (ruler_mark(B, n, RULER_MARK_BORDER)); + if (draw_border_marks) + output.concat (ruler_mark(B, n, MARK_MAJOR)); return output; } diff --git a/src/live_effects/lpe-ruler.h b/src/live_effects/lpe-ruler.h index 48ca5d46f..0d5bf29e0 100644 --- a/src/live_effects/lpe-ruler.h +++ b/src/live_effects/lpe-ruler.h @@ -17,11 +17,23 @@ #include "live_effects/effect.h" #include "live_effects/parameter/text.h" -#include "live_effects/parameter/unit.h" +#include "live_effects/parameter/enum.h" +#include "live_effects/parameter/bool.h" namespace Inkscape { namespace LivePathEffect { +enum MarkType { + MARK_MAJOR, + MARK_MINOR +}; + +enum MarkDirType { + MARKDIR_LEFT, + MARKDIR_RIGHT, + MARKDIR_BOTH, +}; + class LPERuler : public Effect { public: LPERuler(LivePathEffectObject *lpeobject); @@ -30,11 +42,19 @@ public: virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); private: + Geom::Piecewise > ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType marktype); + ScalarParam mark_distance; ScalarParam mark_length; - ScalarParam scale; - TextParamInternal info_text; - UnitParam unit; + ScalarParam minor_mark_length; + ScalarParam major_mark_steps; + ScalarParam shift; + EnumParam mark_dir; + ScalarParam offset; + BoolParam draw_border_marks; + + static Geom::Point n_major, n_minor; // used for internal computations + LPERuler(const LPERuler&); LPERuler& operator=(const LPERuler&); };