summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-07-19 20:31:57 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-07-19 20:31:57 +0000
commit5b8a6e510cb69d33bc8834a7586142be800471b5 (patch)
tree80b05fee53e72d25f56def6dfd14e104c18f8d45 /src
parentPorted "ui/widget/style-swatch.*". (diff)
downloadinkscape-5b8a6e510cb69d33bc8834a7586142be800471b5.tar.gz
inkscape-5b8a6e510cb69d33bc8834a7586142be800471b5.zip
Ported "live_effects/parameter/unit.*".
(bzr r12380.1.41)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/lpe-path_length.cpp5
-rw-r--r--src/live_effects/lpe-ruler.cpp8
-rw-r--r--src/live_effects/parameter/unit.cpp22
-rw-r--r--src/live_effects/parameter/unit.h15
4 files changed, 28 insertions, 22 deletions
diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp
index d3edcda27..504fb53c0 100644
--- a/src/live_effects/lpe-path_length.cpp
+++ b/src/live_effects/lpe-path_length.cpp
@@ -15,6 +15,7 @@
#include "live_effects/lpe-path_length.h"
#include "sp-metrics.h"
+#include "util/units.h"
#include "2geom/sbasis-geometric.h"
@@ -52,11 +53,11 @@ LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & p
/* convert the measured length to the correct unit ... */
double lengthval = Geom::length(pwd2_in) * scale;
- gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit);
+ lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation());
/* ... set it as the canvas text ... */
gchar *arc_length = g_strdup_printf("%.2f %s", lengthval,
- display_unit ? (success ? unit.get_abbreviation() : "px") : "");
+ display_unit ? unit.get_abbreviation() : "");
info_text.param_setValue(arc_length);
g_free(arc_length);
diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp
index fefdad95a..788ab593a 100644
--- a/src/live_effects/lpe-ruler.cpp
+++ b/src/live_effects/lpe-ruler.cpp
@@ -81,9 +81,9 @@ LPERuler::ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const
using namespace Geom;
double real_mark_length = mark_length;
- sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_mark_length = Inkscape::Util::Quantity::convert(real_mark_length, unit.get_abbreviation(), "px");
double real_minor_mark_length = minor_mark_length;
- sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_minor_mark_length = Inkscape::Util::Quantity::convert(real_minor_mark_length, unit.get_abbreviation(), "px");
n_major = real_mark_length * n;
n_minor = real_minor_mark_length * n;
@@ -133,10 +133,10 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_i
std::vector<double> s_cuts;
double real_mark_distance = mark_distance;
- sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_mark_distance = Inkscape::Util::Quantity::convert(real_mark_distance, unit.get_abbreviation(), "px");
double real_offset = offset;
- sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_offset = Inkscape::Util::Quantity::convert(real_offset, unit.get_abbreviation(), "px");
for (double s = real_offset; s<totlength; s+=real_mark_distance){
s_cuts.push_back(s);
}
diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp
index fffbabb1d..264b4b9ee 100644
--- a/src/live_effects/parameter/unit.cpp
+++ b/src/live_effects/parameter/unit.cpp
@@ -10,6 +10,7 @@
#include "live_effects/parameter/unit.h"
#include "live_effects/effect.h"
#include "verbs.h"
+#include "util/units.h"
namespace Inkscape {
@@ -18,10 +19,11 @@ 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)
+ Effect* effect, Glib::ustring default_unit)
: Parameter(label, tip, key, wr, effect)
{
- defunit = &sp_unit_get_by_id(default_value);;
+ Inkscape::Util::UnitTable unit_table;
+ defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit));
unit = defunit;
}
@@ -32,9 +34,9 @@ UnitParam::~UnitParam()
bool
UnitParam::param_readSVGValue(const gchar * strvalue)
{
- SPUnit const *newval = sp_unit_get_by_abbreviation(strvalue);
- if (newval) {
- param_set_value(newval);
+ Inkscape::Util::UnitTable unit_table;
+ if (strvalue) {
+ param_set_value(unit_table.getUnit(strvalue));
return true;
}
return false;
@@ -43,25 +45,25 @@ UnitParam::param_readSVGValue(const gchar * strvalue)
gchar *
UnitParam::param_getSVGValue() const
{
- return g_strdup(sp_unit_get_abbreviation(unit));
+ return g_strdup(unit->abbr.c_str());
}
void
UnitParam::param_set_default()
{
- param_set_value(defunit);
+ param_set_value(*defunit);
}
void
-UnitParam::param_set_value(SPUnit const *val)
+UnitParam::param_set_value(Inkscape::Util::Unit const &val)
{
- unit = val;
+ unit = new Inkscape::Util::Unit(val);
}
const gchar *
UnitParam::get_abbreviation() const
{
- return sp_unit_get_abbreviation(unit);
+ return unit->abbr.c_str();
}
Gtk::Widget *
diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h
index ea7a0112a..59a483018 100644
--- a/src/live_effects/parameter/unit.h
+++ b/src/live_effects/parameter/unit.h
@@ -10,10 +10,13 @@
*/
#include "live_effects/parameter/parameter.h"
-#include <helper/units.h>
namespace Inkscape {
+namespace Util {
+ class Unit;
+}
+
namespace LivePathEffect {
class UnitParam : public Parameter {
@@ -23,22 +26,22 @@ public:
const Glib::ustring& key,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
- SPUnitId default_value = SP_UNIT_PX);
+ Glib::ustring default_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);
+ void param_set_value(Inkscape::Util::Unit const &val);
const gchar *get_abbreviation() const;
virtual Gtk::Widget * param_newWidget();
- operator SPUnit const *() const { return unit; }
+ operator Inkscape::Util::Unit const *() const { return unit; }
private:
- SPUnit const *unit;
- SPUnit const *defunit;
+ Inkscape::Util::Unit const *unit;
+ Inkscape::Util::Unit const *defunit;
UnitParam(const UnitParam&);
UnitParam& operator=(const UnitParam&);