summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: acaf3e7)
raw | patch | inline | side by side (parent: acaf3e7)
author | cilix42 <cilix42@users.sourceforge.net> | |
Tue, 19 Aug 2008 17:52:18 +0000 (17:52 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Tue, 19 Aug 2008 17:52:18 +0000 (17:52 +0000) |
src/live_effects/lpe-ruler.cpp | patch | blob | history | |
src/live_effects/lpe-ruler.h | patch | blob | history |
index 6711fe3f06b91bbbd2023e50b455acd2d88cf9f4..4b41752967b6e41df92b098757565a16c89e7416 100644 (file)
namespace Inkscape {
namespace LivePathEffect {
+static const Util::EnumData<MarkDirType> MarkDirData[] = {
+ {MARKDIR_LEFT , N_("Left"), "left"},
+ {MARKDIR_RIGHT , N_("Right"), "right"},
+ {MARKDIR_BOTH , N_("Both"), "both"},
+};
+static const Util::EnumDataConverter<MarkDirType> 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<Parameter *>(&mark_distance));
registerParameter(dynamic_cast<Parameter *>(&mark_length));
- registerParameter(dynamic_cast<Parameter *>(&scale));
- registerParameter(dynamic_cast<Parameter *>(&info_text));
- registerParameter(dynamic_cast<Parameter *>(&unit));
-
- mark_distance.param_make_integer();
- mark_length.param_make_integer();
+ registerParameter(dynamic_cast<Parameter *>(&minor_mark_length));
+ registerParameter(dynamic_cast<Parameter *>(&major_mark_steps));
+ registerParameter(dynamic_cast<Parameter *>(&shift));
+ registerParameter(dynamic_cast<Parameter *>(&offset));
+ registerParameter(dynamic_cast<Parameter *>(&mark_dir));
+ registerParameter(dynamic_cast<Parameter *>(&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()
}
-enum MarkType {
- RULER_MARK_BORDER,
- RULER_MARK_MAJOR,
- RULER_MARK_MINOR
-};
+Geom::Point LPERuler::n_major;
+Geom::Point LPERuler::n_minor;
-static Geom::Piecewise<Geom::D2<Geom::SBasis> >
-ruler_mark(Geom::Point A, Geom::Point n, MarkType marktype)
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+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<Geom::D2<Geom::SBasis> > const & pwd2_i
Point A(pwd2_in.firstValue());
Point B(pwd2_in.lastValue());
+ double path_length = L2(B - A);
Piecewise<D2<SBasis> >output(D2<SBasis>(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<int>(major_mark_steps);
+ const int j_shift = static_cast<int>(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;
}
index 48ca5d46f653b69e144d8ea94cba3bc07b22012f..0d5bf29e09aefc400c3149cfa9b9eb9577b76868 100644 (file)
#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);
virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
private:
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<MarkDirType> 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&);
};