summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter/vector.h
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2008-09-02 23:21:31 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2008-09-02 23:21:31 +0000
commit1bba63e9fcbdb1d617890c699c29201aebd3c7cd (patch)
tree4635792c87b6ef7bf9360a76169101bd1f4312b4 /src/live_effects/parameter/vector.h
parentadd method to write single paths to svg (diff)
downloadinkscape-1bba63e9fcbdb1d617890c699c29201aebd3c7cd.tar.gz
inkscape-1bba63e9fcbdb1d617890c699c29201aebd3c7cd.zip
add lpe param: VectorParam<float> and VectorParam<double>
(bzr r6757)
Diffstat (limited to 'src/live_effects/parameter/vector.h')
-rw-r--r--src/live_effects/parameter/vector.h123
1 files changed, 123 insertions, 0 deletions
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 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <vector>
+
+#include <glib/gtypes.h>
+
+#include <gtkmm/tooltips.h>
+
+#include "live_effects/parameter/parameter.h"
+
+#include "svg/svg.h"
+#include "svg/stringstream.h"
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+template <typename StorageType>
+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<StorageType> 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<StorageType> const &new_vector) {
+ _vector = new_vector;
+ }
+
+ void param_set_default() {
+ param_setValue( std::vector<StorageType>() );
+ }
+
+ void param_set_and_write_new_value(std::vector<StorageType> 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<StorageType> _vector;
+
+ void writesvg(SVGOStringStream &str, std::vector<StorageType> 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 :