summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b2c2c07)
raw | patch | inline | side by side (parent: b2c2c07)
author | cilix42 <cilix42@users.sourceforge.net> | |
Thu, 31 Jul 2008 15:48:02 +0000 (15:48 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Thu, 31 Jul 2008 15:48:02 +0000 (15:48 +0000) |
po/POTFILES.in | patch | blob | history | |
src/live_effects/lpe-ruler.cpp | patch | blob | history | |
src/live_effects/lpe-ruler.h | patch | blob | history | |
src/live_effects/parameter/Makefile_insert | patch | blob | history | |
src/live_effects/parameter/unit.cpp | [new file with mode: 0644] | patch | blob |
src/live_effects/parameter/unit.h | [new file with mode: 0644] | patch | blob |
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8c6c20c18402195f36883f7e43d82b675344eda3..3bfdfc57dbdb063ab32b980c5d69c00ac85388e7 100644 (file)
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
src/live_effects/parameter/point.cpp
src/live_effects/parameter/pointparam-knotholder.cpp
src/live_effects/parameter/random.cpp
+src/live_effects/parameter/random.cpp
+src/live_effects/parameter/text.cpp
+src/live_effects/parameter/unit.cpp
src/main-cmdlineact.cpp
src/main.cpp
src/menus-skeleton.h
index f41e752cbd46bcce6b3998334c4250a2a36d6f09..8b457da58397b5dab7c48700edce9d8987a404ac 100644 (file)
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(_("Info text"), _("Parameter for text creation"), "info_text", &wr, this, "")
+ info_text(_("Info text"), _("Parameter for text creation"), "info_text", &wr, this, ""),
+ unit(_("Unit"), _("Unit"), "unit", &wr, this)
{
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();
@@ -88,14 +90,21 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_i
Point n(-rot90(dir) * mark_length);
double length = L2(B - A);
- gchar *dist = g_strdup_printf("%8.2f", length * scale);
+ /* 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("%8.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));
+ /* draw the actual ruler */
Point C, D;
C = A - n;
D = A + n;
index 7ebc62fdbae6f0ad37230cc8b0cf73f65b585f9c..48ca5d46f653b69e144d8ea94cba3bc07b22012f 100644 (file)
#include "live_effects/effect.h"
#include "live_effects/parameter/text.h"
+#include "live_effects/parameter/unit.h"
namespace Inkscape {
namespace LivePathEffect {
ScalarParam mark_length;
ScalarParam scale;
TextParamInternal info_text;
+ UnitParam unit;
LPERuler(const LPERuler&);
LPERuler& operator=(const LPERuler&);
};
diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert
index 14bbc3285ba43809b430fe84429b00937a376920..a5bbe3e669e290051f51cc7d4acb2ce760ec57e5 100644 (file)
live_effects/parameter/path.cpp \
live_effects/parameter/path.h \
live_effects/parameter/text.cpp \
- live_effects/parameter/text.h
+ live_effects/parameter/text.h \
+ live_effects/parameter/unit.cpp \
+ live_effects/parameter/unit.h
diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp
--- /dev/null
@@ -0,0 +1,94 @@
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_UNIT_CPP
+
+/*
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/parameter/unit.h"
+#include "live_effects/effect.h"
+#include "ui/widget/registered-widget.h"
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+
+UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip,
+ const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
+ Effect* effect, SPUnitId default_value)
+ : Parameter(label, tip, key, wr, effect)
+{
+ defunit = &sp_unit_get_by_id(default_value);;
+ unit = defunit;
+}
+
+UnitParam::~UnitParam()
+{
+}
+
+bool
+UnitParam::param_readSVGValue(const gchar * strvalue)
+{
+ SPUnit const *newval = sp_unit_get_by_abbreviation(strvalue);
+ if (newval) {
+ param_set_value(newval);
+ return true;
+ }
+ return false;
+}
+
+gchar *
+UnitParam::param_getSVGValue() const
+{
+ return g_strdup(sp_unit_get_abbreviation(unit));
+}
+
+void
+UnitParam::param_set_default()
+{
+ param_set_value(defunit);
+}
+
+void
+UnitParam::param_set_value(SPUnit const *val)
+{
+ unit = val;
+}
+
+const gchar *
+UnitParam::get_abbreviation()
+{
+ return sp_unit_get_abbreviation(unit);
+}
+
+Gtk::Widget *
+UnitParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
+{
+ Inkscape::UI::Widget::RegisteredUnitMenu* unit_menu = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredUnitMenu(param_label,
+ param_key,
+ *param_wr,
+ param_effect->getRepr(),
+ param_effect->getSPDoc()));
+
+ unit_menu->setUnit(unit);
+ unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter"));
+
+ return dynamic_cast<Gtk::Widget *> (unit_menu);
+}
+
+} /* 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/parameter/unit.h b/src/live_effects/parameter/unit.h
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_UNIT_H
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_UNIT_H
+
+/*
+ * Inkscape::LivePathEffectParameters
+ *
+* Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/parameter/parameter.h"
+#include <helper/units.h>
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+class UnitParam : public Parameter {
+public:
+ UnitParam(const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Inkscape::UI::Widget::Registry* wr,
+ Effect* effect,
+ SPUnitId default_value = SP_UNIT_PX);
+ virtual ~UnitParam();
+
+ virtual bool param_readSVGValue(const gchar * strvalue);
+ virtual gchar * param_getSVGValue() const;
+ virtual void param_set_default();
+ void param_set_value(SPUnit const *val);
+ const gchar *get_abbreviation();
+
+ virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips);
+
+ operator SPUnit const *() { return unit; }
+
+private:
+ SPUnit const *unit;
+ SPUnit const *defunit;
+
+ UnitParam(const UnitParam&);
+ UnitParam& operator=(const UnitParam&);
+};
+
+} //namespace LivePathEffect
+
+} //namespace Inkscape
+
+#endif