From 4b6d620057c6cbaf072607eda6d18a7934fc19c8 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Tue, 2 Sep 2008 23:21:31 +0000 Subject: [PATCH] add lpe param: VectorParam and VectorParam --- src/live_effects/parameter/CMakeLists.txt | 3 + src/live_effects/parameter/Makefile_insert | 4 +- src/live_effects/parameter/vector.cpp | 51 +++++++++ src/live_effects/parameter/vector.h | 123 +++++++++++++++++++++ 4 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 src/live_effects/parameter/vector.cpp create mode 100644 src/live_effects/parameter/vector.h diff --git a/src/live_effects/parameter/CMakeLists.txt b/src/live_effects/parameter/CMakeLists.txt index 9d00856b8..d7775f44d 100644 --- a/src/live_effects/parameter/CMakeLists.txt +++ b/src/live_effects/parameter/CMakeLists.txt @@ -6,4 +6,7 @@ path-reference.cpp point.cpp pointparam-knotholder.cpp random.cpp +text.cpp +unit.cpp +vector.cpp ) diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index a5bbe3e66..869f4a7f4 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -24,4 +24,6 @@ live_effects_parameter_liblpeparam_a_SOURCES = \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/unit.cpp \ - live_effects/parameter/unit.h + live_effects/parameter/unit.h \ + live_effects/parameter/vector.cpp \ + live_effects/parameter/vector.h diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp new file mode 100644 index 000000000..90d9ebff9 --- /dev/null +++ b/src/live_effects/parameter/vector.cpp @@ -0,0 +1,51 @@ +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_VECTOR_CPP + +/* + * Copyright (C) Johan Engelen 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/vector.h" + +#include "svg/svg.h" +#include "svg/stringstream.h" + +#include <2geom/coord.h> + +namespace Inkscape { + +namespace LivePathEffect { + +template <> +double +VectorParam::readsvg(const gchar * str) +{ + double newx = Geom::infinity(); + sp_svg_number_read_d(str, &newx); + return newx; +} + +template <> +float +VectorParam::readsvg(const gchar * str) +{ + float newx = Geom::infinity(); + sp_svg_number_read_f(str, &newx); + return newx; +} + +} /* 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/vector.h b/src/live_effects/parameter/vector.h new file mode 100644 index 000000000..0b65fea14 --- /dev/null +++ b/src/live_effects/parameter/vector.h @@ -0,0 +1,123 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_VECTOR_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_VECTOR_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include + +#include + +#include "live_effects/parameter/parameter.h" + +#include "svg/svg.h" +#include "svg/stringstream.h" + +namespace Inkscape { + +namespace LivePathEffect { + +template +class VectorParam : public Parameter { +public: + VectorParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + size_t n = 0 ) + : Parameter(label, tip, key, wr, effect), _vector(n) + { + + } + + virtual ~VectorParam() { + + }; + + std::vector const & data() const { + return _vector; + } + + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) { + return NULL; + } + + virtual bool param_readSVGValue(const gchar * strvalue) { + _vector.clear(); + gchar ** strarray = g_strsplit(strvalue, "|", 0); + gchar ** iter = strarray; + while (*iter != NULL) { + _vector.push_back( readsvg(*iter) ); + iter++; + } + g_strfreev (strarray); + return true; + } + + virtual gchar * param_getSVGValue() const { + Inkscape::SVGOStringStream os; + writesvg(os, _vector); + gchar * str = g_strdup(os.str().c_str()); + return str; + } + + void param_setValue(std::vector const &new_vector) { + _vector = new_vector; + } + + void param_set_default() { + param_setValue( std::vector() ); + } + + void param_set_and_write_new_value(std::vector const &new_vector) { + Inkscape::SVGOStringStream os; + writesvg(os, new_vector); + gchar * str = g_strdup(os.str().c_str()); + param_write_to_repr(str); + g_free(str); + } + +private: + VectorParam(const VectorParam&); + VectorParam& operator=(const VectorParam&); + + std::vector _vector; + + void writesvg(SVGOStringStream &str, std::vector const &vector) const { + for (unsigned int i = 0; i < vector.size(); ++i) { + if (i != 0) { + // separate items with pipe symbol + str << " | "; + } + str << vector[i]; + } + } + + StorageType readsvg(const gchar * str); +}; + + +} //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 : -- 2.30.2