1 #ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H
2 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H
4 /*
5 * Inkscape::LivePathEffectParameters
6 *
7 * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #include <vector>
14 #include <glib/gtypes.h>
16 #include <gtkmm/tooltips.h>
18 #include "live_effects/parameter/parameter.h"
20 #include "svg/svg.h"
21 #include "svg/stringstream.h"
23 namespace Inkscape {
25 namespace LivePathEffect {
27 template <typename StorageType>
28 class ArrayParam : public Parameter {
29 public:
30 ArrayParam( const Glib::ustring& label,
31 const Glib::ustring& tip,
32 const Glib::ustring& key,
33 Inkscape::UI::Widget::Registry* wr,
34 Effect* effect,
35 size_t n = 0 )
36 : Parameter(label, tip, key, wr, effect), _vector(n)
37 {
39 }
41 virtual ~ArrayParam() {
43 };
45 std::vector<StorageType> const & data() const {
46 return _vector;
47 }
49 virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) {
50 return NULL;
51 }
53 virtual bool param_readSVGValue(const gchar * strvalue) {
54 _vector.clear();
55 gchar ** strarray = g_strsplit(strvalue, "|", 0);
56 gchar ** iter = strarray;
57 while (*iter != NULL) {
58 _vector.push_back( readsvg(*iter) );
59 iter++;
60 }
61 g_strfreev (strarray);
62 return true;
63 }
65 virtual gchar * param_getSVGValue() const {
66 Inkscape::SVGOStringStream os;
67 writesvg(os, _vector);
68 gchar * str = g_strdup(os.str().c_str());
69 return str;
70 }
72 void param_setValue(std::vector<StorageType> const &new_vector) {
73 _vector = new_vector;
74 }
76 void param_set_default() {
77 param_setValue( std::vector<StorageType>() );
78 }
80 void param_set_and_write_new_value(std::vector<StorageType> const &new_vector) {
81 Inkscape::SVGOStringStream os;
82 writesvg(os, new_vector);
83 gchar * str = g_strdup(os.str().c_str());
84 param_write_to_repr(str);
85 g_free(str);
86 }
88 private:
89 ArrayParam(const ArrayParam&);
90 ArrayParam& operator=(const ArrayParam&);
92 std::vector<StorageType> _vector;
94 void writesvg(SVGOStringStream &str, std::vector<StorageType> const &vector) const {
95 for (unsigned int i = 0; i < vector.size(); ++i) {
96 if (i != 0) {
97 // separate items with pipe symbol
98 str << " | ";
99 }
100 str << vector[i];
101 }
102 }
104 StorageType readsvg(const gchar * str);
105 };
108 } //namespace LivePathEffect
110 } //namespace Inkscape
112 #endif
114 /*
115 Local Variables:
116 mode:c++
117 c-file-style:"stroustrup"
118 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
119 indent-tabs-mode:nil
120 fill-column:99
121 End:
122 */
123 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :